Skip to content

Commit d5582ec

Browse files
committed
[nrf noup] 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 36d18bb commit d5582ec

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

arch/arm/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ config ARM_ON_EXIT_CPU_IDLE
144144
observed on some SoCs caused by a memory access following WFI/WFE
145145
instructions.
146146

147+
config ARCH_PM_S2RAM_RESUME
148+
bool "Include PM S2RAM resume jump"
149+
depends on ARCH_HAS_SUSPEND_TO_RAM && !PM_S2RAM
150+
depends on CPU_CORTEX_M
151+
help
152+
This option enables suspend-to-RAM (S2RAM) resume intermediary support.
153+
It is dedicated for the bootloader use case where the bootloader is the first stage
154+
and its role (in S2RAM flow) is just to mediate in resuming the application from
155+
the suspension.
156+
147157
rsource "core/Kconfig"
148158
rsource "core/Kconfig.vfp"
149159

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_ARCH_PM_S2RAM_RESUME 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_ARCH_PM_S2RAM_RESUME)
104104
#if DT_NODE_EXISTS(DT_NODELABEL(pm_s2ram_stack)) &&\
105105
DT_NODE_HAS_COMPAT(DT_NODELABEL(pm_s2ram_stack), zephyr_memory_region)
106106
/* 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_ARCH_PM_S2RAM_RESUME.
95+
*/
96+
void pm_s2ram_mark_check_and_mediate(void);
8497
/**
8598
* @}
8699
*/

0 commit comments

Comments
 (0)