Skip to content

Commit

Permalink
Write the image to the correct target app partition (#634)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
simpkins authored May 23, 2024
1 parent 890f17a commit 4acd8f6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed help text for size parameter of read-flash subcommand
- Fixed port detection on `musl` when detection returns paths starting with `/dev/`
- [cargo-espflash]: Always resolve package_id from metadata when finding bootloader and partition table (#632)
- Fixed behavior of the --target-app-partition flag (#634)

### Changed

Expand Down
18 changes: 2 additions & 16 deletions espflash/src/image_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ impl<'a> IdfBootloaderFormat<'a> {
let app_size = data.len() as u32;
let part_size = target_app_partition.size();

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

let app_partition = self
.partition_table
.find("factory")
.or_else(|| self.partition_table.find_by_type(Type::App))
.expect("no application partition found");

if self.flash_segment.data.len() > app_partition.size() as usize {
panic!(
"image size ({} bytes) is larger partition size ({} bytes)",
self.flash_segment.data.len(),
app_partition.size()
);
}

let app_segment = RomSegment {
addr: app_partition.offset(),
addr: self.flash_segment.addr,
data: Cow::Borrowed(&self.flash_segment.data),
};

Expand Down

0 comments on commit 4acd8f6

Please sign in to comment.