Skip to content

Commit 9c8e93f

Browse files
michalek-nonordicjm
authored andcommitted
tests: subsys: bootlader: b0_lock
test for NSIB self lock. Signed-off-by: Mateusz Michalek <mateusz.michalek@nordicsemi.no>
1 parent fbffaa8 commit 9c8e93f

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
9+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
project(NONE)
11+
12+
FILE(GLOB app_sources src/*.c)
13+
target_sources(app PRIVATE ${app_sources})
14+
target_include_directories(app PRIVATE .)
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
CONFIG_ZTEST=y
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr/ztest.h>
8+
#include <hal/nrf_rramc.h>
9+
10+
#define RRAMC_REGION_FOR_BOOTCONF 3
11+
static uint32_t expected_fatal;
12+
static uint32_t actual_fatal;
13+
static nrf_rramc_region_config_t config;
14+
15+
void k_sys_fatal_error_handler(unsigned int reason, const struct arch_esf *pEsf)
16+
{
17+
printk("Caught system error -- reason %d\n", reason);
18+
actual_fatal++;
19+
}
20+
21+
void check_fatal(void *unused)
22+
{
23+
zassert_equal(expected_fatal, actual_fatal,
24+
"Wrong number of fatal errors has occurred (e:%d != a:%d).",
25+
expected_fatal, actual_fatal);
26+
}
27+
28+
void *get_config(void)
29+
{
30+
nrf_rramc_region_config_get(NRF_RRAMC,
31+
RRAMC_REGION_FOR_BOOTCONF,
32+
&config);
33+
zassert_equal(0, config.permissions &
34+
(NRF_RRAMC_REGION_PERM_READ_MASK |
35+
NRF_RRAMC_REGION_PERM_WRITE_MASK |
36+
NRF_RRAMC_REGION_PERM_EXECUTE_MASK),
37+
"Read Write and eXecute permissions aren't cleared");
38+
zassert_true(config.size_kb > 0, "Protected region has zero size.");
39+
return NULL;
40+
}
41+
42+
ZTEST(b0_self_lock_test, test_reading_b0_image)
43+
{
44+
uint32_t protected_end_address = 1024 * config.size_kb;
45+
int val;
46+
47+
printk("Legal read\n");
48+
val = *((volatile int*)protected_end_address);
49+
config.permissions = NRF_RRAMC_REGION_PERM_READ_MASK |
50+
NRF_RRAMC_REGION_PERM_WRITE_MASK |
51+
NRF_RRAMC_REGION_PERM_EXECUTE_MASK;
52+
/* Try unlocking. This should take no effect at this point */
53+
nrf_rramc_region_config_set(NRF_RRAMC, RRAMC_REGION_FOR_BOOTCONF, &config);
54+
printk("Illegal read\n");
55+
expected_fatal++;
56+
val = *((volatile int*)protected_end_address-1);
57+
}
58+
59+
ZTEST_SUITE(b0_self_lock_test, NULL, get_config, NULL, check_fatal, NULL);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
SB_CONFIG_SECURE_BOOT_APPCORE=y
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
tests:
2+
b0.self_lock:
3+
sysbuild: true
4+
extra_args:
5+
- b0_CONFIG_SB_DISABLE_SELF_RWX=y
6+
platform_allow: nrf54l15dk/nrf54l15/cpuapp
7+
integration_platforms:
8+
- nrf54l15dk/nrf54l15/cpuapp
9+
tags:
10+
- b0

0 commit comments

Comments
 (0)