Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/init/main.c | |
3 | * | |
4 | * Copyright (C) 1991, 1992 Linus Torvalds | |
5 | * | |
6 | * GK 2/5/95 - Changed to support mounting root fs via NFS | |
7 | * Added initrd & change_root: Werner Almesberger & Hans Lermen, Feb '96 | |
8 | * Moan early if gcc is old, avoiding bogus kernels - Paul Gortmaker, May '96 | |
9 | * Simplified starting of init: Michael A. Griffith <grif@acm.org> | |
10 | */ | |
11 | ||
ea676e84 AM |
12 | #define DEBUG /* Enable initcall_debug */ |
13 | ||
1da177e4 LT |
14 | #include <linux/types.h> |
15 | #include <linux/module.h> | |
16 | #include <linux/proc_fs.h> | |
1da177e4 LT |
17 | #include <linux/kernel.h> |
18 | #include <linux/syscalls.h> | |
9b5609fd | 19 | #include <linux/stackprotector.h> |
1da177e4 LT |
20 | #include <linux/string.h> |
21 | #include <linux/ctype.h> | |
22 | #include <linux/delay.h> | |
1da177e4 LT |
23 | #include <linux/ioport.h> |
24 | #include <linux/init.h> | |
1da177e4 | 25 | #include <linux/initrd.h> |
1da177e4 | 26 | #include <linux/bootmem.h> |
4a7a16dc | 27 | #include <linux/acpi.h> |
1da177e4 | 28 | #include <linux/tty.h> |
1da177e4 LT |
29 | #include <linux/percpu.h> |
30 | #include <linux/kmod.h> | |
db64fe02 | 31 | #include <linux/vmalloc.h> |
1da177e4 | 32 | #include <linux/kernel_stat.h> |
d7cd5611 | 33 | #include <linux/start_kernel.h> |
1da177e4 | 34 | #include <linux/security.h> |
3d442233 | 35 | #include <linux/smp.h> |
1da177e4 LT |
36 | #include <linux/profile.h> |
37 | #include <linux/rcupdate.h> | |
38 | #include <linux/moduleparam.h> | |
39 | #include <linux/kallsyms.h> | |
40 | #include <linux/writeback.h> | |
41 | #include <linux/cpu.h> | |
42 | #include <linux/cpuset.h> | |
ddbcc7e8 | 43 | #include <linux/cgroup.h> |
1da177e4 | 44 | #include <linux/efi.h> |
906568c9 | 45 | #include <linux/tick.h> |
6168a702 | 46 | #include <linux/interrupt.h> |
c757249a | 47 | #include <linux/taskstats_kern.h> |
ca74e92b | 48 | #include <linux/delayacct.h> |
1da177e4 LT |
49 | #include <linux/unistd.h> |
50 | #include <linux/rmap.h> | |
51 | #include <linux/mempolicy.h> | |
52 | #include <linux/key.h> | |
b6cd0b77 | 53 | #include <linux/buffer_head.h> |
94b6da5a | 54 | #include <linux/page_cgroup.h> |
9a11b49a | 55 | #include <linux/debug_locks.h> |
3ac7fe5a | 56 | #include <linux/debugobjects.h> |
fbb9ce95 | 57 | #include <linux/lockdep.h> |
3c7b4e6b | 58 | #include <linux/kmemleak.h> |
84d73786 | 59 | #include <linux/pid_namespace.h> |
1f21782e | 60 | #include <linux/device.h> |
73c27992 | 61 | #include <linux/kthread.h> |
e6fe6649 | 62 | #include <linux/sched.h> |
a1c9eea9 | 63 | #include <linux/signal.h> |
199f0ca5 | 64 | #include <linux/idr.h> |
0b4b3827 | 65 | #include <linux/kgdb.h> |
68bf21aa | 66 | #include <linux/ftrace.h> |
22a9d645 | 67 | #include <linux/async.h> |
dfec072e | 68 | #include <linux/kmemcheck.h> |
6ae6996a | 69 | #include <linux/sfi.h> |
2b2af54a | 70 | #include <linux/shmem_fs.h> |
5a0e3ad6 | 71 | #include <linux/slab.h> |
24a24bb6 | 72 | #include <linux/perf_event.h> |
4a9d4b02 | 73 | #include <linux/file.h> |
a74fb73c | 74 | #include <linux/ptrace.h> |
bb813f4c TH |
75 | #include <linux/blkdev.h> |
76 | #include <linux/elevator.h> | |
b7a52f51 | 77 | #include <linux/random.h> |
3c2a0909 | 78 | #include <linux/sched_clock.h> |
1da177e4 LT |
79 | |
80 | #include <asm/io.h> | |
81 | #include <asm/bugs.h> | |
82 | #include <asm/setup.h> | |
a940199f | 83 | #include <asm/sections.h> |
37b73c82 | 84 | #include <asm/cacheflush.h> |
1da177e4 | 85 | |
1da177e4 LT |
86 | #ifdef CONFIG_X86_LOCAL_APIC |
87 | #include <asm/smp.h> | |
88 | #endif | |
89 | ||
3c2a0909 S |
90 | #ifdef CONFIG_TIMA_RKP |
91 | #include <linux/vmm.h> | |
92 | #include <linux/rkp_entry.h> | |
93 | #endif //CONFIG_TIMA_RKP | |
94 | ||
aae5f662 | 95 | static int kernel_init(void *); |
1da177e4 LT |
96 | |
97 | extern void init_IRQ(void); | |
1da177e4 LT |
98 | extern void fork_init(unsigned long); |
99 | extern void mca_init(void); | |
100 | extern void sbus_init(void); | |
1da177e4 | 101 | extern void radix_tree_init(void); |
37b73c82 AV |
102 | #ifndef CONFIG_DEBUG_RODATA |
103 | static inline void mark_rodata_ro(void) { } | |
104 | #endif | |
1da177e4 LT |
105 | |
106 | #ifdef CONFIG_TC | |
107 | extern void tc_init(void); | |
108 | #endif | |
109 | ||
3c2a0909 S |
110 | #if defined(CONFIG_USE_HOST_FD_LIBRARY) |
111 | extern void *fd_vaddr; | |
112 | #endif | |
113 | ||
114 | #ifdef CONFIG_KNOX_KAP | |
115 | int boot_mode_security; | |
116 | EXPORT_SYMBOL(boot_mode_security); | |
117 | #endif | |
118 | ||
2ce802f6 TH |
119 | /* |
120 | * Debug helper: via this flag we know that we are in 'early bootup code' | |
121 | * where only the boot processor is running with IRQ disabled. This means | |
122 | * two things - IRQ must not be enabled before the flag is cleared and some | |
123 | * operations which are not allowed with IRQ disabled are allowed while the | |
124 | * flag is set. | |
125 | */ | |
126 | bool early_boot_irqs_disabled __read_mostly; | |
127 | ||
a6826048 | 128 | enum system_states system_state __read_mostly; |
1da177e4 LT |
129 | EXPORT_SYMBOL(system_state); |
130 | ||
131 | /* | |
132 | * Boot command-line arguments | |
133 | */ | |
134 | #define MAX_INIT_ARGS CONFIG_INIT_ENV_ARG_LIMIT | |
135 | #define MAX_INIT_ENVS CONFIG_INIT_ENV_ARG_LIMIT | |
136 | ||
137 | extern void time_init(void); | |
138 | /* Default late time init is NULL. archs can override this later. */ | |
d2e3192b | 139 | void (*__initdata late_time_init)(void); |
1da177e4 LT |
140 | extern void softirq_init(void); |
141 | ||
30d7e0d4 ABL |
142 | /* Untouched command line saved by arch-specific code. */ |
143 | char __initdata boot_command_line[COMMAND_LINE_SIZE]; | |
144 | /* Untouched saved command line (eg. for /proc) */ | |
145 | char *saved_command_line; | |
146 | /* Command line for parameter parsing */ | |
147 | static char *static_command_line; | |
1da177e4 LT |
148 | |
149 | static char *execute_command; | |
ffdfc409 | 150 | static char *ramdisk_execute_command; |
1da177e4 | 151 | |
8b3b2955 JB |
152 | /* |
153 | * If set, this is an indication to the drivers that reset the underlying | |
154 | * device before going ahead with the initialization otherwise driver might | |
155 | * rely on the BIOS and skip the reset operation. | |
156 | * | |
157 | * This is useful if kernel is booting in an unreliable environment. | |
158 | * For ex. kdump situaiton where previous kernel has crashed, BIOS has been | |
159 | * skipped and devices will be in unknown state. | |
160 | */ | |
161 | unsigned int reset_devices; | |
162 | EXPORT_SYMBOL(reset_devices); | |
1da177e4 | 163 | |
7e96287d VG |
164 | static int __init set_reset_devices(char *str) |
165 | { | |
166 | reset_devices = 1; | |
167 | return 1; | |
168 | } | |
169 | ||
170 | __setup("reset_devices", set_reset_devices); | |
171 | ||
d7627467 DH |
172 | static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, }; |
173 | const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, }; | |
1da177e4 LT |
174 | static const char *panic_later, *panic_param; |
175 | ||
914dcaa8 | 176 | extern const struct obs_kernel_param __setup_start[], __setup_end[]; |
1da177e4 LT |
177 | |
178 | static int __init obsolete_checksetup(char *line) | |
179 | { | |
914dcaa8 | 180 | const struct obs_kernel_param *p; |
33df0d19 | 181 | int had_early_param = 0; |
1da177e4 LT |
182 | |
183 | p = __setup_start; | |
184 | do { | |
185 | int n = strlen(p->str); | |
b1e4d20c | 186 | if (parameqn(line, p->str, n)) { |
1da177e4 | 187 | if (p->early) { |
33df0d19 RR |
188 | /* Already done in parse_early_param? |
189 | * (Needs exact match on param part). | |
190 | * Keep iterating, as we can have early | |
191 | * params and __setups of same names 8( */ | |
1da177e4 | 192 | if (line[n] == '\0' || line[n] == '=') |
33df0d19 | 193 | had_early_param = 1; |
1da177e4 | 194 | } else if (!p->setup_func) { |
ea676e84 AM |
195 | pr_warn("Parameter %s is obsolete, ignored\n", |
196 | p->str); | |
1da177e4 LT |
197 | return 1; |
198 | } else if (p->setup_func(line + n)) | |
199 | return 1; | |
200 | } | |
201 | p++; | |
202 | } while (p < __setup_end); | |
33df0d19 RR |
203 | |
204 | return had_early_param; | |
1da177e4 LT |
205 | } |
206 | ||
207 | /* | |
208 | * This should be approx 2 Bo*oMips to start (note initial shift), and will | |
209 | * still work even if initially too large, it will just take slightly longer | |
210 | */ | |
211 | unsigned long loops_per_jiffy = (1<<12); | |
212 | ||
213 | EXPORT_SYMBOL(loops_per_jiffy); | |
214 | ||
215 | static int __init debug_kernel(char *str) | |
216 | { | |
1da177e4 | 217 | console_loglevel = 10; |
f6f21c81 | 218 | return 0; |
1da177e4 LT |
219 | } |
220 | ||
221 | static int __init quiet_kernel(char *str) | |
222 | { | |
1da177e4 | 223 | console_loglevel = 4; |
f6f21c81 | 224 | return 0; |
1da177e4 LT |
225 | } |
226 | ||
f6f21c81 YL |
227 | early_param("debug", debug_kernel); |
228 | early_param("quiet", quiet_kernel); | |
1da177e4 LT |
229 | |
230 | static int __init loglevel(char *str) | |
231 | { | |
808bf29b AS |
232 | int newlevel; |
233 | ||
234 | /* | |
235 | * Only update loglevel value when a correct setting was passed, | |
236 | * to prevent blind crashes (when loglevel being set to 0) that | |
237 | * are quite hard to debug | |
238 | */ | |
239 | if (get_option(&str, &newlevel)) { | |
240 | console_loglevel = newlevel; | |
241 | return 0; | |
242 | } | |
243 | ||
244 | return -EINVAL; | |
1da177e4 LT |
245 | } |
246 | ||
f6f21c81 | 247 | early_param("loglevel", loglevel); |
1da177e4 | 248 | |
a99cd112 | 249 | /* Change NUL term back to "=", to make "param" the whole string. */ |
eb157427 | 250 | static int __init repair_env_string(char *param, char *val, const char *unused) |
1da177e4 | 251 | { |
1da177e4 LT |
252 | if (val) { |
253 | /* param=val or param="val"? */ | |
254 | if (val == param+strlen(param)+1) | |
255 | val[-1] = '='; | |
256 | else if (val == param+strlen(param)+2) { | |
257 | val[-2] = '='; | |
258 | memmove(val-1, val, strlen(val)+1); | |
259 | val--; | |
260 | } else | |
261 | BUG(); | |
262 | } | |
a99cd112 CM |
263 | return 0; |
264 | } | |
265 | ||
266 | /* | |
267 | * Unknown boot options get handed to init, unless they look like | |
268 | * unused parameters (modprobe will find them in /proc/cmdline). | |
269 | */ | |
eb157427 | 270 | static int __init unknown_bootoption(char *param, char *val, const char *unused) |
a99cd112 | 271 | { |
eb157427 | 272 | repair_env_string(param, val, unused); |
1da177e4 LT |
273 | |
274 | /* Handle obsolete-style parameters */ | |
275 | if (obsolete_checksetup(param)) | |
276 | return 0; | |
277 | ||
f066a4f6 RR |
278 | /* Unused module parameter. */ |
279 | if (strchr(param, '.') && (!val || strchr(param, '.') < val)) | |
1da177e4 | 280 | return 0; |
1da177e4 LT |
281 | |
282 | if (panic_later) | |
283 | return 0; | |
284 | ||
285 | if (val) { | |
286 | /* Environment option */ | |
287 | unsigned int i; | |
288 | for (i = 0; envp_init[i]; i++) { | |
289 | if (i == MAX_INIT_ENVS) { | |
290 | panic_later = "Too many boot env vars at `%s'"; | |
291 | panic_param = param; | |
292 | } | |
293 | if (!strncmp(param, envp_init[i], val - param)) | |
294 | break; | |
295 | } | |
296 | envp_init[i] = param; | |
297 | } else { | |
298 | /* Command line option */ | |
299 | unsigned int i; | |
300 | for (i = 0; argv_init[i]; i++) { | |
301 | if (i == MAX_INIT_ARGS) { | |
302 | panic_later = "Too many boot init vars at `%s'"; | |
303 | panic_param = param; | |
304 | } | |
305 | } | |
306 | argv_init[i] = param; | |
307 | } | |
308 | return 0; | |
309 | } | |
310 | ||
311 | static int __init init_setup(char *str) | |
312 | { | |
313 | unsigned int i; | |
314 | ||
315 | execute_command = str; | |
316 | /* | |
317 | * In case LILO is going to boot us with default command line, | |
318 | * it prepends "auto" before the whole cmdline which makes | |
319 | * the shell think it should execute a script with such name. | |
320 | * So we ignore all arguments entered _before_ init=... [MJ] | |
321 | */ | |
322 | for (i = 1; i < MAX_INIT_ARGS; i++) | |
323 | argv_init[i] = NULL; | |
324 | return 1; | |
325 | } | |
326 | __setup("init=", init_setup); | |
327 | ||
ffdfc409 OJ |
328 | static int __init rdinit_setup(char *str) |
329 | { | |
330 | unsigned int i; | |
331 | ||
332 | ramdisk_execute_command = str; | |
333 | /* See "auto" comment in init_setup */ | |
334 | for (i = 1; i < MAX_INIT_ARGS; i++) | |
335 | argv_init[i] = NULL; | |
336 | return 1; | |
337 | } | |
338 | __setup("rdinit=", rdinit_setup); | |
339 | ||
1da177e4 | 340 | #ifndef CONFIG_SMP |
34db18a0 | 341 | static const unsigned int setup_max_cpus = NR_CPUS; |
1da177e4 LT |
342 | #ifdef CONFIG_X86_LOCAL_APIC |
343 | static void __init smp_init(void) | |
344 | { | |
345 | APIC_init_uniprocessor(); | |
346 | } | |
347 | #else | |
348 | #define smp_init() do { } while (0) | |
349 | #endif | |
350 | ||
e0982e90 | 351 | static inline void setup_nr_cpu_ids(void) { } |
1da177e4 | 352 | static inline void smp_prepare_cpus(unsigned int maxcpus) { } |
1da177e4 LT |
353 | #endif |
354 | ||
30d7e0d4 ABL |
355 | /* |
356 | * We need to store the untouched command line for future reference. | |
357 | * We also need to store the touched command line since the parameter | |
358 | * parsing is performed in place, and we should allow a component to | |
359 | * store reference of name/value for future reference. | |
360 | */ | |
361 | static void __init setup_command_line(char *command_line) | |
362 | { | |
363 | saved_command_line = alloc_bootmem(strlen (boot_command_line)+1); | |
364 | static_command_line = alloc_bootmem(strlen (command_line)+1); | |
365 | strcpy (saved_command_line, boot_command_line); | |
366 | strcpy (static_command_line, command_line); | |
367 | } | |
368 | ||
1da177e4 LT |
369 | /* |
370 | * We need to finalize in a non-__init function or else race conditions | |
371 | * between the root thread and the init thread may cause start_kernel to | |
372 | * be reaped by free_initmem before the root thread has proceeded to | |
373 | * cpu_idle. | |
374 | * | |
375 | * gcc-3.4 accidentally inlines this function, so use noinline. | |
376 | */ | |
377 | ||
b433c3d4 PZ |
378 | static __initdata DECLARE_COMPLETION(kthreadd_done); |
379 | ||
f99ebf0a | 380 | static noinline void __init_refok rest_init(void) |
1da177e4 | 381 | { |
73c27992 EB |
382 | int pid; |
383 | ||
7db905e6 | 384 | rcu_scheduler_starting(); |
b433c3d4 | 385 | /* |
97158569 | 386 | * We need to spawn init first so that it obtains pid 1, however |
b433c3d4 PZ |
387 | * the init task will end up wanting to create kthreads, which, if |
388 | * we schedule it before we create kthreadd, will OOPS. | |
389 | */ | |
aae5f662 | 390 | kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND); |
1da177e4 | 391 | numa_default_policy(); |
73c27992 | 392 | pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES); |
d11c563d | 393 | rcu_read_lock(); |
5cd20455 | 394 | kthreadd_task = find_task_by_pid_ns(pid, &init_pid_ns); |
d11c563d | 395 | rcu_read_unlock(); |
b433c3d4 | 396 | complete(&kthreadd_done); |
f340c0d1 IM |
397 | |
398 | /* | |
399 | * The boot idle thread must execute schedule() | |
1df21055 | 400 | * at least once to get things moving: |
f340c0d1 | 401 | */ |
1df21055 | 402 | init_idle_bootup_task(current); |
bd2f5536 | 403 | schedule_preempt_disabled(); |
5bfb5d69 | 404 | /* Call into cpu_idle with preempt disabled */ |
a1a04ec3 | 405 | cpu_startup_entry(CPUHP_ONLINE); |
1df21055 | 406 | } |
1da177e4 LT |
407 | |
408 | /* Check for early params. */ | |
9fb48c74 | 409 | static int __init do_early_param(char *param, char *val, const char *unused) |
1da177e4 | 410 | { |
914dcaa8 | 411 | const struct obs_kernel_param *p; |
1da177e4 LT |
412 | |
413 | for (p = __setup_start; p < __setup_end; p++) { | |
b1e4d20c | 414 | if ((p->early && parameq(param, p->str)) || |
18a8bd94 YL |
415 | (strcmp(param, "console") == 0 && |
416 | strcmp(p->str, "earlycon") == 0) | |
417 | ) { | |
1da177e4 | 418 | if (p->setup_func(val) != 0) |
ea676e84 | 419 | pr_warn("Malformed early option '%s'\n", param); |
1da177e4 LT |
420 | } |
421 | } | |
422 | /* We accept everything at this stage. */ | |
3c2a0909 S |
423 | #ifdef CONFIG_KNOX_KAP |
424 | if ((strncmp(param, "androidboot.security_mode", 26) == 0)) { | |
425 | pr_warn("val = %d\n",*val); | |
426 | if ((strncmp(val, "1526595585", 10) == 0)) { | |
427 | pr_info("Security Boot Mode \n"); | |
428 | boot_mode_security = 1; | |
429 | #ifdef CONFIG_RKP_KDP | |
430 | rkp_cred_enable = 1; | |
431 | #endif /*CONFIG_RKP_KDP*/ | |
432 | } | |
433 | } | |
434 | #endif | |
1da177e4 LT |
435 | return 0; |
436 | } | |
437 | ||
13977091 MD |
438 | void __init parse_early_options(char *cmdline) |
439 | { | |
026cee00 | 440 | parse_args("early options", cmdline, NULL, 0, 0, 0, do_early_param); |
13977091 MD |
441 | } |
442 | ||
1da177e4 LT |
443 | /* Arch code calls this early on, or if not, just before other parsing. */ |
444 | void __init parse_early_param(void) | |
445 | { | |
446 | static __initdata int done = 0; | |
447 | static __initdata char tmp_cmdline[COMMAND_LINE_SIZE]; | |
448 | ||
449 | if (done) | |
450 | return; | |
451 | ||
452 | /* All fall through to do_early_param. */ | |
30d7e0d4 | 453 | strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE); |
13977091 | 454 | parse_early_options(tmp_cmdline); |
1da177e4 LT |
455 | done = 1; |
456 | } | |
457 | ||
458 | /* | |
459 | * Activate the first processor. | |
460 | */ | |
461 | ||
44fd2299 SS |
462 | static void __init boot_cpu_init(void) |
463 | { | |
464 | int cpu = smp_processor_id(); | |
465 | /* Mark the boot cpu "present", "online" etc for SMP and UP case */ | |
915441b6 | 466 | set_cpu_online(cpu, true); |
933b0618 | 467 | set_cpu_active(cpu, true); |
915441b6 RR |
468 | set_cpu_present(cpu, true); |
469 | set_cpu_possible(cpu, true); | |
44fd2299 SS |
470 | } |
471 | ||
839ad62e | 472 | void __init __weak smp_setup_processor_id(void) |
033ab7f8 AM |
473 | { |
474 | } | |
475 | ||
eded09cc | 476 | # if THREAD_SIZE >= PAGE_SIZE |
8c9843e5 BH |
477 | void __init __weak thread_info_cache_init(void) |
478 | { | |
479 | } | |
eded09cc | 480 | #endif |
8c9843e5 | 481 | |
444f478f PE |
482 | /* |
483 | * Set up kernel memory allocators | |
484 | */ | |
485 | static void __init mm_init(void) | |
486 | { | |
ca371c0d | 487 | /* |
7fa87ce7 JC |
488 | * page_cgroup requires contiguous pages, |
489 | * bigger than MAX_ORDER unless SPARSEMEM. | |
ca371c0d KH |
490 | */ |
491 | page_cgroup_init_flatmem(); | |
444f478f PE |
492 | mem_init(); |
493 | kmem_cache_init(); | |
099a19d9 | 494 | percpu_init_late(); |
c868d550 | 495 | pgtable_cache_init(); |
444f478f PE |
496 | vmalloc_init(); |
497 | } | |
3c2a0909 S |
498 | #ifdef CONFIG_TIMA_RKP |
499 | extern void* vmm_extra_mem; | |
500 | u8 rkp_started = 0; | |
501 | static void rkp_init(void) | |
502 | { | |
503 | rkp_init_t init; | |
504 | init.magic = RKP_INIT_MAGIC; | |
505 | init.vmalloc_start = VMALLOC_START; | |
506 | init.vmalloc_end = (u64)high_memory; | |
507 | init.init_mm_pgd = (u64)__pa(swapper_pg_dir); | |
508 | init.id_map_pgd = (u64)__pa(idmap_pg_dir); | |
509 | init.rkp_pgt_bitmap = (u64)__pa(rkp_pgt_bitmap); | |
510 | init.rkp_map_bitmap = (u64)__pa(rkp_map_bitmap); | |
511 | init.rkp_pgt_bitmap_size = RKP_PGT_BITMAP_LEN; | |
512 | init.zero_pg_addr = page_to_phys(empty_zero_page); | |
513 | init._text = (u64) _text; | |
514 | init._etext = (u64) _etext; | |
515 | if (!vmm_extra_mem) { | |
516 | printk(KERN_ERR"Disable RKP: Failed to allocate extra mem\n"); | |
517 | return; | |
518 | } | |
519 | init.extra_memory_addr = __pa(vmm_extra_mem); | |
520 | init.extra_memory_size = 0x600000; | |
521 | init._srodata = (u64) __start_rodata; | |
522 | init._erodata =(u64) __end_rodata; | |
523 | #if defined(CONFIG_USE_HOST_FD_LIBRARY) | |
524 | init.large_memory = (u32) virt_to_phys(fd_vaddr); | |
525 | #else | |
526 | init.large_memory = 0; | |
527 | #endif | |
528 | rkp_call(RKP_INIT, (u64)&init, 0, 0, 0, 0); | |
529 | rkp_started = 1; | |
530 | return; | |
531 | } | |
532 | #endif | |
533 | #ifdef CONFIG_RKP_KDP | |
534 | ||
535 | void kdp_init(void) | |
536 | { | |
537 | kdp_init_t cred; | |
538 | ||
539 | cred.credSize = sizeof(struct cred); | |
540 | cred.pgd_mm = offsetof(struct mm_struct,pgd); | |
541 | cred.uid_cred = offsetof(struct cred,uid); | |
542 | cred.euid_cred = offsetof(struct cred,euid); | |
543 | ||
544 | cred.bp_pgd_cred = offsetof(struct cred,bp_pgd); | |
545 | cred.bp_task_cred = offsetof(struct cred,bp_task); | |
546 | cred.type_cred = offsetof(struct cred,type); | |
547 | cred.security_cred = offsetof(struct cred,security); | |
548 | cred.usage_cred = offsetof(struct cred,use_cnt); | |
549 | ||
550 | cred.cred_task = offsetof(struct task_struct,cred); | |
551 | cred.mm_task = offsetof(struct task_struct,mm); | |
552 | cred.pid_task = offsetof(struct task_struct,pid); | |
553 | cred.rp_task = offsetof(struct task_struct,real_parent); | |
554 | cred.comm_task = offsetof(struct task_struct,comm); | |
555 | ||
556 | cred.task_threadinfo = offsetof(struct thread_info,task); | |
557 | rkp_call(RKP_CMDID(0x40),(u64)&cred,0,0,0,0); | |
558 | } | |
559 | #endif /*CONFIG_RKP_KDP*/ | |
444f478f | 560 | |
1da177e4 LT |
561 | asmlinkage void __init start_kernel(void) |
562 | { | |
563 | char * command_line; | |
914dcaa8 | 564 | extern const struct kernel_param __start___param[], __stop___param[]; |
033ab7f8 | 565 | |
fbb9ce95 IM |
566 | /* |
567 | * Need to run as early as possible, to initialize the | |
568 | * lockdep hash: | |
569 | */ | |
570 | lockdep_init(); | |
73839c5b | 571 | smp_setup_processor_id(); |
3ac7fe5a | 572 | debug_objects_early_init(); |
42059429 IM |
573 | |
574 | /* | |
575 | * Set up the the initial canary ASAP: | |
576 | */ | |
577 | boot_init_stack_canary(); | |
578 | ||
ddbcc7e8 | 579 | cgroup_init_early(); |
fbb9ce95 IM |
580 | |
581 | local_irq_disable(); | |
2ce802f6 | 582 | early_boot_irqs_disabled = true; |
fbb9ce95 | 583 | |
1da177e4 LT |
584 | /* |
585 | * Interrupts are still disabled. Do necessary setups, then | |
586 | * enable them | |
587 | */ | |
44fd2299 | 588 | boot_cpu_init(); |
1da177e4 | 589 | page_address_init(); |
ea676e84 | 590 | pr_notice("%s", linux_banner); |
1da177e4 | 591 | setup_arch(&command_line); |
cf475ad2 | 592 | mm_init_owner(&init_mm, &init_task); |
6345d24d | 593 | mm_init_cpumask(&init_mm); |
30d7e0d4 | 594 | setup_command_line(command_line); |
e0982e90 | 595 | setup_nr_cpu_ids(); |
d6647bdf | 596 | setup_per_cpu_areas(); |
44fd2299 | 597 | smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */ |
1da177e4 | 598 | |
9adb62a5 | 599 | build_all_zonelists(NULL, NULL); |
83b519e8 PE |
600 | page_alloc_init(); |
601 | ||
ea676e84 | 602 | pr_notice("Kernel command line: %s\n", boot_command_line); |
83b519e8 PE |
603 | parse_early_param(); |
604 | parse_args("Booting kernel", static_command_line, __start___param, | |
605 | __stop___param - __start___param, | |
ae82fdb1 | 606 | -1, -1, &unknown_bootoption); |
3c2a0909 S |
607 | #ifdef CONFIG_TIMA_RKP |
608 | #ifdef CONFIG_KNOX_KAP | |
609 | if (boot_mode_security) | |
610 | vmm_init(); | |
611 | else | |
612 | vmm_disable(); | |
613 | #else | |
614 | vmm_init(); | |
615 | #endif //CONFIG_KNOX_KAP | |
616 | #endif //CONFIG_TIMA_RKP | |
97ce2c88 JF |
617 | jump_label_init(); |
618 | ||
83b519e8 PE |
619 | /* |
620 | * These use large bootmem allocations and must precede | |
621 | * kmem_cache_init() | |
622 | */ | |
162a7e75 | 623 | setup_log_buf(0); |
83b519e8 | 624 | pidhash_init(); |
83b519e8 PE |
625 | vfs_caches_init_early(); |
626 | sort_main_extable(); | |
627 | trap_init(); | |
444f478f | 628 | mm_init(); |
de03c72c | 629 | |
1da177e4 LT |
630 | /* |
631 | * Set up the scheduler prior starting any interrupts (such as the | |
632 | * timer interrupt). Full topology setup happens at smp_init() | |
633 | * time - but meanwhile we still have a functioning scheduler. | |
634 | */ | |
635 | sched_init(); | |
636 | /* | |
637 | * Disable preemption - early bootup scheduling is extremely | |
638 | * fragile until we cpu_idle() for the first time. | |
639 | */ | |
640 | preempt_disable(); | |
f91eb62f | 641 | if (WARN(!irqs_disabled(), "Interrupts were enabled *very* early, fixing it\n")) |
c4a68306 | 642 | local_irq_disable(); |
9f58a205 | 643 | idr_init_cache(); |
24a24bb6 | 644 | perf_event_init(); |
1da177e4 | 645 | rcu_init(); |
d1e43fa5 | 646 | tick_nohz_init(); |
773e3eb7 | 647 | radix_tree_init(); |
0b8f1efa YL |
648 | /* init some links before init_ISA_irqs() */ |
649 | early_irq_init(); | |
1da177e4 | 650 | init_IRQ(); |
ad2b1353 | 651 | tick_init(); |
1da177e4 | 652 | init_timers(); |
c0a31329 | 653 | hrtimers_init(); |
1da177e4 | 654 | softirq_init(); |
ad596171 | 655 | timekeeping_init(); |
88fecaa2 | 656 | time_init(); |
3c2a0909 | 657 | sched_clock_postinit(); |
93e02814 | 658 | profile_init(); |
d8ad7d11 | 659 | call_function_init(); |
f91eb62f | 660 | WARN(!irqs_disabled(), "Interrupts were enabled early\n"); |
2ce802f6 | 661 | early_boot_irqs_disabled = false; |
93e02814 | 662 | local_irq_enable(); |
dcce284a | 663 | |
7e85ee0c | 664 | kmem_cache_init_late(); |
1da177e4 LT |
665 | |
666 | /* | |
667 | * HACK ALERT! This is early. We're enabling the console before | |
668 | * we've done PCI setups etc, and console_init() must be aware of | |
669 | * this. But we do want output early, in case something goes wrong. | |
670 | */ | |
671 | console_init(); | |
672 | if (panic_later) | |
673 | panic(panic_later, panic_param); | |
fbb9ce95 IM |
674 | |
675 | lockdep_info(); | |
676 | ||
9a11b49a IM |
677 | /* |
678 | * Need to run this when irqs are enabled, because it wants | |
679 | * to self-test [hard/soft]-irqs on/off lock inversion bugs | |
680 | * too: | |
681 | */ | |
682 | locking_selftest(); | |
683 | ||
1da177e4 LT |
684 | #ifdef CONFIG_BLK_DEV_INITRD |
685 | if (initrd_start && !initrd_below_start_ok && | |
bd673c7c | 686 | page_to_pfn(virt_to_page((void *)initrd_start)) < min_low_pfn) { |
ea676e84 | 687 | pr_crit("initrd overwritten (0x%08lx < 0x%08lx) - disabling it.\n", |
bd673c7c GU |
688 | page_to_pfn(virt_to_page((void *)initrd_start)), |
689 | min_low_pfn); | |
1da177e4 LT |
690 | initrd_start = 0; |
691 | } | |
692 | #endif | |
94b6da5a | 693 | page_cgroup_init(); |
3ac7fe5a | 694 | debug_objects_mem_init(); |
9b090f2d | 695 | kmemleak_init(); |
e7c8d5c9 | 696 | setup_per_cpu_pageset(); |
1da177e4 LT |
697 | numa_policy_init(); |
698 | if (late_time_init) | |
699 | late_time_init(); | |
fa84e9ee | 700 | sched_clock_init(); |
1da177e4 LT |
701 | calibrate_delay(); |
702 | pidmap_init(); | |
1da177e4 | 703 | anon_vma_init(); |
11520e5e | 704 | #ifdef CONFIG_X86 |
83e68189 | 705 | if (efi_enabled(EFI_RUNTIME_SERVICES)) |
11520e5e | 706 | efi_enter_virtual_mode(); |
a7b854c9 | 707 | #endif |
cd4033c9 | 708 | #ifdef CONFIG_X86_ESPFIX64 |
a7b854c9 PA |
709 | /* Should be run before the first non-init thread is created */ |
710 | init_espfix_bsp(); | |
11520e5e | 711 | #endif |
8c9843e5 | 712 | thread_info_cache_init(); |
3c2a0909 S |
713 | #ifdef CONFIG_TIMA_RKP |
714 | ||
715 | #ifdef CONFIG_KNOX_KAP | |
716 | if (boot_mode_security) | |
717 | #endif | |
718 | rkp_init(); | |
719 | #ifdef CONFIG_RKP_KDP | |
720 | if (rkp_cred_enable) | |
721 | kdp_init(); | |
722 | #endif /*CONFIG_RKP_KDP*/ | |
723 | #endif /* CONFIG_TIMA_RKP */ | |
d84f4f99 | 724 | cred_init(); |
4481374c | 725 | fork_init(totalram_pages); |
1da177e4 LT |
726 | proc_caches_init(); |
727 | buffer_init(); | |
1da177e4 LT |
728 | key_init(); |
729 | security_init(); | |
3c2a0909 S |
730 | #ifdef CONFIG_RKP_KDP |
731 | if (rkp_cred_enable) | |
732 | rkp_call(RKP_CMDID(0x51),(u64)__rkp_ro_start,0,0,0,0); | |
733 | #endif /*CONFIG_RKP_KDP*/ | |
0b4b3827 | 734 | dbg_late_init(); |
4481374c | 735 | vfs_caches_init(totalram_pages); |
1da177e4 LT |
736 | signals_init(); |
737 | /* rootfs populating might need page-writeback */ | |
738 | page_writeback_init(); | |
739 | #ifdef CONFIG_PROC_FS | |
740 | proc_root_init(); | |
741 | #endif | |
ddbcc7e8 | 742 | cgroup_init(); |
1da177e4 | 743 | cpuset_init(); |
c757249a | 744 | taskstats_init_early(); |
ca74e92b | 745 | delayacct_init(); |
1da177e4 LT |
746 | |
747 | check_bugs(); | |
748 | ||
749 | acpi_early_init(); /* before LAPIC and SMP init */ | |
6ae6996a | 750 | sfi_init_late(); |
1da177e4 | 751 | |
83e68189 | 752 | if (efi_enabled(EFI_RUNTIME_SERVICES)) { |
2223af38 | 753 | efi_late_init(); |
78510792 | 754 | efi_free_boot_services(); |
2223af38 | 755 | } |
78510792 | 756 | |
68bf21aa SR |
757 | ftrace_init(); |
758 | ||
1da177e4 LT |
759 | /* Do the rest non-__init'ed, we're now alive */ |
760 | rest_init(); | |
761 | } | |
762 | ||
b99b87f7 PO |
763 | /* Call all constructor functions linked into the kernel. */ |
764 | static void __init do_ctors(void) | |
765 | { | |
766 | #ifdef CONFIG_CONSTRUCTORS | |
196a15b4 | 767 | ctor_fn_t *fn = (ctor_fn_t *) __ctors_start; |
b99b87f7 | 768 | |
196a15b4 HS |
769 | for (; fn < (ctor_fn_t *) __ctors_end; fn++) |
770 | (*fn)(); | |
b99b87f7 PO |
771 | #endif |
772 | } | |
773 | ||
2329abfa | 774 | bool initcall_debug; |
d0ea3d7d | 775 | core_param(initcall_debug, initcall_debug, bool, 0644); |
1da177e4 | 776 | |
4a683bf9 | 777 | static char msgbuf[64]; |
4a683bf9 | 778 | |
e4461271 | 779 | static int __init_or_module do_one_initcall_debug(initcall_t fn) |
1da177e4 | 780 | { |
74239072 | 781 | ktime_t calltime, delta, rettime; |
30dbb20e AW |
782 | unsigned long long duration; |
783 | int ret; | |
1da177e4 | 784 | |
ea676e84 | 785 | pr_debug("calling %pF @ %i\n", fn, task_pid_nr(current)); |
22c5c03b | 786 | calltime = ktime_get(); |
30dbb20e | 787 | ret = fn(); |
22c5c03b KW |
788 | rettime = ktime_get(); |
789 | delta = ktime_sub(rettime, calltime); | |
790 | duration = (unsigned long long) ktime_to_ns(delta) >> 10; | |
ea676e84 AM |
791 | pr_debug("initcall %pF returned %d after %lld usecs\n", |
792 | fn, ret, duration); | |
1da177e4 | 793 | |
22c5c03b KW |
794 | return ret; |
795 | } | |
796 | ||
e4461271 | 797 | int __init_or_module do_one_initcall(initcall_t fn) |
22c5c03b KW |
798 | { |
799 | int count = preempt_count(); | |
800 | int ret; | |
801 | ||
802 | if (initcall_debug) | |
803 | ret = do_one_initcall_debug(fn); | |
804 | else | |
805 | ret = fn(); | |
8f0c45cd | 806 | |
e0df154f | 807 | msgbuf[0] = 0; |
e662e1cf | 808 | |
e0df154f | 809 | if (preempt_count() != count) { |
bf5d770b | 810 | sprintf(msgbuf, "preemption imbalance "); |
e0df154f | 811 | preempt_count() = count; |
1da177e4 | 812 | } |
e0df154f | 813 | if (irqs_disabled()) { |
a76bfd0d | 814 | strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf)); |
e0df154f LT |
815 | local_irq_enable(); |
816 | } | |
f91eb62f | 817 | WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf); |
59f9415f | 818 | |
30dbb20e | 819 | return ret; |
e0df154f LT |
820 | } |
821 | ||
822 | ||
026cee00 PM |
823 | extern initcall_t __initcall_start[]; |
824 | extern initcall_t __initcall0_start[]; | |
825 | extern initcall_t __initcall1_start[]; | |
826 | extern initcall_t __initcall2_start[]; | |
827 | extern initcall_t __initcall3_start[]; | |
828 | extern initcall_t __initcall4_start[]; | |
829 | extern initcall_t __initcall5_start[]; | |
830 | extern initcall_t __initcall6_start[]; | |
831 | extern initcall_t __initcall7_start[]; | |
832 | extern initcall_t __initcall_end[]; | |
833 | ||
834 | static initcall_t *initcall_levels[] __initdata = { | |
835 | __initcall0_start, | |
836 | __initcall1_start, | |
837 | __initcall2_start, | |
838 | __initcall3_start, | |
839 | __initcall4_start, | |
840 | __initcall5_start, | |
841 | __initcall6_start, | |
842 | __initcall7_start, | |
843 | __initcall_end, | |
844 | }; | |
845 | ||
96263d28 | 846 | /* Keep these in sync with initcalls in include/linux/init.h */ |
026cee00 | 847 | static char *initcall_level_names[] __initdata = { |
9fb48c74 JC |
848 | "early", |
849 | "core", | |
850 | "postcore", | |
851 | "arch", | |
852 | "subsys", | |
853 | "fs", | |
854 | "device", | |
855 | "late", | |
026cee00 PM |
856 | }; |
857 | ||
026cee00 | 858 | static void __init do_initcall_level(int level) |
e0df154f | 859 | { |
026cee00 | 860 | extern const struct kernel_param __start___param[], __stop___param[]; |
196a15b4 | 861 | initcall_t *fn; |
e0df154f | 862 | |
026cee00 PM |
863 | strcpy(static_command_line, saved_command_line); |
864 | parse_args(initcall_level_names[level], | |
865 | static_command_line, __start___param, | |
866 | __stop___param - __start___param, | |
867 | level, level, | |
eb157427 | 868 | &repair_env_string); |
026cee00 PM |
869 | |
870 | for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) | |
196a15b4 | 871 | do_one_initcall(*fn); |
1da177e4 LT |
872 | } |
873 | ||
026cee00 PM |
874 | static void __init do_initcalls(void) |
875 | { | |
876 | int level; | |
877 | ||
19efb72f | 878 | for (level = 0; level < ARRAY_SIZE(initcall_levels) - 1; level++) |
026cee00 PM |
879 | do_initcall_level(level); |
880 | } | |
881 | ||
1da177e4 LT |
882 | /* |
883 | * Ok, the machine is now initialized. None of the devices | |
884 | * have been touched yet, but the CPU subsystem is up and | |
885 | * running, and memory and process management works. | |
886 | * | |
887 | * Now we can finally start doing some real work.. | |
888 | */ | |
889 | static void __init do_basic_setup(void) | |
890 | { | |
759ee091 | 891 | cpuset_init_smp(); |
1da177e4 | 892 | usermodehelper_init(); |
41ffe5d5 | 893 | shmem_init(); |
1da177e4 | 894 | driver_init(); |
b04c3afb | 895 | init_irq_proc(); |
b99b87f7 | 896 | do_ctors(); |
d5767c53 | 897 | usermodehelper_enable(); |
b0f84374 | 898 | do_initcalls(); |
b7a52f51 | 899 | random_int_secret_init(); |
1da177e4 LT |
900 | } |
901 | ||
7babe8db | 902 | static void __init do_pre_smp_initcalls(void) |
c2147a50 | 903 | { |
196a15b4 | 904 | initcall_t *fn; |
c2147a50 | 905 | |
026cee00 | 906 | for (fn = __initcall_start; fn < __initcall0_start; fn++) |
196a15b4 | 907 | do_one_initcall(*fn); |
c2147a50 EGM |
908 | } |
909 | ||
bb813f4c TH |
910 | /* |
911 | * This function requests modules which should be loaded by default and is | |
912 | * called twice right after initrd is mounted and right before init is | |
913 | * exec'd. If such modules are on either initrd or rootfs, they will be | |
914 | * loaded before control is passed to userland. | |
915 | */ | |
916 | void __init load_default_modules(void) | |
917 | { | |
918 | load_default_elevator_module(); | |
919 | } | |
920 | ||
a74fb73c | 921 | static int run_init_process(const char *init_filename) |
1da177e4 LT |
922 | { |
923 | argv_init[0] = init_filename; | |
ae903caa AV |
924 | return do_execve(init_filename, |
925 | (const char __user *const __user *)argv_init, | |
926 | (const char __user *const __user *)envp_init); | |
1da177e4 LT |
927 | } |
928 | ||
3c2a0909 S |
929 | #ifdef CONFIG_DEFERRED_INITCALLS |
930 | extern initcall_t __deferred_initcall_start[], __deferred_initcall_end[]; | |
931 | ||
932 | /* call deferred init routines */ | |
933 | void __ref do_deferred_initcalls(void) | |
934 | { | |
935 | initcall_t *call; | |
936 | static int already_run=0; | |
937 | ||
938 | if (already_run) { | |
939 | printk("do_deferred_initcalls() has already run\n"); | |
940 | return; | |
941 | } | |
942 | ||
943 | already_run=1; | |
944 | ||
945 | printk("Running do_deferred_initcalls()\n"); | |
946 | ||
947 | for(call = __deferred_initcall_start; | |
948 | call < __deferred_initcall_end; call++) | |
949 | do_one_initcall(*call); | |
950 | ||
951 | flush_scheduled_work(); | |
952 | ||
953 | free_initmem(); | |
954 | } | |
955 | #endif | |
956 | ||
957 | #ifdef CONFIG_SEC_GPIO_DVS | |
958 | extern void gpio_dvs_check_initgpio(void); | |
959 | #endif | |
960 | ||
f80b0c90 | 961 | static noinline void __init kernel_init_freeable(void); |
d6b21238 AV |
962 | |
963 | static int __ref kernel_init(void *unused) | |
ee5bfa64 | 964 | { |
d6b21238 | 965 | kernel_init_freeable(); |
3c2a0909 S |
966 | #ifdef CONFIG_SEC_GPIO_DVS |
967 | /* This function must be located in appropriate INIT position | |
968 | * in accordance with the specification of each BB vendor. | |
969 | */ | |
970 | gpio_dvs_check_initgpio(); | |
971 | #endif | |
22a9d645 AV |
972 | /* need to finish all async __init code before freeing the memory */ |
973 | async_synchronize_full(); | |
3c2a0909 | 974 | #ifndef CONFIG_DEFERRED_INITCALLS |
ee5bfa64 | 975 | free_initmem(); |
3c2a0909 | 976 | #endif |
ee5bfa64 VG |
977 | mark_rodata_ro(); |
978 | system_state = SYSTEM_RUNNING; | |
979 | numa_default_policy(); | |
980 | ||
4a9d4b02 | 981 | flush_delayed_fput(); |
fae5fa44 | 982 | |
ee5bfa64 | 983 | if (ramdisk_execute_command) { |
a74fb73c AV |
984 | if (!run_init_process(ramdisk_execute_command)) |
985 | return 0; | |
ea676e84 | 986 | pr_err("Failed to execute %s\n", ramdisk_execute_command); |
ee5bfa64 VG |
987 | } |
988 | ||
989 | /* | |
990 | * We try each of these until one succeeds. | |
991 | * | |
992 | * The Bourne shell can be used instead of init if we are | |
993 | * trying to recover a really broken machine. | |
994 | */ | |
995 | if (execute_command) { | |
a74fb73c AV |
996 | if (!run_init_process(execute_command)) |
997 | return 0; | |
ea676e84 AM |
998 | pr_err("Failed to execute %s. Attempting defaults...\n", |
999 | execute_command); | |
ee5bfa64 | 1000 | } |
a74fb73c AV |
1001 | if (!run_init_process("/sbin/init") || |
1002 | !run_init_process("/etc/init") || | |
1003 | !run_init_process("/bin/init") || | |
1004 | !run_init_process("/bin/sh")) | |
1005 | return 0; | |
ee5bfa64 | 1006 | |
9a85b8d6 AM |
1007 | panic("No init found. Try passing init= option to kernel. " |
1008 | "See Linux Documentation/init.txt for guidance."); | |
ee5bfa64 VG |
1009 | } |
1010 | ||
f80b0c90 | 1011 | static noinline void __init kernel_init_freeable(void) |
1da177e4 | 1012 | { |
b433c3d4 PZ |
1013 | /* |
1014 | * Wait until kthreadd is all set-up. | |
1015 | */ | |
1016 | wait_for_completion(&kthreadd_done); | |
31a67102 LT |
1017 | |
1018 | /* Now the scheduler is fully set up and can do blocking allocations */ | |
1019 | gfp_allowed_mask = __GFP_BITS_MASK; | |
1020 | ||
58568d2a MX |
1021 | /* |
1022 | * init can allocate pages on any node | |
1023 | */ | |
3c466d46 | 1024 | set_mems_allowed(node_states[N_MEMORY]); |
1da177e4 LT |
1025 | /* |
1026 | * init can run on any cpu. | |
1027 | */ | |
1a2142af | 1028 | set_cpus_allowed_ptr(current, cpu_all_mask); |
1da177e4 | 1029 | |
9ec52099 CLG |
1030 | cad_pid = task_pid(current); |
1031 | ||
ca74a6f8 | 1032 | smp_prepare_cpus(setup_max_cpus); |
1da177e4 LT |
1033 | |
1034 | do_pre_smp_initcalls(); | |
004417a6 | 1035 | lockup_detector_init(); |
1da177e4 | 1036 | |
1da177e4 LT |
1037 | smp_init(); |
1038 | sched_init_smp(); | |
1039 | ||
1da177e4 LT |
1040 | do_basic_setup(); |
1041 | ||
2bd3a997 EB |
1042 | /* Open the /dev/console on the rootfs, this should never fail */ |
1043 | if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) | |
ea676e84 | 1044 | pr_err("Warning: unable to open an initial console.\n"); |
2bd3a997 EB |
1045 | |
1046 | (void) sys_dup(0); | |
1047 | (void) sys_dup(0); | |
1da177e4 LT |
1048 | /* |
1049 | * check if there is an early userspace init. If yes, let it do all | |
1050 | * the work | |
1051 | */ | |
ffdfc409 OJ |
1052 | |
1053 | if (!ramdisk_execute_command) | |
1054 | ramdisk_execute_command = "/init"; | |
1055 | ||
1056 | if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) { | |
1057 | ramdisk_execute_command = NULL; | |
1da177e4 | 1058 | prepare_namespace(); |
ffdfc409 | 1059 | } |
1da177e4 LT |
1060 | |
1061 | /* | |
1062 | * Ok, we have completed the initial bootup, and | |
1063 | * we're essentially up and running. Get rid of the | |
1064 | * initmem segments and start the user-mode stuff.. | |
1065 | */ | |
bb813f4c TH |
1066 | |
1067 | /* rootfs is available now, try loading default modules */ | |
1068 | load_default_modules(); | |
1da177e4 | 1069 | } |