Skip to content

Commit 4e3a01d

Browse files
tejlmandcarlescufi
authored andcommitted
cmake: support shortened file names for single SoC boards
This allow developers to create board files without the SoC name when the board only defines a single SoC. This means that a board, such as rpi_pico, which defines only a single SoC, rp2040, and one variant, now allows the following file names: Board target: rpi_pico/rp2040 - dts: rpi_pico_rp2040.dts, short: rpi_pico.dts - defconfig: rpi_pico_rp2040_defconfig, short: rpi_pico_defconfig - overlay: rpi_pico_rp2040.overlay, short: rpi_pico.overlay - conf: rpi_pico_rp2040.conf, short: rpi_pico.conf Board target: rpi_pico/rp2040/w - dts: rpi_pico_rp2040_w.dts, short: rpi_pico_w.dts - defconfig: rpi_pico_rp2040_w_defconfig, short: rpi_pico_w_defconfig - overlay: rpi_pico_rp2040_w.overlay, short: rpi_pico_w.overlay - conf: rpi_pico_rp2040_w.conf, short: rpi_pico_w.conf A multi CPU cluster board, nrf5340dk: Board target: nrf5340dk/nrf5340/cpunet - dts: nrf5340dk_nrf5340_cpunet.dts, short: nrf5340dk_cpunet.dts - defconfig: nrf5340dk_nrf5340_cpunet_defconfig, short: nrf5340dk_cpunet_defconfig - overlay: nrf5340dk_nrf5340_cpunet.overlay, short: nrf5340dk_cpunet.overlay - conf: nrf5340dk_nrf5340_cpunet.conf, short: nrf5340dk_cpunet.conf A multi SoC board, nrf5340dk (real: nrf52840, emulated: nrf52811): Board target: nrf52840dk/nrf52840 - dts: nrf52840dk_nrf52840.dts, short: Not possible - defconfig: nrf52840dk_nrf52840_defconfig, short: Not possible - overlay: nrf52840dk_nrf52840.overlay, short: Not possible - conf: nrf52840dk_nrf52840.conf, short: Not possible If two conflicting files are found, for example both rpi_pico_rp2040.overlay and rpi_pico.overlay, then an error is raised. If short form is detected for a board target with multiple SoCs, for example nrf52840dk_nrf52840.overlay and nrf52840dk.overlay, then an error is raised. Signed-off-by: Torsten Rasmussen <[email protected]>
1 parent 006ea0f commit 4e3a01d

File tree

4 files changed

+163
-60
lines changed

4 files changed

+163
-60
lines changed

cmake/modules/boards.cmake

+8-4
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,14 @@ elseif(HWMv2)
297297
if(LIST_BOARD_QUALIFIERS)
298298
# Allow users to omit the SoC when building for a board with a single SoC.
299299
list(LENGTH LIST_BOARD_SOCS socs_length)
300-
if(NOT DEFINED BOARD_QUALIFIERS AND socs_length EQUAL 1)
301-
set(BOARD_QUALIFIERS "/${LIST_BOARD_SOCS}")
302-
elseif("${BOARD_QUALIFIERS}" MATCHES "^//.*" AND socs_length EQUAL 1)
303-
string(REGEX REPLACE "^//" "/${LIST_BOARD_SOCS}/" BOARD_QUALIFIERS "${BOARD_QUALIFIERS}")
300+
if(socs_length EQUAL 1)
301+
set(BOARD_SINGLE_SOC TRUE)
302+
set(BOARD_${BOARD}_SINGLE_SOC TRUE)
303+
if(NOT DEFINED BOARD_QUALIFIERS)
304+
set(BOARD_QUALIFIERS "/${LIST_BOARD_SOCS}")
305+
elseif("${BOARD_QUALIFIERS}" MATCHES "^//.*")
306+
string(REGEX REPLACE "^//" "/${LIST_BOARD_SOCS}/" BOARD_QUALIFIERS "${BOARD_QUALIFIERS}")
307+
endif()
304308
endif()
305309

