Skip to content

Commit dddc3f3

Browse files
committed
bootloader: Enable NSIB SB_CLEANUP_RAM for nRF54L
The SB_CLEANUP_RAM was being blocked by the EXT_APIs, which were enabled in the NSIB-s prj.conf There are currently no use cases for EXT_APIs for nRF54L and cleanup up RAM after NSIB finishes its work is an important feature, so the part enabling the EXT_APIs needed to be removed from the NSIB-s prj.conf However, backwards compatibility with applications working on nRF52 and nRF53 needed to be mantained, so the EXT_APIs are now enabled by default in KConfings for the NSIB image for these platforms. Note this change aligns with the EXT_APIs documentation - in the documentation it is not described how to enable the EXT_APIs in NSIB when adding a new custom EXT_API. Now, the template will ensure it is enabled in NSIB. Signed-off-by: Artur Hadasz <[email protected]>
1 parent 4e54417 commit dddc3f3

File tree

7 files changed

+34
-12
lines changed

7 files changed

+34
-12
lines changed

doc/nrf/libraries/security/bootloader/fw_info.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ External APIs
5151

5252
The firmware information structure allows for exchange of arbitrary tagged and versioned interfaces called *external APIs* (EXT_APIs).
5353

54+
.. note::
55+
EXT_APIs are currently only supported on the nRF52 and nRF53 Series devices.
56+
5457
An EXT_API structure is a structure consisting of a header followed by arbitrary data.
5558
The header consists of the following information:
5659

samples/bootloader/prj.conf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ CONFIG_LOG_DEFAULT_LEVEL=0
1717
CONFIG_SECURE_BOOT_VALIDATION=y
1818
CONFIG_SECURE_BOOT_VALIDATION_LOG_LEVEL_INF=y
1919
CONFIG_SECURE_BOOT_STORAGE=y
20-
CONFIG_BL_ROT_VERIFY_EXT_API_ENABLED=y
21-
CONFIG_BL_SHA256_EXT_API_ENABLED=y
22-
CONFIG_BL_SECP256R1_EXT_API_ENABLED=y
23-
CONFIG_BL_VALIDATE_FW_EXT_API_ENABLED=y
24-
CONFIG_EXT_API_PROVIDE_EXT_API_ENABLED=y
2520
CONFIG_MAIN_STACK_SIZE=2048
2621
CONFIG_TIMEOUT_64BIT=n
2722

samples/bootloader/prj_minimal.conf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
#
66

77
CONFIG_B0_MIN_PARTITION_SIZE=y
8-
CONFIG_BL_ROT_VERIFY_EXT_API_ENABLED=y
9-
CONFIG_BL_SECP256R1_EXT_API_ENABLED=y
10-
CONFIG_BL_SHA256_EXT_API_ENABLED=y
11-
CONFIG_BL_VALIDATE_FW_EXT_API_ENABLED=y
12-
CONFIG_EXT_API_PROVIDE_EXT_API_ENABLED=y
138
CONFIG_FPROTECT=y
149
CONFIG_FW_INFO=y
1510
CONFIG_IS_SECURE_BOOTLOADER=y

subsys/bootloader/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ config SB_BPROT_IN_DEBUG
101101
config SB_CLEANUP_RAM
102102
bool "Perform RAM cleanup"
103103
depends on !FW_INFO_PROVIDE_ENABLE
104+
depends on !MPU_STACK_GUARD
104105
depends on CPU_CORTEX_M4 || CPU_CORTEX_M33
105106
help
106107
Sets contents of memory to 0 before jumping to application.

subsys/bootloader/bl_boot/bl_boot.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,25 @@
2323
#define CLEANUP_RAM_GAP_START ((int)__ramfunc_region_start)
2424
#define CLEANUP_RAM_GAP_SIZE ((int) (__ramfunc_end - __ramfunc_region_start))
2525

26+
#ifdef CONFIG_SB_CLEANUP_RAM
27+
#define REGIONS_OVERLAP(addr1, size1, addr2, size2) \
28+
((addr1) < ((addr2) + (size2)) && (addr2) < ((addr1) + (size1)))
29+
30+
#define RETAINED_RAM_ADDR(ret_ram_node) DT_REG_ADDR(DT_PARENT(ret_ram_node))
31+
#define RETAINED_RAM_SIZE(ret_ram_node) DT_REG_SIZE(DT_PARENT(ret_ram_node))
32+
33+
34+
#define CHECK_RETAINED_RAM_NO_SRAM_OVERLAP(ret_ram_node) \
35+
BUILD_ASSERT(!REGIONS_OVERLAP(CONFIG_SRAM_BASE_ADDRESS, CONFIG_SRAM_SIZE * 1024, \
36+
RETAINED_RAM_ADDR(ret_ram_node), RETAINED_RAM_SIZE(ret_ram_node)), \
37+
"Retained RAM region overlaps with defined SRAM, cannot cleanup RAM")
38+
39+
/* Ensure that the retained RAM region does not overlap with the defined SRAM region.
40+
* Otherwise, the RAM cleanup would overwrite the retained RAM region.
41+
*/
42+
DT_FOREACH_STATUS_OKAY(zephyr_retained_ram, CHECK_RETAINED_RAM_NO_SRAM_OVERLAP);
43+
#endif
44+
2645
#if defined(CONFIG_SB_DISABLE_NEXT_W)
2746
#include <hal/nrf_rramc.h>
2847
#define RRAMC_REGION_FOR_NEXT_W 4
@@ -175,8 +194,8 @@ static void __ramfunc jump_in(uint32_t reset)
175194
" bx r0\n"
176195
:
177196
: "r" (reset),
178-
"i" (CONFIG_SRAM_BASE_ADDRESS),
179-
"i" (CONFIG_SRAM_SIZE * 1024),
197+
"r" (CONFIG_SRAM_BASE_ADDRESS),
198+
"r" (CONFIG_SRAM_SIZE * 1024),
180199
"r" (CLEANUP_RAM_GAP_START),
181200
"r" (CLEANUP_RAM_GAP_SIZE),
182201
"i" (0)

subsys/fw_info/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ config FW_INFO_PROVIDE_ENABLE
123123
help
124124
Hidden option, set if at least one *_EXT_API_ENABLED option is enabled.
125125

126+
config EXT_API_SUPPORTED
127+
bool
128+
default y if SOC_SERIES_NRF52X
129+
default y if SOC_NRF5340_CPUAPP
130+
default y if SOC_SERIES_NRF91X
131+
help
132+
External APIs are supported on the current platform.
133+
126134
EXT_API = EXT_API_PROVIDE
127135
id = 0x1200
128136
flags = 0

subsys/fw_info/Kconfig.template.fw_info_ext_api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ config $(EXT_API)_EXT_API_AT_LEAST_REQUIRED
4141

4242
config $(EXT_API)_EXT_API_ENABLED
4343
bool "Provide the $(EXT_API) EXT_API to other images"
44+
default y if IS_SECURE_BOOTLOADER && EXT_API_SUPPORTED
4445
select FW_INFO_PROVIDE_ENABLE
4546
help
4647
Provide this EXT_API to other images.

0 commit comments

Comments
 (0)