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

tests: Enable MCUBoot test on additional platforms #51448

Closed
wants to merge 4 commits into from
Closed
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
3 changes: 0 additions & 3 deletions boards/arm/mg100/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ config MODEM
config MODEM_HL7800
default NETWORKING

config NORDIC_QSPI_NOR
default BOOTLOADER_MCUBOOT

rerickson1 marked this conversation as resolved.
Show resolved Hide resolved
config NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE
default 4096 if NORDIC_QSPI_NOR

Expand Down
3 changes: 0 additions & 3 deletions boards/arm/pinnacle_100_dvk/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ config MODEM
config MODEM_HL7800
default NETWORKING

config NORDIC_QSPI_NOR
default BOOTLOADER_MCUBOOT

config NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE
default 4096 if NORDIC_QSPI_NOR

Expand Down
7 changes: 6 additions & 1 deletion cmake/modules/configuration_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ include_guard(GLOBAL)

include(extensions)

zephyr_get(APPLICATION_CONFIG_DIR)
zephyr_get(SB_FULL_CONFIG_USED)
# Don't use zephyr_get if SB_FULL_CONFIG was on, we don't want to use
# root sysbuild config dir
if(NOT SB_FULL_CONFIG_USED)
zephyr_get(APPLICATION_CONFIG_DIR)
endif()
if(DEFINED APPLICATION_CONFIG_DIR)
string(CONFIGURE ${APPLICATION_CONFIG_DIR} APPLICATION_CONFIG_DIR)
if(NOT IS_ABSOLUTE ${APPLICATION_CONFIG_DIR})
Expand Down
19 changes: 19 additions & 0 deletions cmake/modules/kconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,25 @@ foreach(f ${merge_config_files})
endif()
endforeach()

# If SB_FULL_CONFIG is set, we need to regenerate these configuration files
# with the correct KCONFIG_NAMESPACE to ensure they are used by kconfig.py.
if(SB_FULL_CONFIG)
set(merged_sb_conf "${PROJECT_BINARY_DIR}/include/generated/sysbuild_merged.conf")
file(TOUCH ${merged_sb_conf})
file(APPEND ${merged_sb_conf}
"# Autogenerated file. Do not edit.\n")
foreach(f ${merge_config_files})
file(STRINGS ${f} orig_configs ENCODING UTF-8)
foreach(config ${orig_configs})
# Replace CONFIG_ with SB_CONFIG_ to use correct namespace
string(REGEX REPLACE "CONFIG_(.*)="
"${KCONFIG_NAMESPACE}_\\1=" sb_config ${config})
file(APPEND ${merged_sb_conf} "${sb_config}\n")
endforeach()
endforeach()
set(merge_config_files "${merged_sb_conf}")
endif()

# Calculate a checksum of merge_config_files to determine if we need
# to re-generate .config
set(merge_config_files_checksum "")
Expand Down
12 changes: 12 additions & 0 deletions share/sysbuild/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/modules)
# Note: sysbuild_kconfig will internally load kconfig CMake module.
set(zephyr_modules extensions sysbuild_extensions python west root zephyr_module boards shields sysbuild_kconfig)

# SB_FULL_CONFIG can be used to enable a full set of KConfig values and DTS
# generation for use within Kconfig.sysbuild. Note that this option is
# experimental until there has been futher user testing
# This can be useful to enable or disable sysbuild level KConfig settings.
# Note that all board and SOC level KConfigs will have the SB_CONFIG prefix
if(SB_FULL_CONFIG)
message(STATUS "Full sysbuild configuration was requested")
set(SB_FULL_CONFIG_USED "y" CACHE BOOL "sysbuild full configuration used")
set(zephyr_modules extensions sysbuild_extensions python west root zephyr_module
boards shields arch configuration_files dts sysbuild_kconfig soc)
endif()

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

project(sysbuild LANGUAGES)
Expand Down
1 change: 1 addition & 0 deletions share/sysbuild/cmake/modules/sysbuild_extensions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ function(ExternalZephyrProject_Add)
COMMAND ${CMAKE_COMMAND}
-G${CMAKE_GENERATOR}
-DSYSBUILD:BOOL=True
-DSB_FULL_CONFIG_USED:BOOL=${SB_FULL_CONFIG}
-DSYSBUILD_CACHE:FILEPATH=${sysbuild_cache_file}
${shared_cmake_vars_argument}
-B${CMAKE_BINARY_DIR}/${ZBUILD_APPLICATION}
Expand Down
14 changes: 8 additions & 6 deletions share/sysbuild/cmake/modules/sysbuild_kconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ if(NOT DEFINED SB_CONF_FILE)
endif()

