Skip to content

Commit c3646a3

Browse files
nika-nordickartben
authored andcommitted
soc: nordic: add option for forcing RAM power on reboot
RAM power configuration is preserved through soft reset, meaning that there is a risk of accessing powered off RAM blocks when booting in different application (i.e. bootloader). Add option to force all RAM blocks to be powered on before triggering soft reset to prevent this from happening. Signed-off-by: Nikodem Kastelik <nikodem.kastelik@nordicsemi.no>
1 parent 39c2605 commit c3646a3

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

soc/nordic/common/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ zephyr_linker_symbol(SYMBOL soc_reset_hook EXPR "@SystemInit@")
99
# This file is used when the CMake linker script generator is disabled.
1010
zephyr_linker_sources(SECTIONS platform_init.ld)
1111

12+
# TF-M provides its own reboot sequence
13+
if(NOT CONFIG_TFM_PARTITION_PLATFORM)
14+
zephyr_library_sources_ifdef(CONFIG_ARM reboot.c)
15+
endif()
16+
1217
zephyr_library_sources_ifdef(CONFIG_POWEROFF poweroff.c)
1318
if(CONFIG_ARM)
1419
zephyr_library_sources_ifdef(CONFIG_NRF_PLATFORM_HALTIUM soc_lrcconf.c)

soc/nordic/common/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ config HAS_NORDIC_DMM
77
config HAS_NORDIC_RAM_CTRL
88
bool
99

10+
config NRF_FORCE_RAM_ON_REBOOT
11+
bool "Force all RAM blocks to be powered on before rebooting"
12+
depends on HAS_NORDIC_RAM_CTRL
13+
help
14+
RAM power configuration is preserved through soft reset,
15+
meaning that there is a risk of accessing powered off RAM blocks
16+
when booting in different application (i.e. bootloader).
17+
Force all RAM blocks to be powered on before triggering soft reset
18+
to prevent this from happening.
19+
1020
config NRF_SYS_EVENT
1121
bool "nRF system event support"
1222
select NRFX_POWER if !NRF_PLATFORM_HALTIUM

soc/nordic/common/reboot.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <zephyr/kernel.h>
7+
#include <zephyr/sys/reboot.h>
8+
#if defined(CONFIG_HAS_NORDIC_RAM_CTRL)
9+
#include <helpers/nrfx_ram_ctrl.h>
10+
#endif
11+
12+
void sys_arch_reboot(int type)
13+
{
14+
ARG_UNUSED(type);
15+
16+
#ifdef CONFIG_NRF_FORCE_RAM_ON_REBOOT
17+
uint8_t *ram_start;
18+
size_t ram_size;
19+
20+
#if defined(NRF_MEMORY_RAM_BASE)
21+
ram_start = (uint8_t *)NRF_MEMORY_RAM_BASE;
22+
#else
23+
ram_start = (uint8_t *)NRF_MEMORY_RAM0_BASE;
24+
#endif
25+
26+
ram_size = 0;
27+
#if defined(NRF_MEMORY_RAM_SIZE)
28+
ram_size += NRF_MEMORY_RAM_SIZE;
29+
#endif
30+
#if defined(NRF_MEMORY_RAM0_SIZE)
31+
ram_size += NRF_MEMORY_RAM0_SIZE;
32+
#endif
33+
#if defined(NRF_MEMORY_RAM1_SIZE)
34+
ram_size += NRF_MEMORY_RAM1_SIZE;
35+
#endif
36+
#if defined(NRF_MEMORY_RAM2_SIZE)
37+
ram_size += NRF_MEMORY_RAM2_SIZE;
38+
#endif
39+
40+
/* Power on all RAM blocks */
41+
nrfx_ram_ctrl_power_enable_set(ram_start, ram_size, true);
42+
#endif
43+
44+
NVIC_SystemReset();
45+
}

0 commit comments

Comments
 (0)