From 610b8e2b1b5a678dec04f067986fc725cad0d51b Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Fri, 26 Jul 2024 13:50:19 +0100 Subject: [PATCH] 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 (cherry picked from commit e2e1e945faec3a1914b7490ceb3d77b1820967d7) --- boot/bootutil/src/swap_move.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/boot/bootutil/src/swap_move.c b/boot/bootutil/src/swap_move.c index 9901bc62..8999403c 100644 --- a/boot/bootutil/src/swap_move.c +++ b/boot/bootutil/src/swap_move.c @@ -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