Skip to content

Commit a95bc05

Browse files
nvlsianpuadamkondraciuk
authored andcommitted
[nrf noup] soc/nordic/nrf54h/pm_s2ram: S2RAM resume hardening
Added support for hardening decision on resume from S2RAM by MCUboot bootloader. Application sets additional variable to MCUBOOT_S2RAM_RESUME_MAGIC which allows the bootloader to doublecheck. Signed-off-by: Andrzej Puzdrowski <[email protected]> (cherry picked from commit d4bb1c6)
1 parent 1e59e1e commit a95bc05

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuapp.dts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,21 @@ zephyr_udc0: &usbhs {
357357
};
358358

359359
/* temporary stack for S2RAM resume logic */
360-
pm_s2ram_stack: cpuapp_s2ram_stack@22007fd0 {
360+
pm_s2ram_stack: cpuapp_s2ram_stack@22007fcc {
361361
compatible = "zephyr,memory-region", "mmio-sram";
362-
reg = <0x22007fd0 16>;
362+
reg = <0x22007fcc 16>;
363363
zephyr,memory-region = "pm_s2ram_stack";
364364
};
365365

366+
/* run-time common mcuboot S2RAM support section */
367+
mcuboot_s2ram: cpuapp_s2ram@22007fdc {
368+
compatible = "zephyr,memory-region", "mmio-sram";
369+
reg = <0x22007fdc 4>;
370+
zephyr,memory-region = "mcuboot_s2ram_context";
371+
};
372+
366373
/* run-time common S2RAM cpu context RAM */
367-
pm_s2ram: cpuapp_s2ram@22007fe0 {
374+
pm_s2ram: cpuapp_s2ram@22007fe0 {
368375
compatible = "zephyr,memory-region", "mmio-sram";
369376
reg = <0x22007fe0 32>;
370377
zephyr,memory-region = "pm_s2ram_context";

soc/nordic/nrf54h/pm_s2ram.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,24 @@ static void fpu_restore(_fpu_context_t *backup)
219219
#endif /* !defined(CONFIG_FPU_SHARING) */
220220
#endif /* defined(CONFIG_FPU) */
221221

222+
#if DT_NODE_EXISTS(DT_NODELABEL(mcuboot_s2ram)) &&\
223+
DT_NODE_HAS_COMPAT(DT_NODELABEL(mcuboot_s2ram), zephyr_memory_region)
224+
/* Linker section name is given by `zephyr,memory-region` property of
225+
* `zephyr,memory-region` compatible DT node with nodelabel `mcuboot_s2ram`.
226+
*/
227+
__attribute__((section(DT_PROP(DT_NODELABEL(mcuboot_s2ram), zephyr_memory_region))))
228+
volatile struct mcuboot_resume_s _mcuboot_resume;
229+
230+
#define SET_MCUBOOT_RESUME_MAGIC() _mcuboot_resume.magic = MCUBOOT_S2RAM_RESUME_MAGIC
231+
#else
232+
#define SET_MCUBOOT_RESUME_MAGIC()
233+
#endif
234+
222235
int soc_s2ram_suspend(pm_s2ram_system_off_fn_t system_off)
223236
{
224237
int ret;
225238

239+
SET_MCUBOOT_RESUME_MAGIC();
226240
scb_save(&backup_data.scb_context);
227241
#if defined(CONFIG_FPU)
228242
#if !defined(CONFIG_FPU_SHARING)

soc/nordic/nrf54h/pm_s2ram.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
#ifndef _ZEPHYR_SOC_ARM_NORDIC_NRF_PM_S2RAM_H_
1111
#define _ZEPHYR_SOC_ARM_NORDIC_NRF_PM_S2RAM_H_
1212

13+
#define MCUBOOT_S2RAM_RESUME_MAGIC 0x75832419
14+
15+
struct mcuboot_resume_s {
16+
uint32_t magic; /* magic value to identify valid structure */
17+
};
18+
1319
/**
1420
* @brief Save CPU state on suspend
1521
*

0 commit comments

Comments
 (0)