cmake: enhanced board entry file handling
With a single board now covering what used to be several boards, and with the ability to omit SoC when building for a single SoC board, then <board>_defconfig and <board>.dts lookup is improved. A single SoC board may prefer to keep its defconfig entry point as <board>_defconfig instead of <board>_<soc>_defconfig. Also, a multi-SoC board / multi-core SoC board, which used to be implemented as n-boards may wish to have common _defconfig settings in a common <board>_defconfig file, and the SoC / cpuset specifics in <board>_<soc>_defconfig / <board>_<soc>_<core>_defconfig. Such defconfig support allows also to place build variant specifics in its own <board>_<soc>_<variant>_defconfig file. This commit allows multiple _defconfigs for a board and its identifiers. Similar is implemented for a board's dts file. If a <board>_<soc>_<core>.dts file is not found, the build system will instead use <board>_<soc>.dts, and finally fallback to <board>.dts. This allows a board to have a shared dts file for all board identifiers which are identical while still support specific dts where required. A dts file is a devicetree starting point and thus two dts files cannot be used in together. For such cases, an ordinary board overlay file must be used. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
committed by
Jamie McCrae
parent
312265ee04
commit
4e203c14c7
@@ -122,9 +122,16 @@ set(DTS_CMAKE ${PROJECT_BINARY_DIR}/dts.cmake)
|
||||
# modules.
|
||||
set(VENDOR_PREFIXES dts/bindings/vendor-prefixes.txt)
|
||||
|
||||
zephyr_build_string(dts_board_string BOARD ${BOARD} BOARD_IDENTIFIER ${BOARD_IDENTIFIER})
|
||||
if(NOT DEFINED DTS_SOURCE)
|
||||
zephyr_build_string(dts_board_string BOARD ${BOARD} BOARD_IDENTIFIER ${BOARD_IDENTIFIER} MERGE)
|
||||
foreach(str ${dts_board_string})
|
||||
if(EXISTS ${BOARD_DIR}/${str}.dts)
|
||||
set(DTS_SOURCE ${BOARD_DIR}/${str}.dts)
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
set_ifndef(DTS_SOURCE ${BOARD_DIR}/${dts_board_string}.dts)
|
||||
if(EXISTS ${DTS_SOURCE})
|
||||
# We found a devicetree. Check for a board revision overlay.
|
||||
if(DEFINED BOARD_REVISION)
|
||||
|
||||
@@ -1510,6 +1510,22 @@ endfunction()
|
||||
#
|
||||
# This is a common function to ensure that build strings are always created
|
||||
# in a uniform way.
|
||||
# A single string is returned containing the full build string constructed from
|
||||
# all arguments.
|
||||
#
|
||||
# When MERGE is supplied a list of build strings will be returned with the full
|
||||
# build string as first item in the list.
|
||||
# The full order of build strings returned in the list will be:
|
||||
# - Full build string, including identifier and revision
|
||||
# - Build string with board variants removed in addition
|
||||
# - Build string with cpuset removed in addition
|
||||
# - Build string with soc removed in addition
|
||||
#
|
||||
# If BUILD is supplied, then build type will be appended to each entry in the
|
||||
# list above.
|
||||
# If REVISION is supplied or obtained as system wide setting a build string
|
||||
# with the sanitized revision string will be added in addition to the
|
||||
# non-revisioned entry for each entry.
|
||||
#
|
||||
# Usage:
|
||||
# zephyr_build_string(<out-variable>
|
||||
@@ -1517,12 +1533,15 @@ endfunction()
|
||||
# [BOARD_IDENTIFIER <identifier>]
|
||||
# [BOARD_REVISION <revision>]
|
||||
# [BUILD <type>]
|
||||
# [MERGE [REVERSE]]
|
||||
# )
|
||||
#
|
||||
# <out-variable>: Output variable where the build string will be returned.
|
||||
# BOARD <board>: Board name to use when creating the build string.
|
||||
# BOARD_REVISION <revision>: Board revision to use when creating the build string.
|
||||
# BUILD <type>: Build type to use when creating the build string.
|
||||
# MERGE: Return a list of build identifiers instead of a single build string.
|
||||
# REVERSE: Reverse the list before returning it.
|
||||
#
|
||||
# Examples
|
||||
# calling
|
||||
@@ -1533,10 +1552,20 @@ endfunction()
|
||||
# zephyr_build_string(build_string BOARD alpha BOARD_REVISION 1.0.0 BUILD debug)
|
||||
# will return the string `alpha_1_0_0_debug` in `build_string` parameter.
|
||||
#
|
||||
# calling
|
||||
# zephyr_build_string(build_string BOARD alpha BOARD_IDENTIFIER /soc/bar)
|
||||
# will return the string `alpha_soc_bar` in `build_string` parameter.
|
||||
#
|
||||
# calling
|
||||
# zephyr_build_string(build_string BOARD alpha BOARD_REVISION 1.0.0 BOARD_IDENTIFIER /soc/bar MERGE)
|
||||
# will return a list of the following strings
|
||||
# `alpha_soc_bar_1_0_0;alpha_soc_bar;alpha_soc_1_0_0;alpha_soc;alpha_1_0_0;alpha` in `build_string` parameter.
|
||||
#
|
||||
function(zephyr_build_string outvar)
|
||||
set(options MERGE REVERSE)
|
||||
set(single_args BOARD BOARD_IDENTIFIER BOARD_REVISION BUILD)
|
||||
|
||||
cmake_parse_arguments(BUILD_STR "" "${single_args}" "" ${ARGN})
|
||||
cmake_parse_arguments(BUILD_STR "${options}" "${single_args}" "" ${ARGN})
|
||||
if(BUILD_STR_UNPARSED_ARGUMENTS)
|
||||
message(FATAL_ERROR
|
||||
"zephyr_build_string(${ARGV0} <val> ...) given unknown arguments:"
|
||||
@@ -1558,20 +1587,30 @@ function(zephyr_build_string outvar)
|
||||
)
|
||||
endif()
|
||||
|
||||
set(${outvar} ${BUILD_STR_BOARD})
|
||||
string(REPLACE "/" ";" str_segment_list "${BUILD_STR_BOARD}${BUILD_STR_BOARD_IDENTIFIER}")
|
||||
string(REPLACE "." "_" revision_string "${BUILD_STR_BOARD_REVISION}")
|
||||
|
||||
if(DEFINED BUILD_STR_BOARD_IDENTIFIER)
|
||||
string(REPLACE "/" "_" variant_string ${BUILD_STR_BOARD_IDENTIFIER})
|
||||
set(${outvar} "${${outvar}}${variant_string}")
|
||||
string(JOIN "_" ${outvar} ${str_segment_list} ${revision_string} ${BUILD_STR_BUILD})
|
||||
|
||||
if(BUILD_STR_MERGE)
|
||||
if(DEFINED BUILD_STR_BOARD_REVISION)
|
||||
string(JOIN "_" variant_string ${str_segment_list} ${BUILD_STR_BUILD})
|
||||
list(APPEND ${outvar} "${variant_string}")
|
||||
endif()
|
||||
list(POP_BACK str_segment_list)
|
||||
while(NOT str_segment_list STREQUAL "")
|
||||
if(DEFINED BUILD_STR_BOARD_REVISION)
|
||||
string(JOIN "_" variant_string ${str_segment_list} ${revision_string} ${BUILD_STR_BUILD})
|
||||
list(APPEND ${outvar} "${variant_string}")
|
||||
endif()
|
||||
string(JOIN "_" variant_string ${str_segment_list} ${BUILD_STR_BUILD})
|
||||
list(APPEND ${outvar} "${variant_string}")
|
||||
list(POP_BACK str_segment_list)
|
||||
endwhile()
|
||||
endif()
|
||||
|
||||
if(DEFINED BUILD_STR_BOARD_REVISION)
|
||||
string(REPLACE "." "_" revision_string ${BUILD_STR_BOARD_REVISION})
|
||||
set(${outvar} "${${outvar}}_${revision_string}")
|
||||
endif()
|
||||
|
||||
if(BUILD_STR_BUILD)
|
||||
set(${outvar} "${${outvar}}_${BUILD_STR_BUILD}")
|
||||
if(BUILD_STR_REVERSE)
|
||||
list(REVERSE ${outvar})
|
||||
endif()
|
||||
|
||||
# This updates the provided outvar in parent scope (callers scope)
|
||||
@@ -2449,6 +2488,7 @@ endfunction()
|
||||
# files are returned. Configuration files will be:
|
||||
# - DTS: Overlay files (.overlay)
|
||||
# - Kconfig: Config fragments (.conf)
|
||||
# - defconfig: defconfig files (_defconfig)
|
||||
# The conf file search will return existing configuration
|
||||
# files for the current board.
|
||||
# CONF_FILES takes the following additional arguments:
|
||||
@@ -2467,6 +2507,7 @@ endfunction()
|
||||
#
|
||||
# DTS <list>: List to append DTS overlay files in <path> to
|
||||
# KCONF <list>: List to append Kconfig fragment files in <path> to
|
||||
# DEFCONF <list>: List to append _defconfig files in <path> to
|
||||
# BUILD <type>: Build type to include for search.
|
||||
# For example:
|
||||
# BUILD debug, will look for <board>_debug.conf
|
||||
@@ -2490,7 +2531,7 @@ Please provide one of following: APPLICATION_ROOT, CONF_FILES")
|
||||
set(single_args APPLICATION_ROOT)
|
||||
elseif(${ARGV0} STREQUAL CONF_FILES)
|
||||
set(options REQUIRED)
|
||||
set(single_args BOARD BOARD_REVISION DTS KCONF BUILD SUFFIX)
|
||||
set(single_args BOARD BOARD_REVISION BOARD_IDENTIFIER DTS KCONF DEFCONFIG BUILD SUFFIX)
|
||||
set(multi_args CONF_FILES NAMES)
|
||||
endif()
|
||||
|
||||
@@ -2548,24 +2589,23 @@ Relative paths are only allowed with `-D${ARGV1}=<path>`")
|
||||
if(DEFINED BOARD_REVISION)
|
||||
set(FILE_BOARD_REVISION ${BOARD_REVISION})
|
||||
endif()
|
||||
|
||||
if(DEFINED BOARD_IDENTIFIER)
|
||||
set(FILE_BOARD_IDENTIFIER ${BOARD_IDENTIFIER})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(FILE_NAMES)
|
||||
set(dts_filename_list ${FILE_NAMES})
|
||||
set(kconf_filename_list ${FILE_NAMES})
|
||||
else()
|
||||
zephyr_build_string(filename
|
||||
BOARD ${FILE_BOARD}
|
||||
BUILD ${FILE_BUILD}
|
||||
)
|
||||
set(filename_list ${filename})
|
||||
|
||||
zephyr_build_string(filename
|
||||
zephyr_build_string(filename_list
|
||||
BOARD ${FILE_BOARD}
|
||||
BOARD_REVISION ${FILE_BOARD_REVISION}
|
||||
BOARD_IDENTIFIER ${FILE_BOARD_IDENTIFIER}
|
||||
BUILD ${FILE_BUILD}
|
||||
MERGE REVERSE
|
||||
)
|
||||
list(APPEND filename_list ${filename})
|
||||
list(REMOVE_DUPLICATES filename_list)
|
||||
set(dts_filename_list ${filename_list})
|
||||
list(TRANSFORM dts_filename_list APPEND ".overlay")
|
||||
@@ -2649,6 +2689,19 @@ Relative paths are only allowed with `-D${ARGV1}=<path>`")
|
||||
message(DEPRECATION "prj_<build>.conf was deprecated after Zephyr 3.5,"
|
||||
" you should switch to using -DFILE_SUFFIX instead")
|
||||
endif()
|
||||
|
||||
if(FILE_DEFCONFIG)
|
||||
foreach(path ${FILE_CONF_FILES})
|
||||
foreach(filename ${filename_list})
|
||||
if(EXISTS ${path}/${filename}_defconfig)
|
||||
list(APPEND ${FILE_DEFCONFIG} ${path}/${filename}_defconfig)
|
||||
endif()
|
||||
endforeach()
|
||||
endforeach()
|
||||
|
||||
# This updates the provided list in parent scope (callers scope)
|
||||
set(${FILE_DEFCONFIG} ${${FILE_DEFCONFIG}} PARENT_SCOPE)
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
|
||||
@@ -74,14 +74,23 @@ else()
|
||||
set(KCONFIG_ROOT ${ZEPHYR_BASE}/Kconfig)
|
||||
endif()
|
||||
|
||||
zephyr_build_string(config_board_string BOARD ${BOARD} BOARD_IDENTIFIER ${BOARD_IDENTIFIER})
|
||||
|
||||
if(NOT DEFINED BOARD_DEFCONFIG)
|
||||
set(BOARD_DEFCONFIG ${BOARD_DIR}/${config_board_string}_defconfig)
|
||||
zephyr_file(CONF_FILES ${BOARD_DIR} DEFCONFIG BOARD_DEFCONFIG)
|
||||
endif()
|
||||
if((DEFINED BOARD_REVISION) AND EXISTS ${BOARD_DIR}/${config_board_string}_${BOARD_REVISION_STRING}.conf)
|
||||
set_ifndef(BOARD_REVISION_CONFIG ${BOARD_DIR}/${config_board_string}_${BOARD_REVISION_STRING}.conf)
|
||||
|
||||
if(DEFINED BOARD_REVISION)
|
||||
zephyr_build_string(config_board_string
|
||||
BOARD ${BOARD}
|
||||
BOARD_IDENTIFIER ${BOARD_IDENTIFIER}
|
||||
BOARD_REVISION ${BOARD_REVISION}
|
||||
)
|
||||
set(board_rev_file ${config_board_string})
|
||||
if(EXISTS ${BOARD_DIR}/${board_rev_file}.conf)
|
||||
message(DEPRECATION "Use of '${board_rev_file}.conf' is deprecated, please switch to '${board_rev_file}_defconfig'")
|
||||
set_ifndef(BOARD_REVISION_CONFIG ${BOARD_DIR}/${board_rev_file}.conf)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(DOTCONFIG ${PROJECT_BINARY_DIR}/.config)
|
||||
set(PARSED_KCONFIG_SOURCES_TXT ${PROJECT_BINARY_DIR}/kconfig/sources.txt)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user