306310
set(board_targets ${LIST_BOARD_QUALIFIERS})

cmake/modules/configuration_files.cmake

+8-9
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,14 @@ endif()
8383

8484
# If still not found, search for other overlays in the configuration directory.
8585
if(NOT DEFINED DTC_OVERLAY_FILE)
86-
zephyr_build_string(board_overlay_strings
87-
BOARD ${BOARD}
88-
BOARD_QUALIFIERS ${BOARD_QUALIFIERS}
89-
MERGE
90-
)
91-
list(TRANSFORM board_overlay_strings APPEND ".overlay")
92-
93-
zephyr_file(CONF_FILES ${APPLICATION_CONFIG_DIR} DTS DTC_OVERLAY_FILE
94-
NAMES "${board_overlay_strings};app.overlay" SUFFIX ${FILE_SUFFIX})
86+
zephyr_file(CONF_FILES ${APPLICATION_CONFIG_DIR} DTS DTC_OVERLAY_FILE)
87+
88+
if(NOT DEFINED DTC_OVERLAY_FILE)
89+
zephyr_file(CONF_FILES ${APPLICATION_CONFIG_DIR} DTS DTC_OVERLAY_FILE
90+
NAMES "app.overlay" SUFFIX ${FILE_SUFFIX}
91+
)
92+
endif()
93+
9594
endif()
9695

9796
set(DTC_OVERLAY_FILE ${DTC_OVERLAY_FILE} CACHE STRING "If desired, you can \

cmake/modules/dts.cmake

+17-7
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,23 @@ set(DTS_CMAKE ${PROJECT_BINARY_DIR}/dts.cmake)
123123
set(VENDOR_PREFIXES dts/bindings/vendor-prefixes.txt)
124124

125125
if(NOT DEFINED DTS_SOURCE)
126-
zephyr_build_string(dts_board_string BOARD ${BOARD} BOARD_QUALIFIERS ${BOARD_QUALIFIERS} MERGE)
127-
foreach(str ${dts_board_string})
128-
if(EXISTS ${BOARD_DIR}/${str}.dts)
129-
set(DTS_SOURCE ${BOARD_DIR}/${str}.dts)
130-
break()
131-
endif()
132-
endforeach()
126+
zephyr_build_string(board_string SHORT shortened_board_string
127+
BOARD ${BOARD} BOARD_QUALIFIERS ${BOARD_QUALIFIERS}
128+
)
129+
if(EXISTS ${BOARD_DIR}/${shortened_board_string}.dts AND NOT BOARD_${BOARD}_SINGLE_SOC)
130+
message(FATAL_ERROR "Board ${ZFILE_BOARD} defines multiple SoCs.\nShortened file name "
131+
"(${shortened_board_string}.dts) not allowed, use '<board>_<soc>.dts' naming"
132+
)
133+
elseif(EXISTS ${BOARD_DIR}/${board_string}.dts AND EXISTS ${BOARD_DIR}/${shortened_board_string}.dts)
134+
message(FATAL_ERROR "Conflicting file names discovered. Cannot use both "
135+
"${board_string}.dts and ${shortened_board_string}.dts. "
136+
"Please choose one naming style, ${board_string}.dts is recommended."
137+
)
138+
elseif(EXISTS ${BOARD_DIR}/${board_string}.dts)
139+
set(DTS_SOURCE ${BOARD_DIR}/${board_string}.dts)
140+
elseif(EXISTS ${BOARD_DIR}/${shortened_board_string}.dts)
141+
set(DTS_SOURCE ${BOARD_DIR}/${shortened_board_string}.dts)
142+
endif()
133143
endif()
134144

135145
if(EXISTS ${DTS_SOURCE})

cmake/modules/extensions.cmake

+130-40
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,8 @@ endfunction()
15191519
# build string as first item in the list.
15201520
# The full order of build strings returned in the list will be:
15211521
# - Normalized board target build string, this includes qualifiers and revision
1522-
# - Normalized board target build string, without revision
1522+
# - Build string with board variants removed in addition
1523+
# - Build string with cpuset removed in addition
15231524
# - Build string with soc removed in addition
15241525
#
15251526
# If BUILD is supplied, then build type will be appended to each entry in the
@@ -1538,6 +1539,7 @@ endfunction()
15381539
# )
15391540
#
15401541
# <out-variable>: Output variable where the build string will be returned.
1542+
# SHORT <out-variable>: Output variable where the shortened build string will be returned.
15411543
# BOARD <board>: Board name to use when creating the build string.
15421544
# BOARD_REVISION <revision>: Board revision to use when creating the build string.
15431545
# BUILD <type>: Build type to use when creating the build string.
@@ -1560,11 +1562,17 @@ endfunction()
15601562
# calling
15611563
# zephyr_build_string(build_string BOARD alpha BOARD_REVISION 1.0.0 BOARD_QUALIFIERS /soc/bar MERGE)
15621564
# will return a list of the following strings
1563-
# `alpha_soc_bar_1_0_0;alpha_soc_bar;alpha_bar` in `build_string` parameter.
1565+
# `alpha_soc_bar_1_0_0;alpha_soc_bar` in `build_string` parameter.
1566+
#
1567+
# calling
1568+
# zephyr_build_string(build_string SHORTENED short_build_string BOARD alpha BOARD_REVISION 1.0.0 BOARD_QUALIFIERS /soc/bar MERGE)
1569+
# will return two lists of the following strings
1570+
# `alpha_soc_bar_1_0_0;alpha_soc_bar` in `build_string` parameter.
1571+
# `alpha_bar_1_0_0;alpha_bar` in `short_build_string` parameter.
15641572
#
15651573
function(zephyr_build_string outvar)
15661574
set(options MERGE REVERSE)
1567-
set(single_args BOARD BOARD_QUALIFIERS BOARD_REVISION BUILD)
1575+
set(single_args BOARD BOARD_QUALIFIERS BOARD_REVISION BUILD SHORT)
15681576

15691577
cmake_parse_arguments(BUILD_STR "${options}" "${single_args}" "" ${ARGN})
15701578
if(BUILD_STR_UNPARSED_ARGUMENTS)
@@ -1588,28 +1596,44 @@ function(zephyr_build_string outvar)
15881596
)
15891597
endif()
15901598

