tests: boot: Add MCUboot data sharing test

Adds a test for the data sharing retention feature of MCUboot
configuration to an application.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This commit is contained in:
Jamie McCrae 2023-06-09 14:27:38 +01:00 committed by Anas Nashif
parent db4febc584
commit ce65806cd4
11 changed files with 266 additions and 0 deletions

View file

@ -625,6 +625,7 @@ flagged.
"BOOT_SERIAL_ENTRANCE_GPIO", # Used in (sysbuild-based) test
"BOOT_SERIAL_IMG_GRP_HASH", # Used in documentation
"BOOT_SHARE_DATA", # Used in Kconfig text
"BOOT_SHARE_DATA_BOOTINFO", # Used in (sysbuild-based) test
"BOOT_SHARE_BACKEND_RETENTION", # Used in Kconfig text
"BOOT_SIGNATURE_KEY_FILE", # MCUboot setting used by sysbuild
"BOOT_SIGNATURE_TYPE_ECDSA_P256", # MCUboot setting used by sysbuild

View file

@ -0,0 +1,30 @@
#
# 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})
# Get MCUboot version from the VERSION file in the repository and create a local output header
# version file so that it can be compared against in the test
set(VERSION_FILE ${ZEPHYR_MCUBOOT_MODULE_DIR}/boot/zephyr/VERSION)
set(VERSION_TYPE MCUBOOT)
set(BUILD_VERSION_NAME MCUBOOT_BUILD_VERSION)
include(${ZEPHYR_BASE}/cmake/modules/version.cmake)
file(READ ${ZEPHYR_BASE}/version.h.in version_content)
string(CONFIGURE "${version_content}" version_content)
string(CONFIGURE "${version_content}" version_content)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/zephyr/include/generated/mcuboot_version.h "${version_content}")

View file

@ -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

View file

@ -0,0 +1,58 @@
/* SPDX-License-Identifier: Apache-2.0 */
/ {
sram@2003F000 {
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x2003F000 DT_SIZE_K(1)>;
zephyr,memory-region = "RetainedMem";
status = "okay";
retainedmem {
compatible = "zephyr,retained-ram";
status = "okay";
#address-cells = <1>;
#size-cells = <1>;
boot_info0: boot_info@0 {
compatible = "zephyr,retention";
status = "okay";
reg = <0x0 0x100>;
};
};
};
chosen {
zephyr,bootloader-info = &boot_info0;
};
};
/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 0x00022000>;
};
slot1_partition: partition@42000 {
label = "image-1";
reg = <0x00042000 0x00024000>;
};
};
};

View file

@ -0,0 +1,13 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0
#
CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=y
CONFIG_RETAINED_MEM=y
CONFIG_RETENTION=y
CONFIG_SETTINGS=y
CONFIG_SETTINGS_RUNTIME=y
CONFIG_RETENTION_BOOTLOADER_INFO=y
CONFIG_RETENTION_BOOTLOADER_INFO_TYPE_MCUBOOT=y

View file

