diff --git a/cmake/modules/boards.cmake b/cmake/modules/boards.cmake index f76d89a842..cb07262f15 100644 --- a/cmake/modules/boards.cmake +++ b/cmake/modules/boards.cmake @@ -297,10 +297,14 @@ elseif(HWMv2) if(LIST_BOARD_QUALIFIERS) # Allow users to omit the SoC when building for a board with a single SoC. list(LENGTH LIST_BOARD_SOCS socs_length) - if(NOT DEFINED BOARD_QUALIFIERS AND socs_length EQUAL 1) - set(BOARD_QUALIFIERS "/${LIST_BOARD_SOCS}") - elseif("${BOARD_QUALIFIERS}" MATCHES "^//.*" AND socs_length EQUAL 1) - string(REGEX REPLACE "^//" "/${LIST_BOARD_SOCS}/" BOARD_QUALIFIERS "${BOARD_QUALIFIERS}") + if(socs_length EQUAL 1) + set(BOARD_SINGLE_SOC TRUE) + set(BOARD_${BOARD}_SINGLE_SOC TRUE) + if(NOT DEFINED BOARD_QUALIFIERS) + set(BOARD_QUALIFIERS "/${LIST_BOARD_SOCS}") + elseif("${BOARD_QUALIFIERS}" MATCHES "^//.*") + string(REGEX REPLACE "^//" "/${LIST_BOARD_SOCS}/" BOARD_QUALIFIERS "${BOARD_QUALIFIERS}") + endif() endif() set(board_targets ${LIST_BOARD_QUALIFIERS}) diff --git a/cmake/modules/configuration_files.cmake b/cmake/modules/configuration_files.cmake index 708f0a3c98..78e7bf2a49 100644 --- a/cmake/modules/configuration_files.cmake +++ b/cmake/modules/configuration_files.cmake @@ -83,15 +83,14 @@ endif() # If still not found, search for other overlays in the configuration directory. if(NOT DEFINED DTC_OVERLAY_FILE) - zephyr_build_string(board_overlay_strings - BOARD ${BOARD} - BOARD_QUALIFIERS ${BOARD_QUALIFIERS} - MERGE - ) - list(TRANSFORM board_overlay_strings APPEND ".overlay") + zephyr_file(CONF_FILES ${APPLICATION_CONFIG_DIR} DTS DTC_OVERLAY_FILE) + + if(NOT DEFINED DTC_OVERLAY_FILE) + zephyr_file(CONF_FILES ${APPLICATION_CONFIG_DIR} DTS DTC_OVERLAY_FILE + NAMES "app.overlay" SUFFIX ${FILE_SUFFIX} + ) + endif() - zephyr_file(CONF_FILES ${APPLICATION_CONFIG_DIR} DTS DTC_OVERLAY_FILE - NAMES "${board_overlay_strings};app.overlay" SUFFIX ${FILE_SUFFIX}) endif() set(DTC_OVERLAY_FILE ${DTC_OVERLAY_FILE} CACHE STRING "If desired, you can \ diff --git a/cmake/modules/dts.cmake b/cmake/modules/dts.cmake index 294471b4ad..d1ff4df9bc 100644 --- a/cmake/modules/dts.cmake +++ b/cmake/modules/dts.cmake @@ -123,13 +123,23 @@ set(DTS_CMAKE ${PROJECT_BINARY_DIR}/dts.cmake) set(VENDOR_PREFIXES dts/bindings/vendor-prefixes.txt) if(NOT DEFINED DTS_SOURCE) - zephyr_build_string(dts_board_string BOARD ${BOARD} BOARD_QUALIFIERS ${BOARD_QUALIFIERS} MERGE) - foreach(str ${dts_board_string}) - if(EXISTS ${BOARD_DIR}/${str}.dts) - set(DTS_SOURCE ${BOARD_DIR}/${str}.dts) - break() - endif() - endforeach() + zephyr_build_string(board_string SHORT shortened_board_string + BOARD ${BOARD} BOARD_QUALIFIERS ${BOARD_QUALIFIERS} + ) + if(EXISTS ${BOARD_DIR}/${shortened_board_string}.dts AND NOT BOARD_${BOARD}_SINGLE_SOC) + message(FATAL_ERROR "Board ${ZFILE_BOARD} defines multiple SoCs.\nShortened file name " + "(${shortened_board_string}.dts) not allowed, use '_.dts' naming" + ) + elseif(EXISTS ${BOARD_DIR}/${board_string}.dts AND EXISTS ${BOARD_DIR}/${shortened_board_string}.dts) + message(FATAL_ERROR "Conflicting file names discovered. Cannot use both " + "${board_string}.dts and ${shortened_board_string}.dts. " + "Please choose one naming style, ${board_string}.dts is recommended." + ) + elseif(EXISTS ${BOARD_DIR}/${board_string}.dts) + set(DTS_SOURCE ${BOARD_DIR}/${board_string}.dts) + elseif(EXISTS ${BOARD_DIR}/${shortened_board_string}.dts) + set(DTS_SOURCE ${BOARD_DIR}/${shortened_board_string}.dts) + endif() endif() if(EXISTS ${DTS_SOURCE}) diff --git a/cmake/modules/extensions.cmake b/cmake/modules/extensions.cmake index 909887e639..4c989e808a 100644 --- a/cmake/modules/extensions.cmake +++ b/cmake/modules/extensions.cmake @@ -1519,7 +1519,8 @@ endfunction() # build string as first item in the list. # The full order of build strings returned in the list will be: # - Normalized board target build string, this includes qualifiers and revision -# - Normalized board target build string, without 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 @@ -1538,6 +1539,7 @@ endfunction() # ) # # : Output variable where the build string will be returned. +# SHORT : Output variable where the shortened build string will be returned. # BOARD : Board name to use when creating the build string. # BOARD_REVISION : Board revision to use when creating the build string. # BUILD : Build type to use when creating the build string. @@ -1560,11 +1562,17 @@ endfunction() # calling # zephyr_build_string(build_string BOARD alpha BOARD_REVISION 1.0.0 BOARD_QUALIFIERS /soc/bar MERGE) # will return a list of the following strings -# `alpha_soc_bar_1_0_0;alpha_soc_bar;alpha_bar` in `build_string` parameter. +# `alpha_soc_bar_1_0_0;alpha_soc_bar` in `build_string` parameter. +# +# calling +# zephyr_build_string(build_string SHORTENED short_build_string BOARD alpha BOARD_REVISION 1.0.0 BOARD_QUALIFIERS /soc/bar MERGE) +# will return two lists of the following strings +# `alpha_soc_bar_1_0_0;alpha_soc_bar` in `build_string` parameter. +# `alpha_bar_1_0_0;alpha_bar` in `short_build_string` parameter. # function(zephyr_build_string outvar) set(options MERGE REVERSE) - set(single_args BOARD BOARD_QUALIFIERS BOARD_REVISION BUILD) + set(single_args BOARD BOARD_QUALIFIERS BOARD_REVISION BUILD SHORT) cmake_parse_arguments(BUILD_STR "${options}" "${single_args}" "" ${ARGN}) if(BUILD_STR_UNPARSED_ARGUMENTS) @@ -1588,28 +1596,44 @@ function(zephyr_build_string outvar) ) endif() - string(REPLACE "/" ";" str_segment_list "${BUILD_STR_BOARD}${BUILD_STR_BOARD_QUALIFIERS}") + string(REPLACE "/" ";" str_segment_list "${BUILD_STR_BOARD_QUALIFIERS}") string(REPLACE "." "_" revision_string "${BUILD_STR_BOARD_REVISION}") - string(JOIN "_" ${outvar} ${str_segment_list} ${revision_string} ${BUILD_STR_BUILD}) + string(JOIN "_" ${outvar} ${BUILD_STR_BOARD} ${str_segment_list} ${revision_string} ${BUILD_STR_BUILD}) if(BUILD_STR_MERGE) - string(JOIN "_" variant_string ${str_segment_list} ${BUILD_STR_BUILD}) + string(JOIN "_" variant_string ${BUILD_STR_BOARD} ${str_segment_list} ${BUILD_STR_BUILD}) if(NOT "${variant_string}" IN_LIST ${outvar}) list(APPEND ${outvar} "${variant_string}") endif() - - if(BUILD_STR_BOARD_QUALIFIERS) - string(REGEX REPLACE "^/[^/]*(.*)" "\\1" qualifiers_without_soc "${BUILD_STR_BOARD_QUALIFIERS}") - string(REPLACE "/" "_" qualifiers_without_soc "${qualifiers_without_soc}") - list(APPEND ${outvar} "${BUILD_STR_BOARD}${qualifiers_without_soc}") - endif() endif() if(BUILD_STR_REVERSE) list(REVERSE ${outvar}) endif() + list(REMOVE_DUPLICATES ${outvar}) + + if(BUILD_STR_SHORT AND BUILD_STR_BOARD_QUALIFIERS) + string(REGEX REPLACE "^/[^/]*(.*)" "\\1" shortened_qualifiers "${BOARD_QUALIFIERS}") + string(REPLACE "/" ";" str_short_segment_list "${shortened_qualifiers}") + string(JOIN "_" ${BUILD_STR_SHORT} + ${BUILD_STR_BOARD} ${str_short_segment_list} ${revision_string} ${BUILD_STR_BUILD} + ) + if(BUILD_STR_MERGE) + string(JOIN "_" variant_string ${BUILD_STR_BOARD} ${str_short_segment_list} ${BUILD_STR_BUILD}) + + if(NOT "${variant_string}" IN_LIST ${BUILD_STR_SHORT}) + list(APPEND ${BUILD_STR_SHORT} "${variant_string}") + endif() + endif() + + if(BUILD_STR_REVERSE) + list(REVERSE ${BUILD_STR_SHORT}) + endif() + list(REMOVE_DUPLICATES ${BUILD_STR_SHORT}) + set(${BUILD_STR_SHORT} ${${BUILD_STR_SHORT}} PARENT_SCOPE) + endif() # This updates the provided outvar in parent scope (callers scope) set(${outvar} ${${outvar}} PARENT_SCOPE) @@ -2522,7 +2546,6 @@ endfunction() # creating file names based on board settings. # Only the first match found in will be # returned in the -# # DTS : List to append DTS overlay files in to # KCONF : List to append Kconfig fragment files in to # DEFCONF : List to append _defconfig files in to @@ -2618,32 +2641,44 @@ Relative paths are only allowed with `-D${ARGV1}=`") set(kconf_filename_list ${ZFILE_NAMES}) else() zephyr_build_string(filename_list + SHORT shortened_filename_list BOARD ${ZFILE_BOARD} BOARD_REVISION ${ZFILE_BOARD_REVISION} BOARD_QUALIFIERS ${ZFILE_BOARD_QUALIFIERS} BUILD ${ZFILE_BUILD} MERGE REVERSE ) - list(REMOVE_DUPLICATES filename_list) + set(dts_filename_list ${filename_list}) + set(dts_shortened_filename_list ${shortened_filename_list}) list(TRANSFORM dts_filename_list APPEND ".overlay") + list(TRANSFORM dts_shortened_filename_list APPEND ".overlay") set(kconf_filename_list ${filename_list}) + set(kconf_shortened_filename_list ${shortened_filename_list}) list(TRANSFORM kconf_filename_list APPEND ".conf") + list(TRANSFORM kconf_shortened_filename_list APPEND ".conf") endif() if(ZFILE_DTS) foreach(path ${ZFILE_CONF_FILES}) - foreach(filename ${dts_filename_list}) - if(NOT IS_ABSOLUTE ${filename}) - set(test_file ${path}/${filename}) - else() - set(test_file ${filename}) - endif() - zephyr_file_suffix(test_file SUFFIX ${ZFILE_SUFFIX}) + foreach(filename IN ZIP_LISTS dts_filename_list dts_shortened_filename_list) + foreach(i RANGE 1) + if(NOT IS_ABSOLUTE filename_${i} AND DEFINED filename_${i}) + set(test_file_${i} ${path}/${filename_${i}}) + else() + set(test_file_${i} ${filename_${i}}) + endif() + zephyr_file_suffix(test_file_${i} SUFFIX ${ZFILE_SUFFIX}) - if(EXISTS ${test_file}) - list(APPEND ${ZFILE_DTS} ${test_file}) + if(NOT EXISTS ${test_file_${i}}) + set(test_file_${i}) + endif() + endforeach() + + if(test_file_0 OR test_file_1) + list(APPEND found_dts_files ${test_file_0}) + list(APPEND found_dts_files ${test_file_1}) if(DEFINED ZFILE_BUILD) set(deprecated_file_found y) @@ -2653,29 +2688,48 @@ Relative paths are only allowed with `-D${ARGV1}=`") break() endif() endif() + + if(test_file_1 AND NOT BOARD_${ZFILE_BOARD}_SINGLE_SOC) + message(FATAL_ERROR "Board ${ZFILE_BOARD} defines multiple SoCs.\nShortened file name " + "(${filename_1}) not allowed, use '_.overlay' naming" + ) + endif() + + if(test_file_0 AND test_file_1) + message(FATAL_ERROR "Conflicting file names discovered. Cannot use both ${filename_0} " + "and ${filename_1}. Please choose one naming style, " + "${filename_0} is recommended." + ) + endif() endforeach() endforeach() + list(APPEND ${ZFILE_DTS} ${found_dts_files}) + # This updates the provided list in parent scope (callers scope) set(${ZFILE_DTS} ${${ZFILE_DTS}} PARENT_SCOPE) - - if(NOT ${ZFILE_DTS}) - set(not_found ${dts_filename_list}) - endif() endif() if(ZFILE_KCONF) + set(found_conf_files) foreach(path ${ZFILE_CONF_FILES}) - foreach(filename ${kconf_filename_list}) - if(NOT IS_ABSOLUTE ${filename}) - set(test_file ${path}/${filename}) - else() - set(test_file ${filename}) - endif() - zephyr_file_suffix(test_file SUFFIX ${ZFILE_SUFFIX}) + foreach(filename IN ZIP_LISTS kconf_filename_list kconf_shortened_filename_list) + foreach(i RANGE 1) + if(NOT IS_ABSOLUTE filename_${i} AND DEFINED filename_${i}) + set(test_file_${i} ${path}/${filename_${i}}) + else() + set(test_file_${i} ${filename_${i}}) + endif() + zephyr_file_suffix(test_file_${i} SUFFIX ${ZFILE_SUFFIX}) - if(EXISTS ${test_file}) - list(APPEND ${ZFILE_KCONF} ${test_file}) + if(NOT EXISTS ${test_file_${i}}) + set(test_file_${i}) + endif() + endforeach() + + if(test_file_0 OR test_file_1) + list(APPEND found_conf_files ${test_file_0}) + list(APPEND found_conf_files ${test_file_1}) if(DEFINED ZFILE_BUILD) set(deprecated_file_found y) @@ -2685,9 +2739,24 @@ Relative paths are only allowed with `-D${ARGV1}=`") break() endif() endif() + + if(test_file_1 AND NOT BOARD_${ZFILE_BOARD}_SINGLE_SOC) + message(FATAL_ERROR "Board ${ZFILE_BOARD} defines multiple SoCs.\nShortened file name " + "(${filename_1}) not allowed, use '_.conf' naming" + ) + endif() + + if(test_file_0 AND test_file_1) + message(FATAL_ERROR "Conflicting file names discovered. Cannot use both ${filename_0} " + "and ${filename_1}. Please choose one naming style, " + "${filename_0} is recommended." + ) + endif() endforeach() endforeach() + list(APPEND ${ZFILE_KCONF} ${found_conf_files}) + # This updates the provided list in parent scope (callers scope) set(${ZFILE_KCONF} ${${ZFILE_KCONF}} PARENT_SCOPE) @@ -2709,13 +2778,34 @@ Relative paths are only allowed with `-D${ARGV1}=`") endif() if(ZFILE_DEFCONFIG) + set(found_defconf_files) foreach(path ${ZFILE_CONF_FILES}) - foreach(filename ${filename_list}) - if(EXISTS ${path}/${filename}_defconfig) - list(APPEND ${ZFILE_DEFCONFIG} ${path}/${filename}_defconfig) + foreach(filename IN ZIP_LISTS filename_list shortened_filename_list) + foreach(i RANGE 1) + set(test_file_${i} ${path}/${filename_${i}}_defconfig) + + if(EXISTS ${test_file_${i}}) + list(APPEND found_defconf_files ${test_file_${i}}) + else() + set(test_file_${i}) + endif() + endforeach() + + if(test_file_1 AND NOT BOARD_${ZFILE_BOARD}_SINGLE_SOC) + message(FATAL_ERROR "Board ${ZFILE_BOARD} defines multiple SoCs.\nShortened file name " + "(${filename_1}_defconfig) not allowed, use '__defconfig' naming" + ) + endif() + + if(test_file_0 AND test_file_1) + message(FATAL_ERROR "Conflicting file names discovered. Cannot use both " + "${filename_0}_defconfig and ${filename_1}_defconfig. Please choose one " + "naming style, ${filename_0}_defconfig is recommended." + ) endif() endforeach() endforeach() + list(APPEND ${ZFILE_DEFCONFIG} ${found_defconf_files}) # This updates the provided list in parent scope (callers scope) set(${ZFILE_DEFCONFIG} ${${ZFILE_DEFCONFIG}} PARENT_SCOPE) @@ -4377,7 +4467,7 @@ function(zephyr_linker_dts_section) if(DTS_SECTION_UNPARSED_ARGUMENTS) message(FATAL_ERROR "zephyr_linker_dts_section(${ARGV0} ...) given unknown " - "arguments: ${DTS_SECTION_UNPARSED_ARGUMENTS}" + "arguments: ${DTS_SECTION_UNPARSED_ARGUMENTS}" ) endif()