Skip to content

Commit

Permalink
cmake: dts: import devicetree symbols into CMake
Browse files Browse the repository at this point in the history
This commit introduces devicetree API in CMake so that devicetree
properties and register block can be used in the CMake build system.

The script scripts/dts/gen_dts_cmake.py processes the edt.pickle and
generates a corresponding devicetree property map in a devicetree_target
that is then used in CMake.

The following devicetree API has been made available in Zephyr CMake:
- dt_nodelabel(<var> NODELABEL <label>)
- dt_node_exists(<var> PATH <path>)
- dt_node_has_status(<var> PATH <path> STATUS <status>)
- dt_prop(<var> PATH <path> PROPERTY <prop>)
- dt_prop(<var> PATH <path> INDEX <idx> PROPERTY <prop>)
- dt_num_regs(<var> PATH <path>)
- dt_reg_addr(<var> PATH <path> [INDEX <idx>])
- dt_reg_size(<var> PATH <path> [INDEX <idx>])
- dt_has_chosen(<var> PROPERTY <prop>)
- dt_chosen(<var> PROPERTY <prop>)

Signed-off-by: Marti Bolivar <[email protected]>
Signed-off-by: Torsten Rasmussen <[email protected]>
  • Loading branch information
tejlmand committed Aug 24, 2021
1 parent 689864e commit f0cae1d
Show file tree
Hide file tree
Showing 3 changed files with 520 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cmake/dts.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -171,6 +175,7 @@ if(SUPPORTS_DTS)
CMAKE_CONFIGURE_DEPENDS
${include_files}
${GEN_DEFINES_SCRIPT}
${DTS_CMAKE_SCRIPT}
)

#
Expand Down Expand Up @@ -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! */")
Expand Down
Loading

0 comments on commit f0cae1d

Please sign in to comment.