Skip to content

Commit e2e1e94

Browse files
committed
bootutil: Fix swap move max app size calculation
This calculation failed to take into consideration the additional sector needed for the swap move part of the upgrade process Signed-off-by: Jamie McCrae <[email protected]>
1 parent 4f1ab9e commit e2e1e94

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

boot/bootutil/src/swap_move.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,19 @@ swap_run(struct boot_loader_state *state, struct boot_status *bs,
577577

578578
int app_max_size(struct boot_loader_state *state)
579579
{
580-
uint32_t sector_sz;
580+
uint32_t sector_sz_primary;
581+
uint32_t sector_sz_secondary;
582+
uint32_t sz_primary;
583+
uint32_t sz_secondary;
581584

582-
sector_sz = boot_img_sector_size(state, BOOT_PRIMARY_SLOT, 0);
585+
sector_sz_primary = boot_img_sector_size(state, BOOT_PRIMARY_SLOT, 0);
586+
sector_sz_secondary = boot_img_sector_size(state, BOOT_SECONDARY_SLOT, 0);
587+
588+
/* Account for image flags and move sector */
589+
sz_primary = app_max_sectors(state) * sector_sz_primary - sector_sz_primary;
590+
sz_secondary = boot_img_num_sectors(state, BOOT_SECONDARY_SLOT) * sector_sz_secondary;
583591

584-
return (app_max_sectors(state) * sector_sz);
592+
return (sz_primary <= sz_secondary ? sz_primary : sz_secondary);
585593
}
586594

587595
#endif

0 commit comments

Comments
 (0)