Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions boot/bootutil/src/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ int pcd_version_cmp_net(const struct flash_area *fap, struct image_header *hdr);
#include "bootutil/key_revocation.h"
#endif

#ifdef CONFIG_SOC_NRF54H20_PM_S2RAM_OVERRIDE
void s2ram_designate_slot(uint8_t slot);
#endif

BOOT_LOG_MODULE_DECLARE(mcuboot);

static struct boot_loader_state boot_data;
Expand Down Expand Up @@ -3600,6 +3604,11 @@ context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp)
}
}

#ifdef CONFIG_SOC_NRF54H20_PM_S2RAM_OVERRIDE
/* Designate the slot to be used by the PM_S2RAM resume module */
s2ram_designate_slot((uint8_t)state->slot_usage[0].active_slot);
#endif

/* All image loaded successfully. */
#ifdef MCUBOOT_HAVE_LOGGING
print_loaded_images(state);
Expand Down
28 changes: 28 additions & 0 deletions boot/zephyr/nrf54h20_custom_s2ram.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ volatile struct mcuboot_resume_s mcuboot_resume;
COND_CODE_0(DT_FIXED_PARTITION_EXISTS(DT_NODELABEL(node_label)), (0), \
(DT_REG_ADDR(DT_GPARENT(DT_NODELABEL(node_label))))))

#define S2RAM_SLOT_INFO_A 0x37
#define S2RAM_SLOT_INFO_B 0xA4
Copy link
Contributor

Choose a reason for hiding this comment

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

In theory, you have a full 32-bit field here, so you may go crazy with those magic numbers 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, rest 24 b are reserve for somethin...

Copy link
Contributor

@nordicjm nordicjm Oct 1, 2025

Choose a reason for hiding this comment

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

non-init RAM is garbage when the device is powered on, so the chance that one of these values just happens to be in the RAM location that is checked is 1 in 128? I don't like those odds, and there is no CRC or anything to confirm it's even valid from the image itself Have checked rest of code and can see it is properly protected, 1 byte for this is sufficient


#ifdef CONFIG_BOOT_DIRECT_XIP
/* Called by the image manager when setting the image as active for current boot. */
void s2ram_designate_slot(uint8_t slot)
{
if (slot == 0) {
mcuboot_resume.slot_info = S2RAM_SLOT_INFO_A;
} else {
mcuboot_resume.slot_info = S2RAM_SLOT_INFO_B;
}
}
#endif

int soc_s2ram_suspend(pm_s2ram_system_off_fn_t system_off)
{
Expand Down Expand Up @@ -72,8 +86,22 @@ bool pm_s2ram_mark_check_and_clear(void)

/* s2ram boot */
struct arm_vector_table *vt;

#ifdef CONFIG_BOOT_DIRECT_XIP
if (mcuboot_resume.slot_info == S2RAM_SLOT_INFO_A) {
vt = (struct arm_vector_table *)
(FIXED_PARTITION_ADDR(slot0_partition) + APP_EXE_START_OFFSET);
} else if (mcuboot_resume.slot_info == S2RAM_SLOT_INFO_B) {
vt = (struct arm_vector_table *)
(FIXED_PARTITION_ADDR(slot1_partition) + APP_EXE_START_OFFSET);
} else {
/* invalid slot info */
goto resume_failed;
}
#else
vt = (struct arm_vector_table *)
(FIXED_PARTITION_ADDR(slot0_partition) + APP_EXE_START_OFFSET);
#endif

/* Jump to application */
__asm__ volatile (
Expand Down