Skip to content

Commit c40d237

Browse files
committed
boot: zephyr: Add check for unexpected flash sector size
Prints a debug log message if the device has a write block size for a flash device in DTS that is not the same as what the flash driver reports at run-time, this can be used to see if there is a faulty configuration as these compile-time values are used for various calculations Signed-off-by: Jamie McCrae <[email protected]>
1 parent f9fc591 commit c40d237

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

boot/bootutil/src/swap_move.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,19 @@ boot_slots_compatible(struct boot_loader_state *state)
298298
}
299299
}
300300

301+
#ifdef MCUBOOT_SLOT0_EXPECTED_ERASE_SIZE
302+
if (sector_sz_pri != MCUBOOT_SLOT0_EXPECTED_ERASE_SIZE) {
303+
BOOT_LOG_DBG("Discrepancy, slot0 expected erase size: %d, actual: %d",
304+
MCUBOOT_SLOT0_EXPECTED_ERASE_SIZE, sector_sz_pri);
305+
}
306+
#endif
307+
#ifdef MCUBOOT_SLOT1_EXPECTED_ERASE_SIZE
308+
if (sector_sz_sec != MCUBOOT_SLOT1_EXPECTED_ERASE_SIZE) {
309+
BOOT_LOG_DBG("Discrepancy, slot1 expected erase size: %d, actual: %d",
310+
MCUBOOT_SLOT1_EXPECTED_ERASE_SIZE, sector_sz_sec);
311+
}
312+
#endif
313+
301314
if (num_sectors_pri > num_sectors_sec) {
302315
if (sector_sz_pri != boot_img_sector_size(state, BOOT_PRIMARY_SLOT, i)) {
303316
BOOT_LOG_WRN("Cannot upgrade: not same sector layout");

boot/zephyr/CMakeLists.txt

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,29 @@ function(dt_get_parent node)
375375
set(${node} "${${node}}" PARENT_SCOPE)
376376
endfunction()
377377

378-
if(CONFIG_BOOT_MAX_IMG_SECTORS_AUTO)
379-
dt_nodelabel(slot0_flash NODELABEL "slot0_partition")
380-
dt_prop(slot0_size PATH "${slot0_flash}" PROPERTY "reg" INDEX 1)
381-
dt_get_parent(slot0_flash)
382-
dt_get_parent(slot0_flash)
383-
dt_prop(erase_size_slot0 PATH "${slot0_flash}" PROPERTY "erase-block-size")
378+
dt_nodelabel(slot0_flash NODELABEL "slot0_partition")
379+
dt_prop(slot0_size PATH "${slot0_flash}" PROPERTY "reg" INDEX 1)
380+
dt_get_parent(slot0_flash)
381+
dt_get_parent(slot0_flash)
382+
dt_prop(erase_size_slot0 PATH "${slot0_flash}" PROPERTY "erase-block-size")
383+
384+
if(CONFIG_BOOT_SWAP_USING_MOVE AND DEFINED erase_size_slot0)
385+
zephyr_compile_definitions("MCUBOOT_SLOT0_EXPECTED_ERASE_SIZE=${erase_size_slot0}")
386+
endif()
387+
388+
if(NOT CONFIG_SINGLE_APPLICATION_SLOT)
389+
dt_nodelabel(slot1_flash NODELABEL "slot1_partition")
390+
dt_prop(slot1_size PATH "${slot1_flash}" PROPERTY "reg" INDEX 1)
391+
dt_get_parent(slot1_flash)
392+
dt_get_parent(slot1_flash)
393+
dt_prop(erase_size_slot1 PATH "${slot1_flash}" PROPERTY "erase-block-size")
394+
395+
if(CONFIG_BOOT_SWAP_USING_MOVE AND DEFINED erase_size_slot1)
396+
zephyr_compile_definitions("MCUBOOT_SLOT1_EXPECTED_ERASE_SIZE=${erase_size_slot1}")
397+
endif()
398+
endif()
384399

400+
if(CONFIG_BOOT_MAX_IMG_SECTORS_AUTO)
385401
if(NOT DEFINED slot0_size)
386402
message(WARNING "Unable to determine size of slot0 partition, cannot calculate minimum sector usage")
387403
elseif(NOT DEFINED erase_size_slot0)
@@ -391,12 +407,6 @@ if(CONFIG_BOOT_MAX_IMG_SECTORS_AUTO)
391407
endif()
392408

393409
if(NOT CONFIG_SINGLE_APPLICATION_SLOT)
394-
dt_nodelabel(slot1_flash NODELABEL "slot1_partition")
395-
dt_prop(slot1_size PATH "${slot1_flash}" PROPERTY "reg" INDEX 1)
396-
dt_get_parent(slot1_flash)
397-
dt_get_parent(slot1_flash)
398-
dt_prop(erase_size_slot1 PATH "${slot1_flash}" PROPERTY "erase-block-size")
399-
400410
if(NOT DEFINED slot1_size)
401411
message(WARNING "Unable to determine size of slot1 partition, cannot calculate minimum sector usage")
402412
elseif(NOT DEFINED erase_size_slot1)

0 commit comments

Comments
 (0)