Skip to content

Commit 7bc79fd

Browse files
committed
[nrf noup] boot/zephyr: nRF54h20 resume S2RAM hardening
Use additional check on independent source of true for deciding whether resume the application from S2RAM. Signed-off-by: Andrzej Puzdrowski <[email protected]>
1 parent 393e310 commit 7bc79fd

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

boot/zephyr/nrf54h20_custom_s2ram.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@
1212
#include <zephyr/devicetree.h>
1313
#include <zephyr/storage/flash_map.h>
1414

15+
#include "bootutil/fault_injection_hardening.h"
16+
17+
#if DT_NODE_EXISTS(DT_NODELABEL(mcuboot_s2ram)) &&\
18+
DT_NODE_HAS_COMPAT(DT_NODELABEL(mcuboot_s2ram), zephyr_memory_region)
19+
/* Linker section name is given by `zephyr,memory-region` property of
20+
* `zephyr,memory-region` compatible DT node with nodelabel `mcuboot_s2ram`.
21+
*/
22+
__attribute__((section(DT_PROP(DT_NODELABEL(mcuboot_s2ram), zephyr_memory_region))))
23+
struct mcuboot_resume_s _mcuboot_resume;
24+
#else
25+
#error "mcuboot resume support section not defined in dts"
26+
#endif
27+
1528
int soc_s2ram_suspend(pm_s2ram_system_off_fn_t system_off)
1629
{
1730
(void)(system_off);
@@ -37,6 +50,15 @@ bool pm_s2ram_mark_check_and_clear(void)
3750
return false;
3851
}
3952

53+
/* S2RAM resume expected, do doublecheck */
54+
if (_mcuboot_resume.magic == MCUBOOT_S2RAM_RESUME_MAGIC) {
55+
// clear magic to avoid accidental reuse
56+
_mcuboot_resume.magic = 0;
57+
} else {
58+
// magic not valid, normal boot
59+
goto resume_failed;
60+
}
61+
4062
// s2ram boot
4163
struct arm_vector_table *vt;
4264
vt = (struct arm_vector_table *)(FIXED_PARTITION_OFFSET(slot0_partition) + 0x800);
@@ -56,9 +78,8 @@ bool pm_s2ram_mark_check_and_clear(void)
5678
: "r0", "r1", "memory"
5779
);
5880

59-
while(1)
60-
{
61-
}
81+
resume_failed:
82+
FIH_PANIC;
6283

6384
return true;
6485
}

0 commit comments

Comments
 (0)