tests: boot: add mcuboot test
Add test to verify mcuboot support. This test is only enabled for specific platforms, since it it not possible to filter for mcuboot support. Sysbuild support is required to flash multiple samples using twister. Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
This commit is contained in:
parent
50c7341070
commit
0dacc2583d
9
tests/boot/test_mcuboot/CMakeLists.txt
Normal file
9
tests/boot/test_mcuboot/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(test_mcuboot)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
12
tests/boot/test_mcuboot/README.rst
Normal file
12
tests/boot/test_mcuboot/README.rst
Normal file
|
@ -0,0 +1,12 @@
|
|||
MCUBoot Swap Testing
|
||||
#####################
|
||||
|
||||
Tests MCUBoot's image swap support. This application is built in three parts
|
||||
using sysbuild. The first application is the MCUBoot bootloader. The second
|
||||
application is the main sysbuild target, and will request an image swap
|
||||
from MCUBoot when booted. The third application is build with a load address
|
||||
adjustment using CONFIG_BUILD_OUTPUT_ADJUST_LMA, and will be the application
|
||||
that MCUBoot swaps to when the image swap is requested.
|
||||
|
||||
This sequence of applications allows the test to verify support for the MCUBoot
|
||||
upgrade process on any platform supporting it.
|
6
tests/boot/test_mcuboot/prj.conf
Normal file
6
tests/boot/test_mcuboot/prj.conf
Normal file
|
@ -0,0 +1,6 @@
|
|||
# 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
|
||||
CONFIG_REBOOT=y
|
19
tests/boot/test_mcuboot/src/main.c
Normal file
19
tests/boot/test_mcuboot/src/main.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* Copyright 2022 NXP
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/sys/reboot.h>
|
||||
#include <zephyr/dfu/mcuboot.h>
|
||||
|
||||
/* Main entry point */
|
||||
void main(void)
|
||||
{
|
||||
printk("Launching primary slot application on %s\n", CONFIG_BOARD);
|
||||
/* Perform a permanent swap of MCUBoot application */
|
||||
boot_request_upgrade(1);
|
||||
printk("Secondary application ready for swap, rebooting\n");
|
||||
sys_reboot(SYS_REBOOT_COLD);
|
||||
}
|
9
tests/boot/test_mcuboot/swapped_app/CMakeLists.txt
Normal file
9
tests/boot/test_mcuboot/swapped_app/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(test_mcuboot)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
9
tests/boot/test_mcuboot/swapped_app/Kconfig
Normal file
9
tests/boot/test_mcuboot/swapped_app/Kconfig
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Copyright 2022 NXP
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
source "Kconfig.zephyr"
|
||||
# Workaround for not being able to have commas in macro arguments
|
||||
DT_CHOSEN_Z_CODE_PARTITION := zephyr,code-partition
|
||||
|
||||
config BUILD_OUTPUT_ADJUST_LMA
|
||||
default "$(dt_node_reg_addr_hex,$(dt_nodelabel_path,slot1_partition))-\
|
||||
$(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_CODE_PARTITION))"
|
5
tests/boot/test_mcuboot/swapped_app/prj.conf
Normal file
5
tests/boot/test_mcuboot/swapped_app/prj.conf
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Since LMA adjustment is used to move the image location to the secondary
|
||||
# slot, we need to enable hex build output. Otherwise, some debuggers will not
|
||||
# flash the binary to the second image slot.
|
||||
CONFIG_BUILD_OUTPUT_HEX=y
|
||||
CONFIG_BOOTLOADER_MCUBOOT=y
|
13
tests/boot/test_mcuboot/swapped_app/src/main.c
Normal file
13
tests/boot/test_mcuboot/swapped_app/src/main.c
Normal file
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* Copyright 2022 NXP
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
|
||||
/* Main entry point */
|
||||
void main(void)
|
||||
{
|
||||
printk("Swapped application booted on %s\n", CONFIG_BOARD);
|
||||
}
|
25
tests/boot/test_mcuboot/sysbuild.cmake
Normal file
25
tests/boot/test_mcuboot/sysbuild.cmake
Normal file
|
@ -0,0 +1,25 @@
|
|||
# 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)
|
||||
|
||||
# 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")
|
1
tests/boot/test_mcuboot/sysbuild.conf
Normal file
1
tests/boot/test_mcuboot/sysbuild.conf
Normal file
|
@ -0,0 +1 @@
|
|||
SB_CONFIG_BOOTLOADER_MCUBOOT=y
|
15
tests/boot/test_mcuboot/testcase.yaml
Normal file
15
tests/boot/test_mcuboot/testcase.yaml
Normal file
|
@ -0,0 +1,15 @@
|
|||
common:
|
||||
sysbuild: True
|
||||
harness: console
|
||||
harness_config:
|
||||
type: multi_line
|
||||
regex:
|
||||
- "I: Starting bootloader"
|
||||
- "Launching primary slot application on (.*)"
|
||||
- "Secondary application ready for swap, rebooting"
|
||||
- "I: Starting swap using (.*)"
|
||||
- "Swapped application booted on (.*)"
|
||||
tests:
|
||||
boot.mcuboot:
|
||||
tags: mcuboot
|
||||
platform_allow: frdm_k64f mimxrt1060_evk
|
Loading…
Reference in a new issue