1591-
string(REPLACE "/" ";" str_segment_list "${BUILD_STR_BOARD}${BUILD_STR_BOARD_QUALIFIERS}")
1599+
string(REPLACE "/" ";" str_segment_list "${BUILD_STR_BOARD_QUALIFIERS}")
15921600
string(REPLACE "." "_" revision_string "${BUILD_STR_BOARD_REVISION}")
15931601

1594-
string(JOIN "_" ${outvar} ${str_segment_list} ${revision_string} ${BUILD_STR_BUILD})
1602+
string(JOIN "_" ${outvar} ${BUILD_STR_BOARD} ${str_segment_list} ${revision_string} ${BUILD_STR_BUILD})
15951603

15961604
if(BUILD_STR_MERGE)
1597-
string(JOIN "_" variant_string ${str_segment_list} ${BUILD_STR_BUILD})
1605+
string(JOIN "_" variant_string ${BUILD_STR_BOARD} ${str_segment_list} ${BUILD_STR_BUILD})
15981606

15991607
if(NOT "${variant_string}" IN_LIST ${outvar})
16001608
list(APPEND ${outvar} "${variant_string}")
16011609
endif()
1602-
1603-
if(BUILD_STR_BOARD_QUALIFIERS)
1604-
string(REGEX REPLACE "^/[^/]*(.*)" "\\1" qualifiers_without_soc "${BUILD_STR_BOARD_QUALIFIERS}")
1605-
string(REPLACE "/" "_" qualifiers_without_soc "${qualifiers_without_soc}")
1606-
list(APPEND ${outvar} "${BUILD_STR_BOARD}${qualifiers_without_soc}")
1607-
endif()
16081610
endif()
16091611

