Skip to content

Commit 95cbf6b

Browse files
tomchynvlsianpu
authored andcommitted
[nrf fromlist] 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. Upstream PR #: 95914 Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent 82ca599 commit 95cbf6b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

arch/arm/core/cortex_m/reset.S

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

8585
#if defined(CONFIG_PM_S2RAM) || defined(CONFIG_PM_S2RAM_RESUME_INTERMEDIARY)
86+
#if DT_NODE_EXISTS(DT_NODELABEL(pm_s2ram_stack)) &&\
87+
DT_NODE_HAS_COMPAT(DT_NODELABEL(pm_s2ram_stack), zephyr_memory_region)
88+
/* In certain scenarios, the interrupt stack is actually not safe to overwrite.
89+
* For example, when MCUboot is used, the bootloader's "z_interrupt_stack" and the
90+
* loaded image's "z_interrupt_stacks" are NOT at the same address, and writing to
91+
* the former would corrupt unrelated data from the loaded image. To support such
92+
* scenarios, if the Device Tree provides a specially named "zephyr,memory-region",
93+
* use it as the stack to run arch_pm_s2ram_resume instead of the interrupt stack.
94+
*/
95+
ldr r0, =DT_REG_ADDR(DT_NODELABEL(pm_s2ram_stack)) + DT_REG_SIZE(DT_NODELABEL(pm_s2ram_stack))
96+
#else
8697
/*
8798
* Temporarily set MSP to interrupt stack so that arch_pm_s2ram_resume can
8899
* use stack for calling pm_s2ram_mark_check_and_clear.
@@ -95,6 +106,7 @@ SECTION_SUBSEC_FUNC(TEXT,_reset_section,__start)
95106
* a short while, there is no change in behavior in either of the paths.
96107
*/
97108
ldr r0, =z_interrupt_stacks + CONFIG_ISR_STACK_SIZE + MPU_GUARD_ALIGN_AND_SIZE
109+
#endif
98110
msr msp, r0
99111

100112
bl arch_pm_s2ram_resume

subsys/pm/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ config PM_S2RAM
5151
When enabled on Cortex-M, and a 'zephyr,memory-region' compatible node with nodelabel
5252
'pm_s2ram' is defined in DT, _cpu_context symbol (located in arch/arm/core/cortex_m/pm_s2ram.c)
5353
is placed in linker section given by 'zephyr,memory-region' property of aforementioned node.
54+
Additionally on Cortex-M, if a 'zephyr,memory-region' compatible node with nodelabel
55+
'pm_s2ram_stack' is defined in DT, this region will be used as a temporary program stack
56+
for the S2RAM resume logic. The assembly reset handling code itself makes a single push of
57+
the return address, but the SoC-specific function (pm_s2ram_mark_check_and_clear) must be
58+
analyzed to determine the required stack size.
5459

5560
config PM_S2RAM_CUSTOM_MARKING
5661
bool "Use custom marking functions"

0 commit comments

Comments
 (0)