2019-04-06 15:08:09 +02:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2019-01-18 16:47:05 +01:00
|
|
|
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/include/generated)
|
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
# Zephyr code can configure itself based on a KConfig'uration with the
|
2020-01-16 13:29:53 +01:00
|
|
|
# header file autoconf.h. There exists an analogous file devicetree_unfixed.h
|
2020-10-06 05:02:13 +02:00
|
|
|
# that allows configuration based on information encoded in DTS.
|
2017-10-27 15:43:34 +02:00
|
|
|
#
|
2020-10-06 05:02:13 +02:00
|
|
|
# Here we call on dtc, the gcc preprocessor and
|
|
|
|
# scripts/dts/gen_defines.py to generate various DT-related files at
|
|
|
|
# CMake configure-time.
|
2020-02-29 00:26:52 +01:00
|
|
|
#
|
|
|
|
# See the Devicetree user guide in the Zephyr documentation for details.
|
2020-04-10 20:40:41 +02:00
|
|
|
set(GEN_DEFINES_SCRIPT ${ZEPHYR_BASE}/scripts/dts/gen_defines.py)
|
2020-02-29 00:26:52 +01:00
|
|
|
set(ZEPHYR_DTS ${PROJECT_BINARY_DIR}/zephyr.dts)
|
2020-07-01 19:43:43 +02:00
|
|
|
# This contains the edtlib.EDT object created from zephyr.dts in Python's
|
|
|
|
# pickle data marshalling format (https://docs.python.org/3/library/pickle.html)
|
|
|
|
#
|
|
|
|
# Its existence is an implementation detail used to speed up further
|
|
|
|
# use of the devicetree by processes that run later on in the build,
|
|
|
|
# and should not be made part of the documentation.
|
|
|
|
set(EDT_PICKLE ${PROJECT_BINARY_DIR}/edt.pickle)
|
2020-02-29 00:26:52 +01:00
|
|
|
set(DEVICETREE_UNFIXED_H ${PROJECT_BINARY_DIR}/include/generated/devicetree_unfixed.h)
|
|
|
|
set(DTS_POST_CPP ${PROJECT_BINARY_DIR}/${BOARD}.dts.pre.tmp)
|
2019-03-14 13:06:40 +01:00
|
|
|
|
2018-09-27 17:15:24 +02:00
|
|
|
set_ifndef(DTS_SOURCE ${BOARD_DIR}/${BOARD}.dts)
|
2019-10-11 13:00:49 +02:00
|
|
|
|
cmake: ensure consistent behavior between x_ROOT settings
Fixes: #23825
Today, BOARD, SOC, ARCH, DTS, KCONFIG, and TOOLCHAIN_ROOT can be
specified by users or through other CMake files.
It is not clear if relative paths are permitted and/or from where a
relative path is constructed.
Inside CMake, it is very easy to specify `${ZEPHYR_BASE}`,
`${CMAKE_CURRENT_SOURCE_DIR}`, or similar, thus there is no reason to
use relative path inside CMake, as it easy can lead to discussion on
relative to what.
For users manually invoking CMake using, `cmake ... <app-dir>` it is
nice to have to possibility to specify a relative path.
For this purpose, relative path are considered relative to the
`APPLICATION_SOURCE_DIR`.
This commit updates:
- BOARD_ROOT
- SOC_ROOT
- ARCH_ROOT
- DTS_ROOT
- KCONFIG_ROOT
- TOOLCHAIN_ROOT
to allow paths relative to `APPLICATION_SOURCE_DIR` when specified with
`-D<type>_ROOT=<relative-path>`
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-09-08 14:07:00 +02:00
|
|
|
zephyr_file(APPLICATION_ROOT DTS_ROOT)
|
|
|
|
|
2019-03-14 13:06:40 +01:00
|
|
|
# 'DTS_ROOT' is a list of directories where a directory tree with DT
|
2019-07-04 16:48:53 +02:00
|
|
|
# files may be found. It always includes the application directory,
|
|
|
|
# the board directory, and ${ZEPHYR_BASE}.
|
2019-03-14 13:06:40 +01:00
|
|
|
list(APPEND
|
|
|
|
DTS_ROOT
|
|
|
|
${APPLICATION_SOURCE_DIR}
|
2019-07-04 16:48:53 +02:00
|
|
|
${BOARD_DIR}
|
2019-03-14 13:06:40 +01:00
|
|
|
${ZEPHYR_BASE}
|
|
|
|
)
|
2019-07-12 03:17:57 +02:00
|
|
|
list(REMOVE_DUPLICATES
|
|
|
|
DTS_ROOT
|
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2019-01-18 16:47:05 +01:00
|
|
|
# TODO: What to do about non-posix platforms where NOT CONFIG_HAS_DTS (xtensa)?
|
|
|
|
# Drop support for NOT CONFIG_HAS_DTS perhaps?
|
|
|
|
if(EXISTS ${DTS_SOURCE})
|
|
|
|
set(SUPPORTS_DTS 1)
|
2020-11-11 10:10:41 +01:00
|
|
|
if(BOARD_REVISION AND EXISTS ${BOARD_DIR}/${BOARD}_${BOARD_REVISION_STRING}.overlay)
|
|
|
|
list(APPEND DTS_SOURCE ${BOARD_DIR}/${BOARD}_${BOARD_REVISION_STRING}.overlay)
|
|
|
|
endif()
|
2019-01-18 16:47:05 +01:00
|
|
|
else()
|
|
|
|
set(SUPPORTS_DTS 0)
|
|
|
|
endif()
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2020-11-11 10:10:41 +01:00
|
|
|
set(dts_files
|
|
|
|
${DTS_SOURCE}
|
|
|
|
${shield_dts_files}
|
|
|
|
)
|
|
|
|
|
2019-01-18 16:47:05 +01:00
|
|
|
if(SUPPORTS_DTS)
|
2018-01-31 18:00:49 +01:00
|
|
|
if(DTC_OVERLAY_FILE)
|
|
|
|
# Convert from space-separated files into file list
|
2020-10-15 11:07:53 +02:00
|
|
|
string(REPLACE " " ";" DTC_OVERLAY_FILE_RAW_LIST "${DTC_OVERLAY_FILE}")
|
2020-08-27 13:56:29 +02:00
|
|
|
foreach(file ${DTC_OVERLAY_FILE_RAW_LIST})
|
|
|
|
file(TO_CMAKE_PATH "${file}" cmake_path_file)
|
|
|
|
list(APPEND DTC_OVERLAY_FILE_AS_LIST ${cmake_path_file})
|
|
|
|
endforeach()
|
2018-04-18 09:31:02 +02:00
|
|
|
list(APPEND
|
|
|
|
dts_files
|
|
|
|
${DTC_OVERLAY_FILE_AS_LIST}
|
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
endif()
|
|
|
|
|
2018-11-13 16:50:25 +01:00
|
|
|
set(i 0)
|
2018-01-31 18:00:49 +01:00
|
|
|
unset(DTC_INCLUDE_FLAG_FOR_DTS)
|
|
|
|
foreach(dts_file ${dts_files})
|
|
|
|
list(APPEND DTC_INCLUDE_FLAG_FOR_DTS
|
|
|
|
-include ${dts_file})
|
2018-11-13 16:50:25 +01:00
|
|
|
|
2018-12-19 10:40:57 +01:00
|
|
|
if(i EQUAL 0)
|
2020-02-29 00:26:52 +01:00
|
|
|
message(STATUS "Found BOARD.dts: ${dts_file}")
|
2018-12-19 10:40:57 +01:00
|
|
|
else()
|
2020-02-29 00:26:52 +01:00
|
|
|
message(STATUS "Found devicetree overlay: ${dts_file}")
|
2018-12-19 10:40:57 +01:00
|
|
|
endif()
|
2018-11-13 16:50:25 +01:00
|
|
|
|
2018-12-19 10:40:57 +01:00
|
|
|
math(EXPR i "${i}+1")
|
2018-01-31 18:00:49 +01:00
|
|
|
endforeach()
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2019-07-12 03:17:57 +02:00
|
|
|
unset(DTS_ROOT_SYSTEM_INCLUDE_DIRS)
|
2019-03-14 13:06:40 +01:00
|
|
|
foreach(dts_root ${DTS_ROOT})
|
|
|
|
foreach(dts_root_path
|
|
|
|
include
|
|
|
|
dts/common
|
|
|
|
dts/${ARCH}
|
|
|
|
dts
|
|
|
|
)
|
2020-10-27 13:30:36 +01:00
|
|
|
get_filename_component(full_path ${dts_root}/${dts_root_path} REALPATH)
|
2019-03-14 13:06:40 +01:00
|
|
|
if(EXISTS ${full_path})
|
|
|
|
list(APPEND
|
|
|
|
DTS_ROOT_SYSTEM_INCLUDE_DIRS
|
|
|
|
-isystem ${full_path}
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endforeach()
|
|
|
|
|
2019-07-12 03:17:57 +02:00
|
|
|
unset(DTS_ROOT_BINDINGS)
|
2019-03-14 13:06:40 +01:00
|
|
|
foreach(dts_root ${DTS_ROOT})
|
|
|
|
set(full_path ${dts_root}/dts/bindings)
|
|
|
|
if(EXISTS ${full_path})
|
|
|
|
list(APPEND
|
|
|
|
DTS_ROOT_BINDINGS
|
|
|
|
${full_path}
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2019-11-12 22:13:05 +01:00
|
|
|
# Cache the location of the root bindings so they can be used by
|
|
|
|
# scripts which use the build directory.
|
|
|
|
set(CACHED_DTS_ROOT_BINDINGS ${DTS_ROOT_BINDINGS} CACHE INTERNAL
|
|
|
|
"DT bindings root directories")
|
|
|
|
|
2020-09-03 13:57:45 +02:00
|
|
|
if(NOT DEFINED CMAKE_DTS_PREPROCESSOR)
|
|
|
|
set(CMAKE_DTS_PREPROCESSOR ${CMAKE_C_COMPILER})
|
|
|
|
endif()
|
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
# TODO: Cut down on CMake configuration time by avoiding
|
2020-01-16 13:29:53 +01:00
|
|
|
# regeneration of devicetree_unfixed.h on every configure. How
|
2017-10-27 15:43:34 +02:00
|
|
|
# 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
|
2019-10-15 14:51:57 +02:00
|
|
|
# intermediary file *.dts.pre.tmp. Also, generate a dependency file
|
|
|
|
# so that changes to DT sources are detected.
|
2017-10-27 15:43:34 +02:00
|
|
|
execute_process(
|
2020-09-03 13:57:45 +02:00
|
|
|
COMMAND ${CMAKE_DTS_PREPROCESSOR}
|
2017-10-27 15:43:34 +02:00
|
|
|
-x assembler-with-cpp
|
|
|
|
-nostdinc
|
2019-03-14 13:06:40 +01:00
|
|
|
${DTS_ROOT_SYSTEM_INCLUDE_DIRS}
|
2018-01-31 18:00:49 +01:00
|
|
|
${DTC_INCLUDE_FLAG_FOR_DTS} # include the DTS source and overlays
|
2018-11-01 17:45:54 +01:00
|
|
|
${NOSYSDEF_CFLAG}
|
|
|
|
-D__DTS__
|
2020-08-21 21:52:15 +02:00
|
|
|
${DTS_EXTRA_CPPFLAGS}
|
2017-10-27 15:43:34 +02:00
|
|
|
-P
|
2019-10-15 14:51:57 +02:00
|
|
|
-E # Stop after preprocessing
|
|
|
|
-MD # Generate a dependency file as a side-effect
|
2019-11-11 17:09:06 +01:00
|
|
|
-MF ${PROJECT_BINARY_DIR}/${BOARD}.dts.pre.d
|
|
|
|
-o ${PROJECT_BINARY_DIR}/${BOARD}.dts.pre.tmp
|
2019-10-15 14:51:57 +02:00
|
|
|
${ZEPHYR_BASE}/misc/empty_file.c
|
2019-11-11 17:09:06 +01:00
|
|
|
WORKING_DIRECTORY ${APPLICATION_SOURCE_DIR}
|
2017-10-27 15:43:34 +02:00
|
|
|
RESULT_VARIABLE ret
|
|
|
|
)
|
|
|
|
if(NOT "${ret}" STREQUAL "0")
|
|
|
|
message(FATAL_ERROR "command failed with return code: ${ret}")
|
|
|
|
endif()
|
|
|
|
|
2019-10-15 14:51:57 +02:00
|
|
|
# Parse the generated dependency file to find the DT sources that
|
|
|
|
# were included and then add them to the list of files that trigger
|
|
|
|
# a re-run of CMake.
|
|
|
|
toolchain_parse_make_rule(
|
|
|
|
${PROJECT_BINARY_DIR}/${BOARD}.dts.pre.d
|
|
|
|
include_files # Output parameter
|
|
|
|
)
|
|
|
|
|
|
|
|
set_property(DIRECTORY APPEND PROPERTY
|
|
|
|
CMAKE_CONFIGURE_DEPENDS
|
|
|
|
${include_files}
|
2020-04-10 20:40:41 +02:00
|
|
|
${GEN_DEFINES_SCRIPT}
|
2019-10-15 14:51:57 +02:00
|
|
|
)
|
|
|
|
|
2020-01-07 10:19:07 +01:00
|
|
|
#
|
|
|
|
# Run the C devicetree compiler on *.dts.pre.tmp, just to catch any
|
|
|
|
# warnings/errors from it. dtlib and edtlib parse the devicetree files
|
|
|
|
# themselves, so we don't rely on the C compiler otherwise.
|
|
|
|
#
|
2019-01-18 21:10:04 +01:00
|
|
|
|
2020-01-27 14:55:18 +01:00
|
|
|
if(DTC)
|
2019-01-18 21:10:04 +01:00
|
|
|
set(DTC_WARN_UNIT_ADDR_IF_ENABLED "")
|
|
|
|
check_dtc_flag("-Wunique_unit_address_if_enabled" check)
|
|
|
|
if (check)
|
|
|
|
set(DTC_WARN_UNIT_ADDR_IF_ENABLED "-Wunique_unit_address_if_enabled")
|
|
|
|
endif()
|
2019-01-24 16:46:08 +01:00
|
|
|
set(DTC_NO_WARN_UNIT_ADDR "")
|
|
|
|
check_dtc_flag("-Wno-unique_unit_address" check)
|
|
|
|
if (check)
|
|
|
|
set(DTC_NO_WARN_UNIT_ADDR "-Wno-unique_unit_address")
|
|
|
|
endif()
|
2017-10-27 15:43:34 +02:00
|
|
|
execute_process(
|
|
|
|
COMMAND ${DTC}
|
|
|
|
-O dts
|
2020-01-07 10:19:07 +01:00
|
|
|
-o - # Write output to stdout, which we discard below
|
2017-10-27 15:43:34 +02:00
|
|
|
-b 0
|
2018-10-03 09:13:06 +02:00
|
|
|
-E unit_address_vs_reg
|
2019-01-24 16:46:08 +01:00
|
|
|
${DTC_NO_WARN_UNIT_ADDR}
|
2019-01-18 21:10:04 +01:00
|
|
|
${DTC_WARN_UNIT_ADDR_IF_ENABLED}
|
2018-10-03 10:39:43 +02:00
|
|
|
${EXTRA_DTC_FLAGS} # User settable
|
2018-02-26 17:52:29 +01:00
|
|
|
${BOARD}.dts.pre.tmp
|
2020-01-07 10:19:07 +01:00
|
|
|
OUTPUT_QUIET # Discard stdout
|
2017-10-27 15:43:34 +02:00
|
|
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
|
|
|
RESULT_VARIABLE ret
|
|
|
|
)
|
|
|
|
if(NOT "${ret}" STREQUAL "0")
|
|
|
|
message(FATAL_ERROR "command failed with return code: ${ret}")
|
|
|
|
endif()
|
2020-01-27 14:55:18 +01:00
|
|
|
endif(DTC)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2018-12-17 20:09:47 +01:00
|
|
|
#
|
2020-07-08 23:43:07 +02:00
|
|
|
# Run gen_defines.py to create a header file, zephyr.dts, and edt.pickle.
|
2018-12-17 20:09:47 +01:00
|
|
|
#
|
|
|
|
|
2020-04-10 20:40:41 +02:00
|
|
|
set(CMD_EXTRACT ${PYTHON_EXECUTABLE} ${GEN_DEFINES_SCRIPT}
|
2018-12-17 20:09:47 +01:00
|
|
|
--dts ${BOARD}.dts.pre.tmp
|
2019-11-28 12:46:54 +01:00
|
|
|
--dtc-flags '${EXTRA_DTC_FLAGS}'
|
2019-09-24 12:25:12 +02:00
|
|
|
--bindings-dirs ${DTS_ROOT_BINDINGS}
|
2020-01-16 13:29:53 +01:00
|
|
|
--header-out ${DEVICETREE_UNFIXED_H}
|
2020-02-29 00:26:52 +01:00
|
|
|
--dts-out ${ZEPHYR_DTS} # As a debugging aid
|
2020-07-01 19:43:43 +02:00
|
|
|
--edt-pickle-out ${EDT_PICKLE}
|
2020-02-29 00:26:52 +01:00
|
|
|
)
|
|
|
|
|
2018-12-17 20:09:47 +01:00
|
|
|
execute_process(
|
2020-02-29 00:26:52 +01:00
|
|
|
COMMAND ${CMD_EXTRACT}
|
|
|
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
|
|
|
RESULT_VARIABLE ret
|
|
|
|
)
|
|
|
|
if(NOT "${ret}" STREQUAL "0")
|
|
|
|
message(FATAL_ERROR "gen_defines.py failed with return code: ${ret}")
|
|
|
|
else()
|
|
|
|
message(STATUS "Generated zephyr.dts: ${ZEPHYR_DTS}")
|
|
|
|
message(STATUS "Generated devicetree_unfixed.h: ${DEVICETREE_UNFIXED_H}")
|
|
|
|
endif()
|
|
|
|
|
2020-01-29 06:33:41 +01:00
|
|
|
# A file that used to be generated by 'dtc'. zephyr.dts is the new
|
|
|
|
# equivalent. Will be removed in Zephyr 2.3.
|
|
|
|
file(WRITE ${PROJECT_BINARY_DIR}/${BOARD}.dts_compiled
|
|
|
|
"See zephyr.dts for the final merged devicetree.")
|
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
else()
|
2020-01-16 13:29:53 +01:00
|
|
|
file(WRITE ${DEVICETREE_UNFIXED_H} "/* WARNING. THIS FILE IS AUTO-GENERATED. DO NOT MODIFY! */")
|
2019-01-18 16:47:05 +01:00
|
|
|
endif(SUPPORTS_DTS)
|