@ -0,0 +1,122 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdint.h>
#include <stdio.h>
#include <zephyr/ztest.h>
#include <zephyr/kernel.h>
#include <zephyr/settings/settings.h>
#include <bootutil/boot_status.h>
#include <bootutil/image.h>
#include <mcuboot_version.h>
#define FLASH_SECTOR_SIZE 1024
#define FLASH_SECTOR_SIZE_KB 4
#define FLASH_MAX_APP_SECTORS 34
#define FLASH_RESERVED_SECTORS 1
#define FLASH_MAX_APP_SIZE ((FLASH_MAX_APP_SECTORS - FLASH_RESERVED_SECTORS) \
* FLASH_SECTOR_SIZE_KB)
#define RUNNING_SLOT 0
ZTEST(mcuboot_shared_data, test_mode)
{
uint8_t var[1];
int rc;
memset(var, 0xff, sizeof(var));
rc = settings_runtime_get("blinfo/mode", var, sizeof(var));
zassert_equal(rc, sizeof(var), "Expected data length mismatch");
zassert_equal(var[0], MCUBOOT_MODE_SWAP_USING_MOVE, "Expected data mismatch");
}
ZTEST(mcuboot_shared_data, test_signature_type)
{
uint8_t var[1];
int rc;
memset(var, 0xff, sizeof(var));
rc = settings_runtime_get("blinfo/signature_type", var, sizeof(var));
zassert_equal(rc, sizeof(var), "Expected data length mismatch");
zassert_equal(var[0], MCUBOOT_SIGNATURE_TYPE_RSA, "Expected data mismatch");
}
ZTEST(mcuboot_shared_data, test_recovery)
{
uint8_t var[1];
int rc;
memset(var, 0xff, sizeof(var));
rc = settings_runtime_get("blinfo/recovery", var, sizeof(var));
zassert_equal(rc, sizeof(var), "Expected data length mismatch");
zassert_equal(var[0], MCUBOOT_RECOVERY_MODE_NONE, "Expected data mismatch");
}
ZTEST(mcuboot_shared_data, test_running_slot)
{
uint8_t var[1];
int rc;
memset(var, 0xff, sizeof(var));
rc = settings_runtime_get("blinfo/running_slot", var, sizeof(var));
zassert_equal(rc, sizeof(var), "Expected data length mismatch");
zassert_equal(var[0], RUNNING_SLOT, "Expected data mismatch");
}
ZTEST(mcuboot_shared_data, test_bootloader_version)
{
uint8_t var[8];
int rc;
struct image_version *version = (void *)var;
memset(var, 0xff, sizeof(var));
rc = settings_runtime_get("blinfo/bootloader_version", var, sizeof(var));
zassert_equal(rc, sizeof(var), "Expected data length mismatch");
zassert_equal(version->iv_major, MCUBOOT_VERSION_MAJOR,
"Expected version (major) mismatch");
zassert_equal(version->iv_minor, MCUBOOT_VERSION_MINOR,
"Expected version (minor) mismatch");
zassert_equal(version->iv_revision, MCUBOOT_PATCHLEVEL,
"Expected version (patch level) mismatch");
zassert_equal(version->iv_build_num, 0, "Expected version (build number) mismatch");
}
ZTEST(mcuboot_shared_data, test_max_application_size)
{
uint8_t var[4];
uint32_t value;
int rc;
memset(var, 0xff, sizeof(var));
rc = settings_runtime_get("blinfo/max_application_size", var, sizeof(var));
zassert_equal(rc, sizeof(var), "Expected data length mismatch");
memcpy(&value, var, sizeof(value));
value /= FLASH_SECTOR_SIZE;
zassert_equal(value, FLASH_MAX_APP_SIZE, "Expected data mismatch");
}
ZTEST(mcuboot_shared_data, test_invalid)
{
uint8_t var[4];
int rc;
memset(var, 0xff, sizeof(var));
rc = settings_runtime_get("blinfo/does_not_exist", var, sizeof(var));
zassert_not_equal(rc, sizeof(var), "Expected data length (error) mismatch");
zassert_not_equal(rc, 0, "Expected data length (error) mismatch");
}
ZTEST(mcuboot_shared_data, test_bootloader_version_limited)
{
uint8_t var[2];
int rc;
memset(var, 0xff, sizeof(var));
rc = settings_runtime_get("blinfo/bootloader_version", var, sizeof(var));
zassert_not_equal(rc, sizeof(var), "Expected data length mismatch");
}
ZTEST_SUITE(mcuboot_shared_data, NULL, NULL, NULL, NULL, NULL);

View file

@ -0,0 +1 @@
SB_CONFIG_BOOTLOADER_MCUBOOT=y

View file

@ -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

View file

@ -0,0 +1,8 @@
/* SPDX-License-Identifier: Apache-2.0 */
#include "../../../boards/nrf52840dk_nrf52840.overlay"
/ {
chosen {
zephyr,code-partition = &boot_partition;
};
};

View file

@ -0,0 +1,7 @@
CONFIG_RETAINED_MEM=y
CONFIG_RETENTION=y
CONFIG_BOOT_SHARE_DATA=y
CONFIG_BOOT_SHARE_DATA_BOOTINFO=y
CONFIG_BOOT_SHARE_BACKEND_RETENTION=y
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y

View file

@ -0,0 +1,14 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0
#
common:
sysbuild: true
tests:
mcuboot.data.sharing:
platform_allow: nrf52840dk_nrf52840
tags:
- mcuboot
- sysbuild
- retention