Skip to content

Commit

Permalink
boot: zephyr: Add check for unexpected flash sector size
Browse files Browse the repository at this point in the history
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 <jamie.mccrae@nordicsemi.no>
  • Loading branch information
nordicjm committed Sep 10, 2024
1 parent 84b56b6 commit 338489e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
12 changes: 12 additions & 0 deletions boot/bootutil/src/swap_move.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,18 @@ 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");
Expand Down
34 changes: 22 additions & 12 deletions boot/zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 338489e

Please sign in to comment.