From 0ac073eba929968502cc6e8494e2ebfbe575fdbb Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 18 Dec 2023 13:45:27 +0000 Subject: [PATCH] boot: zephyr: cmake: Fix issue with missing dts entries Fixes an issue whereby a device might not have a write or erase entry for the flash controller in devicetree. In the case whereby the other slot has this information, use that instead. In the case whereby neither slot has this information, use default values and show a warning to the user Signed-off-by: Jamie McCrae --- boot/zephyr/CMakeLists.txt | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/boot/zephyr/CMakeLists.txt b/boot/zephyr/CMakeLists.txt index 78eb653e7..580954fc4 100644 --- a/boot/zephyr/CMakeLists.txt +++ b/boot/zephyr/CMakeLists.txt @@ -393,15 +393,27 @@ if(SYSBUILD) dt_prop(erase_size_slot1 PATH "${slot1_flash}" PROPERTY "erase-block-size") dt_prop(write_size_slot1 PATH "${slot1_flash}" PROPERTY "write-block-size") - if(${erase_size_slot0} GREATER ${erase_size_slot1}) + if(DEFINED erase_size_slot0 AND DEFINED erase_size_slot1) + if(${erase_size_slot0} GREATER ${erase_size_slot1}) + set(erase_size ${erase_size_slot0}) + else() + set(erase_size ${erase_size_slot1}) + endif() + elseif(DEFINED erase_size_slot0) set(erase_size ${erase_size_slot0}) - else() + elseif(DEFINED erase_size_slot1) set(erase_size ${erase_size_slot1}) endif() - if(${write_size_slot0} GREATER ${write_size_slot1}) + if(DEFINED write_size_slot0 AND DEFINED write_size_slot1) + if(${write_size_slot0} GREATER ${write_size_slot1}) + set(write_size ${write_size_slot0}) + else() + set(write_size ${write_size_slot1}) + endif() + elseif(DEFINED write_size_slot0) set(write_size ${write_size_slot0}) - else() + elseif(DEFINED write_size_slot1) set(write_size ${write_size_slot1}) endif() else() @@ -413,7 +425,15 @@ if(SYSBUILD) dt_prop(write_size PATH "${slot0_flash}" PROPERTY "write-block-size") endif() - if(write_size LESS 8) + if(NOT DEFINED erase_size) + message(WARNING "Unable to determine erase size of slot0 or slot1 partition, setting to 1 (this is probably wrong)") + set(erase_size 1) + endif() + + 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()