Skip to content

Commit 5e94541

Browse files
committed
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_PRE_RAM_HOOK=y. Hook implementation is by soc_start_hook() function which should be provided by custom code. Signed-off-by: Andrzej Puzdrowski <[email protected]>
1 parent 727c15a commit 5e94541

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-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_PRE_RAM_HOOK)
39+
GTEXT(soc_pre_ram_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_PRE_RAM_HOOK)
108+
/* Call custom code that executes before any stack is set up or RAM memory is accessed */
109+
bl soc_pre_ram_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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
* directly from application code but may be freely used within the OS.
2020
*/
2121

22+
/**
23+
* @brief SoC hook executed before RAM initialization, at the beginning
24+
* of the reset vector.
25+
*
26+
* This hook is implemented by the SoC and can be used to perform any
27+
* SoC-specific initialization. Its execution takes place even before
28+
* the stack is initialized or RAM is accessed.
29+
*/
30+
void soc_pre_ram_hook(void);
2231

2332
#ifdef CONFIG_SOC_RESET_HOOK
2433
/**

kernel/Kconfig.init

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

77
menu "SoC and Board Hooks"
88

9+
config SOC_PRE_RAM_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_pre_ram_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.
16+
17+
Returning from this hook is not mandatory: it can be used to implement
18+
special logic to resume execution in some scenarios (for example, when
19+
a bootloader is used).
20+
21+
The stack pointer register is considered as scratch by the caller of
22+
this hook. In particular, this means that the hook is NOT allowed to
23+
"push" any data using this stack pointer. However, the hook may use
24+
an implementation-specific area as stack if desired; in such case,
25+
the original value of the stack pointer needs not to be "restored"
26+
before returning control to the hook's caller.
27+
28+
Additional constraints may be imposed on the hook by the architecture.
29+
930
config SOC_RESET_HOOK
1031
bool "Run early SoC reset hook"
1132
help

0 commit comments

Comments
 (0)