Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions boot/bootutil/src/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,19 @@ boot_copy_image(struct boot_loader_state *state, struct boot_status *bs)
size += this_size;
}

#if defined(MCUBOOT_SWAP_USING_MOVE)
/* When using MCUBOOT_SWAP_USING_MOVE, primary region is larger then the secondary region
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adjust commit title to: boot: bootutil: loader: Fix bootstrap copying in swap move mode

* Optimal region configuration: # useful regions in primary region = # regions in secondary region + 1
* This means that we have to use the size of the secondary region (so without the swap sector)
*/
size = 0;
sect_count = boot_img_num_sectors(state, BOOT_SECONDARY_SLOT);
for (sect = 0, size = 0; sect < sect_count; sect++) {
this_size = boot_img_sector_size(state, BOOT_SECONDARY_SLOT, sect);
size += this_size;
}
#endif

#if defined(MCUBOOT_OVERWRITE_ONLY_FAST)
trailer_sz = boot_trailer_sz(BOOT_WRITE_SZ(state));
sector = boot_img_num_sectors(state, BOOT_SLOT_PRIMARY) - 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fix: Corrected the copy size calculation when bootstrapping and swapping using MCUBOOT_SWAP_USING_MOVE.
Previously, the primary region size was used, which could be larger than the secondary region, when using the optimal region sizes. Now, the size of the secondary region (excluding the swap sector and sectors needed for swapping) is used, ensuring only the valid image area is copied. This prevents potential over-copying and related issues during image upgrade or bootstrap operations.
Loading