12 #include <linux/types.h>
13 #include <linux/module.h>
15 #include <linux/kernel.h>
18 #include <linux/string.h>
19 #include <linux/ctype.h>
26 #include <linux/tty.h>
49 #include <linux/mempolicy.h>
58 #include <linux/device.h>
60 #include <linux/sched.h>
61 #include <linux/signal.h>
69 #include <linux/slab.h>
70 #include <linux/perf_event.h>
72 #include <linux/ptrace.h>
76 #include <asm/setup.h>
77 #include <asm/sections.h>
78 #include <asm/cacheflush.h>
80 #ifdef CONFIG_X86_LOCAL_APIC
84 static int kernel_init(
void *);
91 #ifndef CONFIG_DEBUG_RODATA
92 static inline void mark_rodata_ro(
void) { }
96 extern void tc_init(
void);
114 #define MAX_INIT_ARGS CONFIG_INIT_ENV_ARG_LIMIT
115 #define MAX_INIT_ENVS CONFIG_INIT_ENV_ARG_LIMIT
127 static char *static_command_line;
129 static char *execute_command;
130 static char *ramdisk_execute_command;
144 static int __init set_reset_devices(
char *
str)
150 __setup(
"reset_devices", set_reset_devices);
154 static const char *panic_later, *panic_param;
158 static int __init obsolete_checksetup(
char *
line)
161 int had_early_param = 0;
172 if (line[n] ==
'\0' || line[n] ==
'=')
176 " ignored\n", p->
str);
182 }
while (p < __setup_end);
184 return had_early_param;
195 static int __init debug_kernel(
char *
str)
201 static int __init quiet_kernel(
char *
str)
234 if (val == param+
strlen(param)+1)
236 else if (val == param+
strlen(param)+2) {
250 static int __init unknown_bootoption(
char *param,
char *val,
const char *unused)
252 repair_env_string(param, val, unused);
255 if (obsolete_checksetup(param))
259 if (
strchr(param,
'.') && (!val ||
strchr(param,
'.') < val))
270 panic_later =
"Too many boot env vars at `%s'";
280 for (i = 0; argv_init[
i]; i++) {
282 panic_later =
"Too many boot init vars at `%s'";
291 static int __init init_setup(
char *str)
295 execute_command =
str;
308 static int __init rdinit_setup(
char *str)
312 ramdisk_execute_command =
str;
318 __setup(
"rdinit=", rdinit_setup);
322 #ifdef CONFIG_X86_LOCAL_APIC
328 #define smp_init() do { } while (0)
341 static void __init setup_command_line(
char *command_line)
346 strcpy (static_command_line, command_line);
389 static int __init do_early_param(
char *param,
char *val,
const char *unused)
395 (
strcmp(param,
"console") == 0 &&
400 "Malformed early option '%s'\n", param);
409 parse_args(
"early options", cmdline,
NULL, 0, 0, 0, do_early_param);
431 static void __init boot_cpu_init(
void)
445 # if THREAD_SIZE >= PAGE_SIZE
454 static void __init mm_init(
void)
471 extern const struct kernel_param __start___param[], __stop___param[];
484 boot_init_stack_canary();
502 setup_command_line(command_line);
512 parse_args(
"Booting kernel", static_command_line, __start___param,
513 __stop___param - __start___param,
514 -1, -1, &unknown_bootoption);
542 "enabled *very* early, fixing it\n");
558 call_function_init();
574 panic(panic_later, panic_param);
585 #ifdef CONFIG_BLK_DEV_INITRD
622 #ifdef CONFIG_PROC_FS
647 static void __init do_ctors(
void)
649 #ifdef CONFIG_CONSTRUCTORS
652 for (; fn < (
ctor_fn_t *) __ctors_end; fn++)
658 core_param(initcall_debug, initcall_debug,
bool, 0644);
672 delta = ktime_sub(rettime, calltime);
673 duration = (
unsigned long long) ktime_to_ns(delta) >> 10;
686 ret = do_one_initcall_debug(fn);
692 if (ret && ret != -
ENODEV && initcall_debug)
693 sprintf(msgbuf,
"error code %d ", ret);
696 strlcat(msgbuf,
"preemption imbalance ",
sizeof(msgbuf));
700 strlcat(msgbuf,
"disabled interrupts ",
sizeof(msgbuf));
704 printk(
"initcall %pF returned with %s\n", fn, msgbuf);
735 static char *initcall_level_names[] __initdata = {
753 static_command_line, __start___param,
754 __stop___param - __start___param,
758 for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
762 static void __init do_initcalls(
void)
766 for (level = 0; level <
ARRAY_SIZE(initcall_levels) - 1; level++)
767 do_initcall_level(level);
777 static void __init do_basic_setup(
void)
785 usermodehelper_enable();
789 static void __init do_pre_smp_initcalls(
void)
793 for (fn = __initcall_start; fn < __initcall0_start; fn++)
797 static int run_init_process(
const char *init_filename)
799 argv_init[0] = init_filename;
803 static void __init kernel_init_freeable(
void);
805 static int __ref kernel_init(
void *unused)
807 kernel_init_freeable();
818 if (ramdisk_execute_command) {
819 if (!run_init_process(ramdisk_execute_command))
822 ramdisk_execute_command);
831 if (execute_command) {
832 if (!run_init_process(execute_command))
835 "defaults...\n", execute_command);
837 if (!run_init_process(
"/sbin/init") ||
838 !run_init_process(
"/etc/init") ||
839 !run_init_process(
"/bin/init") ||
840 !run_init_process(
"/bin/sh"))
843 panic(
"No init found. Try passing init= option to kernel. "
844 "See Linux Documentation/init.txt for guidance.");
847 static void __init kernel_init_freeable(
void)
870 do_pre_smp_initcalls();
879 if (
sys_open((
const char __user *)
"/dev/console",
O_RDWR, 0) < 0)
889 if (!ramdisk_execute_command)
890 ramdisk_execute_command =
"/init";
892 if (
sys_access((
const char __user *) ramdisk_execute_command, 0) != 0) {
893 ramdisk_execute_command =
NULL;