From 9fb7ce5d026db42768d63f04cc60ce022d27b555 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Tue, 12 Mar 2024 13:51:22 +0000 Subject: [PATCH] boot: zephyr: Fix estimated size calculation Fixes an issue with the estimated size calculation which wrongly used the maximum align size for some multiplications, this would mean that in some instances the estimated maximum image size was smaller than the actual allowed size Signed-off-by: Jamie McCrae --- boot/zephyr/CMakeLists.txt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/boot/zephyr/CMakeLists.txt b/boot/zephyr/CMakeLists.txt index 9156ad23d..f6c4b7eea 100644 --- a/boot/zephyr/CMakeLists.txt +++ b/boot/zephyr/CMakeLists.txt @@ -433,8 +433,12 @@ if(SYSBUILD) if(NOT DEFINED write_size) message(WARNING "Unable to determine write size of slot0 or slot1 partition, setting to 8 (this is probably wrong)") set(write_size 8) - elseif(write_size LESS 8) - set(write_size 8) + endif() + + if(${write_size} LESS 8) + set(max_align_size 8) + else() + set(max_align_size ${write_size}) endif() set(key_size 0) @@ -473,7 +477,7 @@ if(SYSBUILD) set(key_size "${boot_enc_key_size}") endif() - align_up(${key_size} ${write_size} key_size) + align_up(${key_size} ${max_align_size} key_size) math(EXPR key_size "${key_size} * 2") endif() @@ -482,7 +486,7 @@ if(SYSBUILD) if(CONFIG_SINGLE_APPLICATION_SLOT OR CONFIG_BOOT_FIRMWARE_LOADER) set(boot_swap_data_size 0) else() - math(EXPR boot_swap_data_size "${write_size} * 4") + math(EXPR boot_swap_data_size "${max_align_size} * 4") endif() if(CONFIG_BOOT_SWAP_USING_SCRATCH OR CONFIG_BOOT_SWAP_USING_MOVE)