Skip to content

Commit 4acd8f6

Browse files
authored
Write the image to the correct target app partition (#634)
This updates the code to honor the --target-app-partition flag, and write the application image to the specified partition. Previously the code always wrote the image to the "factory" app partition if one was present, regardless of the partition specified with the `--target-app-partition` flag. (It seems like this behavior was likely broken in d886d33, which updated the code to always write to the factory partition again.) I confirmed that using `espflash flash --target-app-partition ota_0` now causes espflash to write the image to the `ota_0` partition. Note that this leaves the `factory` partition and any `ota_data` partition unchanged, so the bootloader will still boot from the factory partition by default, but this makes it possible to write new app images to the OTA partitions for testing purposes.
1 parent 890f17a commit 4acd8f6

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Fixed help text for size parameter of read-flash subcommand
1515
- Fixed port detection on `musl` when detection returns paths starting with `/dev/`
1616
- [cargo-espflash]: Always resolve package_id from metadata when finding bootloader and partition table (#632)
17+
- Fixed behavior of the --target-app-partition flag (#634)
1718

1819
### Changed
1920

espflash/src/image_format.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl<'a> IdfBootloaderFormat<'a> {
259259
let app_size = data.len() as u32;
260260
let part_size = target_app_partition.size();
261261

262-
// The size of the application must not exceed the size of the factory
262+
// The size of the application must not exceed the size of the target app
263263
// partition.
264264
if app_size as f32 / part_size as f32 > 1.0 {
265265
return Err(Error::ElfTooBig(app_size, part_size));
@@ -307,22 +307,8 @@ impl<'a> IdfBootloaderFormat<'a> {
307307
data: Cow::Owned(self.partition_table.to_bin().unwrap()),
308308
};
309309

310-
let app_partition = self
311-
.partition_table
312-
.find("factory")
313-
.or_else(|| self.partition_table.find_by_type(Type::App))
314-
.expect("no application partition found");
315-
316-
if self.flash_segment.data.len() > app_partition.size() as usize {
317-
panic!(
318-
"image size ({} bytes) is larger partition size ({} bytes)",
319-
self.flash_segment.data.len(),
320-
app_partition.size()
321-
);
322-
}
323-
324310
let app_segment = RomSegment {
325-
addr: app_partition.offset(),
311+
addr: self.flash_segment.addr,
326312
data: Cow::Borrowed(&self.flash_segment.data),
327313
};
328314

0 commit comments

Comments
 (0)