Skip to content

Commit

Permalink
sysbuild: refactor image_config.cmake handling
Browse files Browse the repository at this point in the history
Refactor image_config.cmake so that it is no longer sourced
unconditionally for all images. Instead image_config.cmake has been
split into BOOTLOADER_image_default.cmake and MAIN_image_default.cmake
and is set as property on the image.

This means the code in image_config.cmake can be split into dedicated
files which depends on the image type. Furthermore it allows sysbuild
modules to append extra config snippets to process for sysbuild kconfig
overwrite, or even remove the default snippet and have full control.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
  • Loading branch information
tejlmand authored and carlescufi committed Aug 24, 2023
1 parent 5e4710c commit f380f82
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 49 deletions.
1 change: 0 additions & 1 deletion share/sysbuild/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ endwhile()

sysbuild_module_call(PRE_CMAKE MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES})
foreach(image ${IMAGES})
include(image_config.cmake)
ExternalZephyrProject_Cmake(APPLICATION ${image})
endforeach()
sysbuild_module_call(POST_CMAKE MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES})
Expand Down
13 changes: 13 additions & 0 deletions share/sysbuild/cmake/modules/sysbuild_extensions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ function(ExternalZephyrProject_Add)
set_target_properties(${ZBUILD_APPLICATION} PROPERTIES MAIN_APP True)
endif()

if(DEFINED ZBUILD_APP_TYPE)
set(image_default "${CMAKE_SOURCE_DIR}/image_configurations/${ZBUILD_APP_TYPE}_image_default.cmake")
set_target_properties(${ZBUILD_APPLICATION} PROPERTIES IMAGE_CONF_SCRIPT ${image_default})
endif()

if(DEFINED ZBUILD_BOARD)
# Only set image specific board if provided.
# The sysbuild BOARD is exported through sysbuild cache, and will be used
Expand Down Expand Up @@ -349,6 +354,10 @@ function(ExternalZephyrProject_Cmake)
get_target_property(${ZCMAKE_APPLICATION}_BOARD ${ZCMAKE_APPLICATION} BOARD)
get_target_property(${ZCMAKE_APPLICATION}_MAIN_APP ${ZCMAKE_APPLICATION} MAIN_APP)

get_property(${ZCMAKE_APPLICATION}_CONF_SCRIPT TARGET ${ZCMAKE_APPLICATION}
PROPERTY IMAGE_CONF_SCRIPT
)

# Update ROOT variables with relative paths to use absolute paths based on
# the source application directory.
foreach(type MODULE_EXT BOARD SOC ARCH SCA)
Expand Down Expand Up @@ -400,6 +409,10 @@ function(ExternalZephyrProject_Cmake)
${${ZCMAKE_APPLICATION}_CACHE_FILE} ONLY_IF_DIFFERENT
)

foreach(script ${${ZCMAKE_APPLICATION}_CONF_SCRIPT})
include(${script})
endforeach()

set(dotconfigsysbuild ${BINARY_DIR}/zephyr/.config.sysbuild)
get_target_property(config_content ${ZCMAKE_APPLICATION} CONFIG)
string(CONFIGURE "${config_content}" config_content)
Expand Down
48 changes: 0 additions & 48 deletions share/sysbuild/image_config.cmake

This file was deleted.

37 changes: 37 additions & 0 deletions share/sysbuild/image_configurations/BOOTLOADER_image_default.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (c) 2023 Nordic Semiconductor
#
# SPDX-License-Identifier: Apache-2.0

# This sysbuild CMake file sets the sysbuild controlled settings as properties
# on Zephyr MCUboot / bootloader image.

set(keytypes CONFIG_BOOT_SIGNATURE_TYPE_NONE
CONFIG_BOOT_SIGNATURE_TYPE_RSA
CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256
CONFIG_BOOT_SIGNATURE_TYPE_ED25519)

if(SB_CONFIG_BOOT_SIGNATURE_TYPE_NONE)
set(keytype CONFIG_BOOT_SIGNATURE_TYPE_NONE)
elseif(SB_CONFIG_BOOT_SIGNATURE_TYPE_RSA)
set(keytype CONFIG_BOOT_SIGNATURE_TYPE_RSA)
elseif(SB_CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256)
set(keytype CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256)
elseif(SB_CONFIG_BOOT_SIGNATURE_TYPE_ED25519)
set(keytype CONFIG_BOOT_SIGNATURE_TYPE_ED25519)
endif()

foreach(loopkeytype ${keytypes})
if("${loopkeytype}" STREQUAL "${keytype}")
set_config_bool(${ZCMAKE_APPLICATION} ${loopkeytype} y)
else()
set_config_bool(${ZCMAKE_APPLICATION} ${loopkeytype} n)
endif()
endforeach()

if(SB_CONFIG_BOOTLOADER_MCUBOOT)
if("${SB_CONFIG_SIGNATURE_TYPE}" STREQUAL "NONE")
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE y)
else()
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE n)
endif()
endif()
19 changes: 19 additions & 0 deletions share/sysbuild/image_configurations/MAIN_image_default.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) 2023 Nordic Semiconductor
#
# SPDX-License-Identifier: Apache-2.0

# This sysbuild CMake file sets the sysbuild controlled settings as properties
# on the main Zephyr image.

set_config_bool(${ZCMAKE_APPLICATION} CONFIG_BOOTLOADER_MCUBOOT "${SB_CONFIG_BOOTLOADER_MCUBOOT}")
set_config_string(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_SIGNATURE_KEY_FILE
"${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE}"
)

if(SB_CONFIG_BOOTLOADER_MCUBOOT)
if("${SB_CONFIG_SIGNATURE_TYPE}" STREQUAL "NONE")
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE y)
else()
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE n)
endif()
endif()

0 comments on commit f380f82

Please sign in to comment.