From 07dc5a391549067609605a97e537341f14fd3c23 Mon Sep 17 00:00:00 2001 From: Tomasz Chyrowicz Date: Tue, 30 Sep 2025 13:57:19 +0200 Subject: [PATCH] cmake: Add function to read partition address Add a common bootloader_dts_util to read both the relative and absolute address of a fixed sub/partition from DTS. Signed-off-by: Tomasz Chyrowicz --- cmake/modules/kconfig.cmake | 4 +- cmake/sysbuild/bootloader_dts_utils.cmake | 121 +++++++++++++++++++--- cmake/sysbuild/image_signing.cmake | 4 +- cmake/sysbuild/sign_nrf54h20.cmake | 8 +- west.yml | 2 +- 5 files changed, 120 insertions(+), 19 deletions(-) diff --git a/cmake/modules/kconfig.cmake b/cmake/modules/kconfig.cmake index 8aed0a828eef..b1917249ea35 100644 --- a/cmake/modules/kconfig.cmake +++ b/cmake/modules/kconfig.cmake @@ -27,8 +27,10 @@ if(CONFIG_NCS_IS_VARIANT_IMAGE) import_kconfig("CONFIG" ${DOTCONFIG}) else() + include(${ZEPHYR_NRF_MODULE_DIR}/cmake/sysbuild/bootloader_dts_utils.cmake) + dt_chosen(code_partition PROPERTY "zephyr,code-partition") - dt_reg_addr(code_partition_offset PATH "${code_partition}" REQUIRED) + dt_partition_addr(code_partition_offset PATH "${code_partition}" REQUIRED) dt_reg_size(code_partition_size PATH "${code_partition}" REQUIRED) set(preload_autoconf_h ${PRELOAD_BINARY_DIR}/zephyr/include/generated/zephyr/autoconf.h) diff --git a/cmake/sysbuild/bootloader_dts_utils.cmake b/cmake/sysbuild/bootloader_dts_utils.cmake index 9567120a60b4..789118fd24ad 100644 --- a/cmake/sysbuild/bootloader_dts_utils.cmake +++ b/cmake/sysbuild/bootloader_dts_utils.cmake @@ -5,20 +5,115 @@ # data coming from the devicetree for configurations using # a bootloader. -function(get_address_from_dt_partition_nodelabel label address) - dt_nodelabel(partition_node TARGET ${DEFAULT_IMAGE} NODELABEL ${label} REQUIRED) - dt_reg_addr(partition_offset TARGET ${DEFAULT_IMAGE} PATH ${partition_node}) +function(dt_get_parent node) + string(FIND "${${node}}" "/" pos REVERSE) + + if(pos EQUAL -1) + message(FATAL_ERROR "Unable to get parent of node: ${${node}}") + endif() + + string(SUBSTRING "${${node}}" 0 ${pos} ${node}) + set(${node} "${${node}}" PARENT_SCOPE) +endfunction() + +# Usage: +# dt_partition_addr( [LABEL