Skip to content

Commit 09661c5

Browse files
tejlmand57300
authored andcommitted
[nrf fromtree] cmake: scripts: support board extension
Fixes: #69548 Support extending an existing board with new board variants. This commit introduces the following changes to allow a board to be extended out-of-tree. The board yaml schema is extended to support an extend field which will be used to identify the board to be extended. A board 'plank' can be extended like this: > board: > extend: plank > variants: > - name: ext > qualifier: soc1 For the rest of the build system this means that there is no longer a single board directory. The existing CMake variable BOARD_DIR is kept and reference the directory which defines the board. A new CMake variable BOARD_DIRECTORIES provides a list of all directories which defines board targets for the board. This means the directory which defines the board as well as all directories that extends the board. Signed-off-by: Torsten Rasmussen <[email protected]> (cherry picked from commit 536d34f)
1 parent 769594f commit 09661c5

File tree

19 files changed

+200
-102
lines changed

19 files changed

+200
-102
lines changed

Kconfig.zephyr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ osource "${APPLICATION_SOURCE_DIR}/VERSION"
1717
# Shield defaults should have precedence over board defaults, which should have
1818
# precedence over SoC defaults, so include them in that order.
1919
#
20-
# $ARCH and $BOARD_DIR will be glob patterns when building documentation.
20+
# $ARCH and $KCONFIG_BOARD_DIR will be glob patterns when building documentation.
2121
# This loads custom shields defconfigs (from BOARD_ROOT)
2222
osource "$(KCONFIG_BINARY_DIR)/Kconfig.shield.defconfig"
2323
# This loads Zephyr base shield defconfigs
2424
source "boards/shields/*/Kconfig.defconfig"
2525

26-
osource "$(BOARD_DIR)/Kconfig.defconfig"
26+
osource "$(KCONFIG_BOARD_DIR)/Kconfig.defconfig"
2727

2828
# This loads Zephyr specific SoC root defconfigs
2929
source "$(KCONFIG_BINARY_DIR)/soc/Kconfig.defconfig"

boards/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ config QEMU_EXTRA_FLAGS
129129
GDBstub over serial with `-serial tcp:127.0.0.1:5678,server`
130130

131131
# There might not be any board options, hence the optional source
132-
osource "$(BOARD_DIR)/Kconfig"
132+
osource "$(KCONFIG_BOARD_DIR)/Kconfig"
133133
endmenu
134134

135135
config BOARD_HAS_TIMING_FUNCTIONS

boards/Kconfig.v1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
# SPDX-License-Identifier: Apache-2.0
44

5+
# In HWMv1 the KCONFIG_BOARD_DIR points directly to the BOARD_DIR.
6+
# Set the BOARD_DIR variable for backwards compatibility to legacy hardware model.
7+
BOARD_DIR := $(KCONFIG_BOARD_DIR)
8+
59
choice
610
prompt "Board Selection"
711

8-
source "$(BOARD_DIR)/Kconfig.board"
12+
source "$(KCONFIG_BOARD_DIR)/Kconfig.board"
913

1014
endchoice

boards/Kconfig.v2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ config BOARD_QUALIFIERS
2525
For example, if building for ``nrf5340dk/nrf5340/cpuapp`` then this will contain the
2626
value ``nrf5340/cpuapp``.
2727

28-
osource "$(BOARD_DIR)/Kconfig.$(BOARD)"
28+
osource "$(KCONFIG_BOARD_DIR)/Kconfig.$(BOARD)"

cmake/modules/boards.cmake

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,7 @@ set(format_str "{NAME}\;{DIR}\;{HWM}\;")
185185
set(format_str "${format_str}{REVISION_FORMAT}\;{REVISION_DEFAULT}\;{REVISION_EXACT}\;")
186186
set(format_str "${format_str}{REVISIONS}\;{SOCS}\;{QUALIFIERS}")
187187

