Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zephyr sysbuild / multi image #40555

Merged
merged 9 commits into from
Aug 3, 2022
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ scripts/build/gen_image_info.py @tejlmand
/scripts/build/uf2conv.py @petejohanson
/scripts/build/user_wordsize.py @cfriedt
/scripts/valgrind.supp @aescolar @daor-oti
/share/sysbuild/ @tejlmand
/share/zephyr-package/ @tejlmand
/share/zephyrunittest-package/ @tejlmand
/subsys/bluetooth/ @alwa-nordic @jhedberg @Vudentz
Expand Down
29 changes: 16 additions & 13 deletions cmake/modules/kconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${AUTOCONF_H})
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/kconfig/include/generated)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/kconfig/include/config)

set_ifndef(KCONFIG_NAMESPACE "CONFIG")
mbolivar-nordic marked this conversation as resolved.
Show resolved Hide resolved

# Support multiple SOC_ROOT, remove ZEPHYR_BASE as that is always sourced.
set(kconfig_soc_root ${SOC_ROOT})
list(REMOVE_ITEM kconfig_soc_root ${ZEPHYR_BASE})
Expand Down Expand Up @@ -59,7 +61,7 @@ else()
set(KCONFIG_ROOT ${ZEPHYR_BASE}/Kconfig)
endif()

set(BOARD_DEFCONFIG ${BOARD_DIR}/${BOARD}_defconfig)
set_ifndef(BOARD_DEFCONFIG ${BOARD_DIR}/${BOARD}_defconfig)
set(DOTCONFIG ${PROJECT_BINARY_DIR}/.config)
set(PARSED_KCONFIG_SOURCES_TXT ${PROJECT_BINARY_DIR}/kconfig/sources.txt)

Expand Down Expand Up @@ -109,6 +111,7 @@ set(COMMON_KCONFIG_ENV_SETTINGS
PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
srctree=${ZEPHYR_BASE}
KERNELVERSION=${KERNELVERSION}
CONFIG_=${KCONFIG_NAMESPACE}_
KCONFIG_CONFIG=${DOTCONFIG}
# Set environment variables so that Kconfig can prune Kconfig source
# files for other architectures
Expand Down Expand Up @@ -146,10 +149,10 @@ set(EXTRA_KCONFIG_TARGET_COMMAND_FOR_hardenconfig
${ZEPHYR_BASE}/scripts/kconfig/hardenconfig.py
)

set_ifndef(KCONFIG_TARGETS menuconfig guiconfig hardenconfig)

foreach(kconfig_target
menuconfig
guiconfig
hardenconfig
${KCONFIG_TARGETS}
mbolivar-nordic marked this conversation as resolved.
Show resolved Hide resolved
${EXTRA_KCONFIG_TARGETS}
)
add_custom_target(
Expand All @@ -170,15 +173,15 @@ foreach(kconfig_target
endforeach()

# Support assigning Kconfig symbols on the command-line with CMake
# cache variables prefixed with 'CONFIG_'. This feature is
# experimental and undocumented until it has undergone more
# cache variables prefixed according to the Kconfig namespace.
# This feature is experimental and undocumented until it has undergone more
# user-testing.
unset(EXTRA_KCONFIG_OPTIONS)
get_cmake_property(cache_variable_names CACHE_VARIABLES)
foreach (name ${cache_variable_names})
if("${name}" MATCHES "^CONFIG_")
# When a cache variable starts with 'CONFIG_', it is assumed to be
# a Kconfig symbol assignment from the CMake command line.
if("${name}" MATCHES "^${KCONFIG_NAMESPACE}_")
# When a cache variable starts with the 'KCONFIG_NAMESPACE' value, it is
# assumed to be a Kconfig symbol assignment from the CMake command line.
set(EXTRA_KCONFIG_OPTIONS
"${EXTRA_KCONFIG_OPTIONS}\n${name}=${${name}}"
)
Expand Down Expand Up @@ -316,18 +319,18 @@ add_custom_target(config-twister DEPENDS ${DOTCONFIG})
# CMakeCache.txt. If the symbols end up in DOTCONFIG they will be
# re-introduced to the namespace through 'import_kconfig'.
foreach (name ${cache_variable_names})
if("${name}" MATCHES "^CONFIG_")
if("${name}" MATCHES "^${KCONFIG_NAMESPACE}_")
unset(${name})
unset(${name} CACHE)
endif()
endforeach()

# Parse the lines prefixed with CONFIG_ in the .config file from Kconfig
import_kconfig(CONFIG_ ${DOTCONFIG})
# Import the .config file and make all settings available in CMake processing.
import_kconfig(${KCONFIG_NAMESPACE} ${DOTCONFIG})

# Re-introduce the CLI Kconfig symbols that survived
foreach (name ${cache_variable_names})
if("${name}" MATCHES "^CONFIG_")
if("${name}" MATCHES "^${KCONFIG_NAMESPACE}_")
if(DEFINED ${name})
set(${name} ${${name}} CACHE STRING "")
endif()
Expand Down
44 changes: 44 additions & 0 deletions share/sysbuild/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright (c) 2021 Nordic Semiconductor
#
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20)

if(NOT DEFINED APP_DIR)
message(FATAL_ERROR "No main application specified")
endif()

# This will update the APP_DIR cache variable to PATH type and apply a comment.
# If APP_DIR is a relative path, then CMake will adjust to absolute path based
# on current working dir.
set(APP_DIR ${APP_DIR} CACHE PATH "Main Application Source Directory")

# Add sysbuild/cmake/modules to CMAKE_MODULE_PATH which allows us to integrate
# sysbuild CMake modules with general Zephyr CMake modules.
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/modules)
# List of Zephyr and sysbuild CMake modules we need for sysbuild.
# Note: sysbuild_kconfig will internally load kconfig CMake module.
set(zephyr_modules extensions sysbuild_extensions python west root zephyr_module boards shields sysbuild_kconfig)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} COMPONENTS ${zephyr_modules})

