Skip to content

Commit 77fd66f

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 410c494 commit 77fd66f

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
@@ -366,14 +366,21 @@ zephyr_udc0: &usbhs {
366366
};
367367

368368
/* temporary stack for S2RAM resume logic */
369-
pm_s2ram_stack: cpuapp_s2ram_stack@22007fd0 {
369+
pm_s2ram_stack: cpuapp_s2ram_stack@22007fcc {
370370
compatible = "zephyr,memory-region", "mmio-sram";
371-
reg = <0x22007fd0 16>;
371+
reg = <0x22007fcc 16>;
372372
zephyr,memory-region = "pm_s2ram_stack";
373373
};
374374

375+
/* run-time common mcuboot S2RAM support section */
376+
mcuboot_s2ram: cpuapp_s2ram@22007fdc {
377+
compatible = "zephyr,memory-region", "mmio-sram";
378+
reg = <0x22007fdc 4>;
379+
zephyr,memory-region = "mcuboot_s2ram_context";
380+
};
381+
375382
/* run-time common S2RAM cpu context RAM */
376-
pm_s2ram: cpuapp_s2ram@22007fe0 {
383+
pm_s2ram: cpuapp_s2ram@22007fe0 {
377384
compatible = "zephyr,memory-region", "mmio-sram";
378385
reg = <0x22007fe0 32>;
379386
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)