MOS Source Code
Loading...
Searching...
No Matches
setup.c
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#include "mos/misc/setup.h"
4
5#include "mos/misc/cmdline.h"
6#include "mos/syslog/printk.h"
7
9{
10 extern const mos_init_t __MOS_INIT_START[];
11 extern const mos_init_t __MOS_INIT_END[];
12
13 for (const mos_init_t *init = __MOS_INIT_START; init < __MOS_INIT_END; init++)
14 {
15 if (init->target == target)
16 init->init_fn();
17 }
18}
19
20static void do_invoke_setup(const mos_cmdline_hook_t start[], const mos_cmdline_hook_t end[])
21{
22 for (const mos_cmdline_hook_t *func = start; func < end; func++)
23 {
24 cmdline_option_t *option = cmdline_get_option(func->param);
25
26 if (unlikely(!option))
27 {
28 pr_dinfo2(setup, "no option given for '%s'", func->param);
29 continue;
30 }
31
32 if (unlikely(option->used))
33 {
34 pr_warn("option '%s' already used", func->param);
35 continue;
36 }
37
38 pr_dinfo2(setup, "invoking setup function for '%s'", func->param);
39 if (unlikely(!func->hook(option->arg)))
40 {
41 pr_warn("setup function for '%s' failed", func->param);
42 continue;
43 }
44
45 option->used = true;
46 }
47}
48
50{
51 extern const mos_cmdline_hook_t __MOS_SETUP_START[]; // defined in linker script
52 extern const mos_cmdline_hook_t __MOS_SETUP_END[];
53 do_invoke_setup(__MOS_SETUP_START, __MOS_SETUP_END);
54}
55
57{
58 extern const mos_cmdline_hook_t __MOS_EARLY_SETUP_START[]; // defined in linker script
59 extern const mos_cmdline_hook_t __MOS_EARLY_SETUP_END[];
60 do_invoke_setup(__MOS_EARLY_SETUP_START, __MOS_EARLY_SETUP_END);
61}
cmdline_option_t * cmdline_get_option(const char *option_name)
Definition cmdline.c:21
#define unlikely(x)
Definition mos_global.h:40
#define pr_warn(fmt,...)
Definition printk.h:38
#define pr_dinfo2(feat, fmt,...)
Definition printk.h:27
static void do_invoke_setup(const mos_cmdline_hook_t start[], const mos_cmdline_hook_t end[])
Definition setup.c:20
void startup_invoke_early_cmdline_hooks(void)
Definition setup.c:56
void startup_invoke_cmdline_hooks(void)
Definition setup.c:49
void startup_invoke_autoinit(init_target_t target)
Definition setup.c:8
init_target_t
Definition setup.h:8
const char * arg
Definition cmdline.h:10