project(sysbuild LANGUAGES)

# Global list of images enabled in this multi image build system.
set(IMAGES)

get_filename_component(APP_DIR ${APP_DIR} ABSOLUTE)
get_filename_component(app_name ${APP_DIR} NAME)

# This adds the primary application to the build.
ExternalZephyrProject_Add(
APPLICATION ${app_name}
SOURCE_DIR ${APP_DIR}
MAIN_APP
)

add_subdirectory(bootloader)

# This allows for board and app specific images to be included.
include(${BOARD_DIR}/sysbuild.cmake OPTIONAL)
include(${APP_DIR}/sysbuild.cmake OPTIONAL)
36 changes: 36 additions & 0 deletions share/sysbuild/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (c) 2021 Nordic Semiconductor
#
# SPDX-License-Identifier: Apache-2.0

comment "Sysbuild image configuration"

osource "$(BOARD_DIR)/Kconfig.sysbuild"

config EXPERIMENTAL
bool
help
Symbol that must be selected by a feature if it is considered to be
at an experimental implementation stage.

config WARN_EXPERIMENTAL
bool
prompt "Warn on experimental usage"
help
Print a warning when the Kconfig tree is parsed if any experimental
features are enabled.

config DEPRECATED
bool
help
Symbol that must be selected by a feature or module if it is
considered to be deprecated.

config WARN_DEPRECATED
bool
default y
prompt "Warn on deprecated usage"
help
Print a warning when the Kconfig tree is parsed if any deprecated
features are enabled.

rsource "bootloader/Kconfig"
11 changes: 11 additions & 0 deletions share/sysbuild/bootloader/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2022 Nordic Semiconductor
#
# SPDX-License-Identifier: Apache-2.0

# Include MCUboot if enabled.
if(SB_CONFIG_BOOTLOADER_MCUBOOT)
ExternalZephyrProject_Add(
APPLICATION mcuboot
SOURCE_DIR ${ZEPHYR_MCUBOOT_MODULE_DIR}/boot/zephyr/
)
endif()
29 changes: 29 additions & 0 deletions share/sysbuild/bootloader/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2022 Nordic Semiconductor
#
# SPDX-License-Identifier: Apache-2.0

config SUPPORT_BOOTLOADER
bool
default y

config SUPPORT_BOOTLOADER_MCUBOOT_ZEPHYR
bool
default y

choice BOOTLOADER
prompt "Bootloader support"
default BOOTLOADER_NONE
depends on SUPPORT_BOOTLOADER

config BOOTLOADER_NONE
bool "None"
help
Do not Include a bootloader in the build

config BOOTLOADER_MCUBOOT
Copy link
Collaborator

Choose a reason for hiding this comment

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

As I understand there is dedicated namespace for these Kconfig properties (and will never merge to with the application properties).
For instance this property does something else than CONFIG_BOOTLOADER_MCUBOOT of zephyr-rtos app.
I want to avoid confusion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe the help text can definitely be improved.

But whether we should invent two different setting names or have them identical as now depends a lot on how you look at this.

The Zephyr setting states:

zephyr/Kconfig.zephyr

Lines 682 to 686 in 83d73f6

This option signifies that the target uses MCUboot as a bootloader,
or in other words that the image is to be chain-loaded by MCUboot.
This sets several required build system and Device Tree options in
order for the image generated to be bootable using the MCUboot open
source bootloader. Currently this includes:

and my view on this is that this is also true for the sysbuild BOOTLOADER_MCUBOOT because it propagates this setting to the application so that the app is chain loaded by MCUboot, as well as devicetree is setup accordingly.
Not inside sysbuild itself, but in the images built by sysbuild.
Ref:

# Propagate bootloader and signing settings from this system to the MCUboot and
# application image build systems.
if(SB_CONFIG_BOOTLOADER_MCUBOOT)
set(${app_name}_CONFIG_BOOTLOADER_MCUBOOT y CACHE STRING
"MCUBOOT is enabled as bootloader" FORCE

Of course sysbuild itself does one more thing which the application itself cannot do, and that is building and flashing of MCUboot in addition.

I believe having identical name for BOOTLOADER_MCUBOOT makes it easier for users to transition to sysbuild and understand how to build a sample with MCUboot, and that the small addition that sysbuild provides is not sufficient to justify two different names.

bool "MCUboot"
depends on SUPPORT_BOOTLOADER_MCUBOOT_ZEPHYR
help
Include MCUboot (Zephyr port) as the bootloader to use

endchoice
Loading