16101612
if(BUILD_STR_REVERSE)
16111613
list(REVERSE ${outvar})
16121614
endif()
1615+
list(REMOVE_DUPLICATES ${outvar})
1616+
1617+
if(BUILD_STR_SHORT AND BUILD_STR_BOARD_QUALIFIERS)
1618+
string(REGEX REPLACE "^/[^/]*(.*)" "\\1" shortened_qualifiers "${BOARD_QUALIFIERS}")
1619+
string(REPLACE "/" ";" str_short_segment_list "${shortened_qualifiers}")
1620+
string(JOIN "_" ${BUILD_STR_SHORT}
1621+
${BUILD_STR_BOARD} ${str_short_segment_list} ${revision_string} ${BUILD_STR_BUILD}
1622+
)
1623+
if(BUILD_STR_MERGE)
1624+
string(JOIN "_" variant_string ${BUILD_STR_BOARD} ${str_short_segment_list} ${BUILD_STR_BUILD})
1625+
1626+
if(NOT "${variant_string}" IN_LIST ${BUILD_STR_SHORT})
1627+
list(APPEND ${BUILD_STR_SHORT} "${variant_string}")
1628+
endif()
1629+
endif()
1630+
1631+
if(BUILD_STR_REVERSE)
1632+
list(REVERSE ${BUILD_STR_SHORT})
1633+
endif()
1634+
list(REMOVE_DUPLICATES ${BUILD_STR_SHORT})
1635+
set(${BUILD_STR_SHORT} ${${BUILD_STR_SHORT}} PARENT_SCOPE)
1636+
endif()
16131637

16141638
# This updates the provided outvar in parent scope (callers scope)
16151639
set(${outvar} ${${outvar}} PARENT_SCOPE)
@@ -2522,7 +2546,6 @@ endfunction()
25222546
# creating file names based on board settings.
25232547
# Only the first match found in <paths> will be
25242548
# returned in the <list>
2525-
#
25262549
# DTS <list>: List to append DTS overlay files in <path> to
25272550
# KCONF <list>: List to append Kconfig fragment files in <path> to
25282551
# DEFCONF <list>: List to append _defconfig files in <path> to
@@ -2618,32 +2641,44 @@ Relative paths are only allowed with `-D${ARGV1}=<path>`")
26182641
set(kconf_filename_list ${ZFILE_NAMES})
26192642
else()
26202643
zephyr_build_string(filename_list
2644+
SHORT shortened_filename_list
26212645
BOARD ${ZFILE_BOARD}
26222646
BOARD_REVISION ${ZFILE_BOARD_REVISION}
26232647
BOARD_QUALIFIERS ${ZFILE_BOARD_QUALIFIERS}
26242648
BUILD ${ZFILE_BUILD}
26252649
MERGE REVERSE
26262650
)
2627-
list(REMOVE_DUPLICATES filename_list)
2651+
26282652
set(dts_filename_list ${filename_list})
2653+
set(dts_shortened_filename_list ${shortened_filename_list})
26292654
list(TRANSFORM dts_filename_list APPEND ".overlay")
2655+
list(TRANSFORM dts_shortened_filename_list APPEND ".overlay")
26302656

26312657
set(kconf_filename_list ${filename_list})
2658+
set(kconf_shortened_filename_list ${shortened_filename_list})
26322659
list(TRANSFORM kconf_filename_list APPEND ".conf")
2660+
list(TRANSFORM kconf_shortened_filename_list APPEND ".conf")
26332661
endif()
26342662

