Skip to content

Commit 8c9a2b1

Browse files
committed
Allow flashing when factory partition is not present
1 parent 99f1445 commit 8c9a2b1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

espflash/src/image_format/esp32bootloader.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::{
1212
error::{Error, FlashDetectError},
1313
flasher::FlashSize,
1414
image_format::{EspCommonHeader, ImageFormat, SegmentHeader, ESP_MAGIC, WP_PIN_DISABLED},
15+
partition_table::Type,
1516
Chip, PartitionTable,
1617
};
1718

@@ -123,8 +124,12 @@ impl<'a> Esp32BootloaderFormat<'a> {
123124

124125
// The default partition table contains the "factory" partition, and if a user
125126
// provides a partition table via command-line then the validation step confirms
126-
// this is present, so it's safe to unwrap.
127-
let factory_partition = partition_table.find("factory").unwrap();
127+
// that at least one "app" partition is present. We prefer the "factory" partition,
128+
// and use any available "app" partitions if not present.
129+
let factory_partition = partition_table
130+
.find("factory")
131+
.or_else(|| partition_table.find_by_type(Type::App))
132+
.unwrap();
128133

129134
let flash_segment = RomSegment {
130135
addr: factory_partition.offset(),

0 commit comments

Comments
 (0)