tests: Add mcuboot_recovery_retention test
Adds a test that exercises the boot mode (retention subsystem) feature to check that an application can successfully boot into mcuboot's serial recovery mode. Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This commit is contained in:
parent
9c6e394731
commit
a445ee538c
15 changed files with 248 additions and 0 deletions
19
tests/boot/mcuboot_recovery_retention/CMakeLists.txt
Normal file
19
tests/boot/mcuboot_recovery_retention/CMakeLists.txt
Normal file
|
@ -0,0 +1,19 @@
|
|||
#
|
||||
# Copyright (c) 2023 Nordic Semiconductor ASA
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(mcuboot_recovery_retention)
|
||||
|
||||
if(NOT (DEFINED SYSBUILD))
|
||||
message(FATAL_ERROR "This test must be built with sysbuild.")
|
||||
endif()
|
||||
|
||||
FILE(GLOB app_sources
|
||||
src/*.c
|
||||
)
|
||||
|
||||
target_sources(app PRIVATE ${app_sources})
|
|
@ -0,0 +1,42 @@
|
|||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
|
||||
/ {
|
||||
chosen {
|
||||
zephyr,boot-mode = &boot_mode0;
|
||||
};
|
||||
};
|
||||
|
||||
&gpregret1 {
|
||||
status = "okay";
|
||||
|
||||
boot_mode0: boot_mode@0 {
|
||||
compatible = "zephyr,retention";
|
||||
status = "okay";
|
||||
reg = <0x0 0x1>;
|
||||
};
|
||||
};
|
||||
|
||||
/delete-node/ &boot_partition;
|
||||
/delete-node/ &slot0_partition;
|
||||
/delete-node/ &slot1_partition;
|
||||
|
||||
&flash0 {
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
boot_partition: partition@0 {
|
||||
label = "mcuboot";
|
||||
reg = <0x00000000 0x00020000>;
|
||||
};
|
||||
slot0_partition: partition@20000 {
|
||||
label = "image-0";
|
||||
reg = <0x00020000 0x00020000>;
|
||||
};
|
||||
slot1_partition: partition@40000 {
|
||||
label = "image-1";
|
||||
reg = <0x00040000 0x00020000>;
|
||||
};
|
||||
};
|
||||
};
|
|
@ -0,0 +1,7 @@
|
|||
#
|
||||
# Copyright (c) 2023 Nordic Semiconductor ASA
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
CONFIG_RETAINED_MEM_NRF_GPREGRET=n
|
||||
CONFIG_RETAINED_MEM_ZEPHYR_RAM=y
|
|
@ -0,0 +1,61 @@
|
|||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
|
||||
/ {
|
||||
sram@2003FC00 {
|
||||
compatible = "zephyr,memory-region", "mmio-sram";
|
||||
reg = <0x2003FC00 DT_SIZE_K(1)>;
|
||||
zephyr,memory-region = "RetainedMem";
|
||||
status = "okay";
|
||||
|
||||
retainedmem {
|
||||
compatible = "zephyr,retained-ram";
|
||||
status = "okay";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
boot_mode0: boot_mode@0 {
|
||||
compatible = "zephyr,retention";
|
||||
status = "okay";
|
||||
reg = <0x0 0x100>;
|
||||
prefix = [08 04];
|
||||
checksum = <1>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
chosen {
|
||||
zephyr,boot-mode = &boot_mode0;
|
||||
};
|
||||
};
|
||||
|
||||
/delete-node/ &gpregret1;
|
||||
/delete-node/ &gpregret2;
|
||||
/delete-node/ &boot_partition;
|
||||
/delete-node/ &slot0_partition;
|
||||
/delete-node/ &slot1_partition;
|
||||
|
||||
&sram0 {
|
||||
reg = <0x20000000 DT_SIZE_K(255)>;
|
||||
};
|
||||
|
||||
&flash0 {
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
boot_partition: partition@0 {
|
||||
label = "mcuboot";
|
||||
reg = <0x00000000 0x00020000>;
|
||||
};
|
||||
slot0_partition: partition@20000 {
|
||||
label = "image-0";
|
||||
reg = <0x00020000 0x00020000>;
|
||||
};
|
||||
slot1_partition: partition@40000 {
|
||||
label = "image-1";
|
||||
reg = <0x00040000 0x00020000>;
|
||||
};
|
||||
};
|
||||
};
|
10
tests/boot/mcuboot_recovery_retention/prj.conf
Normal file
10
tests/boot/mcuboot_recovery_retention/prj.conf
Normal file
|
@ -0,0 +1,10 @@
|
|||
#
|
||||
# Copyright (c) 2023 Nordic Semiconductor ASA
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
CONFIG_RETAINED_MEM=y
|
||||
CONFIG_RETENTION=y
|
||||
CONFIG_RETENTION_BOOT_MODE=y
|
||||
CONFIG_REBOOT=y
|
||||
CONFIG_LOG=y
|
25
tests/boot/mcuboot_recovery_retention/src/main.c
Normal file
25
tests/boot/mcuboot_recovery_retention/src/main.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <zephyr/sys/reboot.h>
|
||||
#include <zephyr/retention/bootmode.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void main(void)
|
||||
{
|
||||
printf("Waiting...\n");
|
||||
k_sleep(K_SECONDS(1));
|
||||
|
||||
int rc = bootmode_set(BOOT_MODE_TYPE_BOOTLOADER);
|
||||
|
||||
if (rc == 0) {
|
||||
sys_reboot(SYS_REBOOT_WARM);
|
||||
} else {
|
||||
printf("Error, failed to set boot mode: %d\n", rc);
|
||||
}
|
||||
}
|
1
tests/boot/mcuboot_recovery_retention/sysbuild.cmake
Normal file
1
tests/boot/mcuboot_recovery_retention/sysbuild.cmake
Normal file
|
@ -0,0 +1 @@
|
|||
set(mcuboot_ZEPHYR_EXTRA_MODULES "${CMAKE_CURRENT_LIST_DIR}/test_module" CACHE INTERNAL "test_module directory")
|
1
tests/boot/mcuboot_recovery_retention/sysbuild.conf
Normal file
1
tests/boot/mcuboot_recovery_retention/sysbuild.conf
Normal file
|
@ -0,0 +1 @@
|
|||
SB_CONFIG_BOOTLOADER_MCUBOOT=y
|
|
@ -0,0 +1,5 @@
|
|||
CONFIG_USE_SEGGER_RTT=n
|
||||
CONFIG_NORDIC_QSPI_NOR=n
|
||||
CONFIG_BOOT_VALIDATE_SLOT0=n
|
||||
CONFIG_MCUBOOT_CLEANUP_ARM_CORE=n
|
||||
CONFIG_BOOT_WATCHDOG_FEED=n
|
|
@ -0,0 +1,14 @@
|
|||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
#include "../../../boards/nrf52840dk_nrf52840.overlay"
|
||||
|
||||
/ {
|
||||
chosen {
|
||||
zephyr,code-partition = &boot_partition;
|
||||
};
|
||||
};
|
||||
|
||||
&zephyr_udc0 {
|
||||
cdc_acm_uart0 {
|
||||
compatible = "zephyr,cdc-acm-uart";
|
||||
};
|
||||
};
|
|
@ -0,0 +1,11 @@
|
|||
CONFIG_MCUBOOT_SERIAL=y
|
||||
CONFIG_BOOT_SERIAL_CDC_ACM=y
|
||||
CONFIG_BOOT_SERIAL_ENTRANCE_GPIO=n
|
||||
CONFIG_BOOT_SERIAL_BOOT_MODE=y
|
||||
CONFIG_RETAINED_MEM=y
|
||||
CONFIG_RETENTION=y
|
||||
CONFIG_RETENTION_BOOT_MODE=y
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FLASH_MAP=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_MCUBOOT_ACTION_HOOKS=y
|
|
@ -0,0 +1,4 @@
|
|||
if(CONFIG_MCUBOOT)
|
||||
# Append source file which outputs the current mode of mcuboot
|
||||
target_sources(app PRIVATE src/hook.c)
|
||||
endif()
|
14
tests/boot/mcuboot_recovery_retention/test_module/src/hook.c
Normal file
14
tests/boot/mcuboot_recovery_retention/test_module/src/hook.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <bootutil/mcuboot_status.h>
|
||||
|
||||
void mcuboot_status_change(mcuboot_status_type_t status)
|
||||
{
|
||||
printf("mcuboot_status: %d\n", status);
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
build:
|
||||
cmake: .
|
32
tests/boot/mcuboot_recovery_retention/testcase.yaml
Normal file
32
tests/boot/mcuboot_recovery_retention/testcase.yaml
Normal file
|
@ -0,0 +1,32 @@
|
|||
#
|
||||
# Copyright (c) 2023 Nordic Semiconductor ASA
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
common:
|
||||
sysbuild: true
|
||||
timeout: 10
|
||||
harness: console
|
||||
harness_config:
|
||||
type: multi_line
|
||||
regex:
|
||||
- "mcuboot_status: 0"
|
||||
- "mcuboot_status: 1"
|
||||
- "mcuboot_status: 2"
|
||||
- "Waiting..."
|
||||
- "mcuboot_status: 0"
|
||||
- "mcuboot_status: 1"
|
||||
- "mcuboot_status: 8"
|
||||
- "Starting bootloader"
|
||||
- "Secondary image: magic"
|
||||
- "Boot source: none"
|
||||
tests:
|
||||
mcuboot.recovery.retention:
|
||||
platform_allow: nrf52840dk_nrf52840
|
||||
tags: mcuboot sysbuild recovery
|
||||
mcuboot.recovery.retention.mem:
|
||||
platform_allow: nrf52840dk_nrf52840
|
||||
extra_args: |
|
||||
'OVERLAY_CONFIG="nrf52840dk_nrf52840_mem.conf"'
|
||||
'DTC_OVERLAY_FILE="boards/nrf52840dk_nrf52840_mem.overlay"'
|
||||
tags: mcuboot sysbuild recovery
|
Loading…
Add table
Add a link
Reference in a new issue