Skip to content

Commit 30183a0

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 7b91e8f commit 30183a0

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-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
@@ -100,7 +100,7 @@ SECTION_SUBSEC_FUNC(TEXT,_reset_section,__start)
100100

101101
#endif /* CONFIG_INIT_ARCH_HW_AT_BOOT */
102102

103-
#if defined(CONFIG_PM_S2RAM)
103+
#if defined(CONFIG_PM_S2RAM) || defined(CONFIG_PM_S2RAM_RESUME_INTERMEDIARY)
104104
/*
105105
* Temporarily set MSP to interrupt stack so that arch_pm_s2ram_resume can
106106
* use stack for calling pm_s2ram_mark_check_and_clear.

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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ 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+
depends on CPU_CORTEX_M
26+
help
27+
This option enables suspend-to-RAM (S2RAM) resume intermediary support.
28+
It is dedicated for the bootloader use case where the bootloader is the first stage
29+
and its role (in S2RAM flow) is just to mediate in resuming the application from
30+
the suspension.
31+
2232
rsource "policy/Kconfig"
2333

2434
if PM

0 commit comments

Comments
 (0)