Skip to content

Commit 4e4e86b

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 4e4e86b

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66

77
menu "SoC and Board Hooks"
88

9+
config SOC_PRE_RAM_HOOK
10+
bool "Run early SoC pre-RAM reset hook"
11+
help
12+
Run an early SoC reset hook, before RAM get initialize.
13+
14+
A custom hook soc_pre_ram_hook() is executed at the beginning of the
15+
startup code (__start), even before any stack is initiated
16+
or RAM is accessed. soc_pre_ram_hook() must be implemented by the SoC.
17+
918
config SOC_RESET_HOOK
1019
bool "Run early SoC reset hook"
1120
help

0 commit comments

Comments
 (0)