-
Notifications
You must be signed in to change notification settings - Fork 239
[nrf noup] boot/zephyr: nRF54h20 resume from S2RAM #489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright (c) 2025 Nordic Semiconductor ASA | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <stdbool.h> | ||
#include <zephyr/arch/common/pm_s2ram.h> | ||
#include <hal/nrf_resetinfo.h> | ||
#include "pm_s2ram.h" | ||
#include "power.h" | ||
|
||
#include <zephyr/devicetree.h> | ||
#include <zephyr/storage/flash_map.h> | ||
|
||
#include "bootutil/fault_injection_hardening.h" | ||
|
||
#if DT_NODE_EXISTS(DT_NODELABEL(mcuboot_s2ram)) &&\ | ||
DT_NODE_HAS_COMPAT(DT_NODELABEL(mcuboot_s2ram), zephyr_memory_region) | ||
/* Linker section name is given by `zephyr,memory-region` property of | ||
* `zephyr,memory-region` compatible DT node with nodelabel `mcuboot_s2ram`. | ||
*/ | ||
__attribute__((section(DT_PROP(DT_NODELABEL(mcuboot_s2ram), zephyr_memory_region)))) | ||
volatile struct mcuboot_resume_s mcuboot_resume; | ||
#else | ||
#error "mcuboot resume support section not defined in dts" | ||
#endif | ||
|
||
#define FIXED_PARTITION_ADDR(node_label) \ | ||
(DT_REG_ADDR(DT_NODELABEL(node_label)) + \ | ||
COND_CODE_0(DT_FIXED_PARTITION_EXISTS(DT_NODELABEL(node_label)), (0), \ | ||
(DT_REG_ADDR(DT_GPARENT(DT_NODELABEL(node_label)))))) | ||
|
||
|
||
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; | ||
}; | ||
|
||
/* This could be read from slot's image_header.ih_hdr_size, but immediate value | ||
* is much faster to reach | ||
*/ | ||
#define APP_EXE_START_OFFSET 0x800 /* nRF54H20 */ | ||
|
||
bool pm_s2ram_mark_check_and_clear(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; | ||
} | ||
|
||
/* S2RAM resume expected, do doublecheck */ | ||
if (mcuboot_resume.magic == MCUBOOT_S2RAM_RESUME_MAGIC) { | ||
/* clear magic to avoid accidental reuse */ | ||
mcuboot_resume.magic = 0; | ||
} else { | ||
/* magic not valid, normal boot */ | ||
goto resume_failed; | ||
} | ||
|
||
/* s2ram boot */ | ||
struct arm_vector_table *vt; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't this need volatile to avoid the LTO issue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no - content of pointed data is non-volatile during function execution. |
||
vt = (struct arm_vector_table *) | ||
(FIXED_PARTITION_ADDR(slot0_partition) + APP_EXE_START_OFFSET); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (non blocking) this will not work with direct-xip There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes we know - direct-xip not supported. |
||
|
||
/* Jump to application */ | ||
__asm__ volatile ( | ||
/* vt->reset -> r0 */ | ||
" mov r0, %0\n" | ||
/* vt->msp -> r1 */ | ||
" mov r1, %1\n" | ||
/* set stack pointer */ | ||
" msr msp, r1\n" | ||
/* jump to reset vector of an app */ | ||
" bx r0\n" | ||
: | ||
: "r" (vt->reset), "r" (vt->msp) | ||
nvlsianpu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
: "r0", "r1", "memory" | ||
); | ||
|
||
resume_failed: | ||
FIH_PANIC; | ||
|
||
return true; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright (c) 2025 Nordic Semiconductor ASA | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
# Configuration which is needed for supporting resume the application execution | ||
# 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_S2RAM=y | ||
CONFIG_PM_S2RAM_CUSTOM_MARKING=y | ||
CONFIG_SOC_NRF54H20_PM_S2RAM_OVERRIDE=y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by how much? Why can't it just be read?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by the time needed to access word which encodes heder size of 0x800 in MRAM. No much, but always a dozen CPU cycles for reaching data which are expected to be a constant value. Rationale in sentence above.