Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Kconfig.zephyr
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ osource "${APPLICATION_SOURCE_DIR}/VERSION"
# Shield defaults should have precedence over board defaults, which should have
# precedence over SoC defaults, so include them in that order.
#
# $ARCH and $BOARD_DIR will be glob patterns when building documentation.
# $ARCH and $KCONFIG_BOARD_DIR will be glob patterns when building documentation.
# This loads custom shields defconfigs (from BOARD_ROOT)
osource "$(KCONFIG_BINARY_DIR)/Kconfig.shield.defconfig"
# This loads Zephyr base shield defconfigs
source "boards/shields/*/Kconfig.defconfig"

osource "$(BOARD_DIR)/Kconfig.defconfig"
osource "$(KCONFIG_BOARD_DIR)/Kconfig.defconfig"

# This loads Zephyr specific SoC root defconfigs
source "$(KCONFIG_BINARY_DIR)/soc/Kconfig.defconfig"
Expand Down
2 changes: 1 addition & 1 deletion boards/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ config QEMU_EXTRA_FLAGS
GDBstub over serial with `-serial tcp:127.0.0.1:5678,server`

# There might not be any board options, hence the optional source
osource "$(BOARD_DIR)/Kconfig"
osource "$(KCONFIG_BOARD_DIR)/Kconfig"
endmenu

config BOARD_HAS_TIMING_FUNCTIONS
Expand Down
6 changes: 5 additions & 1 deletion boards/Kconfig.v1
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

# SPDX-License-Identifier: Apache-2.0

# In HWMv1 the KCONFIG_BOARD_DIR points directly to the BOARD_DIR.
# Set the BOARD_DIR variable for backwards compatibility to legacy hardware model.
BOARD_DIR := $(KCONFIG_BOARD_DIR)

choice
prompt "Board Selection"

source "$(BOARD_DIR)/Kconfig.board"
source "$(KCONFIG_BOARD_DIR)/Kconfig.board"

endchoice
2 changes: 1 addition & 1 deletion boards/Kconfig.v2
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ config BOARD_QUALIFIERS
For example, if building for ``nrf5340dk/nrf5340/cpuapp`` then this will contain the
value ``nrf5340/cpuapp``.

osource "$(BOARD_DIR)/Kconfig.$(BOARD)"
osource "$(KCONFIG_BOARD_DIR)/Kconfig.$(BOARD)"
34 changes: 9 additions & 25 deletions cmake/modules/boards.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ set(format_str "{NAME}\;{DIR}\;{HWM}\;")
set(format_str "${format_str}{REVISION_FORMAT}\;{REVISION_DEFAULT}\;{REVISION_EXACT}\;")
set(format_str "${format_str}{REVISIONS}\;{SOCS}\;{QUALIFIERS}")

if(BOARD_DIR)
set(board_dir_arg "--board-dir=${BOARD_DIR}")
endif()
list(TRANSFORM BOARD_DIRECTORIES PREPEND "--board-dir=" OUTPUT_VARIABLE board_dir_arg)
execute_process(${list_boards_commands} --board=${BOARD} ${board_dir_arg}
--cmakeformat=${format_str}
OUTPUT_VARIABLE ret_board
Expand All @@ -200,29 +198,15 @@ endif()

if(NOT "${ret_board}" STREQUAL "")
string(STRIP "${ret_board}" ret_board)
string(FIND "${ret_board}" "\n" idx REVERSE)
if(idx GREATER -1)
while(TRUE)
math(EXPR start "${idx} + 1")
string(SUBSTRING "${ret_board}" ${start} -1 line)
string(SUBSTRING "${ret_board}" 0 ${idx} ret_board)

cmake_parse_arguments(LIST_BOARD "" "DIR" "" ${line})
set(board_dirs "${board_dirs}\n${LIST_BOARD_DIR}")

if(idx EQUAL -1)
break()
endif()
string(FIND "${ret_board}" "\n" idx REVERSE)
endwhile()
message(FATAL_ERROR "Multiple boards named '${BOARD}' found in:${board_dirs}")
endif()

set(single_val "NAME;DIR;HWM;REVISION_FORMAT;REVISION_DEFAULT;REVISION_EXACT")
set(multi_val "REVISIONS;SOCS;QUALIFIERS")
set(single_val "NAME;HWM;REVISION_FORMAT;REVISION_DEFAULT;REVISION_EXACT")
set(multi_val "DIR;REVISIONS;SOCS;QUALIFIERS")
cmake_parse_arguments(LIST_BOARD "" "${single_val}" "${multi_val}" ${ret_board})
set(BOARD_DIR ${LIST_BOARD_DIR} CACHE PATH "Board directory for board (${BOARD})" FORCE)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${BOARD_DIR}/board.yml)
list(GET LIST_BOARD_DIR 0 BOARD_DIR)
set(BOARD_DIR ${BOARD_DIR} CACHE PATH "Main board directory for board (${BOARD})" FORCE)
set(BOARD_DIRECTORIES ${LIST_BOARD_DIR} CACHE INTERNAL "List of board directories for board (${BOARD})" FORCE)
foreach(dir ${BOARD_DIRECTORIES})
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${dir}/board.yml)
endforeach()

