2017-10-27 21:43:34 +08:00
|
|
|
# Zephyr code can configure itself based on a KConfig'uration with the
|
|
|
|
# header file autoconf.h. There exists an analogous file
|
|
|
|
# generated_dts_board.h that allows configuration based on information
|
|
|
|
# encoded in DTS.
|
|
|
|
#
|
|
|
|
# Here we call on dtc, the gcc preprocessor, and
|
|
|
|
# scripts/dts/extract_dts_includes.py to generate this header file at
|
|
|
|
# CMake configure-time.
|
|
|
|
#
|
|
|
|
# See ~/zephyr/doc/dts
|
|
|
|
set(GENERATED_DTS_BOARD_H ${PROJECT_BINARY_DIR}/include/generated/generated_dts_board.h)
|
|
|
|
set(GENERATED_DTS_BOARD_CONF ${PROJECT_BINARY_DIR}/include/generated/generated_dts_board.conf)
|
2018-02-27 00:52:29 +08:00
|
|
|
set_ifndef(DTS_SOURCE ${BOARD_ROOT}/boards/${ARCH}/${BOARD_FAMILY}/${BOARD}.dts)
|
2018-06-15 02:21:18 +08:00
|
|
|
set_ifndef(DTS_COMMON_OVERLAYS ${ZEPHYR_BASE}/dts/common/common.dts)
|
2018-08-21 17:02:48 +08:00
|
|
|
set_ifndef(DTS_APP_BINDINGS ${APPLICATION_SOURCE_DIR}/dts/bindings)
|
2017-10-27 21:43:34 +08:00
|
|
|
|
|
|
|
message(STATUS "Generating zephyr/include/generated/generated_dts_board.h")
|
|
|
|
|
|
|
|
if(CONFIG_HAS_DTS)
|
|
|
|
|
2018-02-01 01:00:49 +08:00
|
|
|
if(DTC_OVERLAY_FILE)
|
|
|
|
# Convert from space-separated files into file list
|
|
|
|
string(REPLACE " " ";" DTC_OVERLAY_FILE_AS_LIST ${DTC_OVERLAY_FILE})
|
2017-10-27 21:43:34 +08:00
|
|
|
endif()
|
|
|
|
|
2018-02-07 19:37:56 +08:00
|
|
|
# Prepend common overlays
|
|
|
|
set(DTC_OVERLAY_FILE_AS_LIST ${DTS_COMMON_OVERLAYS} ${DTC_OVERLAY_FILE_AS_LIST})
|
|
|
|
|
2018-02-01 01:00:49 +08:00
|
|
|
set(
|
|
|
|
dts_files
|
|
|
|
${DTS_SOURCE}
|
|
|
|
${DTC_OVERLAY_FILE_AS_LIST}
|
|
|
|
)
|
|
|
|
|
|
|
|
unset(DTC_INCLUDE_FLAG_FOR_DTS)
|
|
|
|
foreach(dts_file ${dts_files})
|
|
|
|
list(APPEND DTC_INCLUDE_FLAG_FOR_DTS
|
|
|
|
-include ${dts_file})
|
|
|
|
endforeach()
|
2017-10-27 21:43:34 +08:00
|
|
|
|
|
|
|
# TODO: Cut down on CMake configuration time by avoiding
|
|
|
|
# regeneration of generated_dts_board.h on every configure. How
|
|
|
|
# challenging is this? What are the dts dependencies? We run the
|
|
|
|
# preprocessor, and it seems to be including all kinds of
|
|
|
|
# directories with who-knows how many header files.
|
|
|
|
|
|
|
|
# Run the C preprocessor on an empty C source file that has one or
|
|
|
|
# more DTS source files -include'd into it to create the
|
|
|
|
# intermediary file *.dts.pre.tmp
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${CMAKE_C_COMPILER}
|
|
|
|
-x assembler-with-cpp
|
|
|
|
-nostdinc
|
2018-09-04 04:20:14 +08:00
|
|
|
-I${ZEPHYR_BASE}/soc/${ARCH}
|
2018-06-15 02:21:18 +08:00
|
|
|
-isystem ${ZEPHYR_BASE}/include
|
|
|
|
-isystem ${ZEPHYR_BASE}/dts/${ARCH}
|
|
|
|
-isystem ${ZEPHYR_BASE}/dts
|
2017-10-27 21:43:34 +08:00
|
|
|
-include ${AUTOCONF_H}
|
2018-02-01 01:00:49 +08:00
|
|
|
${DTC_INCLUDE_FLAG_FOR_DTS} # include the DTS source and overlays
|
2018-06-15 02:21:18 +08:00
|
|
|
-I${ZEPHYR_BASE}/dts/common
|
|
|
|
-I${ZEPHYR_BASE}/drivers
|
2017-10-27 21:43:34 +08:00
|
|
|
-undef -D__DTS__
|
|
|
|
-P
|
2018-01-11 22:46:44 +08:00
|
|
|
-E ${ZEPHYR_BASE}/misc/empty_file.c
|
2018-02-27 00:52:29 +08:00
|
|
|
-o ${BOARD}.dts.pre.tmp
|
2017-10-27 21:43:34 +08:00
|
|
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
|
|
|
RESULT_VARIABLE ret
|
|
|
|
)
|
|
|
|
if(NOT "${ret}" STREQUAL "0")
|
|
|
|
message(FATAL_ERROR "command failed with return code: ${ret}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Run the DTC on *.dts.pre.tmp to create the intermediary file *.dts_compiled
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${DTC}
|
|
|
|
-O dts
|
2018-02-27 00:52:29 +08:00
|
|
|
-o ${BOARD}.dts_compiled
|
2017-10-27 21:43:34 +08:00
|
|
|
-b 0
|
2018-02-27 00:52:29 +08:00
|
|
|
${BOARD}.dts.pre.tmp
|
2017-10-27 21:43:34 +08:00
|
|
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
|
|
|
RESULT_VARIABLE ret
|
|
|
|
)
|
|
|
|
if(NOT "${ret}" STREQUAL "0")
|
|
|
|
message(FATAL_ERROR "command failed with return code: ${ret}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Run extract_dts_includes.py for the header file
|
|
|
|
# generated_dts_board.h
|
2018-02-12 12:30:57 +08:00
|
|
|
set_ifndef(DTS_BOARD_FIXUP_FILE ${BOARD_ROOT}/boards/${ARCH}/${BOARD_FAMILY}/dts.fixup)
|
2017-11-09 23:50:07 +08:00
|
|
|
if(EXISTS ${DTS_BOARD_FIXUP_FILE})
|
2018-03-07 18:15:00 +08:00
|
|
|
set(DTS_BOARD_FIXUP ${DTS_BOARD_FIXUP_FILE})
|
2017-10-27 21:43:34 +08:00
|
|
|
endif()
|
2018-09-05 03:34:06 +08:00
|
|
|
set_ifndef(DTS_SOC_FIXUP_FILE ${SOC_DIR}/${ARCH}/${SOC_PATH}/dts.fixup)
|
2018-01-24 03:30:30 +08:00
|
|
|
if(EXISTS ${DTS_SOC_FIXUP_FILE})
|
2018-03-07 18:15:00 +08:00
|
|
|
set(DTS_SOC_FIXUP ${DTS_SOC_FIXUP_FILE})
|
2018-01-24 03:30:30 +08:00
|
|
|
endif()
|
2018-01-27 01:24:13 +08:00
|
|
|
if(EXISTS ${APPLICATION_SOURCE_DIR}/dts.fixup)
|
2018-03-07 18:15:00 +08:00
|
|
|
set(DTS_APP_FIXUP ${APPLICATION_SOURCE_DIR}/dts.fixup)
|
2018-01-27 01:24:13 +08:00
|
|
|
endif()
|
2018-03-07 18:15:00 +08:00
|
|
|
|
|
|
|
set(DTS_FIXUPS ${DTS_SOC_FIXUP} ${DTS_BOARD_FIXUP} ${DTS_APP_FIXUP})
|
|
|
|
if(NOT "${DTS_FIXUPS}" STREQUAL "")
|
|
|
|
set(DTS_FIXUPS --fixup ${DTS_FIXUPS})
|
|
|
|
endif()
|
|
|
|
|
2018-08-21 17:02:48 +08:00
|
|
|
if(NOT EXISTS ${DTS_APP_BINDINGS})
|
|
|
|
set(DTS_APP_BINDINGS)
|
|
|
|
endif()
|
|
|
|
|
2018-06-15 02:21:18 +08:00
|
|
|
set(CMD_EXTRACT_DTS_INCLUDES ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/dts/extract_dts_includes.py
|
2018-02-27 00:52:29 +08:00
|
|
|
--dts ${BOARD}.dts_compiled
|
2018-08-21 17:02:48 +08:00
|
|
|
--yaml ${ZEPHYR_BASE}/dts/bindings ${DTS_APP_BINDINGS}
|
2018-03-07 18:15:00 +08:00
|
|
|
${DTS_FIXUPS}
|
|
|
|
--keyvalue ${GENERATED_DTS_BOARD_CONF}
|
|
|
|
--include ${GENERATED_DTS_BOARD_H}
|
2017-10-27 21:43:34 +08:00
|
|
|
)
|
|
|
|
|
2018-03-07 18:15:00 +08:00
|
|
|
# Run extract_dts_includes.py to create a .conf and a header file that can be
|
2017-10-27 21:43:34 +08:00
|
|
|
# included into the CMake namespace
|
|
|
|
execute_process(
|
2018-03-07 18:15:00 +08:00
|
|
|
COMMAND ${CMD_EXTRACT_DTS_INCLUDES}
|
2017-10-27 21:43:34 +08:00
|
|
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
|
|
|
RESULT_VARIABLE ret
|
|
|
|
)
|
|
|
|
if(NOT "${ret}" STREQUAL "0")
|
|
|
|
message(FATAL_ERROR "command failed with return code: ${ret}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
import_kconfig(${GENERATED_DTS_BOARD_CONF})
|
|
|
|
|
|
|
|
else()
|
|
|
|
file(WRITE ${GENERATED_DTS_BOARD_H} "/* WARNING. THIS FILE IS AUTO-GENERATED. DO NOT MODIFY! */")
|
|
|
|
endif()
|