Skip to content

Commit bdccaf1

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 a3a5f9e commit bdccaf1

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
@@ -361,14 +361,21 @@ zephyr_udc0: &usbhs {
361361
};
362362

363363
/* temporary stack for S2RAM resume logic */
364-
pm_s2ram_stack: cpuapp_s2ram_stack@22007fd0 {
364+
pm_s2ram_stack: cpuapp_s2ram_stack@22007fcc {
365365
compatible = "zephyr,memory-region", "mmio-sram";
366-
reg = <0x22007fd0 16>;
366+
reg = <0x22007fcc 16>;
367367
zephyr,memory-region = "pm_s2ram_stack";
368368
};
369369

370+
/* run-time common mcuboot S2RAM support section */
371+
mcuboot_s2ram: cpuapp_s2ram@22007fdc {
372+
compatible = "zephyr,memory-region", "mmio-sram";
373+
reg = <0x22007fdc 4>;
374+
zephyr,memory-region = "mcuboot_s2ram_context";
375+
};
376+
370377
/* run-time common S2RAM cpu context RAM */
371-
pm_s2ram: cpuapp_s2ram@22007fe0 {
378+
pm_s2ram: cpuapp_s2ram@22007fe0 {
372379
compatible = "zephyr,memory-region", "mmio-sram";
373380
reg = <0x22007fe0 32>;
374381
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
@@ -77,11 +77,25 @@ static void fpu_power_up(void)
7777
}
7878
#endif /* defined(CONFIG_FPU) */
7979

80+
#if DT_NODE_EXISTS(DT_NODELABEL(mcuboot_s2ram)) &&\
81+
DT_NODE_HAS_COMPAT(DT_NODELABEL(mcuboot_s2ram), zephyr_memory_region)
82+
/* Linker section name is given by `zephyr,memory-region` property of
83+
* `zephyr,memory-region` compatible DT node with nodelabel `mcuboot_s2ram`.
84+
*/
85+
__attribute__((section(DT_PROP(DT_NODELABEL(mcuboot_s2ram), zephyr_memory_region))))
86+
volatile struct mcuboot_resume_s _mcuboot_resume;
87+
88+
#define SET_MCUBOOT_RESUME_MAGIC() _mcuboot_resume.magic = MCUBOOT_S2RAM_RESUME_MAGIC
89+
#else
90+
#define SET_MCUBOOT_RESUME_MAGIC()
91+
#endif
92+
8093
int soc_s2ram_suspend(pm_s2ram_system_off_fn_t system_off)
8194
{
8295
int ret;
8396

8497
z_arm_save_scb_context(&backup_data.scb_context);
98+
SET_MCUBOOT_RESUME_MAGIC();
8599
#if defined(CONFIG_FPU)
86100
#if !defined(CONFIG_FPU_SHARING)
87101
z_arm_save_fp_context(&backup_data.fpu_context);

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)