Skip to content

Commit 902eefb

Browse files
committed
subsys: retention: Allow earlier initalization
Add Kconfig options to allow initializing retained mem and retention in PRE_KERNEL_1 phase for platforms that require jumping to the bootloader very early in the startup process. Signed-off-by: Peter Johanson <[email protected]>
1 parent 784b23b commit 902eefb

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

drivers/retained_mem/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ config RETAINED_MEM_INIT_PRIORITY
1515
help
1616
Retained memory devices initialization priority,
1717

18+
config RETAINED_MEM_INIT_LEVEL_PRE_KERNEL_1
19+
bool "Retained memory devices init during PRE_KERNEL_1"
20+
help
21+
Retained memory devices initialization during PRE_KERNEL_1 level
22+
1823
config RETAINED_MEM_MUTEXES
1924
bool
2025
default y

drivers/retained_mem/retained_mem_zephyr_ram.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ static DEVICE_API(retained_mem, zephyr_retained_mem_ram_api) = {
126126
.clear = zephyr_retained_mem_ram_clear,
127127
};
128128

129+
#if defined(CONFIG_RETAINED_MEM_INIT_LEVEL_PRE_KERNEL_1)
130+
#define RETAINED_MEM_LEVEL PRE_KERNEL_1
131+
#else
132+
#define RETAINED_MEM_LEVEL POST_KERNEL
133+
#endif
134+
129135
#define ZEPHYR_RETAINED_MEM_RAM_DEVICE(inst) \
130136
IF_ENABLED(CONFIG_RETAINED_MEM_MUTEXES, \
131137
(static struct zephyr_retained_mem_ram_data \
@@ -143,7 +149,7 @@ static DEVICE_API(retained_mem, zephyr_retained_mem_ram_api) = {
143149
(&zephyr_retained_mem_ram_data_##inst), (NULL) \
144150
), \
145151
&zephyr_retained_mem_ram_config_##inst, \
146-
POST_KERNEL, \
152+
RETAINED_MEM_LEVEL, \
147153
CONFIG_RETAINED_MEM_INIT_PRIORITY, \
148154
&zephyr_retained_mem_ram_api);
149155

subsys/retention/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ menuconfig RETENTION
1212

1313
if RETENTION
1414

15+
config RETENTION_INIT_LEVEL_PRE_KERNEL_1
16+
bool "Retention device init during PRE_KERNEL_1"
17+
help
18+
Retention device initialization during PRE_KERNEL_1 level
19+
1520
config RETENTION_INIT_PRIORITY
1621
int "Retention devices init priority"
1722
default 86

subsys/retention/retention.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,13 @@ static const struct retention_api retention_api = {
400400
.clear = retention_clear,
401401
};
402402

403+
#if defined(CONFIG_RETENTION_INIT_LEVEL_PRE_KERNEL_1)
404+
#define RETENTION_INIT_LEVEL PRE_KERNEL_1
405+
#else
406+
#define RETENTION_INIT_LEVEL POST_KERNEL
407+
#endif
408+
409+
403410
#define RETENTION_DEVICE(inst) \
404411
static struct retention_data \
405412
retention_data_##inst = { \
@@ -423,7 +430,7 @@ static const struct retention_api retention_api = {
423430
NULL, \
424431
&retention_data_##inst, \
425432
&retention_config_##inst, \
426-
POST_KERNEL, \
433+
RETENTION_INIT_LEVEL, \
427434
CONFIG_RETENTION_INIT_PRIORITY, \
428435
&retention_api);
429436

0 commit comments

Comments
 (0)