Commit c40d237a authored by Jamie McCrae's avatar Jamie McCrae Committed by Jamie
Browse files

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: default avatarJamie McCrae <jamie.mccrae@nordicsemi.no>
parent f9fc5918
Loading
Loading
Loading
Loading
+13 −0
Changes for boot/bootutil/src/swap_move.c: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -298,6 +298,19 @@ boot_slots_compatible(struct boot_loader_state *state)
        }
    }

#ifdef MCUBOOT_SLOT0_EXPECTED_ERASE_SIZE
    if (sector_sz_pri != MCUBOOT_SLOT0_EXPECTED_ERASE_SIZE) {
        BOOT_LOG_DBG("Discrepancy, slot0 expected erase size: %d, actual: %d",
                     MCUBOOT_SLOT0_EXPECTED_ERASE_SIZE, sector_sz_pri);
    }
#endif
#ifdef MCUBOOT_SLOT1_EXPECTED_ERASE_SIZE
    if (sector_sz_sec != MCUBOOT_SLOT1_EXPECTED_ERASE_SIZE) {
        BOOT_LOG_DBG("Discrepancy, slot1 expected erase size: %d, actual: %d",
                     MCUBOOT_SLOT1_EXPECTED_ERASE_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");
+17 −7
Changes for boot/zephyr/CMakeLists.txt: 17 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -375,19 +375,14 @@ 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")

  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)
    message(WARNING "Unable to determine erase size of slot0 partition, cannot calculate minimum sector usage")
  else()
    math(EXPR slot_min_sectors "${slot0_size} / ${erase_size_slot0}")
if(CONFIG_BOOT_SWAP_USING_MOVE AND DEFINED erase_size_slot0)
  zephyr_compile_definitions("MCUBOOT_SLOT0_EXPECTED_ERASE_SIZE=${erase_size_slot0}")
endif()

if(NOT CONFIG_SINGLE_APPLICATION_SLOT)
@@ -397,6 +392,21 @@ if(CONFIG_BOOT_MAX_IMG_SECTORS_AUTO)
  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_ERASE_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)
    message(WARNING "Unable to determine erase size of slot0 partition, cannot calculate minimum sector usage")
  else()
    math(EXPR slot_min_sectors "${slot0_size} / ${erase_size_slot0}")
  endif()

  if(NOT CONFIG_SINGLE_APPLICATION_SLOT)
    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)