Skip to content

Commit 92fd1cb

Browse files
committed
arch: Allow to specify memory for S2RAM resume
If the area, dedicated for the interrupt stack is not available, allow to specify a memory region that will be used as the stack for the S2RAM resume logic. Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent 335e1c2 commit 92fd1cb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

arch/arm/core/cortex_m/reset.S

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ SECTION_SUBSEC_FUNC(TEXT,_reset_section,__start)
101101
#endif /* CONFIG_INIT_ARCH_HW_AT_BOOT */
102102

103103
#if defined(CONFIG_PM_S2RAM)
104+
#if DT_NODE_EXISTS(DT_NODELABEL(pm_s2ram_stack)) &&\
105+
DT_NODE_HAS_COMPAT(DT_NODELABEL(pm_s2ram_stack), zephyr_memory_region)
106+
/* In certain scenarios, the interrupt stack is actually not safe to overwrite.
107+
* For example, when MCUboot is used, the bootloader's "z_interrupt_stack" and the
108+
* loaded image's "z_interrupt_stacks" are NOT at the same address, and writing to
109+
* the former would corrupt unrelated data from the loaded image. To support such
110+
* scenarios, if the Device Tree provides a specially named "zephyr,memory-region",
111+
* use it as the stack to run arch_pm_s2ram_resume instead of the interrupt stack.
112+
*/
113+
ldr r0, =DT_REG_ADDR(DT_NODELABEL(pm_s2ram_stack)) + DT_REG_SIZE(DT_NODELABEL(pm_s2ram_stack))
114+
#else
104115
/*
105116
* Temporarily set MSP to interrupt stack so that arch_pm_s2ram_resume can
106117
* use stack for calling pm_s2ram_mark_check_and_clear.
@@ -113,6 +124,7 @@ SECTION_SUBSEC_FUNC(TEXT,_reset_section,__start)
113124
* a short while, there is no change in behavior in either of the paths.
114125
*/
115126
ldr r0, =z_interrupt_stacks + CONFIG_ISR_STACK_SIZE + MPU_GUARD_ALIGN_AND_SIZE
127+
#endif
116128
msr msp, r0
117129

118130
bl arch_pm_s2ram_resume

0 commit comments

Comments
 (0)