From b480fc3883ed6f515f57ad51a768130483329005 Mon Sep 17 00:00:00 2001 From: Andrzej Puzdrowski Date: Thu, 18 Sep 2025 15:56:42 +0200 Subject: [PATCH 1/2] [nrf noup] boot/zephyr: improve S2RAM resume support using dedicated API nrf-squash! [nrf noup] boot/zephyr: nRF54h20 resume from S2RAM (hardened) CONFIG_ARM_SOC_START_HOOK=y allow to rework the resume from S2RAM code to work without PM_S2RAM mocking. It allows to implement only what really needed from the MCUboot perspective. Signed-off-by: Andrzej Puzdrowski --- boot/zephyr/CMakeLists.txt | 3 +- boot/zephyr/nrf54h20_custom_s2ram.S | 43 +++++++++++++++++++++++++++++ boot/zephyr/nrf54h20_custom_s2ram.c | 17 ++---------- 3 files changed, 47 insertions(+), 16 deletions(-) create mode 100644 boot/zephyr/nrf54h20_custom_s2ram.S diff --git a/boot/zephyr/CMakeLists.txt b/boot/zephyr/CMakeLists.txt index 6bd93f35a..b34824def 100644 --- a/boot/zephyr/CMakeLists.txt +++ b/boot/zephyr/CMakeLists.txt @@ -496,7 +496,8 @@ if(CONFIG_MCUBOOT_CLEANUP_ARM_CORE) ) endif() -if(CONFIG_SOC_NRF54H20_PM_S2RAM_OVERRIDE) +if(CONFIG_SOC_EARLY_RESET_HOOK) + zephyr_library_sources(${BOOT_DIR}/zephyr/nrf54h20_custom_s2ram.S) zephyr_library_sources(${BOOT_DIR}/zephyr/nrf54h20_custom_s2ram.c) endif() diff --git a/boot/zephyr/nrf54h20_custom_s2ram.S b/boot/zephyr/nrf54h20_custom_s2ram.S new file mode 100644 index 000000000..1ffa17f42 --- /dev/null +++ b/boot/zephyr/nrf54h20_custom_s2ram.S @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025, Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief ARM Cortex-M suspend-to-RAM resume intermediary code (S2RAM) + */ + + + +/* + * resume or + * reboot reboot==T + *[S2RAM sleep]---------->[ boot (reset.S) ]---->[soc_early_reset_hook]---------->[regular boot] + * | + * | resume==T + * \/ + * [jump to well-known] + * [ App reset vector ] + */ + + + +#include +#include + +GTEXT(pm_s2ram_mark_check_and_mediate) + +GTEXT(soc_early_reset_hook) +SECTION_FUNC(TEXT, soc_early_reset_hook) +#if DT_NODE_EXISTS(DT_NODELABEL(pm_s2ram_stack)) &&\ + DT_NODE_HAS_COMPAT(DT_NODELABEL(pm_s2ram_stack), zephyr_memory_region) + ldr r0, =DT_REG_ADDR(DT_NODELABEL(pm_s2ram_stack)) + DT_REG_SIZE(DT_NODELABEL(pm_s2ram_stack)) +#else +#error "The support of bridge for S2RAM resume requires dedicated small stack" +#endif + msr msp, r0 + push {r0, lr} + bl pm_s2ram_mark_check_and_mediate + pop {r0, pc} diff --git a/boot/zephyr/nrf54h20_custom_s2ram.c b/boot/zephyr/nrf54h20_custom_s2ram.c index 51146e7b3..faa8d9b46 100644 --- a/boot/zephyr/nrf54h20_custom_s2ram.c +++ b/boot/zephyr/nrf54h20_custom_s2ram.c @@ -45,17 +45,6 @@ void s2ram_designate_slot(uint8_t slot) } #endif -int soc_s2ram_suspend(pm_s2ram_system_off_fn_t system_off) -{ - (void)(system_off); - return -1; -} - -void pm_s2ram_mark_set(void) -{ - /* empty */ -} - struct arm_vector_table { uint32_t msp; uint32_t reset; @@ -66,13 +55,13 @@ struct arm_vector_table { */ #define APP_EXE_START_OFFSET 0x800 /* nRF54H20 */ -bool pm_s2ram_mark_check_and_clear(void) +void pm_s2ram_mark_check_and_mediate(void) { uint32_t reset_reason = nrf_resetinfo_resetreas_local_get(NRF_RESETINFO); if (reset_reason != NRF_RESETINFO_RESETREAS_LOCAL_UNRETAINED_MASK) { /* Normal boot */ - return false; + return; } /* S2RAM resume expected, do doublecheck */ @@ -120,6 +109,4 @@ bool pm_s2ram_mark_check_and_clear(void) resume_failed: FIH_PANIC; - - return true; } From db5e91cc913d4f6c4a7a3c1cce9c404057043455 Mon Sep 17 00:00:00 2001 From: Andrzej Puzdrowski Date: Fri, 26 Sep 2025 13:56:46 +0200 Subject: [PATCH 2/2] [nrf noup] boot/zephyr/socs: update nrf54h20 prj.conf for S2RAM nrf-squash! [nrf noup] boot/zephyr/socs: nrf54h20 prj.conf for S2RAM Updated in order to use optimized configuration. Signed-off-by: Andrzej Puzdrowski --- boot/zephyr/socs/nrf54h20_cpuapp.conf | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/boot/zephyr/socs/nrf54h20_cpuapp.conf b/boot/zephyr/socs/nrf54h20_cpuapp.conf index 9e75ccbb9..2a6df8b12 100644 --- a/boot/zephyr/socs/nrf54h20_cpuapp.conf +++ b/boot/zephyr/socs/nrf54h20_cpuapp.conf @@ -7,8 +7,4 @@ # after suspend to RAM (S2RAM) requested by the application. # MCUboot does not support S2RAM itself, but serves as an immediate actor while waking up # from suspension. -CONFIG_PM=y -CONFIG_PM_DEVICE=n -CONFIG_PM_S2RAM=y -CONFIG_PM_S2RAM_CUSTOM_MARKING=y -CONFIG_SOC_NRF54H20_PM_S2RAM_OVERRIDE=y +CONFIG_SOC_EARLY_RESET_HOOK=y