# Create two CMake variables identifying the hw model.
# CMake variable: HWM=[v1,v2]
Expand Down
40 changes: 21 additions & 19 deletions cmake/modules/dts.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ find_package(Dtc 1.4.6)
#
# Optional variables:
# - BOARD: board name to use when looking for DTS_SOURCE
# - BOARD_DIR: board directory to use when looking for DTS_SOURCE
# - BOARD_DIRECTORIES: list of board directories to use when looking for DTS_SOURCE
# - BOARD_REVISION_STRING: used when looking for a board revision's
# devicetree overlay file in BOARD_DIR
# devicetree overlay file in one of the BOARD_DIRECTORIES
# - CMAKE_DTS_PREPROCESSOR: the path to the preprocessor to use
# for devicetree files
# - DTC_OVERLAY_FILE: list of devicetree overlay files which will be
Expand All @@ -94,7 +94,7 @@ find_package(Dtc 1.4.6)
# C preprocessor when generating the devicetree from DTS_SOURCE
# - DTS_SOURCE: the devicetree source file to use may be pre-set
# with this variable; otherwise, it defaults to
# ${BOARD_DIR}/${BOARD}.dts
# ${BOARD_DIRECTORIES}/<normalized_board_target>.dts
#
# Variables set by this module and not mentioned above are for internal
# use only, and may be removed, renamed, or re-purposed without prior notice.
Expand Down Expand Up @@ -137,28 +137,30 @@ if(NOT DEFINED DTS_SOURCE)
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 '<board>_<soc>.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()
foreach(dir ${BOARD_DIRECTORIES})
if(EXISTS ${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 '<board>_<soc>.dts' naming"
)
elseif(EXISTS ${dir}/${board_string}.dts AND EXISTS ${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 ${dir}/${board_string}.dts)
set(DTS_SOURCE ${dir}/${board_string}.dts)
elseif(EXISTS ${dir}/${shortened_board_string}.dts)
set(DTS_SOURCE ${dir}/${shortened_board_string}.dts)
endif()
endforeach()
endif()

if(EXISTS ${DTS_SOURCE})
# We found a devicetree. Append all relevant dts overlays we can find...
zephyr_file(CONF_FILES ${BOARD_DIR} DTS DTS_SOURCE)
zephyr_file(CONF_FILES ${BOARD_DIRECTORIES} DTS DTS_SOURCE)

zephyr_file(
CONF_FILES ${BOARD_DIR}
CONF_FILES ${BOARD_DIRECTORIES}
DTS no_rev_suffix_dts_board_overlays
BOARD ${BOARD}
BOARD_QUALIFIERS ${BOARD_QUALIFIERS}
Expand Down
58 changes: 26 additions & 32 deletions cmake/modules/hwm_v2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ if(NOT HWMv2)
endif()

# Internal helper function for creation of Kconfig files.
function(kconfig_gen bin_dir file dirs)
file(MAKE_DIRECTORY "${bin_dir}")
set(kconfig_file ${bin_dir}/${file})
function(kconfig_gen bin_dir file dirs comment)
set(kconfig_header "# Load ${comment} descriptions.\n")
set(kconfig_file ${KCONFIG_BINARY_DIR}/${bin_dir}/${file})
file(WRITE ${kconfig_file} "${kconfig_header}")

foreach(dir ${dirs})
cmake_path(CONVERT "${dir}" TO_CMAKE_PATH_LIST dir)
file(APPEND ${kconfig_file} "osource \"${dir}/${file}\"\n")
Expand Down Expand Up @@ -71,19 +73,23 @@ while(TRUE)
string(TOUPPER "${ARCH_V2_NAME}" ARCH_V2_NAME_UPPER)
set(ARCH_V2_${ARCH_V2_NAME_UPPER}_DIR ${ARCH_V2_DIR})
elseif(HWM_TYPE MATCHES "^soc|^series|^family")
cmake_parse_arguments(SOC_V2 "" "NAME;DIR;HWM" "" ${line})
cmake_parse_arguments(SOC_V2 "" "NAME;HWM" "DIR" ${line})

list(APPEND kconfig_soc_source_dir "${SOC_V2_DIR}")
string(TOUPPER "${SOC_V2_NAME}" SOC_V2_NAME_UPPER)
string(TOUPPER "${HWM_TYPE}" HWM_TYPE_UPPER)

if(HWM_TYPE STREQUAL "soc")
set(setting_name SOC_${SOC_V2_NAME}_DIR)
# We support both SOC_foo_DIR and SOC_FOO_DIR.
set(SOC_${SOC_V2_NAME}_DIRECTORIES ${SOC_V2_DIR})
set(SOC_${SOC_V2_NAME_UPPER}_DIRECTORIES ${SOC_V2_DIR})
list(GET SOC_V2_DIR 0 SOC_${SOC_V2_NAME}_DIR)
list(GET SOC_V2_DIR 0 SOC_${SOC_V2_NAME_UPPER}_DIR)
else()
set(setting_name SOC_${HWM_TYPE}_${SOC_V2_NAME}_DIR)
# We support both SOC_series_foo_DIR and SOC_SERIES_FOO_DIR (and family / FAMILY).
set(SOC_${HWM_TYPE}_${SOC_V2_NAME}_DIR ${SOC_V2_DIR})
set(SOC_${HWM_TYPE_UPPER}_${SOC_V2_NAME_UPPER}_DIR ${SOC_V2_DIR})
endif()
# We support both SOC_foo_DIR and SOC_FOO_DIR.
set(${setting_name} ${SOC_V2_DIR})
string(TOUPPER ${setting_name} setting_name)
set(${setting_name} ${SOC_V2_DIR})
endif()

if(idx EQUAL -1)
Expand All @@ -92,28 +98,16 @@ while(TRUE)
endwhile()
list(REMOVE_DUPLICATES kconfig_soc_source_dir)

# Support multiple ARCH_ROOT and SOC_ROOT
set(arch_kconfig_file Kconfig)
set(soc_defconfig_file Kconfig.defconfig)
set(soc_zephyr_file Kconfig)
set(soc_kconfig_file Kconfig.soc)
set(soc_sysbuild_file Kconfig.sysbuild)
set(arch_kconfig_header "# Load arch Kconfig descriptions.\n")
set(defconfig_header "# Load Zephyr SoC Kconfig defconfig.\n")
set(soc_zephyr_header "# Load Zephyr SoC Kconfig descriptions.\n")
set(soc_kconfig_header "# Load SoC Kconfig descriptions.\n")
set(soc_sysbuild_header "# Load SoC sysbuild Kconfig descriptions.\n")
file(WRITE ${KCONFIG_BINARY_DIR}/arch/${arch_kconfig_file} "${arch_kconfig_header}")
file(WRITE ${KCONFIG_BINARY_DIR}/soc/${soc_defconfig_file} "${defconfig_header}")
file(WRITE ${KCONFIG_BINARY_DIR}/soc/${soc_zephyr_file} "${soc_zephyr_header}")
file(WRITE ${KCONFIG_BINARY_DIR}/soc/${soc_kconfig_file} "${soc_kconfig_header}")
file(WRITE ${KCONFIG_BINARY_DIR}/soc/${soc_sysbuild_file} "${soc_sysbuild_header}")

kconfig_gen("${KCONFIG_BINARY_DIR}/arch" "${arch_kconfig_file}" "${kconfig_arch_source_dir}")
kconfig_gen("${KCONFIG_BINARY_DIR}/soc" "${soc_defconfig_file}" "${kconfig_soc_source_dir}")
kconfig_gen("${KCONFIG_BINARY_DIR}/soc" "${soc_zephyr_file}" "${kconfig_soc_source_dir}")
kconfig_gen("${KCONFIG_BINARY_DIR}/soc" "${soc_kconfig_file}" "${kconfig_soc_source_dir}")
kconfig_gen("${KCONFIG_BINARY_DIR}/soc" "${soc_sysbuild_file}" "${kconfig_soc_source_dir}")
# Support multiple ARCH_ROOT, SOC_ROOT and BOARD_ROOT
kconfig_gen("arch" "Kconfig" "${kconfig_arch_source_dir}" "Zephyr Arch Kconfig")
kconfig_gen("soc" "Kconfig.defconfig" "${kconfig_soc_source_dir}" "Zephyr SoC defconfig")
kconfig_gen("soc" "Kconfig" "${kconfig_soc_source_dir}" "Zephyr SoC Kconfig")
kconfig_gen("soc" "Kconfig.soc" "${kconfig_soc_source_dir}" "SoC Kconfig")
kconfig_gen("soc" "Kconfig.sysbuild" "${kconfig_soc_source_dir}" "Sysbuild SoC Kconfig")
kconfig_gen("boards" "Kconfig.defconfig" "${BOARD_DIRECTORIES}" "Zephyr board defconfig")
kconfig_gen("boards" "Kconfig.${BOARD}" "${BOARD_DIRECTORIES}" "board Kconfig")
kconfig_gen("boards" "Kconfig" "${BOARD_DIRECTORIES}" "Zephyr board Kconfig")
kconfig_gen("boards" "Kconfig.sysbuild" "${BOARD_DIRECTORIES}" "Sysbuild board Kconfig")

# Clear variables created by cmake_parse_arguments
unset(SOC_V2_NAME)
Expand Down
7 changes: 5 additions & 2 deletions cmake/modules/kconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/kconfig/include/config)
set_ifndef(KCONFIG_NAMESPACE "CONFIG")

set_ifndef(KCONFIG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/Kconfig)
set(KCONFIG_BOARD_DIR ${KCONFIG_BINARY_DIR}/boards)
file(MAKE_DIRECTORY ${KCONFIG_BINARY_DIR})

if(HWMv1)
# HWMv1 only supoorts a single board dir which points directly to the board dir.
set(KCONFIG_BOARD_DIR ${BOARD_DIR})
# Support multiple SOC_ROOT
file(MAKE_DIRECTORY ${KCONFIG_BINARY_DIR}/soc)
set(kconfig_soc_root ${SOC_ROOT})
Expand Down Expand Up @@ -73,7 +76,7 @@ else()
endif()

if(NOT DEFINED BOARD_DEFCONFIG)
zephyr_file(CONF_FILES ${BOARD_DIR} DEFCONFIG BOARD_DEFCONFIG)
zephyr_file(CONF_FILES ${BOARD_DIRECTORIES} DEFCONFIG BOARD_DEFCONFIG)
endif()

if(DEFINED BOARD_REVISION)
Expand Down Expand Up @@ -157,7 +160,7 @@ set(COMMON_KCONFIG_ENV_SETTINGS
APP_VERSION_TWEAK_STRING=${APP_VERSION_TWEAK_STRING}
CONFIG_=${KCONFIG_NAMESPACE}_
KCONFIG_CONFIG=${DOTCONFIG}
BOARD_DIR=${BOARD_DIR}
KCONFIG_BOARD_DIR=${KCONFIG_BOARD_DIR}
BOARD=${BOARD}
BOARD_REVISION=${BOARD_REVISION}
BOARD_QUALIFIERS=${BOARD_QUALIFIERS}
Expand Down
4 changes: 3 additions & 1 deletion cmake/modules/kernel.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ if(CONFIG_LLEXT AND CONFIG_LLEXT_TYPE_ELF_SHAREDLIB)
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
endif()

include(${BOARD_DIR}/board.cmake OPTIONAL)
foreach(dir ${BOARD_DIRECTORIES})
include(${dir}/board.cmake OPTIONAL)
endforeach()

# If we are using a suitable ethernet driver inside qemu, then these options
# must be set, otherwise a zephyr instance cannot receive any network packets.
Expand Down
7 changes: 6 additions & 1 deletion cmake/modules/soc_v2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,10 @@ if(HWMv2)
set(SOC_FAMILY ${CONFIG_SOC_FAMILY})
set(SOC_V2_DIR ${SOC_${SOC_NAME}_DIR})
set(SOC_FULL_DIR ${SOC_V2_DIR} CACHE PATH "Path to the SoC directory." FORCE)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${SOC_V2_DIR}/soc.yml)
set(SOC_DIRECTORIES ${SOC_${SOC_NAME}_DIRECTORIES} CACHE INTERNAL
"List of SoC directories for SoC (${SOC_NAME})" FORCE
)
foreach(dir ${SOC_DIRECTORIES})
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${dir}/soc.yml)
endforeach()
endif()
9 changes: 5 additions & 4 deletions doc/_extensions/zephyr/kconfig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def kconfig_load(app: Sphinx) -> Tuple[kconfiglib.Kconfig, Dict[str, str]]:
root_args = argparse.Namespace(**{'soc_roots': [Path(ZEPHYR_BASE)]})
v2_systems = list_hardware.find_v2_systems(root_args)

soc_folders = {soc.folder for soc in v2_systems.get_socs()}
soc_folders = {soc.folder[0] for soc in v2_systems.get_socs()}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If board/SoC extensions will be allowed in-tree, will this have to be updated to include all folders?

Suggested change
soc_folders = {soc.folder[0] for soc in v2_systems.get_socs()}
soc_folders = {folder for soc in v2_systems.get_socs() for folder in soc.folder}

Same with the occurrences of board.dir[0].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that depends on how we want to organize the docs in such case.

Will we want docs describing the in-tree soc / board to be located in a single folder, or do we want to allow documentation for a given soc / board to be placed at multiple locations.

I would like to leave such decision to doc maintainers and not as part of this PR.
@kartben thoughts ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I would agree that the docs can be handled later, same with compliance.

with open(Path(td) / "soc" / "Kconfig.defconfig", "w") as f:
f.write('')

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

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

with open(Path(td) / "boards" / "Kconfig.boards", "w") as f:
for board in v2_boards:
Expand All @@ -140,7 +141,7 @@ def kconfig_load(app: Sphinx) -> Tuple[kconfiglib.Kconfig, Dict[str, str]]:
os.environ["HWM_SCHEME"] = "v2"

os.environ["BOARD"] = "boards"
os.environ["BOARD_DIR"] = str(Path(td) / "boards")
os.environ["KCONFIG_BOARD_DIR"] = str(Path(td) / "boards")

# insert external Kconfigs to the environment
module_paths = dict()
Expand Down
4 changes: 2 additions & 2 deletions doc/_scripts/gen_boards_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ def get_catalog():
arch_roots=module_settings["arch_root"],
board_roots=module_settings["board_root"],
soc_roots=module_settings["soc_root"],
board_dir=ZEPHYR_BASE / "boards",
board_dir=[],
board=None,
)

boards = list_boards.find_v2_boards(args_find_boards)
systems = list_hardware.find_v2_systems(args_find_boards)
board_catalog = {}

for board in boards:
for board in boards.values():
# We could use board.vendor but it is often incorrect. Instead, deduce vendor from
# containing folder. There are a few exceptions, like the "native" and "others" folders
# which we know are not actual vendors so treat them as such.
Expand Down
Loading
Loading