Skip to content

Commit 3261eac

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_EARLY_RESET_HOOK=y. Hook implementation is by soc_early_reset_hook() function which should be provided by custom code. Signed-off-by: Andrzej Puzdrowski <[email protected]>
1 parent 727c15a commit 3261eac

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@
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. Its execution might takes place even before
29+
* the stack is initialized or data RAM is accessed.
30+
* Refer to relevant architecture zephyr-rtos startup implementation for more details.
31+
*/
32+
void soc_early_reset_hook(void);
33+
#else
34+
#define soc_early_reset_hook() do { } while (0)
35+
#endif
2236

2337
#ifdef CONFIG_SOC_RESET_HOOK
2438
/**

kernel/Kconfig.init

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,29 @@
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.
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 hook is called immediately after reset so use stack wisely if
22+
the hook intends to return to continue with arch's resume/reset activity.
23+
The stack pointer register should be considered as not initialized by the caller of
24+
this hook. In particular, this means that the hook is NOT allowed to
25+
"push" any data using this stack pointer value. However, the hook may use
26+
an implementation-specific area as stack if desired; in such case,
27+
the original value of the stack pointer needs not to be "restored"
28+
before returning control to the hook's caller.
29+
30+
Additional constraints may be imposed on the hook by the architecture.
31+
932
config SOC_RESET_HOOK
1033
bool "Run early SoC reset hook"
1134
help

0 commit comments

Comments
 (0)