188-
if(BOARD_DIR)
189-
set(board_dir_arg "--board-dir=${BOARD_DIR}")
190-
endif()
188+
list(TRANSFORM BOARD_DIRECTORIES PREPEND "--board-dir=" OUTPUT_VARIABLE board_dir_arg)
191189
execute_process(${list_boards_commands} --board=${BOARD} ${board_dir_arg}
192190
--cmakeformat=${format_str}
193191
OUTPUT_VARIABLE ret_board
@@ -200,29 +198,15 @@ endif()
200198

201199
if(NOT "${ret_board}" STREQUAL "")
202200
string(STRIP "${ret_board}" ret_board)
203-
string(FIND "${ret_board}" "\n" idx REVERSE)
204-
if(idx GREATER -1)
205-
while(TRUE)
206-
math(EXPR start "${idx} + 1")
207-
string(SUBSTRING "${ret_board}" ${start} -1 line)
208-
string(SUBSTRING "${ret_board}" 0 ${idx} ret_board)
209-
210-
cmake_parse_arguments(LIST_BOARD "" "DIR" "" ${line})
211-
set(board_dirs "${board_dirs}\n${LIST_BOARD_DIR}")
212-
213-
if(idx EQUAL -1)
214-
break()
215-
endif()
216-
string(FIND "${ret_board}" "\n" idx REVERSE)
217-
endwhile()
218-
message(FATAL_ERROR "Multiple boards named '${BOARD}' found in:${board_dirs}")
219-
endif()
220-
221-
set(single_val "NAME;DIR;HWM;REVISION_FORMAT;REVISION_DEFAULT;REVISION_EXACT")
222-
set(multi_val "REVISIONS;SOCS;QUALIFIERS")
201+
set(single_val "NAME;HWM;REVISION_FORMAT;REVISION_DEFAULT;REVISION_EXACT")
202+
set(multi_val "DIR;REVISIONS;SOCS;QUALIFIERS")
223203
cmake_parse_arguments(LIST_BOARD "" "${single_val}" "${multi_val}" ${ret_board})
224-
set(BOARD_DIR ${LIST_BOARD_DIR} CACHE PATH "Board directory for board (${BOARD})" FORCE)
225-
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${BOARD_DIR}/board.yml)
204+
list(GET LIST_BOARD_DIR 0 BOARD_DIR)
205+
set(BOARD_DIR ${BOARD_DIR} CACHE PATH "Main board directory for board (${BOARD})" FORCE)
206+
set(BOARD_DIRECTORIES ${LIST_BOARD_DIR} CACHE INTERNAL "List of board directories for board (${BOARD})" FORCE)
207+
foreach(dir ${BOARD_DIRECTORIES})
208+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${dir}/board.yml)
209+
endforeach()
226210

227211
# Create two CMake variables identifying the hw model.
228212
# CMake variable: HWM=[v1,v2]

cmake/modules/dts.cmake

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ find_package(Dtc 1.4.6)
7676
#
7777
# Optional variables:
7878
# - BOARD: board name to use when looking for DTS_SOURCE
79-
# - BOARD_DIR: board directory to use when looking for DTS_SOURCE
79+
# - BOARD_DIRECTORIES: list of board directories to use when looking for DTS_SOURCE
8080
# - BOARD_REVISION_STRING: used when looking for a board revision's
81-
# devicetree overlay file in BOARD_DIR
81+
# devicetree overlay file in one of the BOARD_DIRECTORIES
8282
# - CMAKE_DTS_PREPROCESSOR: the path to the preprocessor to use
8383
# for devicetree files
8484
# - DTC_OVERLAY_FILE: list of devicetree overlay files which will be
@@ -94,7 +94,7 @@ find_package(Dtc 1.4.6)
9494
# C preprocessor when generating the devicetree from DTS_SOURCE
9595
# - DTS_SOURCE: the devicetree source file to use may be pre-set
9696
# with this variable; otherwise, it defaults to
97-
# ${BOARD_DIR}/${BOARD}.dts
97+
# ${BOARD_DIRECTORIES}/<normalized_board_target>.dts
9898
#
9999
# Variables set by this module and not mentioned above are for internal
100100
# use only, and may be removed, renamed, or re-purposed without prior notice.
@@ -137,28 +137,30 @@ if(NOT DEFINED DTS_SOURCE)
137137
zephyr_build_string(board_string SHORT shortened_board_string
138138
BOARD ${BOARD} BOARD_QUALIFIERS ${BOARD_QUALIFIERS}
139139
)
140-
if(EXISTS ${BOARD_DIR}/${shortened_board_string}.dts AND NOT BOARD_${BOARD}_SINGLE_SOC)
141-
message(FATAL_ERROR "Board ${ZFILE_BOARD} defines multiple SoCs.\nShortened file name "
142-
"(${shortened_board_string}.dts) not allowed, use '<board>_<soc>.dts' naming"
143-
)
144-
elseif(EXISTS ${BOARD_DIR}/${board_string}.dts AND EXISTS ${BOARD_DIR}/${shortened_board_string}.dts)
145-
message(FATAL_ERROR "Conflicting file names discovered. Cannot use both "
146-
"${board_string}.dts and ${shortened_board_string}.dts. "
147-
"Please choose one naming style, ${board_string}.dts is recommended."
148-
)
149-
elseif(EXISTS ${BOARD_DIR}/${board_string}.dts)
150-
set(DTS_SOURCE ${BOARD_DIR}/${board_string}.dts)
151-
elseif(EXISTS ${BOARD_DIR}/${shortened_board_string}.dts)
152-
set(DTS_SOURCE ${BOARD_DIR}/${shortened_board_string}.dts)
153-
endif()
140+
foreach(dir ${BOARD_DIRECTORIES})
141+
if(EXISTS ${dir}/${shortened_board_string}.dts AND NOT BOARD_${BOARD}_SINGLE_SOC)
142+
message(FATAL_ERROR "Board ${ZFILE_BOARD} defines multiple SoCs.\nShortened file name "
143+
"(${shortened_board_string}.dts) not allowed, use '<board>_<soc>.dts' naming"
144+
)
145+
elseif(EXISTS ${dir}/${board_string}.dts AND EXISTS ${dir}/${shortened_board_string}.dts)
146+
message(FATAL_ERROR "Conflicting file names discovered. Cannot use both "
147+
"${board_string}.dts and ${shortened_board_string}.dts. "
148+
"Please choose one naming style, ${board_string}.dts is recommended."
149+
)
150+
elseif(EXISTS ${dir}/${board_string}.dts)
151+
set(DTS_SOURCE ${dir}/${board_string}.dts)
152+
elseif(EXISTS ${dir}/${shortened_board_string}.dts)
153+
set(DTS_SOURCE ${dir}/${shortened_board_string}.dts)
154+
endif()
155+
endforeach()
154156
endif()
155157

