Skip to content

Commit e69b330

Browse files
committed
[nrf fromlist] arch/arm: introduce the pre-stack/RAM init hook
Introduce hook for customize reset.S code even before stack is initialized or RAM is accessed. Hook can be enabled using CONFIG_SOC_EARLY_RESET_HOOK=y. Hook implementation is by soc_early_reset_hook() function which should be provided by custom code. Upstream PR #: 96962 Signed-off-by: Andrzej Puzdrowski <[email protected]>
1 parent 4426f7f commit e69b330

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

arch/arm/core/cortex_m/reset.S

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ GTEXT(z_arm_init_arch_hw_at_boot)
3535
#if defined(CONFIG_PM_S2RAM)
3636
GTEXT(arch_pm_s2ram_resume)
3737
#endif
38+
#if defined(CONFIG_SOC_EARLY_RESET_HOOK)
39+
GTEXT(soc_early_reset_hook)
40+
#endif
41+
3842

3943
/*
4044
* PACBTI Mask for CONTROL register:
@@ -100,6 +104,10 @@ SECTION_SUBSEC_FUNC(TEXT,_reset_section,__start)
100104

101105
#endif /* CONFIG_INIT_ARCH_HW_AT_BOOT */
102106

107+
#if defined(CONFIG_SOC_EARLY_RESET_HOOK)
108+
/* Call custom code that executes before any stack is set up or RAM memory is accessed */
109+
bl soc_early_reset_hook
110+
#endif
103111
#if defined(CONFIG_PM_S2RAM)
104112
/*
105113
* Temporarily set MSP to interrupt stack so that arch_pm_s2ram_resume can

include/zephyr/platform/hooks.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@
1919
* directly from application code but may be freely used within the OS.
2020
*/
2121

22+
#ifdef CONFIG_SOC_EARLY_RESET_HOOK
23+
/**
24+
* @brief SoC hook executed before data RAM initialization, at the beginning
25+
* of the reset vector.
26+
*
27+
* This hook is implemented by the SoC and can be used to perform any
28+
* SoC-specific initialization. Refer to :kconfig:option:`SOC_EARLY_RESET_HOOK`
29+
* and relevant architecture zephyr-rtos startup implementation for more details.
30+
*/
31+
void soc_early_reset_hook(void);
32+
#else
33+
#define soc_early_reset_hook() do { } while (0)
34+
#endif
2235

2336
/**
2437
* @brief SoC hook executed at the beginning of the reset vector.

kernel/Kconfig.init

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,28 @@
66

77
menu "SoC and Board Hooks"
88

9+
config SOC_EARLY_RESET_HOOK
10+
bool "Run SoC-specific early reset hook"
11+
help
12+
Run a SoC-specific hook early in the reset/startup code (__start).
13+
A custom hook soc_early_reset_hook() will be executed at the beginning
14+
of the architecture-specific startup code, after hardware has been
15+
configured (as required by CONFIG_INIT_ARCH_HW_AT_BOOT) but before
16+
architecture's own resume logic.
17+
18+
Returning from this hook is not mandatory: it can be used to implement
19+
special logic to resume execution in some scenarios (for example, when
20+
a bootloader is used).
21+
22+
The stack pointer register should be considered as not initialized upon
23+
call to this hook. In particular, this means that the hook is NOT allowed
24+
to "push" any data using this stack pointer value. However, the hook may
25+
use an implementation-specific area as stack if desired; in such case,
26+
the original value of the stack pointer needs not to be "restored" before
27+
returning control to the hook's caller.
28+
29+
Additional constraints may be imposed on the hook by the architecture.
30+
931
config SOC_RESET_HOOK
1032
bool "Run early SoC reset hook"
1133
help

0 commit comments

Comments
 (0)