From d1b473483d10b68eeec115144d1429bb5971e1cb Mon Sep 17 00:00:00 2001 From: Grzegorz Swiderski Date: Fri, 7 Jun 2024 11:55:31 +0200 Subject: [PATCH 1/2] scripts: gen_dts_cmake: Support variable target name in dts.cmake Instead of hardcoding the name `devicetree_target`, we can update the generated `dts.cmake` to accept `DEVICETREE_TARGET` as input variable. This will become useful in multi-image builds, where we would like to process multiple devicetrees. Signed-off-by: Grzegorz Swiderski --- cmake/modules/dts.cmake | 2 ++ scripts/dts/gen_dts_cmake.py | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/cmake/modules/dts.cmake b/cmake/modules/dts.cmake index ec0999d366b9..6bdce4aaa20e 100644 --- a/cmake/modules/dts.cmake +++ b/cmake/modules/dts.cmake @@ -117,6 +117,8 @@ set(GEN_DTS_CMAKE_SCRIPT ${DT_SCRIPTS}/gen_dts_cmake.py) # The generated information itself, which we include() after # creating it. set(DTS_CMAKE ${PROJECT_BINARY_DIR}/dts.cmake) +# The CMake target to be initialized by including ${DTS_CMAKE}. +set(DEVICETREE_TARGET devicetree_target) # The location of a file containing known vendor prefixes, relative to # each element of DTS_ROOT. Users can define their own in their own diff --git a/scripts/dts/gen_dts_cmake.py b/scripts/dts/gen_dts_cmake.py index 6fa4a3478802..653910cbf8d0 100755 --- a/scripts/dts/gen_dts_cmake.py +++ b/scripts/dts/gen_dts_cmake.py @@ -11,12 +11,13 @@ The generated CMake file looks like this: - add_custom_target(devicetree_target) - set_target_properties(devicetree_target PROPERTIES + add_custom_target(${DEVICETREE_TARGET}) + set_target_properties(${DEVICETREE_TARGET} PROPERTIES "DT_PROP|/soc|compatible" "vnd,soc;") ... -It defines a special CMake target, and saves various values in the +It takes an input variable - DEVICETREE_TARGET - and creates a special +CMake target with this name, which will contain various values in the devicetree as CMake target properties. Be careful: @@ -154,15 +155,13 @@ def main(): cmake_comp = f'DT_COMP|{comp}' cmake_props.append(f'"{cmake_comp}" "{cmake_path}"') + cmake_props = map( + 'set_target_properties(${{DEVICETREE_TARGET}} PROPERTIES {})'.format, + cmake_props + ) with open(args.cmake_out, "w", encoding="utf-8") as cmake_file: - print('add_custom_target(devicetree_target)', file=cmake_file) - print(file=cmake_file) - - for prop in cmake_props: - print( - f'set_target_properties(devicetree_target PROPERTIES {prop})', - file=cmake_file - ) + print('add_custom_target(${DEVICETREE_TARGET})\n', *cmake_props, + sep='\n', file=cmake_file) if __name__ == "__main__": From f6de4d0593b14352e8f86f78ea32757150560123 Mon Sep 17 00:00:00 2001 From: Grzegorz Swiderski Date: Fri, 7 Jun 2024 11:55:31 +0200 Subject: [PATCH 2/2] sysbuild: dts: Introduce sysbuild_dt_* API Add new functions to `sysbuild_extensions.cmake`, which will mirror the familiar dt_* API from Zephyr `extensions.cmake`. For example: dt_nodelabel( NODELABEL