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 <jamie.mccrae@nordicsemi.no>
(cherry picked from commit e2e1e945fa)
This commit is contained in:
Jamie McCrae 2024-07-26 13:50:19 +01:00
parent a4800ce0cf
commit 610b8e2b1b
1 changed files with 11 additions and 3 deletions

View File

@ -577,11 +577,19 @@ swap_run(struct boot_loader_state *state, struct boot_status *bs,
int app_max_size(struct boot_loader_state *state)
{
uint32_t sector_sz;
uint32_t sector_sz_primary;
uint32_t sector_sz_secondary;
uint32_t sz_primary;
uint32_t sz_secondary;
sector_sz = boot_img_sector_size(state, BOOT_PRIMARY_SLOT, 0);
sector_sz_primary = boot_img_sector_size(state, BOOT_PRIMARY_SLOT, 0);
sector_sz_secondary = boot_img_sector_size(state, BOOT_SECONDARY_SLOT, 0);
return (app_max_sectors(state) * sector_sz);
/* Account for image flags and move sector */
sz_primary = app_max_sectors(state) * sector_sz_primary - sector_sz_primary;
sz_secondary = boot_img_num_sectors(state, BOOT_SECONDARY_SLOT) * sector_sz_secondary;
return (sz_primary <= sz_secondary ? sz_primary : sz_secondary);
}
#endif