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 | |
8 | void startup_invoke_autoinit(init_target_t target) |
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 | |
20 | static 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(option_name: 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 | |
49 | void startup_invoke_cmdline_hooks(void) |
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(start: __MOS_SETUP_START, end: __MOS_SETUP_END); |
54 | } |
55 | |
56 | void startup_invoke_early_cmdline_hooks(void) |
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(start: __MOS_EARLY_SETUP_START, end: __MOS_EARLY_SETUP_END); |
61 | } |
62 |