init: remove _SYS_INIT_LEVEL* definitions
The _SYS_INIT_LEVEL* definitions were used to indicate the index entry into the levels array defined in init.c (z_sys_init_run_level). init.c uses this information internally, so there is no point in exposing this in a public header. It has been replaced with an enum inside init.c. The device shell was re-using the same defines to index its own array. This is a fragile design, the shell needs to be responsible of its own data indexing. A similar situation happened with some unit tests. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
831239300f
commit
495245a971
4 changed files with 42 additions and 31 deletions
|
|
@ -16,22 +16,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* System initialization levels. The PRE_KERNEL_1 and PRE_KERNEL_2 levels are
|
||||
* executed in the kernel's initialization context, which uses the interrupt
|
||||
* stack. The remaining levels are executed in the kernel's main task.
|
||||
*/
|
||||
|
||||
#define _SYS_INIT_LEVEL_EARLY 0
|
||||
#define _SYS_INIT_LEVEL_PRE_KERNEL_1 1
|
||||
#define _SYS_INIT_LEVEL_PRE_KERNEL_2 2
|
||||
#define _SYS_INIT_LEVEL_POST_KERNEL 3
|
||||
#define _SYS_INIT_LEVEL_APPLICATION 4
|
||||
|
||||
#ifdef CONFIG_SMP
|
||||
#define _SYS_INIT_LEVEL_SMP 5
|
||||
#endif
|
||||
|
||||
struct device;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -60,6 +60,17 @@ extern const struct init_entry __init_POST_KERNEL_start[];
|
|||
extern const struct init_entry __init_APPLICATION_start[];
|
||||
extern const struct init_entry __init_end[];
|
||||
|
||||
enum init_level {
|
||||
INIT_LEVEL_EARLY = 0,
|
||||
INIT_LEVEL_PRE_KERNEL_1,
|
||||
INIT_LEVEL_PRE_KERNEL_2,
|
||||
INIT_LEVEL_POST_KERNEL,
|
||||
INIT_LEVEL_APPLICATION,
|
||||
#ifdef CONFIG_SMP
|
||||
INIT_LEVEL_SMP,
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef CONFIG_SMP
|
||||
extern const struct init_entry __init_SMP_start[];
|
||||
#endif
|
||||
|
|
@ -216,7 +227,7 @@ bool z_sys_post_kernel;
|
|||
*
|
||||
* @param level init level to run.
|
||||
*/
|
||||
static void z_sys_init_run_level(int32_t level)
|
||||
static void z_sys_init_run_level(enum init_level level)
|
||||
{
|
||||
static const struct init_entry *levels[] = {
|
||||
__init_EARLY_start,
|
||||
|
|
@ -279,7 +290,7 @@ static void bg_thread_main(void *unused1, void *unused2, void *unused3)
|
|||
#endif /* CONFIG_MMU */
|
||||
z_sys_post_kernel = true;
|
||||
|
||||
z_sys_init_run_level(_SYS_INIT_LEVEL_POST_KERNEL);
|
||||
z_sys_init_run_level(INIT_LEVEL_POST_KERNEL);
|
||||
#if CONFIG_STACK_POINTER_RANDOM
|
||||
z_stack_adjust_initialized = 1;
|
||||
#endif
|
||||
|
|
@ -291,7 +302,7 @@ static void bg_thread_main(void *unused1, void *unused2, void *unused3)
|
|||
#endif
|
||||
|
||||
/* Final init level before app starts */
|
||||
z_sys_init_run_level(_SYS_INIT_LEVEL_APPLICATION);
|
||||
z_sys_init_run_level(INIT_LEVEL_APPLICATION);
|
||||
|
||||
z_init_static_threads();
|
||||
|
||||
|
|
@ -303,7 +314,7 @@ static void bg_thread_main(void *unused1, void *unused2, void *unused3)
|
|||
if (!IS_ENABLED(CONFIG_SMP_BOOT_DELAY)) {
|
||||
z_smp_init();
|
||||
}
|
||||
z_sys_init_run_level(_SYS_INIT_LEVEL_SMP);
|
||||
z_sys_init_run_level(INIT_LEVEL_SMP);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MMU
|
||||
|
|
@ -489,7 +500,7 @@ FUNC_NORETURN void z_cstart(void)
|
|||
gcov_static_init();
|
||||
|
||||
/* initialize early init calls */
|
||||
z_sys_init_run_level(_SYS_INIT_LEVEL_EARLY);
|
||||
z_sys_init_run_level(INIT_LEVEL_EARLY);
|
||||
|
||||
/* perform any architecture-specific initialization */
|
||||
arch_kernel_init();
|
||||
|
|
@ -508,8 +519,8 @@ FUNC_NORETURN void z_cstart(void)
|
|||
z_device_state_init();
|
||||
|
||||
/* perform basic hardware initialization */
|
||||
z_sys_init_run_level(_SYS_INIT_LEVEL_PRE_KERNEL_1);
|
||||
z_sys_init_run_level(_SYS_INIT_LEVEL_PRE_KERNEL_2);
|
||||
z_sys_init_run_level(INIT_LEVEL_PRE_KERNEL_1);
|
||||
z_sys_init_run_level(INIT_LEVEL_PRE_KERNEL_2);
|
||||
|
||||
#ifdef CONFIG_STACK_CANARIES
|
||||
uintptr_t stack_guard;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,17 @@ extern const struct device __device_end[];
|
|||
extern const struct device __device_SMP_start[];
|
||||
#endif
|
||||
|
||||
/* init levels, used as indices for levels array */
|
||||
enum init_level {
|
||||
INIT_LEVEL_PRE_KERNEL_1 = 0,
|
||||
INIT_LEVEL_PRE_KERNEL_2,
|
||||
INIT_LEVEL_POST_KERNEL,
|
||||
INIT_LEVEL_APPLICATION,
|
||||
#ifdef CONFIG_SMP
|
||||
INIT_LEVEL_SMP,
|
||||
#endif
|
||||
};
|
||||
|
||||
static const struct device *const levels[] = {
|
||||
__device_PRE_KERNEL_1_start,
|
||||
__device_PRE_KERNEL_2_start,
|
||||
|
|
@ -49,7 +60,8 @@ static const char *get_device_name(const struct device *dev,
|
|||
return name;
|
||||
}
|
||||
|
||||
static bool device_get_config_level(const struct shell *shell, int level)
|
||||
static bool device_get_config_level(const struct shell *shell,
|
||||
enum init_level level)
|
||||
{
|
||||
const struct device *dev;
|
||||
bool devices = false;
|
||||
|
|
@ -74,32 +86,32 @@ static int cmd_device_levels(const struct shell *shell,
|
|||
bool ret;
|
||||
|
||||
shell_fprintf(shell, SHELL_NORMAL, "PRE KERNEL 1:\n");
|
||||
ret = device_get_config_level(shell, _SYS_INIT_LEVEL_PRE_KERNEL_1);
|
||||
ret = device_get_config_level(shell, INIT_LEVEL_PRE_KERNEL_1);
|
||||
if (ret == false) {
|
||||
shell_fprintf(shell, SHELL_NORMAL, "- None\n");
|
||||
}
|
||||
|
||||
shell_fprintf(shell, SHELL_NORMAL, "PRE KERNEL 2:\n");
|
||||
ret = device_get_config_level(shell, _SYS_INIT_LEVEL_PRE_KERNEL_2);
|
||||
ret = device_get_config_level(shell, INIT_LEVEL_PRE_KERNEL_2);
|
||||
if (ret == false) {
|
||||
shell_fprintf(shell, SHELL_NORMAL, "- None\n");
|
||||
}
|
||||
|
||||
shell_fprintf(shell, SHELL_NORMAL, "POST_KERNEL:\n");
|
||||
ret = device_get_config_level(shell, _SYS_INIT_LEVEL_POST_KERNEL);
|
||||
ret = device_get_config_level(shell, INIT_LEVEL_POST_KERNEL);
|
||||
if (ret == false) {
|
||||
shell_fprintf(shell, SHELL_NORMAL, "- None\n");
|
||||
}
|
||||
|
||||
shell_fprintf(shell, SHELL_NORMAL, "APPLICATION:\n");
|
||||
ret = device_get_config_level(shell, _SYS_INIT_LEVEL_APPLICATION);
|
||||
ret = device_get_config_level(shell, INIT_LEVEL_APPLICATION);
|
||||
if (ret == false) {
|
||||
shell_fprintf(shell, SHELL_NORMAL, "- None\n");
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SMP
|
||||
shell_fprintf(shell, SHELL_NORMAL, "SMP:\n");
|
||||
ret = device_get_config_level(shell, _SYS_INIT_LEVEL_SMP);
|
||||
ret = device_get_config_level(shell, INIT_LEVEL_SMP);
|
||||
if (ret == false) {
|
||||
shell_fprintf(shell, SHELL_NORMAL, "- None\n");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,11 +75,15 @@ ZTEST(no_multithreading, test_cpu_idle)
|
|||
zassert_within(diff, 10, 2, "Unexpected time passed: %d ms", (int)diff);
|
||||
}
|
||||
|
||||
#define IDX_PRE_KERNEL_1 0
|
||||
#define IDX_PRE_KERNEL_2 1
|
||||
#define IDX_POST_KERNEL 2
|
||||
|
||||
#define SYS_INIT_CREATE(level) \
|
||||
static int pre_kernel_##level##_init_func(const struct device *dev) \
|
||||
{ \
|
||||
ARG_UNUSED(dev); \
|
||||
if (init_order != _SYS_INIT_LEVEL_##level && sys_init_result == 0) { \
|
||||
if (init_order != IDX_##level && sys_init_result == 0) { \
|
||||
sys_init_result = -1; \
|
||||
return -EIO; \
|
||||
} \
|
||||
|
|
@ -95,7 +99,7 @@ FOR_EACH(SYS_INIT_CREATE, (;), PRE_KERNEL_1, PRE_KERNEL_2, POST_KERNEL);
|
|||
|
||||
ZTEST(no_multithreading, test_sys_init)
|
||||
{
|
||||
zassert_equal(init_order, _SYS_INIT_LEVEL_PRE_KERNEL_2, "SYS_INIT failed: %d", init_order);
|
||||
zassert_equal(init_order, 3, "SYS_INIT failed: %d", init_order);
|
||||
}
|
||||
|
||||
ZTEST_SUITE(no_multithreading, NULL, NULL, NULL, NULL, NULL);
|
||||
|
|
|
|||
Loading…
Reference in a new issue