26352663
if(ZFILE_DTS)
26362664
foreach(path ${ZFILE_CONF_FILES})
2637-
foreach(filename ${dts_filename_list})
2638-
if(NOT IS_ABSOLUTE ${filename})
2639-
set(test_file ${path}/${filename})
2640-
else()
2641-
set(test_file ${filename})
2642-
endif()
2643-
zephyr_file_suffix(test_file SUFFIX ${ZFILE_SUFFIX})
2665+
foreach(filename IN ZIP_LISTS dts_filename_list dts_shortened_filename_list)
2666+
foreach(i RANGE 1)
2667+
if(NOT IS_ABSOLUTE filename_${i} AND DEFINED filename_${i})
2668+
set(test_file_${i} ${path}/${filename_${i}})
2669+
else()
2670+
set(test_file_${i} ${filename_${i}})
2671+
endif()
2672+
zephyr_file_suffix(test_file_${i} SUFFIX ${ZFILE_SUFFIX})
26442673

2645-
if(EXISTS ${test_file})
2646-
list(APPEND ${ZFILE_DTS} ${test_file})
2674+
if(NOT EXISTS ${test_file_${i}})
2675+
set(test_file_${i})
2676+
endif()
2677+
endforeach()
2678+
2679+
if(test_file_0 OR test_file_1)
2680+
list(APPEND found_dts_files ${test_file_0})
2681+
list(APPEND found_dts_files ${test_file_1})
26472682

26482683
if(DEFINED ZFILE_BUILD)
26492684
set(deprecated_file_found y)
@@ -2653,29 +2688,48 @@ Relative paths are only allowed with `-D${ARGV1}=<path>`")
26532688
break()
26542689
endif()
26552690
endif()
2691+
2692+
if(test_file_1 AND NOT BOARD_${ZFILE_BOARD}_SINGLE_SOC)
2693+
message(FATAL_ERROR "Board ${ZFILE_BOARD} defines multiple SoCs.\nShortened file name "
2694+
"(${filename_1}) not allowed, use '<board>_<soc>.overlay' naming"
2695+
)
2696+
endif()
2697+
2698+
if(test_file_0 AND test_file_1)
2699+
message(FATAL_ERROR "Conflicting file names discovered. Cannot use both ${filename_0} "
2700+
"and ${filename_1}. Please choose one naming style, "
2701+
"${filename_0} is recommended."
2702+
)
2703+
endif()
26562704
endforeach()
26572705
endforeach()
26582706

2707+
list(APPEND ${ZFILE_DTS} ${found_dts_files})
2708+
26592709
# This updates the provided list in parent scope (callers scope)
26602710
set(${ZFILE_DTS} ${${ZFILE_DTS}} PARENT_SCOPE)
2661-
2662-
if(NOT ${ZFILE_DTS})
2663-
set(not_found ${dts_filename_list})
2664-
endif()
26652711
endif()
26662712

26672713
if(ZFILE_KCONF)
2714+
set(found_conf_files)
26682715
foreach(path ${ZFILE_CONF_FILES})
2669-
foreach(filename ${kconf_filename_list})
2670-
if(NOT IS_ABSOLUTE ${filename})
2671-
set(test_file ${path}/${filename})
2672-
else()
2673-
set(test_file ${filename})
2674-
endif()
2675-
zephyr_file_suffix(test_file SUFFIX ${ZFILE_SUFFIX})
2716+
foreach(filename IN ZIP_LISTS kconf_filename_list kconf_shortened_filename_list)
2717+
foreach(i RANGE 1)
2718+
if(NOT IS_ABSOLUTE filename_${i} AND DEFINED filename_${i})
2719+
set(test_file_${i} ${path}/${filename_${i}})
2720+
else()
2721+
set(test_file_${i} ${filename_${i}})
2722+
endif()
2723+
zephyr_file_suffix(test_file_${i} SUFFIX ${ZFILE_SUFFIX})
2724+
2725+
if(NOT EXISTS ${test_file_${i}})
2726+
set(test_file_${i})
2727+
endif()
2728+
endforeach()
26762729

2677-
if(EXISTS ${test_file})
2678-
list(APPEND ${ZFILE_KCONF} ${test_file})
2730+
if(test_file_0 OR test_file_1)
2731+
list(APPEND found_conf_files ${test_file_0})
2732+
list(APPEND found_conf_files ${test_file_1})
26792733