156158
if(EXISTS ${DTS_SOURCE})
157159
# We found a devicetree. Append all relevant dts overlays we can find...
158-
zephyr_file(CONF_FILES ${BOARD_DIR} DTS DTS_SOURCE)
160+
zephyr_file(CONF_FILES ${BOARD_DIRECTORIES} DTS DTS_SOURCE)
159161

160162
zephyr_file(
161-
CONF_FILES ${BOARD_DIR}
163+
CONF_FILES ${BOARD_DIRECTORIES}
162164
DTS no_rev_suffix_dts_board_overlays
163165
BOARD ${BOARD}
164166
BOARD_QUALIFIERS ${BOARD_QUALIFIERS}

cmake/modules/hwm_v2.cmake

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,15 @@ endwhile()
9595
list(REMOVE_DUPLICATES kconfig_soc_source_dir)
9696

9797
# Support multiple ARCH_ROOT, SOC_ROOT and BOARD_ROOT
98-
kconfig_gen("arch" "Kconfig" "${kconfig_arch_source_dir}" "Zephyr Arch Kconfig")
99-
kconfig_gen("soc" "Kconfig.defconfig" "${kconfig_soc_source_dir}" "Zephyr SoC defconfig")
100-
kconfig_gen("soc" "Kconfig" "${kconfig_soc_source_dir}" "Zephyr SoC Kconfig")
101-
kconfig_gen("soc" "Kconfig.soc" "${kconfig_soc_source_dir}" "SoC Kconfig")
102-
kconfig_gen("soc" "Kconfig.sysbuild" "${kconfig_soc_source_dir}" "Sysbuild SoC Kconfig")
98+
kconfig_gen("arch" "Kconfig" "${kconfig_arch_source_dir}" "Zephyr Arch Kconfig")
99+
kconfig_gen("soc" "Kconfig.defconfig" "${kconfig_soc_source_dir}" "Zephyr SoC defconfig")
100+
kconfig_gen("soc" "Kconfig" "${kconfig_soc_source_dir}" "Zephyr SoC Kconfig")
101+
kconfig_gen("soc" "Kconfig.soc" "${kconfig_soc_source_dir}" "SoC Kconfig")
102+
kconfig_gen("soc" "Kconfig.sysbuild" "${kconfig_soc_source_dir}" "Sysbuild SoC Kconfig")
103+
kconfig_gen("boards" "Kconfig.defconfig" "${BOARD_DIRECTORIES}" "Zephyr board defconfig")
104+
kconfig_gen("boards" "Kconfig.${BOARD}" "${BOARD_DIRECTORIES}" "board Kconfig")
105+
kconfig_gen("boards" "Kconfig" "${BOARD_DIRECTORIES}" "Zephyr board Kconfig")
106+
kconfig_gen("boards" "Kconfig.sysbuild" "${BOARD_DIRECTORIES}" "Sysbuild board Kconfig")
103107

104108
# Clear variables created by cmake_parse_arguments
105109
unset(SOC_V2_NAME)

cmake/modules/kconfig.cmake

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/kconfig/include/config)
2121
set_ifndef(KCONFIG_NAMESPACE "CONFIG")
2222

2323
set_ifndef(KCONFIG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/Kconfig)
24+
set(KCONFIG_BOARD_DIR ${KCONFIG_BINARY_DIR}/boards)
2425
file(MAKE_DIRECTORY ${KCONFIG_BINARY_DIR})
2526

