4 * Copyright (C) 1991, 1992 Linus Torvalds
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>
12 #define DEBUG /* Enable initcall_debug */
14 #include <linux/types.h>
15 #include <linux/module.h>
16 #include <linux/proc_fs.h>
17 #include <linux/kernel.h>
18 #include <linux/syscalls.h>
19 #include <linux/stackprotector.h>
20 #include <linux/string.h>
21 #include <linux/ctype.h>
22 #include <linux/delay.h>
23 #include <linux/ioport.h>
24 #include <linux/init.h>
25 #include <linux/initrd.h>
26 #include <linux/bootmem.h>
27 #include <linux/acpi.h>
28 #include <linux/tty.h>
29 #include <linux/percpu.h>
30 #include <linux/kmod.h>
31 #include <linux/vmalloc.h>
32 #include <linux/kernel_stat.h>
33 #include <linux/start_kernel.h>
34 #include <linux/security.h>
35 #include <linux/smp.h>
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>
43 #include <linux/cgroup.h>
44 #include <linux/efi.h>
45 #include <linux/tick.h>
46 #include <linux/interrupt.h>
47 #include <linux/taskstats_kern.h>
48 #include <linux/delayacct.h>
49 #include <linux/unistd.h>
50 #include <linux/rmap.h>
51 #include <linux/mempolicy.h>
52 #include <linux/key.h>
53 #include <linux/buffer_head.h>
54 #include <linux/page_cgroup.h>
55 #include <linux/debug_locks.h>
56 #include <linux/debugobjects.h>
57 #include <linux/lockdep.h>
58 #include <linux/kmemleak.h>
59 #include <linux/pid_namespace.h>
60 #include <linux/device.h>
61 #include <linux/kthread.h>
62 #include <linux/sched.h>
63 #include <linux/signal.h>
64 #include <linux/idr.h>
65 #include <linux/kgdb.h>
66 #include <linux/ftrace.h>
67 #include <linux/async.h>
68 #include <linux/kmemcheck.h>
69 #include <linux/sfi.h>
70 #include <linux/shmem_fs.h>
71 #include <linux/slab.h>
72 #include <linux/perf_event.h>
73 #include <linux/file.h>
74 #include <linux/ptrace.h>
75 #include <linux/blkdev.h>
76 #include <linux/elevator.h>
77 #include <linux/random.h>
78 #include <linux/sched_clock.h>
82 #include <asm/setup.h>
83 #include <asm/sections.h>
84 #include <asm/cacheflush.h>
86 #ifdef CONFIG_X86_LOCAL_APIC
90 #ifdef CONFIG_TIMA_RKP
91 #include <linux/vmm.h>
92 #include <linux/rkp_entry.h>
93 #endif //CONFIG_TIMA_RKP
95 static int kernel_init(void *);
97 extern void init_IRQ(void);
98 extern void fork_init(unsigned long);
99 extern void mca_init(void);
100 extern void sbus_init(void);
101 extern void radix_tree_init(void);
102 #ifndef CONFIG_DEBUG_RODATA
103 static inline void mark_rodata_ro(void) { }
107 extern void tc_init(void);
110 #if defined(CONFIG_USE_HOST_FD_LIBRARY)
111 extern void *fd_vaddr
;
114 #ifdef CONFIG_KNOX_KAP
115 int boot_mode_security
;
116 EXPORT_SYMBOL(boot_mode_security
);
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
126 bool early_boot_irqs_disabled __read_mostly
;
128 enum system_states system_state __read_mostly
;
129 EXPORT_SYMBOL(system_state
);
132 * Boot command-line arguments
134 #define MAX_INIT_ARGS CONFIG_INIT_ENV_ARG_LIMIT
135 #define MAX_INIT_ENVS CONFIG_INIT_ENV_ARG_LIMIT
137 extern void time_init(void);
138 /* Default late time init is NULL. archs can override this later. */
139 void (*__initdata late_time_init
)(void);
140 extern void softirq_init(void);
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
;
149 static char *execute_command
;
150 static char *ramdisk_execute_command
;
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.
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.
161 unsigned int reset_devices
;
162 EXPORT_SYMBOL(reset_devices
);
164 static int __init
set_reset_devices(char *str
)
170 __setup("reset_devices", set_reset_devices
);
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
, };
174 static const char *panic_later
, *panic_param
;
176 extern const struct obs_kernel_param __setup_start
[], __setup_end
[];
178 static int __init
obsolete_checksetup(char *line
)
180 const struct obs_kernel_param
*p
;
181 int had_early_param
= 0;
185 int n
= strlen(p
->str
);
186 if (parameqn(line
, p
->str
, n
)) {
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( */
192 if (line
[n
] == '\0' || line
[n
] == '=')
194 } else if (!p
->setup_func
) {
195 pr_warn("Parameter %s is obsolete, ignored\n",
198 } else if (p
->setup_func(line
+ n
))
202 } while (p
< __setup_end
);
204 return had_early_param
;
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
211 unsigned long loops_per_jiffy
= (1<<12);
213 EXPORT_SYMBOL(loops_per_jiffy
);
215 static int __init
debug_kernel(char *str
)
217 console_loglevel
= 10;
221 static int __init
quiet_kernel(char *str
)
223 console_loglevel
= 4;
227 early_param("debug", debug_kernel
);
228 early_param("quiet", quiet_kernel
);
230 static int __init
loglevel(char *str
)
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
239 if (get_option(&str
, &newlevel
)) {
240 console_loglevel
= newlevel
;
247 early_param("loglevel", loglevel
);
249 /* Change NUL term back to "=", to make "param" the whole string. */
250 static int __init
repair_env_string(char *param
, char *val
, const char *unused
)
253 /* param=val or param="val"? */
254 if (val
== param
+strlen(param
)+1)
256 else if (val
== param
+strlen(param
)+2) {
258 memmove(val
-1, val
, strlen(val
)+1);
267 * Unknown boot options get handed to init, unless they look like
268 * unused parameters (modprobe will find them in /proc/cmdline).
270 static int __init
unknown_bootoption(char *param
, char *val
, const char *unused
)
272 repair_env_string(param
, val
, unused
);
274 /* Handle obsolete-style parameters */
275 if (obsolete_checksetup(param
))
278 /* Unused module parameter. */
279 if (strchr(param
, '.') && (!val
|| strchr(param
, '.') < val
))
286 /* Environment option */
288 for (i
= 0; envp_init
[i
]; i
++) {
289 if (i
== MAX_INIT_ENVS
) {
290 panic_later
= "Too many boot env vars at `%s'";
293 if (!strncmp(param
, envp_init
[i
], val
- param
))
296 envp_init
[i
] = param
;
298 /* Command line option */
300 for (i
= 0; argv_init
[i
]; i
++) {
301 if (i
== MAX_INIT_ARGS
) {
302 panic_later
= "Too many boot init vars at `%s'";
306 argv_init
[i
] = param
;
311 static int __init
init_setup(char *str
)
315 execute_command
= str
;
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]
322 for (i
= 1; i
< MAX_INIT_ARGS
; i
++)
326 __setup("init=", init_setup
);
328 static int __init
rdinit_setup(char *str
)
332 ramdisk_execute_command
= str
;
333 /* See "auto" comment in init_setup */
334 for (i
= 1; i
< MAX_INIT_ARGS
; i
++)
338 __setup("rdinit=", rdinit_setup
);
341 static const unsigned int setup_max_cpus
= NR_CPUS
;
342 #ifdef CONFIG_X86_LOCAL_APIC
343 static void __init
smp_init(void)
345 APIC_init_uniprocessor();
348 #define smp_init() do { } while (0)
351 static inline void setup_nr_cpu_ids(void) { }
352 static inline void smp_prepare_cpus(unsigned int maxcpus
) { }
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.
361 static void __init
setup_command_line(char *command_line
)
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
);
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
375 * gcc-3.4 accidentally inlines this function, so use noinline.
378 static __initdata
DECLARE_COMPLETION(kthreadd_done
);
380 static noinline
void __init_refok
rest_init(void)
384 rcu_scheduler_starting();
386 * We need to spawn init first so that it obtains pid 1, however
387 * the init task will end up wanting to create kthreads, which, if
388 * we schedule it before we create kthreadd, will OOPS.
390 kernel_thread(kernel_init
, NULL
, CLONE_FS
| CLONE_SIGHAND
);
391 numa_default_policy();
392 pid
= kernel_thread(kthreadd
, NULL
, CLONE_FS
| CLONE_FILES
);
394 kthreadd_task
= find_task_by_pid_ns(pid
, &init_pid_ns
);
396 complete(&kthreadd_done
);
399 * The boot idle thread must execute schedule()
400 * at least once to get things moving:
402 init_idle_bootup_task(current
);
403 schedule_preempt_disabled();
404 /* Call into cpu_idle with preempt disabled */
405 cpu_startup_entry(CPUHP_ONLINE
);
408 /* Check for early params. */
409 static int __init
do_early_param(char *param
, char *val
, const char *unused
)
411 const struct obs_kernel_param
*p
;
413 for (p
= __setup_start
; p
< __setup_end
; p
++) {
414 if ((p
->early
&& parameq(param
, p
->str
)) ||
415 (strcmp(param
, "console") == 0 &&
416 strcmp(p
->str
, "earlycon") == 0)
418 if (p
->setup_func(val
) != 0)
419 pr_warn("Malformed early option '%s'\n", param
);
422 /* We accept everything at this stage. */
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
431 #endif /*CONFIG_RKP_KDP*/
438 void __init
parse_early_options(char *cmdline
)
440 parse_args("early options", cmdline
, NULL
, 0, 0, 0, do_early_param
);
443 /* Arch code calls this early on, or if not, just before other parsing. */
444 void __init
parse_early_param(void)
446 static __initdata
int done
= 0;
447 static __initdata
char tmp_cmdline
[COMMAND_LINE_SIZE
];
452 /* All fall through to do_early_param. */
453 strlcpy(tmp_cmdline
, boot_command_line
, COMMAND_LINE_SIZE
);
454 parse_early_options(tmp_cmdline
);
459 * Activate the first processor.
462 static void __init
boot_cpu_init(void)
464 int cpu
= smp_processor_id();
465 /* Mark the boot cpu "present", "online" etc for SMP and UP case */
466 set_cpu_online(cpu
, true);
467 set_cpu_active(cpu
, true);
468 set_cpu_present(cpu
, true);
469 set_cpu_possible(cpu
, true);
472 void __init __weak
smp_setup_processor_id(void)
476 # if THREAD_SIZE >= PAGE_SIZE
477 void __init __weak
thread_info_cache_init(void)
483 * Set up kernel memory allocators
485 static void __init
mm_init(void)
488 * page_cgroup requires contiguous pages,
489 * bigger than MAX_ORDER unless SPARSEMEM.
491 page_cgroup_init_flatmem();
495 pgtable_cache_init();
498 #ifdef CONFIG_TIMA_RKP
499 extern void* vmm_extra_mem
;
501 static void rkp_init(void)
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");
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
);
526 init
.large_memory
= 0;
528 rkp_call(RKP_INIT
, (u64
)&init
, 0, 0, 0, 0);
533 #ifdef CONFIG_RKP_KDP
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
);
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
);
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
);
556 cred
.task_threadinfo
= offsetof(struct thread_info
,task
);
557 rkp_call(RKP_CMDID(0x40),(u64
)&cred
,0,0,0,0);
559 #endif /*CONFIG_RKP_KDP*/
561 asmlinkage
void __init
start_kernel(void)
564 extern const struct kernel_param __start___param
[], __stop___param
[];
567 * Need to run as early as possible, to initialize the
571 smp_setup_processor_id();
572 debug_objects_early_init();
575 * Set up the the initial canary ASAP:
577 boot_init_stack_canary();
582 early_boot_irqs_disabled
= true;
585 * Interrupts are still disabled. Do necessary setups, then
590 pr_notice("%s", linux_banner
);
591 setup_arch(&command_line
);
592 mm_init_owner(&init_mm
, &init_task
);
593 mm_init_cpumask(&init_mm
);
594 setup_command_line(command_line
);
596 setup_per_cpu_areas();
597 smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
599 build_all_zonelists(NULL
, NULL
);
602 pr_notice("Kernel command line: %s\n", boot_command_line
);
604 parse_args("Booting kernel", static_command_line
, __start___param
,
605 __stop___param
- __start___param
,
606 -1, -1, &unknown_bootoption
);
607 #ifdef CONFIG_TIMA_RKP
608 #ifdef CONFIG_KNOX_KAP
609 if (boot_mode_security
)
615 #endif //CONFIG_KNOX_KAP
616 #endif //CONFIG_TIMA_RKP
620 * These use large bootmem allocations and must precede
625 vfs_caches_init_early();
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.
637 * Disable preemption - early bootup scheduling is extremely
638 * fragile until we cpu_idle() for the first time.
641 if (WARN(!irqs_disabled(), "Interrupts were enabled *very* early, fixing it\n"))
648 /* init some links before init_ISA_irqs() */
657 sched_clock_postinit();
659 call_function_init();
660 WARN(!irqs_disabled(), "Interrupts were enabled early\n");
661 early_boot_irqs_disabled
= false;
664 kmem_cache_init_late();
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.
673 panic(panic_later
, panic_param
);
678 * Need to run this when irqs are enabled, because it wants
679 * to self-test [hard/soft]-irqs on/off lock inversion bugs
684 #ifdef CONFIG_BLK_DEV_INITRD
685 if (initrd_start
&& !initrd_below_start_ok
&&
686 page_to_pfn(virt_to_page((void *)initrd_start
)) < min_low_pfn
) {
687 pr_crit("initrd overwritten (0x%08lx < 0x%08lx) - disabling it.\n",
688 page_to_pfn(virt_to_page((void *)initrd_start
)),
694 debug_objects_mem_init();
696 setup_per_cpu_pageset();
705 if (efi_enabled(EFI_RUNTIME_SERVICES
))
706 efi_enter_virtual_mode();
708 #ifdef CONFIG_X86_ESPFIX64
709 /* Should be run before the first non-init thread is created */
712 thread_info_cache_init();
713 #ifdef CONFIG_TIMA_RKP
715 #ifdef CONFIG_KNOX_KAP
716 if (boot_mode_security
)
719 #ifdef CONFIG_RKP_KDP
722 #endif /*CONFIG_RKP_KDP*/
723 #endif /* CONFIG_TIMA_RKP */
725 fork_init(totalram_pages
);
730 #ifdef CONFIG_RKP_KDP
732 rkp_call(RKP_CMDID(0x51),(u64
)__rkp_ro_start
,0,0,0,0);
733 #endif /*CONFIG_RKP_KDP*/
735 vfs_caches_init(totalram_pages
);
737 /* rootfs populating might need page-writeback */
738 page_writeback_init();
739 #ifdef CONFIG_PROC_FS
744 taskstats_init_early();
749 acpi_early_init(); /* before LAPIC and SMP init */
752 if (efi_enabled(EFI_RUNTIME_SERVICES
)) {
754 efi_free_boot_services();
759 /* Do the rest non-__init'ed, we're now alive */
763 /* Call all constructor functions linked into the kernel. */
764 static void __init
do_ctors(void)
766 #ifdef CONFIG_CONSTRUCTORS
767 ctor_fn_t
*fn
= (ctor_fn_t
*) __ctors_start
;
769 for (; fn
< (ctor_fn_t
*) __ctors_end
; fn
++)
775 core_param(initcall_debug
, initcall_debug
, bool, 0644);
777 static char msgbuf
[64];
779 static int __init_or_module
do_one_initcall_debug(initcall_t fn
)
781 ktime_t calltime
, delta
, rettime
;
782 unsigned long long duration
;
785 pr_debug("calling %pF @ %i\n", fn
, task_pid_nr(current
));
786 calltime
= ktime_get();
788 rettime
= ktime_get();
789 delta
= ktime_sub(rettime
, calltime
);
790 duration
= (unsigned long long) ktime_to_ns(delta
) >> 10;
791 pr_debug("initcall %pF returned %d after %lld usecs\n",
797 int __init_or_module
do_one_initcall(initcall_t fn
)
799 int count
= preempt_count();
803 ret
= do_one_initcall_debug(fn
);
809 if (preempt_count() != count
) {
810 sprintf(msgbuf
, "preemption imbalance ");
811 preempt_count() = count
;
813 if (irqs_disabled()) {
814 strlcat(msgbuf
, "disabled interrupts ", sizeof(msgbuf
));
817 WARN(msgbuf
[0], "initcall %pF returned with %s\n", fn
, msgbuf
);
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
[];
834 static initcall_t
*initcall_levels
[] __initdata
= {
846 /* Keep these in sync with initcalls in include/linux/init.h */
847 static char *initcall_level_names
[] __initdata
= {
858 static void __init
do_initcall_level(int level
)
860 extern const struct kernel_param __start___param
[], __stop___param
[];
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
,
870 for (fn
= initcall_levels
[level
]; fn
< initcall_levels
[level
+1]; fn
++)
871 do_one_initcall(*fn
);
874 static void __init
do_initcalls(void)
878 for (level
= 0; level
< ARRAY_SIZE(initcall_levels
) - 1; level
++)
879 do_initcall_level(level
);
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.
887 * Now we can finally start doing some real work..
889 static void __init
do_basic_setup(void)
892 usermodehelper_init();
897 usermodehelper_enable();
899 random_int_secret_init();
902 static void __init
do_pre_smp_initcalls(void)
906 for (fn
= __initcall_start
; fn
< __initcall0_start
; fn
++)
907 do_one_initcall(*fn
);
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.
916 void __init
load_default_modules(void)
918 load_default_elevator_module();
921 static int run_init_process(const char *init_filename
)
923 argv_init
[0] = init_filename
;
924 return do_execve(init_filename
,
925 (const char __user
*const __user
*)argv_init
,
926 (const char __user
*const __user
*)envp_init
);
929 #ifdef CONFIG_DEFERRED_INITCALLS
930 extern initcall_t __deferred_initcall_start
[], __deferred_initcall_end
[];
932 /* call deferred init routines */
933 void __ref
do_deferred_initcalls(void)
936 static int already_run
=0;
939 printk("do_deferred_initcalls() has already run\n");
945 printk("Running do_deferred_initcalls()\n");
947 for(call
= __deferred_initcall_start
;
948 call
< __deferred_initcall_end
; call
++)
949 do_one_initcall(*call
);
951 flush_scheduled_work();
957 #ifdef CONFIG_SEC_GPIO_DVS
958 extern void gpio_dvs_check_initgpio(void);
961 static noinline
void __init
kernel_init_freeable(void);
963 static int __ref
kernel_init(void *unused
)
965 kernel_init_freeable();
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.
970 gpio_dvs_check_initgpio();
972 /* need to finish all async __init code before freeing the memory */
973 async_synchronize_full();
974 #ifndef CONFIG_DEFERRED_INITCALLS
978 system_state
= SYSTEM_RUNNING
;
979 numa_default_policy();
981 flush_delayed_fput();
983 if (ramdisk_execute_command
) {
984 if (!run_init_process(ramdisk_execute_command
))
986 pr_err("Failed to execute %s\n", ramdisk_execute_command
);
990 * We try each of these until one succeeds.
992 * The Bourne shell can be used instead of init if we are
993 * trying to recover a really broken machine.
995 if (execute_command
) {
996 if (!run_init_process(execute_command
))
998 pr_err("Failed to execute %s. Attempting defaults...\n",
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"))
1007 panic("No init found. Try passing init= option to kernel. "
1008 "See Linux Documentation/init.txt for guidance.");
1011 static noinline
void __init
kernel_init_freeable(void)
1014 * Wait until kthreadd is all set-up.
1016 wait_for_completion(&kthreadd_done
);
1018 /* Now the scheduler is fully set up and can do blocking allocations */
1019 gfp_allowed_mask
= __GFP_BITS_MASK
;
1022 * init can allocate pages on any node
1024 set_mems_allowed(node_states
[N_MEMORY
]);
1026 * init can run on any cpu.
1028 set_cpus_allowed_ptr(current
, cpu_all_mask
);
1030 cad_pid
= task_pid(current
);
1032 smp_prepare_cpus(setup_max_cpus
);
1034 do_pre_smp_initcalls();
1035 lockup_detector_init();
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)
1044 pr_err("Warning: unable to open an initial console.\n");
1049 * check if there is an early userspace init. If yes, let it do all
1053 if (!ramdisk_execute_command
)
1054 ramdisk_execute_command
= "/init";
1056 if (sys_access((const char __user
*) ramdisk_execute_command
, 0) != 0) {
1057 ramdisk_execute_command
= NULL
;
1058 prepare_namespace();
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..
1067 /* rootfs is available now, try loading default modules */
1068 load_default_modules();