26802734
if(DEFINED ZFILE_BUILD)
26812735
set(deprecated_file_found y)
@@ -2685,9 +2739,24 @@ Relative paths are only allowed with `-D${ARGV1}=<path>`")
26852739
break()
26862740
endif()
26872741
endif()
2742+
2743+
if(test_file_1 AND NOT BOARD_${ZFILE_BOARD}_SINGLE_SOC)
2744+
message(FATAL_ERROR "Board ${ZFILE_BOARD} defines multiple SoCs.\nShortened file name "
2745+
"(${filename_1}) not allowed, use '<board>_<soc>.conf' naming"
2746+
)
2747+
endif()
2748+
2749+
if(test_file_0 AND test_file_1)
2750+
message(FATAL_ERROR "Conflicting file names discovered. Cannot use both ${filename_0} "
2751+
"and ${filename_1}. Please choose one naming style, "
2752+
"${filename_0} is recommended."
2753+
)
2754+
endif()
26882755
endforeach()
26892756
endforeach()
26902757

2758+
list(APPEND ${ZFILE_KCONF} ${found_conf_files})
2759+
26912760
# This updates the provided list in parent scope (callers scope)
26922761
set(${ZFILE_KCONF} ${${ZFILE_KCONF}} PARENT_SCOPE)
26932762

@@ -2709,13 +2778,34 @@ Relative paths are only allowed with `-D${ARGV1}=<path>`")
27092778
endif()
27102779

27112780
if(ZFILE_DEFCONFIG)
2781+
set(found_defconf_files)
27122782
foreach(path ${ZFILE_CONF_FILES})
2713-
foreach(filename ${filename_list})
2714-
if(EXISTS ${path}/${filename}_defconfig)
2715-
list(APPEND ${ZFILE_DEFCONFIG} ${path}/${filename}_defconfig)
2783+
foreach(filename IN ZIP_LISTS filename_list shortened_filename_list)
2784+
foreach(i RANGE 1)
2785+
set(test_file_${i} ${path}/${filename_${i}}_defconfig)
2786+
2787+
if(EXISTS ${test_file_${i}})
2788+
list(APPEND found_defconf_files ${test_file_${i}})
2789+
else()
2790+
set(test_file_${i})
2791+
endif()
2792+
endforeach()
2793+
2794+
if(test_file_1 AND NOT BOARD_${ZFILE_BOARD}_SINGLE_SOC)
2795+
message(FATAL_ERROR "Board ${ZFILE_BOARD} defines multiple SoCs.\nShortened file name "
2796+
"(${filename_1}_defconfig) not allowed, use '<board>_<soc>_defconfig' naming"
2797+
)
2798+
endif()
2799+
2800+
if(test_file_0 AND test_file_1)
2801+
message(FATAL_ERROR "Conflicting file names discovered. Cannot use both "
2802+
"${filename_0}_defconfig and ${filename_1}_defconfig. Please choose one "
2803+
"naming style, ${filename_0}_defconfig is recommended."
2804+
)
27162805
endif()
27172806
endforeach()
27182807
endforeach()
2808+
list(APPEND ${ZFILE_DEFCONFIG} ${found_defconf_files})
27192809

27202810
# This updates the provided list in parent scope (callers scope)
27212811
set(${ZFILE_DEFCONFIG} ${${ZFILE_DEFCONFIG}} PARENT_SCOPE)
@@ -4377,7 +4467,7 @@ function(zephyr_linker_dts_section)
43774467

43784468
if(DTS_SECTION_UNPARSED_ARGUMENTS)
43794469
message(FATAL_ERROR "zephyr_linker_dts_section(${ARGV0} ...) given unknown "
4380-
"arguments: ${DTS_SECTION_UNPARSED_ARGUMENTS}"
4470+
"arguments: ${DTS_SECTION_UNPARSED_ARGUMENTS}"
43814471
)
43824472
endif()
43834473

0 commit comments

Comments
 (0)