Skip to content

Commit 077fd10

Browse files
committed
arch/arm/cortex_m: support for bridge for S2RAM
for case when the zephyr-rtos application is the bootloader and booted target application had suspended the device, the resume operation would be initiated by the bootloader which could redirect execution to the application S2RAM routines directly. Thanks to that target application would resume using compiled in S2RAM routines. Such scheme allows the zephyr-rtos based bootloader to not mock the application while does S2RAM resume operation. Therefore no need for keeping compatibility with S2RAM resume mechanism in application. No need to enable PM nor PM_S2RAM anymore in the bootloader. Signed-off-by: Andrzej Puzdrowski <[email protected]>
1 parent d32b794 commit 077fd10

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

arch/arm/core/cortex_m/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ zephyr_library_sources_ifdef(CONFIG_DEBUG_COREDUMP coredump.c)
4141
zephyr_library_sources_ifdef(CONFIG_THREAD_LOCAL_STORAGE __aeabi_read_tp.S)
4242
zephyr_library_sources_ifdef(CONFIG_SEMIHOST semihost.c)
4343
zephyr_library_sources_ifdef(CONFIG_PM_S2RAM pm_s2ram.c pm_s2ram.S)
44+
zephyr_library_sources_ifdef(CONFIG_PM_S2RAM_RESUME_INTERMEDIARY pm_s2ram_intermediary.S)
4445
zephyr_library_sources_ifdef(CONFIG_ARCH_CACHE cache.c)
4546
zephyr_library_sources_ifdef(CONFIG_SW_VECTOR_RELAY irq_relay.S)
4647

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
#include <zephyr/toolchain.h>
13+
#include <zephyr/arch/cpu.h>
14+
#include <zephyr/arch/common/pm_s2ram.h>
15+
16+
GTEXT(pm_s2ram_mark_check_and_mediate)
17+
18+
GTEXT(arch_pm_s2ram_resume)
19+
SECTION_FUNC(TEXT, arch_pm_s2ram_resume)
20+
/*
21+
* Check if reset occurred after suspending to RAM.
22+
* Store LR to ensure we can continue boot when we are not suspended
23+
* to RAM. In addition to LR, R0 is pushed too, to ensure "SP mod 8 = 0",
24+
* as stated by ARM rule 6.2.1.2 for AAPCS32.
25+
*/
26+
push {r0, lr}
27+
bl pm_s2ram_mark_check_and_mediate
28+
pop {r0, pc}

arch/arm/core/cortex_m/reset.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ SECTION_SUBSEC_FUNC(TEXT,_reset_section,__start)
8282

8383
#endif /* CONFIG_INIT_ARCH_HW_AT_BOOT */
8484

85-
#if defined(CONFIG_PM_S2RAM)
85+
#if defined(CONFIG_PM_S2RAM) || defined(CONFIG_PM_S2RAM_RESUME_INTERMEDIARY)
8686
#if DT_NODE_EXISTS(DT_NODELABEL(pm_s2ram_stack)) &&\
8787
DT_NODE_HAS_COMPAT(DT_NODELABEL(pm_s2ram_stack), zephyr_memory_region)
8888
/* In certain scenarios, the interrupt stack is actually not safe to overwrite.

include/zephyr/arch/common/pm_s2ram.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ void pm_s2ram_mark_set(void);
8181
* @retval false if marking is not found which indicates standard boot.
8282
*/
8383
bool pm_s2ram_mark_check_and_clear(void);
84+
85+
/**
86+
* @brief Check suspend-to-RAM marking and does mediation.
87+
*
88+
* Function does resume mediation if determines resuming after suspend-to-RAM
89+
* or return so standard boot will be executed.
90+
*
91+
* Implementation is up to given application - usually a bootloader. The function is expected
92+
* to do mediation needed for resuming the application from S2AM state, which usually means no
93+
* return to caller. Usage of this API implementation shall be enabled using
94+
* CONFIG_PM_S2RAM_RESUME_INTERMEDIARY.
95+
*/
96+
void pm_s2ram_mark_check_and_mediate(void);
8497
/**
8598
* @}
8699
*/

subsys/pm/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ config PM
1919
power management subsystem of the number of ticks until the next kernel
2020
timer is due to expire.
2121

22+
config PM_S2RAM_RESUME_INTERMEDIARY
23+
bool "Resume intermeniary fo Suspend-to-RAM (S2RAM)"
24+
depends on ARCH_HAS_SUSPEND_TO_RAM &&! PM_S2RAM
25+
help
26+
This option enables suspend-to-RAM (S2RAM) resume intermediary support.
27+
It is dedicated fothe r bootloader use case where the bootloader is the first stage
28+
and its role (in S2RAM flow) is to mediate in resuming the application from the suspension.
29+
30+
2231
rsource "policy/Kconfig"
2332

2433
if PM

0 commit comments

Comments
 (0)