cmake: kconfig: support for multiple SOC_ROOT
This commit introduces support for multiple SOC_ROOT. This means that additional SOC_ROOTs specified using -DSOC_ROOT as argument to CMake will be forming a list together with ${ZEPHYR_BASE}. This allows for greater flexibility, as developers can now specify multiple out-of-tree SoCs and not worry about the SoC used for the board they compile for. Also it avoid code, such as: if(BOARD STREQUAL my_board_using_out_of_tree_soc) set(SOC_ROOT some/out/of/tree/soc/path) endif() in application CMakeLists.txt. Finally, allowing multiple SOC_ROOTs prepares for specifying SOC_ROOTs in Zephyr modules. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
parent
01f55a4e53
commit
5f7cc8ded9
6 changed files with 79 additions and 14 deletions
|
@ -22,10 +22,10 @@ endmenu
|
||||||
# $ARCH and $BOARD_DIR will be glob patterns when building documentation.
|
# $ARCH and $BOARD_DIR will be glob patterns when building documentation.
|
||||||
source "boards/shields/*/Kconfig.defconfig"
|
source "boards/shields/*/Kconfig.defconfig"
|
||||||
source "$(BOARD_DIR)/Kconfig.defconfig"
|
source "$(BOARD_DIR)/Kconfig.defconfig"
|
||||||
source "$(SOC_DIR)/$(ARCH)/*/Kconfig.defconfig"
|
source "$(KCONFIG_BINARY_DIR)/Kconfig.soc.defconfig"
|
||||||
|
|
||||||
source "boards/Kconfig"
|
source "boards/Kconfig"
|
||||||
source "$(SOC_DIR)/Kconfig"
|
source "soc/Kconfig"
|
||||||
source "arch/Kconfig"
|
source "arch/Kconfig"
|
||||||
source "kernel/Kconfig"
|
source "kernel/Kconfig"
|
||||||
source "dts/Kconfig"
|
source "dts/Kconfig"
|
||||||
|
|
|
@ -276,11 +276,9 @@ set(CACHED_SHIELD ${SHIELD} CACHE STRING "Selected shield")
|
||||||
# be found. It always includes ${ZEPHYR_BASE} at the lowest priority.
|
# be found. It always includes ${ZEPHYR_BASE} at the lowest priority.
|
||||||
list(APPEND BOARD_ROOT ${ZEPHYR_BASE})
|
list(APPEND BOARD_ROOT ${ZEPHYR_BASE})
|
||||||
|
|
||||||
if(NOT SOC_ROOT)
|
# 'SOC_ROOT' is a prioritized list of directories where socs may be
|
||||||
set(SOC_DIR ${ZEPHYR_BASE}/soc)
|
# found. It always includes ${ZEPHYR_BASE}/soc at the lowest priority.
|
||||||
else()
|
list(APPEND SOC_ROOT ${ZEPHYR_BASE})
|
||||||
set(SOC_DIR ${SOC_ROOT}/soc)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(NOT ARCH_ROOT)
|
if(NOT ARCH_ROOT)
|
||||||
set(ARCH_DIR ${ZEPHYR_BASE}/arch)
|
set(ARCH_DIR ${ZEPHYR_BASE}/arch)
|
||||||
|
@ -493,6 +491,7 @@ include(${ZEPHYR_BASE}/cmake/host-tools.cmake)
|
||||||
include(${BOARD_DIR}/pre_dt_board.cmake OPTIONAL)
|
include(${BOARD_DIR}/pre_dt_board.cmake OPTIONAL)
|
||||||
|
|
||||||
# Build directory for generated KConfig files, such as:
|
# Build directory for generated KConfig files, such as:
|
||||||
|
# - Multiple SOC_ROOT inclusion
|
||||||
# - Zephyr modules Kconfig files
|
# - Zephyr modules Kconfig files
|
||||||
set(KCONFIG_BINARY_DIR ${CMAKE_BINARY_DIR}/Kconfig)
|
set(KCONFIG_BINARY_DIR ${CMAKE_BINARY_DIR}/Kconfig)
|
||||||
file(MAKE_DIRECTORY ${KCONFIG_BINARY_DIR})
|
file(MAKE_DIRECTORY ${KCONFIG_BINARY_DIR})
|
||||||
|
@ -525,6 +524,21 @@ else()
|
||||||
set(SOC_PATH ${SOC_FAMILY}/${SOC_SERIES})
|
set(SOC_PATH ${SOC_FAMILY}/${SOC_SERIES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Use SOC to search for a 'CMakeLists.txt' file.
|
||||||
|
# e.g. zephyr/soc/xtense/intel_apl_adsp/CMakeLists.txt.
|
||||||
|
foreach(root ${SOC_ROOT})
|
||||||
|
if(EXISTS ${root}/soc/${ARCH}/${SOC_PATH})
|
||||||
|
set(SOC_DIR ${root}/soc)
|
||||||
|
break()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
if(NOT SOC_DIR)
|
||||||
|
message(FATAL_ERROR "Could not find SOC=${SOC_NAME} for BOARD=${BOARD}, \
|
||||||
|
please check your installation. SOC roots searched: \n\
|
||||||
|
${SOC_ROOT}")
|
||||||
|
endif()
|
||||||
|
|
||||||
include(${ZEPHYR_BASE}/cmake/target_toolchain.cmake)
|
include(${ZEPHYR_BASE}/cmake/target_toolchain.cmake)
|
||||||
|
|
||||||
project(Zephyr-Kernel VERSION ${PROJECT_VERSION})
|
project(Zephyr-Kernel VERSION ${PROJECT_VERSION})
|
||||||
|
|
|
@ -5,6 +5,22 @@
|
||||||
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/kconfig/include/generated)
|
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/kconfig/include/generated)
|
||||||
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/kconfig/include/config)
|
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/kconfig/include/config)
|
||||||
|
|
||||||
|
# Support multiple SOC_ROOT
|
||||||
|
set(OPERATION WRITE)
|
||||||
|
foreach(root ${SOC_ROOT})
|
||||||
|
file(${OPERATION} ${KCONFIG_BINARY_DIR}/Kconfig.soc.defconfig
|
||||||
|
"osource \"${root}/soc/$(ARCH)/*/Kconfig.defconfig\"\n"
|
||||||
|
)
|
||||||
|
file(${OPERATION} ${KCONFIG_BINARY_DIR}/Kconfig.soc
|
||||||
|
"osource \"${root}/soc/$(ARCH)/*/Kconfig.soc\"\n"
|
||||||
|
)
|
||||||
|
file(${OPERATION} ${KCONFIG_BINARY_DIR}/Kconfig.soc.arch
|
||||||
|
"osource \"${root}/soc/$(ARCH)/Kconfig\"\n"
|
||||||
|
"osource \"${root}/soc/$(ARCH)/*/Kconfig\"\n"
|
||||||
|
)
|
||||||
|
set(OPERATION APPEND)
|
||||||
|
endforeach()
|
||||||
|
|
||||||
if(KCONFIG_ROOT)
|
if(KCONFIG_ROOT)
|
||||||
# KCONFIG_ROOT has either been specified as a CMake variable or is
|
# KCONFIG_ROOT has either been specified as a CMake variable or is
|
||||||
# already in the CMakeCache.txt. This has precedence.
|
# already in the CMakeCache.txt. This has precedence.
|
||||||
|
@ -41,7 +57,6 @@ set(ENV{PYTHON_EXECUTABLE} ${PYTHON_EXECUTABLE})
|
||||||
# files for other architectures
|
# files for other architectures
|
||||||
set(ENV{ARCH} ${ARCH})
|
set(ENV{ARCH} ${ARCH})
|
||||||
set(ENV{BOARD_DIR} ${BOARD_DIR})
|
set(ENV{BOARD_DIR} ${BOARD_DIR})
|
||||||
set(ENV{SOC_DIR} ${SOC_DIR})
|
|
||||||
set(ENV{SHIELD_AS_LIST} "${SHIELD_AS_LIST}")
|
set(ENV{SHIELD_AS_LIST} "${SHIELD_AS_LIST}")
|
||||||
set(ENV{KCONFIG_BINARY_DIR} ${KCONFIG_BINARY_DIR})
|
set(ENV{KCONFIG_BINARY_DIR} ${KCONFIG_BINARY_DIR})
|
||||||
set(ENV{ARCH_DIR} ${ARCH_DIR})
|
set(ENV{ARCH_DIR} ${ARCH_DIR})
|
||||||
|
@ -85,7 +100,6 @@ foreach(kconfig_target
|
||||||
KCONFIG_CONFIG=${DOTCONFIG}
|
KCONFIG_CONFIG=${DOTCONFIG}
|
||||||
ARCH=$ENV{ARCH}
|
ARCH=$ENV{ARCH}
|
||||||
BOARD_DIR=$ENV{BOARD_DIR}
|
BOARD_DIR=$ENV{BOARD_DIR}
|
||||||
SOC_DIR=$ENV{SOC_DIR}
|
|
||||||
SHIELD_AS_LIST=$ENV{SHIELD_AS_LIST}
|
SHIELD_AS_LIST=$ENV{SHIELD_AS_LIST}
|
||||||
KCONFIG_BINARY_DIR=$ENV{KCONFIG_BINARY_DIR}
|
KCONFIG_BINARY_DIR=$ENV{KCONFIG_BINARY_DIR}
|
||||||
ZEPHYR_TOOLCHAIN_VARIANT=${ZEPHYR_TOOLCHAIN_VARIANT}
|
ZEPHYR_TOOLCHAIN_VARIANT=${ZEPHYR_TOOLCHAIN_VARIANT}
|
||||||
|
|
|
@ -42,6 +42,8 @@ endif()
|
||||||
# Include version info
|
# Include version info
|
||||||
include(${ZEPHYR_BASE}/cmake/version.cmake)
|
include(${ZEPHYR_BASE}/cmake/version.cmake)
|
||||||
# Process modules
|
# Process modules
|
||||||
|
set(KCONFIG_BINARY_DIR ${CMAKE_BINARY_DIR}/Kconfig)
|
||||||
|
file(MAKE_DIRECTORY ${KCONFIG_BINARY_DIR})
|
||||||
include(${ZEPHYR_BASE}/cmake/zephyr_module.cmake)
|
include(${ZEPHYR_BASE}/cmake/zephyr_module.cmake)
|
||||||
|
|
||||||
# Note that this won't force fatal error if latexmk is not found.
|
# Note that this won't force fatal error if latexmk is not found.
|
||||||
|
@ -195,6 +197,17 @@ else()
|
||||||
set(SEP :)
|
set(SEP :)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
file(WRITE ${KCONFIG_BINARY_DIR}/Kconfig.soc.defconfig
|
||||||
|
"osource \"${ZEPHYR_BASE}/soc/$(ARCH)/*/Kconfig.defconfig\"\n"
|
||||||
|
)
|
||||||
|
file(WRITE ${KCONFIG_BINARY_DIR}/Kconfig.soc
|
||||||
|
"osource \"${ZEPHYR_BASE}/soc/$(ARCH)/*/Kconfig.soc\"\n"
|
||||||
|
)
|
||||||
|
file(WRITE ${KCONFIG_BINARY_DIR}/Kconfig.soc.arch
|
||||||
|
"osource \"${ZEPHYR_BASE}/soc/$(ARCH)/Kconfig\"\n"
|
||||||
|
"osource \"${ZEPHYR_BASE}/soc/$(ARCH)/*/Kconfig\"\n"
|
||||||
|
)
|
||||||
|
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
kconfig
|
kconfig
|
||||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${RST_OUT}/doc/reference/kconfig
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${RST_OUT}/doc/reference/kconfig
|
||||||
|
@ -206,7 +219,7 @@ add_custom_target(
|
||||||
ARCH=*
|
ARCH=*
|
||||||
ARCH_DIR=arch
|
ARCH_DIR=arch
|
||||||
SOC_DIR=soc
|
SOC_DIR=soc
|
||||||
CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}
|
KCONFIG_BINARY_DIR=${KCONFIG_BINARY_DIR}
|
||||||
KCONFIG_WARN_UNDEF=y
|
KCONFIG_WARN_UNDEF=y
|
||||||
KCONFIG_TURBO_MODE=${KCONFIG_TURBO_MODE}
|
KCONFIG_TURBO_MODE=${KCONFIG_TURBO_MODE}
|
||||||
KCONFIG_DOC_MODE=1
|
KCONFIG_DOC_MODE=1
|
||||||
|
|
|
@ -256,6 +256,28 @@ class KconfigCheck(ComplianceTest):
|
||||||
except subprocess.CalledProcessError as ex:
|
except subprocess.CalledProcessError as ex:
|
||||||
self.error(ex.output)
|
self.error(ex.output)
|
||||||
|
|
||||||
|
def write_kconfig_soc(self):
|
||||||
|
"""
|
||||||
|
Write KConfig soc files to be sourced during Kconfig parsing
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
soc_defconfig_file = os.path.join(tempfile.gettempdir(), "Kconfig.soc.defconfig")
|
||||||
|
soc_file = os.path.join(tempfile.gettempdir(), "Kconfig.soc")
|
||||||
|
soc_arch_file = os.path.join(tempfile.gettempdir(), "Kconfig.soc.arch")
|
||||||
|
try:
|
||||||
|
with open(soc_defconfig_file, 'w', encoding="utf-8") as fp:
|
||||||
|
fp.write(f'osource "{ZEPHYR_BASE}/soc/$(ARCH)/*/Kconfig.defconfig"\n')
|
||||||
|
|
||||||
|
with open(soc_file, 'w', encoding="utf-8") as fp:
|
||||||
|
fp.write(f'osource "{ZEPHYR_BASE}/soc/$(ARCH)/*/Kconfig.soc"\n')
|
||||||
|
|
||||||
|
with open(soc_arch_file, 'w', encoding="utf-8") as fp:
|
||||||
|
fp.write(f'osource "{ZEPHYR_BASE}/soc/$(ARCH)/Kconfig"\n\
|
||||||
|
osource "{ZEPHYR_BASE}/soc/$(ARCH)/*/Kconfig"\n')
|
||||||
|
except IOError as ex:
|
||||||
|
self.error(ex.output)
|
||||||
|
|
||||||
def parse_kconfig(self):
|
def parse_kconfig(self):
|
||||||
"""
|
"""
|
||||||
Returns a kconfiglib.Kconfig object for the Kconfig files. We reuse
|
Returns a kconfiglib.Kconfig object for the Kconfig files. We reuse
|
||||||
|
@ -284,7 +306,7 @@ class KconfigCheck(ComplianceTest):
|
||||||
os.environ["ARCH_DIR"] = "arch/"
|
os.environ["ARCH_DIR"] = "arch/"
|
||||||
os.environ["BOARD_DIR"] = "boards/*/*"
|
os.environ["BOARD_DIR"] = "boards/*/*"
|
||||||
os.environ["ARCH"] = "*"
|
os.environ["ARCH"] = "*"
|
||||||
os.environ["CMAKE_BINARY_DIR"] = tempfile.gettempdir()
|
os.environ["KCONFIG_BINARY_DIR"] = tempfile.gettempdir()
|
||||||
os.environ['DEVICETREE_CONF'] = "dummy"
|
os.environ['DEVICETREE_CONF'] = "dummy"
|
||||||
|
|
||||||
# Older name for DEVICETREE_CONF, for compatibility with older Zephyr
|
# Older name for DEVICETREE_CONF, for compatibility with older Zephyr
|
||||||
|
@ -294,6 +316,9 @@ class KconfigCheck(ComplianceTest):
|
||||||
# For multi repo support
|
# For multi repo support
|
||||||
self.get_modules(os.path.join(tempfile.gettempdir(), "Kconfig.modules"))
|
self.get_modules(os.path.join(tempfile.gettempdir(), "Kconfig.modules"))
|
||||||
|
|
||||||
|
# For list of SOC_ROOT support
|
||||||
|
self.write_kconfig_soc()
|
||||||
|
|
||||||
# Tells Kconfiglib to generate warnings for all references to undefined
|
# Tells Kconfiglib to generate warnings for all references to undefined
|
||||||
# symbols within Kconfig files
|
# symbols within Kconfig files
|
||||||
os.environ["KCONFIG_WARN_UNDEF"] = "y"
|
os.environ["KCONFIG_WARN_UNDEF"] = "y"
|
||||||
|
|
|
@ -3,13 +3,12 @@
|
||||||
choice
|
choice
|
||||||
prompt "SoC/CPU/Configuration Selection"
|
prompt "SoC/CPU/Configuration Selection"
|
||||||
|
|
||||||
source "$(SOC_DIR)/$(ARCH)/*/Kconfig.soc"
|
source "$(KCONFIG_BINARY_DIR)/Kconfig.soc"
|
||||||
|
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
menu "Hardware Configuration"
|
menu "Hardware Configuration"
|
||||||
osource "$(SOC_DIR)/$(ARCH)/Kconfig"
|
source "$(KCONFIG_BINARY_DIR)/Kconfig.soc.arch"
|
||||||
osource "$(SOC_DIR)/$(ARCH)/*/Kconfig"
|
|
||||||
|
|
||||||
|
|
||||||
module = SOC
|
module = SOC
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue