Skip to content

Commit 9d5d95f

Browse files
nvlsianputomchy
authored andcommitted
[nrf noup] boot/zephyr: improve S2RAM resume support using dedicated API
nrf-squash! [nrf noup] boot/zephyr: nRF54h20 resume from S2RAM (hardened) CONFIG_ARM_SOC_START_HOOK=y allow to rework the resume from S2RAM code to work without PM_S2RAM mocking. It allows to implement only what really needed from the MCUboot perspective. Signed-off-by: Andrzej Puzdrowski <[email protected]> (cherry picked from commit dd353bc)
1 parent 2d12ed6 commit 9d5d95f

File tree

4 files changed

+49
-18
lines changed

4 files changed

+49
-18
lines changed

boot/bootutil/src/loader.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ int pcd_version_cmp_net(const struct flash_area *fap, struct image_header *hdr);
8484
#include "bootutil/key_revocation.h"
8585
#endif
8686

87-
#ifdef CONFIG_SOC_NRF54H20_PM_S2RAM_OVERRIDE
87+
#ifdef CONFIG_SOC_EARLY_RESET_HOOK
8888
void s2ram_designate_slot(uint8_t slot);
8989
#endif
9090

@@ -2965,7 +2965,7 @@ context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp)
29652965
}
29662966
}
29672967

2968-
#ifdef CONFIG_SOC_NRF54H20_PM_S2RAM_OVERRIDE
2968+
#ifdef CONFIG_SOC_EARLY_RESET_HOOK
29692969
/* Designate the slot to be used by the PM_S2RAM resume module */
29702970
s2ram_designate_slot((uint8_t)state->slot_usage[0].active_slot);
29712971
#endif

boot/zephyr/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,8 @@ if(CONFIG_MCUBOOT_CLEANUP_ARM_CORE)
518518
)
519519
endif()
520520

521-
if(CONFIG_SOC_NRF54H20_PM_S2RAM_OVERRIDE)
521+
if(CONFIG_SOC_EARLY_RESET_HOOK)
522+
zephyr_library_sources(${BOOT_DIR}/zephyr/nrf54h20_custom_s2ram.S)
522523
zephyr_library_sources(${BOOT_DIR}/zephyr/nrf54h20_custom_s2ram.c)
523524
endif()
524525

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2025, Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @file
9+
* @brief ARM Cortex-M suspend-to-RAM resume intermediary code (S2RAM)
10+
*/
11+
12+
13+
14+
/*
15+
* resume or
16+
* reboot reboot==T
17+
*[S2RAM sleep]---------->[ boot (reset.S) ]---->[soc_early_reset_hook]---------->[regular boot]
18+
* |
19+
* | resume==T
20+
* \/
21+
* [jump to well-known]
22+
* [ App reset vector ]
23+
*/
24+
25+
26+
27+
#include <zephyr/toolchain.h>
28+
#include <zephyr/arch/cpu.h>
29+
30+
GTEXT(pm_s2ram_mark_check_and_mediate)
31+
32+
GTEXT(soc_early_reset_hook)
33+
SECTION_FUNC(TEXT, soc_early_reset_hook)
34+
#if DT_NODE_EXISTS(DT_NODELABEL(pm_s2ram_stack)) &&\
35+
DT_NODE_HAS_COMPAT(DT_NODELABEL(pm_s2ram_stack), zephyr_memory_region)
36+
ldr r0, =DT_REG_ADDR(DT_NODELABEL(pm_s2ram_stack)) + DT_REG_SIZE(DT_NODELABEL(pm_s2ram_stack))
37+
#else
38+
#error "The support of bridge for S2RAM resume requires dedicated small stack"
39+
#endif
40+
msr msp, r0
41+
push {r0, lr}
42+
bl pm_s2ram_mark_check_and_mediate
43+
pop {r0, pc}

boot/zephyr/nrf54h20_custom_s2ram.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,6 @@ void s2ram_designate_slot(uint8_t slot)
4545
}
4646
#endif
4747

48-
int soc_s2ram_suspend(pm_s2ram_system_off_fn_t system_off)
49-
{
50-
(void)(system_off);
51-
return -1;
52-
}
53-
54-
void pm_s2ram_mark_set(void)
55-
{
56-
/* empty */
57-
}
58-
5948
struct arm_vector_table {
6049
uint32_t msp;
6150
uint32_t reset;
@@ -66,13 +55,13 @@ struct arm_vector_table {
6655
*/
6756
#define APP_EXE_START_OFFSET 0x800 /* nRF54H20 */
6857

69-
bool pm_s2ram_mark_check_and_clear(void)
58+
void pm_s2ram_mark_check_and_mediate(void)
7059
{
7160
uint32_t reset_reason = nrf_resetinfo_resetreas_local_get(NRF_RESETINFO);
7261

7362
if (reset_reason != NRF_RESETINFO_RESETREAS_LOCAL_UNRETAINED_MASK) {
7463
/* Normal boot */
75-
return false;
64+
return;
7665
}
7766

7867
/* S2RAM resume expected, do doublecheck */
@@ -120,6 +109,4 @@ bool pm_s2ram_mark_check_and_clear(void)
120109

121110
resume_failed:
122111
FIH_PANIC;
123-
124-
return true;
125112
}

0 commit comments

Comments
 (0)