diff --git a/boot/bootutil/src/swap_move.c b/boot/bootutil/src/swap_move.c index 8999403c5..4d29e0972 100644 --- a/boot/bootutil/src/swap_move.c +++ b/boot/bootutil/src/swap_move.c @@ -298,6 +298,19 @@ boot_slots_compatible(struct boot_loader_state *state) } } +#ifdef MCUBOOT_SLOT0_EXPECTED_SECTOR_SIZE + if (sector_sz_pri != MCUBOOT_SLOT0_EXPECTED_SECTOR_SIZE) { + BOOT_LOG_DBG("Discrepancy, slot0 expected sector size: %d, actual: %d" + MCUBOOT_SLOT0_EXPECTED_SECTOR_SIZE, sector_sz_pri); + } +#endif +#ifdef MCUBOOT_SLOT1_EXPECTED_SECTOR_SIZE + if (sector_sz_sec != MCUBOOT_SLOT1_EXPECTED_SECTOR_SIZE) { + BOOT_LOG_DBG("Discrepancy, slot1 expected sector size: %d, actual: %d" + MCUBOOT_SLOT1_EXPECTED_SECTOR_SIZE, sector_sz_sec); + } +#endif + if (num_sectors_pri > num_sectors_sec) { if (sector_sz_pri != boot_img_sector_size(state, BOOT_PRIMARY_SLOT, i)) { BOOT_LOG_WRN("Cannot upgrade: not same sector layout"); diff --git a/boot/zephyr/CMakeLists.txt b/boot/zephyr/CMakeLists.txt index d02f93a40..e71968b5f 100644 --- a/boot/zephyr/CMakeLists.txt +++ b/boot/zephyr/CMakeLists.txt @@ -379,13 +379,29 @@ function(dt_get_parent node) set(${node} "${${node}}" PARENT_SCOPE) endfunction() -if(CONFIG_BOOT_MAX_IMG_SECTORS_AUTO) - dt_nodelabel(slot0_flash NODELABEL "slot0_partition") - dt_prop(slot0_size PATH "${slot0_flash}" PROPERTY "reg" INDEX 1) - dt_get_parent(slot0_flash) - dt_get_parent(slot0_flash) - dt_prop(erase_size_slot0 PATH "${slot0_flash}" PROPERTY "erase-block-size") +dt_nodelabel(slot0_flash NODELABEL "slot0_partition") +dt_prop(slot0_size PATH "${slot0_flash}" PROPERTY "reg" INDEX 1) +dt_get_parent(slot0_flash) +dt_get_parent(slot0_flash) +dt_prop(erase_size_slot0 PATH "${slot0_flash}" PROPERTY "erase-block-size") + +if(CONFIG_BOOT_SWAP_USING_MOVE AND DEFINED erase_size_slot0) + zephyr_compile_definitions("MCUBOOT_SLOT0_EXPECTED_SECTOR_SIZE=${erase_size_slot0}") +endif() + +if(NOT CONFIG_SINGLE_APPLICATION_SLOT) + dt_nodelabel(slot1_flash NODELABEL "slot1_partition") + dt_prop(slot1_size PATH "${slot1_flash}" PROPERTY "reg" INDEX 1) + dt_get_parent(slot1_flash) + dt_get_parent(slot1_flash) + dt_prop(erase_size_slot1 PATH "${slot1_flash}" PROPERTY "erase-block-size") + + if(CONFIG_BOOT_SWAP_USING_MOVE AND DEFINED erase_size_slot1) + zephyr_compile_definitions("MCUBOOT_SLOT1_EXPECTED_SECTOR_SIZE=${erase_size_slot1}") + endif() +endif() +if(CONFIG_BOOT_MAX_IMG_SECTORS_AUTO) if(NOT DEFINED slot0_size) message(WARNING "Unable to determine size of slot0 partition, cannot calculate minimum sector usage") elseif(NOT DEFINED erase_size_slot0) @@ -395,12 +411,6 @@ if(CONFIG_BOOT_MAX_IMG_SECTORS_AUTO) endif() if(NOT CONFIG_SINGLE_APPLICATION_SLOT) - dt_nodelabel(slot1_flash NODELABEL "slot1_partition") - dt_prop(slot1_size PATH "${slot1_flash}" PROPERTY "reg" INDEX 1) - dt_get_parent(slot1_flash) - dt_get_parent(slot1_flash) - dt_prop(erase_size_slot1 PATH "${slot1_flash}" PROPERTY "erase-block-size") - if(NOT DEFINED slot1_size) message(WARNING "Unable to determine size of slot1 partition, cannot calculate minimum sector usage") elseif(NOT DEFINED erase_size_slot1)