Skip to content

Commit 123e125

Browse files
committed
[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]>
1 parent 82c2b6b commit 123e125

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuapp.dts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,19 @@ zephyr_udc0: &usbhs {
343343

344344
/* Trim this RAM block for making room on all run-time common S2RAM cpu context. */
345345
&cpuapp_ram0 {
346-
reg = <0x22000000 (DT_SIZE_K(32)-32)>;
347-
ranges = <0x0 0x22000000 (0x8000-0x20)>;
346+
reg = <0x22000000 (DT_SIZE_K(32)-36)>;
347+
ranges = <0x0 0x22000000 (0x8000-0x24)>;
348348
};
349349

350350
/ {
351351
soc {
352+
/* run-time common mcuboot S2RAM support section */
353+
mcuboot_s2ram: cpuapp_s2ram@22007fa0 {
354+
compatible = "zephyr,memory-region", "mmio-sram";
355+
reg = <0x22007fa0 4>;
356+
zephyr,memory-region = "mcuboot_s2ram_context";
357+
};
358+
352359
/* run-time common S2RAM cpu context RAM */
353360
pm_s2ram: cpuapp_s2ram@22007fe0 {
354361
compatible = "zephyr,memory-region", "mmio-sram";

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+
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)