# Empty files to make kconfig.py happy.
file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/empty.conf)
set(APPLICATION_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(KCONFIG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(AUTOCONF_H ${CMAKE_CURRENT_BINARY_DIR}/autoconf.h)
set(CONF_FILE ${SB_CONF_FILE})
set(BOARD_DEFCONFIG "${CMAKE_CURRENT_BINARY_DIR}/empty.conf")
list(APPEND ZEPHYR_KCONFIG_MODULES_DIR BOARD=${BOARD})
set(KCONFIG_NAMESPACE SB_CONFIG)
if(NOT SB_FULL_CONFIG)
file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/empty.conf)
set(APPLICATION_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(KCONFIG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(AUTOCONF_H ${CMAKE_CURRENT_BINARY_DIR}/autoconf.h)
set(CONF_FILE ${SB_CONF_FILE})
set(BOARD_DEFCONFIG "${CMAKE_CURRENT_BINARY_DIR}/empty.conf")
endif()

if(EXISTS ${APP_DIR}/Kconfig.sysbuild)
set(KCONFIG_ROOT ${APP_DIR}/Kconfig.sysbuild)
Expand Down
4 changes: 2 additions & 2 deletions soc/riscv/esp32c3/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

if SOC_ESP32C3

if BOOTLOADER_MCUBOOT

config HAS_FLASH_LOAD_OFFSET
default y

if BOOTLOADER_MCUBOOT

config MCUBOOT_GENERATE_UNSIGNED_IMAGE
default y

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ config TEST_EXTRA_STACK_SIZE
default 1024

config HAS_FLASH_LOAD_OFFSET
default y if BOOTLOADER_MCUBOOT
default y

endif # SOC_SERIES_RISCV_TELINK_B91
5 changes: 3 additions & 2 deletions soc/xtensa/esp32/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

if SOC_ESP32

config HAS_FLASH_LOAD_OFFSET
default y

if BOOTLOADER_MCUBOOT
config HAS_FLASH_LOAD_OFFSET
default y

config MCUBOOT_GENERATE_UNSIGNED_IMAGE
default y
Expand Down
4 changes: 2 additions & 2 deletions soc/xtensa/esp32s2/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

if SOC_ESP32S2

if BOOTLOADER_MCUBOOT

config HAS_FLASH_LOAD_OFFSET
default y

if BOOTLOADER_MCUBOOT

config MCUBOOT_GENERATE_UNSIGNED_IMAGE
default y

Expand Down
24 changes: 24 additions & 0 deletions tests/boot/test_mcuboot/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2022 NXP
#
# SPDX-License-Identifier: Apache-2.0

source "Kconfig.zephyr"

# Enable zephyr dfu boot utility library here, so that if
# KConfig dependencies prevent this symbol from being enabled, CMake
# still will succeed.
config IMG_MANAGER
default y
depends on FLASH_HAS_PAGE_LAYOUT

# Workaround for not being able to have commas in macro arguments
DT_CHOSEN_Z_FLASH := zephyr,flash
ZEPHYR_FLASH_NODE := $(dt_chosen_path,$(DT_CHOSEN_Z_FLASH))

# Since twister cannot parse the DTS to extract the write
# size of the flash node, we will use Kconfig functions to
# do this within the sample. Twister can then filter
# based on this KConfig
config FLASH_WRITE_SIZE
int
default $(dt_node_int_prop_int,$(ZEPHYR_FLASH_NODE),write-block-size)
58 changes: 58 additions & 0 deletions tests/boot/test_mcuboot/Kconfig.sysbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright 2022 NXP
#
# SPDX-License-Identifier: Apache-2.0

# Note that "Kconfig.zephyr" can only be sourced when SB_FULL_CONFIG=y
source "Kconfig.zephyr"

config FLASH
default y

config BOOTLOADER_MCUBOOT
depends on HAS_FLASH_LOAD_OFFSET && \
FLASH_HAS_DRIVER_ENABLED && \
$(dt_nodelabel_enabled,boot_partition) && \
$(dt_nodelabel_enabled,slot0_partition) && \
$(dt_nodelabel_enabled,slot1_partition)
default y


# Since we don't source share/sysbuild/Kconfig, add bootloader options here.

if BOOTLOADER_MCUBOOT

config SIGNATURE_TYPE
string
default NONE if BOOT_SIGNATURE_TYPE_NONE
default RSA if BOOT_SIGNATURE_TYPE_RSA
default ECDSA_P256 if BOOT_SIGNATURE_TYPE_ECDSA_P256
default ED25519 if BOOT_SIGNATURE_TYPE_ED25519

choice
prompt "Signature type"
default BOOT_SIGNATURE_TYPE_RSA

config BOOT_SIGNATURE_TYPE_NONE
bool "No signature; use only hash check"

config BOOT_SIGNATURE_TYPE_RSA
bool "RSA signatures"

config BOOT_SIGNATURE_TYPE_ECDSA_P256
bool "Elliptic curve digital signatures with curve P-256"

config BOOT_SIGNATURE_TYPE_ED25519
bool "Edwards curve digital signatures using ed25519"

endchoice

config BOOT_SIGNATURE_KEY_FILE
string "PEM key file"
default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/root-ec-p256.pem" if BOOT_SIGNATURE_TYPE_ECDSA_P256
default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/root-ed25519.pem" if BOOT_SIGNATURE_TYPE_ED25519
default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/root-rsa-2048.pem" if BOOT_SIGNATURE_TYPE_RSA
default ""
help
Absolute path to key file to use with MCUBoot.

endif
2 changes: 0 additions & 2 deletions tests/boot/test_mcuboot/prj.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Enable zephyr dfu boot utility library
CONFIG_IMG_MANAGER=y
# Enable flash drivers for MCUBoot
CONFIG_FLASH=y
# Enable reboot API to reset board after selecting new image
Expand Down
48 changes: 28 additions & 20 deletions tests/boot/test_mcuboot/sysbuild.cmake
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
# Copyright 2022 NXP
# SPDX-License-Identifier: Apache-2.0

# Add the mcuboot key file to the secondary swapped app
# This must be done here to ensure that the same key file is used for signing
# both the primary and secondary apps
set(swapped_app_CONFIG_MCUBOOT_SIGNATURE_KEY_FILE
\"${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE}\" CACHE STRING
"Signature key file for signing" FORCE)
if(NOT SB_FULL_CONFIG)
message(ERROR "Please pass -DSB_FULL_CONFIG=y when building this sample")
endif()

# Add the swapped app to the build
ExternalZephyrProject_Add(
APPLICATION swapped_app
SOURCE_DIR ${APP_DIR}/swapped_app
)
if (SB_CONFIG_BOOTLOADER_MCUBOOT)
# Add the mcuboot key file to the secondary swapped app
# This must be done here to ensure that the same key file is used for signing
# both the primary and secondary apps
set(swapped_app_CONFIG_MCUBOOT_SIGNATURE_KEY_FILE
\"${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE}\" CACHE STRING
"Signature key file for signing" FORCE)

# Add the swapped app to the list of images to flash
# Ensure the order of images is as follows:
# - mcuboot
# - swapped app
# - primary app (test_mcuboot)
# This order means that if the debugger resets the MCU in between flash
# iterations, the MCUBoot swap won't be triggered until the secondary app
# is actually present in flash.
set(IMAGES "mcuboot" "swapped_app" "test_mcuboot")
# Add the swapped app to the build
ExternalZephyrProject_Add(
APPLICATION swapped_app
SOURCE_DIR ${APP_DIR}/swapped_app
)

# Add the swapped app to the list of images to flash
# Ensure the order of images is as follows:
# - mcuboot
# - swapped app
# - primary app (test_mcuboot)
# This order means that if the debugger resets the MCU in between flash
# iterations, the MCUBoot swap won't be triggered until the secondary app
# is actually present in flash.
set(IMAGES "mcuboot" "swapped_app" "test_mcuboot")
else()
message(WARNING "Target board ${BOARD} does not support mcuboot")
endif()
1 change: 0 additions & 1 deletion tests/boot/test_mcuboot/sysbuild.conf

This file was deleted.

20 changes: 19 additions & 1 deletion tests/boot/test_mcuboot/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,22 @@ common:
tests:
boot.mcuboot:
tags: mcuboot
platform_allow: frdm_k64f mimxrt1060_evk
# riscv32 compiler has issues with LMA adjustment required for this test
arch_exclude: riscv32
extra_args: SB_FULL_CONFIG=y
# Duplicate the target support check MCUBoot does within this filter,
# plus the following additions:
# - ESP32 uses MCUBoot internally, upstream mcuboot does not compile
# - Flash write block size must be less than 32 to sign the image
# - A flash driver must be available
# - Flash load offsets must be supported
filter: "CONFIG_HAS_FLASH_LOAD_OFFSET and
CONFIG_FLASH_HAS_DRIVER_ENABLED and
(not (CONFIG_SOC_ESP32 or CONFIG_SOC_ESP32C3 or CONFIG_SOC_ESP32S2)) and
((dt_chosen_enabled(\"zephyr,flash-controller\") or CONFIG_XTENSA) or
(dt_compat_enabled(\"jedec_spi_nor\") and CONFIG_XTENSA)) and
CONFIG_FLASH_WRITE_SIZE <= 32 and
CONFIG_FLASH_WRITE_SIZE != 0 and
dt_nodelabel_enabled(\"boot_partition\") and
dt_nodelabel_enabled(\"slot0_partition\") and
dt_nodelabel_enabled(\"slot1_partition\")"