2627
if(HWMv1)
28+
# HWMv1 only supoorts a single board dir which points directly to the board dir.
29+
set(KCONFIG_BOARD_DIR ${BOARD_DIR})
2730
# Support multiple SOC_ROOT
2831
file(MAKE_DIRECTORY ${KCONFIG_BINARY_DIR}/soc)
2932
set(kconfig_soc_root ${SOC_ROOT})
@@ -73,7 +76,7 @@ else()
7376
endif()
7477

7578
if(NOT DEFINED BOARD_DEFCONFIG)
76-
zephyr_file(CONF_FILES ${BOARD_DIR} DEFCONFIG BOARD_DEFCONFIG)
79+
zephyr_file(CONF_FILES ${BOARD_DIRECTORIES} DEFCONFIG BOARD_DEFCONFIG)
7780
endif()
7881

7982
if(DEFINED BOARD_REVISION)
@@ -157,7 +160,7 @@ set(COMMON_KCONFIG_ENV_SETTINGS
157160
APP_VERSION_TWEAK_STRING=${APP_VERSION_TWEAK_STRING}
158161
CONFIG_=${KCONFIG_NAMESPACE}_
159162
KCONFIG_CONFIG=${DOTCONFIG}
160-
BOARD_DIR=${BOARD_DIR}
163+
KCONFIG_BOARD_DIR=${KCONFIG_BOARD_DIR}
161164
BOARD=${BOARD}
162165
BOARD_REVISION=${BOARD_REVISION}
163166
BOARD_QUALIFIERS=${BOARD_QUALIFIERS}

cmake/modules/kernel.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ if(CONFIG_LLEXT AND CONFIG_LLEXT_TYPE_ELF_SHAREDLIB)
173173
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
174174
endif()
175175

176-
include(${BOARD_DIR}/board.cmake OPTIONAL)
176+
foreach(dir ${BOARD_DIRECTORIES})
177+
include(${dir}/board.cmake OPTIONAL)
178+
endforeach()
177179

178180
# If we are using a suitable ethernet driver inside qemu, then these options
179181
# must be set, otherwise a zephyr instance cannot receive any network packets.

doc/_extensions/zephyr/kconfig/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def kconfig_load(app: Sphinx) -> Tuple[kconfiglib.Kconfig, Dict[str, str]]:
9191
root_args = argparse.Namespace(**{'soc_roots': [Path(ZEPHYR_BASE)]})
9292
v2_systems = list_hardware.find_v2_systems(root_args)
9393

94-
soc_folders = {soc.folder for soc in v2_systems.get_socs()}
94+
soc_folders = {soc.folder[0] for soc in v2_systems.get_socs()}
9595
with open(Path(td) / "soc" / "Kconfig.defconfig", "w") as f:
9696
f.write('')
9797

@@ -114,8 +114,9 @@ def kconfig_load(app: Sphinx) -> Tuple[kconfiglib.Kconfig, Dict[str, str]]:
114114

115115
(Path(td) / 'boards').mkdir(exist_ok=True)
116116
root_args = argparse.Namespace(**{'board_roots': [Path(ZEPHYR_BASE)],
117-
'soc_roots': [Path(ZEPHYR_BASE)], 'board': None})
118-
v2_boards = list_boards.find_v2_boards(root_args)
117+
'soc_roots': [Path(ZEPHYR_BASE)], 'board': None,
118+
'board_dir': []})
119+
v2_boards = list_boards.find_v2_boards(root_args).values()
119120

120121
with open(Path(td) / "boards" / "Kconfig.boards", "w") as f:
121122
for board in v2_boards:
@@ -126,7 +127,8 @@ def kconfig_load(app: Sphinx) -> Tuple[kconfiglib.Kconfig, Dict[str, str]]:
126127
board_str = 'BOARD_' + re.sub(r"[^a-zA-Z0-9_]", "_", qualifier).upper()
127128
f.write('config ' + board_str + '\n')
128129
f.write('\t bool\n')
129-
f.write('source "' + (board.dir / ('Kconfig.' + board.name)).as_posix() + '"\n\n')
130+
f.write('source "' +
131+
(board.directories[0] / ('Kconfig.' + board.name)).as_posix() + '"\n\n')
130132

131133
# base environment
132134
os.environ["ZEPHYR_BASE"] = str(ZEPHYR_BASE)
@@ -140,7 +142,7 @@ def kconfig_load(app: Sphinx) -> Tuple[kconfiglib.Kconfig, Dict[str, str]]:
140142
os.environ["HWM_SCHEME"] = "v2"
141143

142144
os.environ["BOARD"] = "boards"
143-
os.environ["BOARD_DIR"] = str(Path(td) / "boards")
145+
os.environ["KCONFIG_BOARD_DIR"] = str(Path(td) / "boards")
144146

145147
# insert external Kconfigs to the environment
146148
module_paths = dict()

0 commit comments

Comments
 (0)