Skip to content

Conversation

nvlsianpu
Copy link
Contributor

@nvlsianpu nvlsianpu commented Aug 1, 2025

Application need special support in the bootloader in order to resume the application for suspend to RAM.

MCUboot Is just immediate actor which redirects execution to the application (application reset vector) when wake-up from S2RAM is detected. Detection is based on HW (NRF_RESETINFO) and hardened using additional check over independent source of truth (variable with magic value).

Thanks to above the application is resuming using its routines - instead of mocking that by routines compiled in by the MCUboot.

ref: NCSDK-34750

manifest-pr-skip

@nvlsianpu nvlsianpu changed the title [nrf noup] boot/zephyr: nRF54h20 resume from S2RAM [nrf noup] POC: boot/zephyr: nRF54h20 resume from S2RAM Aug 1, 2025
@nvlsianpu nvlsianpu force-pushed the nrf54h20_pm_s2rm_redirect branch from 5c05797 to 4d6d20f Compare August 1, 2025 16:24
@nvlsianpu nvlsianpu changed the title [nrf noup] POC: boot/zephyr: nRF54h20 resume from S2RAM WIP [nrf noup] boot/zephyr: nRF54h20 resume from S2RAM Aug 1, 2025
@nvlsianpu
Copy link
Contributor Author

@kl-cruz This is not building due to issues with hal and other headers.

@nvlsianpu nvlsianpu marked this pull request as draft August 1, 2025 16:27
@nvlsianpu nvlsianpu force-pushed the nrf54h20_pm_s2rm_redirect branch from 4d6d20f to 70b82fb Compare August 1, 2025 16:28
Copy link

sonarqubecloud bot commented Aug 1, 2025

@nvlsianpu nvlsianpu force-pushed the nrf54h20_pm_s2rm_redirect branch from 70b82fb to 342ddf4 Compare September 5, 2025 11:53
@nvlsianpu nvlsianpu force-pushed the nrf54h20_pm_s2rm_redirect branch 2 times, most recently from ba6ada5 to c488b52 Compare September 9, 2025 15:08
@nvlsianpu nvlsianpu changed the title WIP [nrf noup] boot/zephyr: nRF54h20 resume from S2RAM [nrf noup] boot/zephyr: nRF54h20 resume from S2RAM Sep 9, 2025
@nvlsianpu nvlsianpu marked this pull request as ready for review September 9, 2025 15:17
@nvlsianpu nvlsianpu force-pushed the nrf54h20_pm_s2rm_redirect branch from c488b52 to 37eb7e0 Compare September 9, 2025 15:55
@nvlsianpu nvlsianpu force-pushed the nrf54h20_pm_s2rm_redirect branch from 37eb7e0 to 0a19e33 Compare September 10, 2025 07:16
@nvlsianpu nvlsianpu force-pushed the nrf54h20_pm_s2rm_redirect branch from 36452d3 to e66f82a Compare September 11, 2025 16:05
@nvlsianpu nvlsianpu force-pushed the nrf54h20_pm_s2rm_redirect branch 2 times, most recently from 0c18806 to e11c558 Compare September 12, 2025 14:56
@nvlsianpu nvlsianpu added this to the 3.2.0-preview1 milestone Sep 15, 2025
Comment on lines +50 to +53
/* 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 */
Copy link
Contributor

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?

Copy link
Contributor Author

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.

uint32_t reset_reason = nrf_resetinfo_resetreas_local_get(NRF_RESETINFO);

if (reset_reason != NRF_RESETINFO_RESETREAS_LOCAL_UNRETAINED_MASK) {
/* normal boot */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments start with capital letter


if (reset_reason != NRF_RESETINFO_RESETREAS_LOCAL_UNRETAINED_MASK) {
/* normal boot */
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tab indent, other parts are space indent

/* s2ram boot */
struct arm_vector_table *vt;
vt = (struct arm_vector_table *)
(FIXED_PARTITION_ADDR(slot0_partition) + APP_EXE_START_OFFSET);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(non blocking) this will not work with direct-xip

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we know - direct-xip not supported.

}

/* s2ram boot */
struct arm_vector_table *vt;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this need volatile to avoid the LTO issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no - content of pointed data is non-volatile during function execution.

__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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

random indent

Comment on lines 28 to 31
#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))))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use DT_FIXED_PARTITION_ADDR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't work for mram

* `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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also do not start variable with underscore, that type of naming is compiler reserved

@nvlsianpu
Copy link
Contributor Author

I'm going to apply review comments shortly

@nvlsianpu nvlsianpu force-pushed the nrf54h20_pm_s2rm_redirect branch 2 times, most recently from fb3ee90 to f295558 Compare September 16, 2025 11:39
@carlescufi carlescufi requested a review from nordicjm September 16, 2025 12:31
@nvlsianpu nvlsianpu force-pushed the nrf54h20_pm_s2rm_redirect branch from f295558 to 0e7cea3 Compare September 16, 2025 12:32

int soc_s2ram_suspend(pm_s2ram_system_off_fn_t system_off)
{
(void)(system_off);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still has tabs intermixed with spaces


bool pm_s2ram_mark_check_and_clear(void)
{
uint32_t reset_reason = nrf_resetinfo_resetreas_local_get(NRF_RESETINFO);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g. here

Application need special support in the bootloader
in order to resume for suspend to RAM.

MCUboot is immediate actor which redirects execution to the application
(application reset vector) when wake-up from S2RAM is detected.
Detection is based on HW (NRF_RESETINFO) and hardened using additional
check over independent source of truth (variable with magic value).

Thanks to above the application is resuming using its routines - instead
of mocking that by routines compiled in by the MCUboot.

Implementation is able to support only MCUboot modes with a swap.
Direct-XIP is not handled as it require a way to run-time recognization of
active application slot.

Signed-off-by: Karol Lasończyk <[email protected]>
Signed-off-by: Tomasz Chyrowicz <[email protected]>
Signed-off-by: Andrzej Puzdrowski <[email protected]>
Added configuration which pre-configures MCUboot so It is able
to support operation of resuming the App from S2RAM by the application
itself.

Signed-off-by: Andrzej Puzdrowski <[email protected]>
@nvlsianpu nvlsianpu force-pushed the nrf54h20_pm_s2rm_redirect branch from f4ef86e to 1cb1def Compare September 16, 2025 12:59
Copy link

@nvlsianpu nvlsianpu requested a review from nordicjm September 16, 2025 13:22
@nvlsianpu nvlsianpu merged commit c390295 into nrfconnect:main Sep 16, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants