diff --git a/cmake/dts.cmake b/cmake/dts.cmake index 961fab7fd99f2c..6f094b2e7de13b 100644 --- a/cmake/dts.cmake +++ b/cmake/dts.cmake @@ -26,6 +26,10 @@ set(DTS_POST_CPP ${PROJECT_BINARY_DIR}/${BOARD}.dts.pre.tmp) # A list of generally accepted vendor prefixes. set_ifndef(VENDOR_PREFIXES ${ZEPHYR_BASE}/dts/bindings/vendor-prefixes.txt) +# Devicetree in CMake. +set(DTS_CMAKE_SCRIPT ${ZEPHYR_BASE}/scripts/dts/gen_dts_cmake.py) +set(DTS_CMAKE ${PROJECT_BINARY_DIR}/dts.cmake) + set_ifndef(DTS_SOURCE ${BOARD_DIR}/${BOARD}.dts) zephyr_file(APPLICATION_ROOT DTS_ROOT) @@ -171,6 +175,7 @@ if(SUPPORTS_DTS) CMAKE_CONFIGURE_DEPENDS ${include_files} ${GEN_DEFINES_SCRIPT} + ${DTS_CMAKE_SCRIPT} ) # @@ -247,6 +252,20 @@ if(SUPPORTS_DTS) message(STATUS "Generated device_extern.h: ${DEVICE_EXTERN_H}") endif() + execute_process( + COMMAND ${PYTHON_EXECUTABLE} ${DTS_CMAKE_SCRIPT} + --edt-pickle ${EDT_PICKLE} + --cmake-out ${DTS_CMAKE} + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + RESULT_VARIABLE ret + ) + if(NOT "${ret}" STREQUAL "0") + message(FATAL_ERROR "gen_dts_cmake.py failed with return code: ${ret}") + else() + message(STATUS "Including generated dts.cmake file: ${DTS_CMAKE}") + include(${DTS_CMAKE}) + endif() + else() file(WRITE ${DEVICETREE_UNFIXED_H} "/* WARNING. THIS FILE IS AUTO-GENERATED. DO NOT MODIFY! */") file(WRITE ${DEVICE_EXTERN_H} "/* WARNING. THIS FILE IS AUTO-GENERATED. DO NOT MODIFY! */") diff --git a/cmake/extensions.cmake b/cmake/extensions.cmake index f9c992f7114746..792556c2ee21bb 100644 --- a/cmake/extensions.cmake +++ b/cmake/extensions.cmake @@ -19,6 +19,8 @@ # 3.3.1 Toolchain integration # 3.4. Debugging CMake # 3.5. File system management +# 4. Devicetree extensions +# 4.1 dt_* ######################################################## # 1. Zephyr-aware extensions @@ -2261,3 +2263,409 @@ function(target_byproducts) COMMENT "Logical command for additional byproducts on target: ${TB_TARGET}" ) endfunction() + +######################################################## +# 4. Zephyr devicetree function +######################################################## +# 4.1. dt_* +# +# The following methods are for retrieving devicetree information in CMake. +# +# Note: In CMake we refer to the nodes using the node's path, therefore there +# is no dt_path(...) function for obtaining a node identifier. + +# Usage: +# dt_nodelabel( NODELABEL