main.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  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. #include <linux/types.h>
  12. #include <linux/module.h>
  13. #include <linux/proc_fs.h>
  14. #include <linux/kernel.h>
  15. #include <linux/syscalls.h>
  16. #include <linux/stackprotector.h>
  17. #include <linux/string.h>
  18. #include <linux/ctype.h>
  19. #include <linux/delay.h>
  20. #include <linux/ioport.h>
  21. #include <linux/init.h>
  22. #include <linux/initrd.h>
  23. #include <linux/bootmem.h>
  24. #include <linux/acpi.h>
  25. #include <linux/tty.h>
  26. #include <linux/percpu.h>
  27. #include <linux/kmod.h>
  28. #include <linux/vmalloc.h>
  29. #include <linux/kernel_stat.h>
  30. #include <linux/start_kernel.h>
  31. #include <linux/security.h>
  32. #include <linux/smp.h>
  33. #include <linux/profile.h>
  34. #include <linux/rcupdate.h>
  35. #include <linux/moduleparam.h>
  36. #include <linux/kallsyms.h>
  37. #include <linux/writeback.h>
  38. #include <linux/cpu.h>
  39. #include <linux/cpuset.h>
  40. #include <linux/cgroup.h>
  41. #include <linux/efi.h>
  42. #include <linux/tick.h>
  43. #include <linux/interrupt.h>
  44. #include <linux/taskstats_kern.h>
  45. #include <linux/delayacct.h>
  46. #include <linux/unistd.h>
  47. #include <linux/rmap.h>
  48. #include <linux/mempolicy.h>
  49. #include <linux/key.h>
  50. #include <linux/buffer_head.h>
  51. #include <linux/page_cgroup.h>
  52. #include <linux/debug_locks.h>
  53. #include <linux/debugobjects.h>
  54. #include <linux/lockdep.h>
  55. #include <linux/kmemleak.h>
  56. #include <linux/pid_namespace.h>
  57. #include <linux/device.h>
  58. #include <linux/kthread.h>
  59. #include <linux/sched.h>
  60. #include <linux/signal.h>
  61. #include <linux/idr.h>
  62. #include <linux/kgdb.h>
  63. #include <linux/ftrace.h>
  64. #include <linux/async.h>
  65. #include <linux/kmemcheck.h>
  66. #include <linux/sfi.h>
  67. #include <linux/shmem_fs.h>
  68. #include <linux/slab.h>
  69. #include <linux/perf_event.h>
  70. #ifdef CONFIG_TIMA_RKP_COHERENT_TT
  71. #include <linux/memblock.h>
  72. #endif
  73. #include <linux/random.h>
  74. #include <linux/sched_clock.h>
  75. #include <asm/io.h>
  76. #include <asm/bugs.h>
  77. #include <asm/setup.h>
  78. #include <asm/sections.h>
  79. #include <asm/cacheflush.h>
  80. #ifdef CONFIG_X86_LOCAL_APIC
  81. #include <asm/smp.h>
  82. #endif
  83. #ifdef CONFIG_SEC_GPIO_DVS
  84. #include <linux/secgpio_dvs.h>
  85. #endif
  86. static int kernel_init(void *);
  87. extern void init_IRQ(void);
  88. extern void fork_init(unsigned long);
  89. extern void mca_init(void);
  90. extern void sbus_init(void);
  91. extern void prio_tree_init(void);
  92. extern void radix_tree_init(void);
  93. #ifndef CONFIG_DEBUG_RODATA
  94. static inline void mark_rodata_ro(void) { }
  95. #endif
  96. #ifdef CONFIG_TC
  97. extern void tc_init(void);
  98. #endif
  99. #ifdef CONFIG_TIMA_RKP_30
  100. #define PGT_BIT_ARRAY_LENGTH 0x40000
  101. unsigned long pgt_bit_array[PGT_BIT_ARRAY_LENGTH];
  102. EXPORT_SYMBOL(pgt_bit_array);
  103. #endif
  104. /*
  105. * Debug helper: via this flag we know that we are in 'early bootup code'
  106. * where only the boot processor is running with IRQ disabled. This means
  107. * two things - IRQ must not be enabled before the flag is cleared and some
  108. * operations which are not allowed with IRQ disabled are allowed while the
  109. * flag is set.
  110. */
  111. bool early_boot_irqs_disabled __read_mostly;
  112. enum system_states system_state __read_mostly;
  113. EXPORT_SYMBOL(system_state);
  114. /*
  115. * Boot command-line arguments
  116. */
  117. #define MAX_INIT_ARGS CONFIG_INIT_ENV_ARG_LIMIT
  118. #define MAX_INIT_ENVS CONFIG_INIT_ENV_ARG_LIMIT
  119. extern void time_init(void);
  120. /* Default late time init is NULL. archs can override this later. */
  121. void (*__initdata late_time_init)(void);
  122. extern void softirq_init(void);
  123. /* Untouched command line saved by arch-specific code. */
  124. char __initdata boot_command_line[COMMAND_LINE_SIZE];
  125. /* Untouched saved command line (eg. for /proc) */
  126. char *saved_command_line;
  127. /* Command line for parameter parsing */
  128. static char *static_command_line;
  129. static char *execute_command;
  130. static char *ramdisk_execute_command;
  131. int boot_mode_lpm;
  132. int boot_mode_recovery;
  133. EXPORT_SYMBOL(boot_mode_recovery);
  134. /*
  135. * If set, this is an indication to the drivers that reset the underlying
  136. * device before going ahead with the initialization otherwise driver might
  137. * rely on the BIOS and skip the reset operation.
  138. *
  139. * This is useful if kernel is booting in an unreliable environment.
  140. * For ex. kdump situaiton where previous kernel has crashed, BIOS has been
  141. * skipped and devices will be in unknown state.
  142. */
  143. unsigned int reset_devices;
  144. EXPORT_SYMBOL(reset_devices);
  145. static int __init set_reset_devices(char *str)
  146. {
  147. reset_devices = 1;
  148. return 1;
  149. }
  150. __setup("reset_devices", set_reset_devices);
  151. static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
  152. const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
  153. static const char *panic_later, *panic_param;
  154. extern const struct obs_kernel_param __setup_start[], __setup_end[];
  155. static int __init obsolete_checksetup(char *line)
  156. {
  157. const struct obs_kernel_param *p;
  158. int had_early_param = 0;
  159. p = __setup_start;
  160. do {
  161. int n = strlen(p->str);
  162. if (parameqn(line, p->str, n)) {
  163. if (p->early) {
  164. /* Already done in parse_early_param?
  165. * (Needs exact match on param part).
  166. * Keep iterating, as we can have early
  167. * params and __setups of same names 8( */
  168. if (line[n] == '\0' || line[n] == '=')
  169. had_early_param = 1;
  170. } else if (!p->setup_func) {
  171. printk(KERN_WARNING "Parameter %s is obsolete,"
  172. " ignored\n", p->str);
  173. return 1;
  174. } else if (p->setup_func(line + n))
  175. return 1;
  176. }
  177. p++;
  178. } while (p < __setup_end);
  179. return had_early_param;
  180. }
  181. /*
  182. * This should be approx 2 Bo*oMips to start (note initial shift), and will
  183. * still work even if initially too large, it will just take slightly longer
  184. */
  185. unsigned long loops_per_jiffy = (1<<12);
  186. EXPORT_SYMBOL(loops_per_jiffy);
  187. static int __init debug_kernel(char *str)
  188. {
  189. console_loglevel = 10;
  190. return 0;
  191. }
  192. static int __init quiet_kernel(char *str)
  193. {
  194. console_loglevel = 4;
  195. return 0;
  196. }
  197. early_param("debug", debug_kernel);
  198. early_param("quiet", quiet_kernel);
  199. static int __init loglevel(char *str)
  200. {
  201. int newlevel;
  202. /*
  203. * Only update loglevel value when a correct setting was passed,
  204. * to prevent blind crashes (when loglevel being set to 0) that
  205. * are quite hard to debug
  206. */
  207. if (get_option(&str, &newlevel)) {
  208. console_loglevel = newlevel;
  209. return 0;
  210. }
  211. return -EINVAL;
  212. }
  213. early_param("loglevel", loglevel);
  214. /*androidboot.uart_debug */
  215. int jig_boot_clk_limit;
  216. int console_jig_stat;
  217. static int __init jigStatus_phone(char *str)
  218. {
  219. int jig_val;
  220. if (get_option(&str, &jig_val)) {
  221. jig_boot_clk_limit |= jig_val;
  222. console_jig_stat |= jig_val;
  223. return 0;
  224. }
  225. return -EINVAL;
  226. }
  227. early_param("uart_dbg", jigStatus_phone);
  228. static int __init jigStatus_tablet(char *str)
  229. {
  230. int jig_val;
  231. if (get_option(&str, &jig_val)) {
  232. jig_boot_clk_limit |= jig_val;
  233. console_jig_stat |= jig_val;
  234. return 0;
  235. }
  236. return -EINVAL;
  237. }
  238. early_param("androidboot.uart_debug", jigStatus_tablet);
  239. /* Change NUL term back to "=", to make "param" the whole string. */
  240. static int __init repair_env_string(char *param, char *val)
  241. {
  242. if (val) {
  243. /* param=val or param="val"? */
  244. if (val == param+strlen(param)+1)
  245. val[-1] = '=';
  246. else if (val == param+strlen(param)+2) {
  247. val[-2] = '=';
  248. memmove(val-1, val, strlen(val)+1);
  249. val--;
  250. } else
  251. BUG();
  252. }
  253. return 0;
  254. }
  255. /*
  256. * Unknown boot options get handed to init, unless they look like
  257. * unused parameters (modprobe will find them in /proc/cmdline).
  258. */
  259. static int __init unknown_bootoption(char *param, char *val)
  260. {
  261. repair_env_string(param, val);
  262. /* Handle obsolete-style parameters */
  263. if (obsolete_checksetup(param))
  264. return 0;
  265. /* Unused module parameter. */
  266. if (strchr(param, '.') && (!val || strchr(param, '.') < val))
  267. return 0;
  268. if (panic_later)
  269. return 0;
  270. if (val) {
  271. /* Environment option */
  272. unsigned int i;
  273. for (i = 0; envp_init[i]; i++) {
  274. if (i == MAX_INIT_ENVS) {
  275. panic_later = "Too many boot env vars at `%s'";
  276. panic_param = param;
  277. }
  278. if (!strncmp(param, envp_init[i], val - param))
  279. break;
  280. }
  281. envp_init[i] = param;
  282. } else {
  283. /* Command line option */
  284. unsigned int i;
  285. for (i = 0; argv_init[i]; i++) {
  286. if (i == MAX_INIT_ARGS) {
  287. panic_later = "Too many boot init vars at `%s'";
  288. panic_param = param;
  289. }
  290. }
  291. argv_init[i] = param;
  292. }
  293. return 0;
  294. }
  295. static int __init init_setup(char *str)
  296. {
  297. unsigned int i;
  298. execute_command = str;
  299. /*
  300. * In case LILO is going to boot us with default command line,
  301. * it prepends "auto" before the whole cmdline which makes
  302. * the shell think it should execute a script with such name.
  303. * So we ignore all arguments entered _before_ init=... [MJ]
  304. */
  305. for (i = 1; i < MAX_INIT_ARGS; i++)
  306. argv_init[i] = NULL;
  307. return 1;
  308. }
  309. __setup("init=", init_setup);
  310. static int __init rdinit_setup(char *str)
  311. {
  312. unsigned int i;
  313. ramdisk_execute_command = str;
  314. /* See "auto" comment in init_setup */
  315. for (i = 1; i < MAX_INIT_ARGS; i++)
  316. argv_init[i] = NULL;
  317. return 1;
  318. }
  319. __setup("rdinit=", rdinit_setup);
  320. #ifndef CONFIG_SMP
  321. static const unsigned int setup_max_cpus = NR_CPUS;
  322. #ifdef CONFIG_X86_LOCAL_APIC
  323. static void __init smp_init(void)
  324. {
  325. APIC_init_uniprocessor();
  326. }
  327. #else
  328. #define smp_init() do { } while (0)
  329. #endif
  330. static inline void setup_nr_cpu_ids(void) { }
  331. static inline void smp_prepare_cpus(unsigned int maxcpus) { }
  332. #endif
  333. /*
  334. * We need to store the untouched command line for future reference.
  335. * We also need to store the touched command line since the parameter
  336. * parsing is performed in place, and we should allow a component to
  337. * store reference of name/value for future reference.
  338. */
  339. static void __init setup_command_line(char *command_line)
  340. {
  341. saved_command_line = alloc_bootmem(strlen (boot_command_line)+1);
  342. static_command_line = alloc_bootmem(strlen (command_line)+1);
  343. strcpy (saved_command_line, boot_command_line);
  344. strcpy (static_command_line, command_line);
  345. }
  346. #ifdef CONFIG_TIMA_RKP
  347. /* Block of Code for RKP initialization */
  348. static noinline void rkp_init(void)
  349. {
  350. #ifdef CONFIG_TIMA_RKP_COHERENT_TT
  351. struct memblock_type *type = (struct memblock_type*)(&memblock.memory);
  352. #endif /*CONFIG_TIMA_RKP_COHERENT_TT*/
  353. #ifdef CONFIG_TIMA_RKP_RO_CRED
  354. /* Code for initializing Credential Protection */
  355. tima_send_cmd5((unsigned long)__rkp_ro_start, (unsigned long)__rkp_ro_end,
  356. sizeof(struct cred), offsetof(struct task_struct, cred),
  357. offsetof(struct task_struct, active_mm), 0x40);
  358. tima_send_cmd5(offsetof(struct cred, uid), offsetof(struct cred, euid),
  359. offsetof(struct cred, bp_pgd), offsetof(struct cred, bp_task),
  360. offsetof(struct cred, exec_depth), 0x41);
  361. tima_send_cmd4(offsetof(struct cred,security),offsetof(struct task_struct,pid),
  362. offsetof(struct task_struct,real_parent),offsetof(struct task_struct,comm),0x42);
  363. printk(KERN_ERR"RKP CRED INIT %x\n", sizeof(struct cred));
  364. #endif /*CONFIG_TIMA_RKP_RO_CRED*/
  365. #ifdef CONFIG_TIMA_RKP
  366. #ifdef CONFIG_TIMA_RKP_30
  367. #ifdef CONFIG_TIMA_RKP_COHERENT_TT
  368. tima_send_cmd2(type->cnt, __pa(type->regions), 0x04);
  369. #endif /*CONFIG_TIMA_RKP_COHERENT_TT*/
  370. tima_send_cmd5((unsigned long)_stext, (unsigned long)init_mm.pgd, (unsigned long)__init_begin, (unsigned long)__init_end,(unsigned long)__pa(pgt_bit_array),0x0c);
  371. tima_send_cmd3((unsigned long)__pa((unsigned long)_sdata), ((unsigned long)__pa((unsigned long)_edata)-(unsigned long)__pa((unsigned long)_sdata)), 1, 0x26);
  372. tima_send_cmd((unsigned long)__pa((unsigned long)_text),0x28);
  373. #else
  374. tima_send_cmd4((unsigned long)_stext, (unsigned long)init_mm.pgd, (unsigned long)__init_begin, (unsigned long)__init_end, 0x0c);
  375. #endif /* CONFIG_TIMA_RKP_30 */
  376. #endif /*CONFIG_TIMA_RKP*/
  377. }
  378. #endif /*CONFIG_TIMA_RKP*/
  379. /*
  380. * We need to finalize in a non-__init function or else race conditions
  381. * between the root thread and the init thread may cause start_kernel to
  382. * be reaped by free_initmem before the root thread has proceeded to
  383. * cpu_idle.
  384. *
  385. * gcc-3.4 accidentally inlines this function, so use noinline.
  386. */
  387. static __initdata DECLARE_COMPLETION(kthreadd_done);
  388. static noinline void __init_refok rest_init(void)
  389. {
  390. int pid;
  391. const struct sched_param param = { .sched_priority = 1 };
  392. #ifdef CONFIG_TIMA_RKP
  393. rkp_init();
  394. #endif
  395. rcu_scheduler_starting();
  396. /*
  397. * We need to spawn init first so that it obtains pid 1, however
  398. * the init task will end up wanting to create kthreads, which, if
  399. * we schedule it before we create kthreadd, will OOPS.
  400. */
  401. kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND);
  402. numa_default_policy();
  403. pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);
  404. rcu_read_lock();
  405. kthreadd_task = find_task_by_pid_ns(pid, &init_pid_ns);
  406. rcu_read_unlock();
  407. sched_setscheduler_nocheck(kthreadd_task, SCHED_FIFO, &param);
  408. complete(&kthreadd_done);
  409. /*
  410. * The boot idle thread must execute schedule()
  411. * at least once to get things moving:
  412. */
  413. init_idle_bootup_task(current);
  414. schedule_preempt_disabled();
  415. /* Call into cpu_idle with preempt disabled */
  416. cpu_idle();
  417. }
  418. /* Check for early params. */
  419. static int __init do_early_param(char *param, char *val)
  420. {
  421. const struct obs_kernel_param *p;
  422. for (p = __setup_start; p < __setup_end; p++) {
  423. if ((p->early && parameq(param, p->str)) ||
  424. (strcmp(param, "console") == 0 &&
  425. strcmp(p->str, "earlycon") == 0)
  426. ) {
  427. if (p->setup_func(val) != 0)
  428. printk(KERN_WARNING
  429. "Malformed early option '%s'\n", param);
  430. }
  431. }
  432. /* We accept everything at this stage. */
  433. /* Check LPM(Power Off Charging) Mode */
  434. if ((strncmp(param, "androidboot.mode", 17) == 0)) {
  435. if (strncmp(val, "charger", 7) == 0) {
  436. pr_info("LPM Boot Mode \n");
  437. boot_mode_lpm = 1;
  438. }
  439. }
  440. /* Check Recovery Mode , 1: recovery mode, 2: factory reset mode(recovery)
  441. otherwise normal mode*/
  442. if ((strncmp(param, "androidboot.boot_recovery", 26) == 0)) {
  443. if ((strncmp(val, "1", 1) == 0)||(strncmp(val, "2", 1) == 0)) {
  444. pr_info("Recovery Boot Mode \n");
  445. boot_mode_recovery = 1;
  446. }
  447. }
  448. return 0;
  449. }
  450. void __init parse_early_options(char *cmdline)
  451. {
  452. parse_args("early options", cmdline, NULL, 0, 0, 0, do_early_param);
  453. }
  454. /* Arch code calls this early on, or if not, just before other parsing. */
  455. void __init parse_early_param(void)
  456. {
  457. static __initdata int done = 0;
  458. static __initdata char tmp_cmdline[COMMAND_LINE_SIZE];
  459. if (done)
  460. return;
  461. /* All fall through to do_early_param. */
  462. strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
  463. parse_early_options(tmp_cmdline);
  464. done = 1;
  465. }
  466. /*
  467. * Activate the first processor.
  468. */
  469. static void __init boot_cpu_init(void)
  470. {
  471. int cpu = smp_processor_id();
  472. /* Mark the boot cpu "present", "online" etc for SMP and UP case */
  473. set_cpu_online(cpu, true);
  474. set_cpu_active(cpu, true);
  475. set_cpu_present(cpu, true);
  476. set_cpu_possible(cpu, true);
  477. }
  478. void __init __weak smp_setup_processor_id(void)
  479. {
  480. }
  481. void __init __weak thread_info_cache_init(void)
  482. {
  483. }
  484. /*
  485. * Set up kernel memory allocators
  486. */
  487. static void __init mm_init(void)
  488. {
  489. /*
  490. * page_cgroup requires contiguous pages,
  491. * bigger than MAX_ORDER unless SPARSEMEM.
  492. */
  493. page_cgroup_init_flatmem();
  494. mem_init();
  495. kmem_cache_init();
  496. percpu_init_late();
  497. pgtable_cache_init();
  498. vmalloc_init();
  499. }
  500. #ifdef CONFIG_CRYPTO_FIPS_OLD_INTEGRITY_CHECK
  501. /* change@ksingh.sra-dallas - in kernel 3.4 and +
  502. * the mmu clears the unused/unreserved memory with default RAM initial sticky
  503. * bit data.
  504. * Hence to preseve the copy of zImage in the unmarked area, the Copied zImage
  505. * memory range has to be marked reserved.
  506. */
  507. #define SHA256_DIGEST_SIZE 32
  508. // this is the size of memory area that is marked as reserved
  509. long integrity_mem_reservoir = 0;
  510. // internal API to mark zImage copy memory area as reserved
  511. static void __init integrity_mem_reserve(void) {
  512. int result = 0;
  513. long len = 0;
  514. u8* zBuffer = 0;
  515. zBuffer = (u8*)phys_to_virt((unsigned long)CONFIG_CRYPTO_FIPS_INTEG_COPY_ADDRESS);
  516. if (*((u32 *) &zBuffer[36]) != 0x016F2818) {
  517. printk(KERN_ERR "FIPS main.c: invalid zImage magic number.");
  518. return;
  519. }
  520. if (*(u32 *) &zBuffer[44] <= *(u32 *) &zBuffer[40]) {
  521. printk(KERN_ERR "FIPS main.c: invalid zImage calculated len");
  522. return;
  523. }
  524. len = *(u32 *) &zBuffer[44] - *(u32 *) &zBuffer[40];
  525. printk(KERN_NOTICE "FIPS Actual zImage len = %ld\n", len);
  526. integrity_mem_reservoir = len + SHA256_DIGEST_SIZE;
  527. result = reserve_bootmem((unsigned long)CONFIG_CRYPTO_FIPS_INTEG_COPY_ADDRESS, integrity_mem_reservoir, 1);
  528. if(result != 0) {
  529. integrity_mem_reservoir = 0;
  530. }
  531. printk(KERN_NOTICE "FIPS integrity_mem_reservoir = %ld\n", integrity_mem_reservoir);
  532. }
  533. // change@ksingh.sra-dallas - end
  534. #endif // CONFIG_CRYPTO_FIPS_OLD_INTEGRITY_CHECK
  535. asmlinkage void __init start_kernel(void)
  536. {
  537. char * command_line;
  538. extern const struct kernel_param __start___param[], __stop___param[];
  539. /*
  540. * Need to run as early as possible, to initialize the
  541. * lockdep hash:
  542. */
  543. lockdep_init();
  544. smp_setup_processor_id();
  545. debug_objects_early_init();
  546. cgroup_init_early();
  547. local_irq_disable();
  548. early_boot_irqs_disabled = true;
  549. /*
  550. * Interrupts are still disabled. Do necessary setups, then
  551. * enable them
  552. */
  553. tick_init();
  554. boot_cpu_init();
  555. page_address_init();
  556. printk(KERN_NOTICE "%s", linux_banner);
  557. setup_arch(&command_line);
  558. /*
  559. * Set up the the initial canary ASAP:
  560. */
  561. boot_init_stack_canary();
  562. mm_init_owner(&init_mm, &init_task);
  563. mm_init_cpumask(&init_mm);
  564. setup_command_line(command_line);
  565. setup_nr_cpu_ids();
  566. setup_per_cpu_areas();
  567. smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
  568. build_all_zonelists(NULL);
  569. page_alloc_init();
  570. printk(KERN_NOTICE "Kernel command line: %s\n", boot_command_line);
  571. parse_early_param();
  572. parse_args("Booting kernel", static_command_line, __start___param,
  573. __stop___param - __start___param,
  574. -1, -1, &unknown_bootoption);
  575. jump_label_init();
  576. #ifdef CONFIG_CRYPTO_FIPS_OLD_INTEGRITY_CHECK
  577. /* change@ksingh.sra-dallas
  578. * marks the zImage copy area as reserve before mmu can clear it
  579. */
  580. integrity_mem_reserve();
  581. #endif // CONFIG_CRYPTO_FIPS_OLD_INTEGRITY_CHECK
  582. /*
  583. * These use large bootmem allocations and must precede
  584. * kmem_cache_init()
  585. */
  586. setup_log_buf(0);
  587. pidhash_init();
  588. vfs_caches_init_early();
  589. sort_main_extable();
  590. trap_init();
  591. mm_init();
  592. /*
  593. * Set up the scheduler prior starting any interrupts (such as the
  594. * timer interrupt). Full topology setup happens at smp_init()
  595. * time - but meanwhile we still have a functioning scheduler.
  596. */
  597. sched_init();
  598. /*
  599. * Disable preemption - early bootup scheduling is extremely
  600. * fragile until we cpu_idle() for the first time.
  601. */
  602. preempt_disable();
  603. if (!irqs_disabled()) {
  604. printk(KERN_WARNING "start_kernel(): bug: interrupts were "
  605. "enabled *very* early, fixing it\n");
  606. local_irq_disable();
  607. }
  608. idr_init_cache();
  609. perf_event_init();
  610. rcu_init();
  611. radix_tree_init();
  612. /* init some links before init_ISA_irqs() */
  613. early_irq_init();
  614. init_IRQ();
  615. prio_tree_init();
  616. init_timers();
  617. hrtimers_init();
  618. softirq_init();
  619. timekeeping_init();
  620. time_init();
  621. sched_clock_postinit();
  622. profile_init();
  623. call_function_init();
  624. if (!irqs_disabled())
  625. printk(KERN_CRIT "start_kernel(): bug: interrupts were "
  626. "enabled early\n");
  627. early_boot_irqs_disabled = false;
  628. local_irq_enable();
  629. kmem_cache_init_late();
  630. /*
  631. * HACK ALERT! This is early. We're enabling the console before
  632. * we've done PCI setups etc, and console_init() must be aware of
  633. * this. But we do want output early, in case something goes wrong.
  634. */
  635. console_init();
  636. if (panic_later)
  637. panic(panic_later, panic_param);
  638. lockdep_info();
  639. /*
  640. * Need to run this when irqs are enabled, because it wants
  641. * to self-test [hard/soft]-irqs on/off lock inversion bugs
  642. * too:
  643. */
  644. locking_selftest();
  645. #ifdef CONFIG_BLK_DEV_INITRD
  646. if (initrd_start && !initrd_below_start_ok &&
  647. page_to_pfn(virt_to_page((void *)initrd_start)) < min_low_pfn) {
  648. printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
  649. "disabling it.\n",
  650. page_to_pfn(virt_to_page((void *)initrd_start)),
  651. min_low_pfn);
  652. initrd_start = 0;
  653. }
  654. #endif
  655. page_cgroup_init();
  656. debug_objects_mem_init();
  657. kmemleak_init();
  658. setup_per_cpu_pageset();
  659. numa_policy_init();
  660. if (late_time_init)
  661. late_time_init();
  662. sched_clock_init();
  663. calibrate_delay();
  664. pidmap_init();
  665. anon_vma_init();
  666. #ifdef CONFIG_X86
  667. if (efi_enabled(EFI_RUNTIME_SERVICES))
  668. efi_enter_virtual_mode();
  669. #endif
  670. #ifdef CONFIG_X86_ESPFIX64
  671. /* Should be run before the first non-init thread is created */
  672. init_espfix_bsp();
  673. #endif
  674. thread_info_cache_init();
  675. cred_init();
  676. fork_init(totalram_pages);
  677. proc_caches_init();
  678. buffer_init();
  679. key_init();
  680. security_init();
  681. dbg_late_init();
  682. vfs_caches_init(totalram_pages);
  683. signals_init();
  684. /* rootfs populating might need page-writeback */
  685. page_writeback_init();
  686. #ifdef CONFIG_PROC_FS
  687. proc_root_init();
  688. #endif
  689. cgroup_init();
  690. cpuset_init();
  691. taskstats_init_early();
  692. delayacct_init();
  693. check_bugs();
  694. acpi_early_init(); /* before LAPIC and SMP init */
  695. sfi_init_late();
  696. if (efi_enabled(EFI_RUNTIME_SERVICES))
  697. efi_free_boot_services();
  698. ftrace_init();
  699. /* Do the rest non-__init'ed, we're now alive */
  700. rest_init();
  701. }
  702. /* Call all constructor functions linked into the kernel. */
  703. static void __init do_ctors(void)
  704. {
  705. #ifdef CONFIG_CONSTRUCTORS
  706. ctor_fn_t *fn = (ctor_fn_t *) __ctors_start;
  707. for (; fn < (ctor_fn_t *) __ctors_end; fn++)
  708. (*fn)();
  709. #endif
  710. }
  711. bool initcall_debug;
  712. core_param(initcall_debug, initcall_debug, bool, 0644);
  713. static char msgbuf[64];
  714. static int __init_or_module do_one_initcall_debug(initcall_t fn)
  715. {
  716. ktime_t calltime, delta, rettime;
  717. unsigned long long duration;
  718. int ret;
  719. printk(KERN_DEBUG "calling %pF @ %i\n", fn, task_pid_nr(current));
  720. calltime = ktime_get();
  721. ret = fn();
  722. rettime = ktime_get();
  723. delta = ktime_sub(rettime, calltime);
  724. duration = (unsigned long long) ktime_to_ns(delta) >> 10;
  725. printk(KERN_DEBUG "initcall %pF returned %d after %lld usecs\n", fn,
  726. ret, duration);
  727. return ret;
  728. }
  729. int __init_or_module do_one_initcall(initcall_t fn)
  730. {
  731. int count = preempt_count();
  732. int ret;
  733. if (initcall_debug)
  734. ret = do_one_initcall_debug(fn);
  735. else
  736. ret = fn();
  737. msgbuf[0] = 0;
  738. if (ret && ret != -ENODEV && initcall_debug)
  739. sprintf(msgbuf, "error code %d ", ret);
  740. if (preempt_count() != count) {
  741. strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
  742. preempt_count() = count;
  743. }
  744. if (irqs_disabled()) {
  745. strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
  746. local_irq_enable();
  747. }
  748. if (msgbuf[0]) {
  749. printk("initcall %pF returned with %s\n", fn, msgbuf);
  750. }
  751. return ret;
  752. }
  753. extern initcall_t __initcall_start[];
  754. extern initcall_t __initcall0_start[];
  755. extern initcall_t __initcall1_start[];
  756. extern initcall_t __initcall2_start[];
  757. extern initcall_t __initcall3_start[];
  758. extern initcall_t __initcall4_start[];
  759. extern initcall_t __initcall5_start[];
  760. extern initcall_t __initcall6_start[];
  761. extern initcall_t __initcall7_start[];
  762. extern initcall_t __initcall_end[];
  763. static initcall_t *initcall_levels[] __initdata = {
  764. __initcall0_start,
  765. __initcall1_start,
  766. __initcall2_start,
  767. __initcall3_start,
  768. __initcall4_start,
  769. __initcall5_start,
  770. __initcall6_start,
  771. __initcall7_start,
  772. __initcall_end,
  773. };
  774. static char *initcall_level_names[] __initdata = {
  775. "early parameters",
  776. "core parameters",
  777. "postcore parameters",
  778. "arch parameters",
  779. "subsys parameters",
  780. "fs parameters",
  781. "device parameters",
  782. "late parameters",
  783. };
  784. static void __init do_initcall_level(int level)
  785. {
  786. extern const struct kernel_param __start___param[], __stop___param[];
  787. initcall_t *fn;
  788. strcpy(static_command_line, saved_command_line);
  789. parse_args(initcall_level_names[level],
  790. static_command_line, __start___param,
  791. __stop___param - __start___param,
  792. level, level,
  793. repair_env_string);
  794. for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
  795. do_one_initcall(*fn);
  796. }
  797. static void __init do_initcalls(void)
  798. {
  799. int level;
  800. for (level = 0; level < ARRAY_SIZE(initcall_levels) - 1; level++)
  801. do_initcall_level(level);
  802. }
  803. /*
  804. * Ok, the machine is now initialized. None of the devices
  805. * have been touched yet, but the CPU subsystem is up and
  806. * running, and memory and process management works.
  807. *
  808. * Now we can finally start doing some real work..
  809. */
  810. static void __init do_basic_setup(void)
  811. {
  812. cpuset_init_smp();
  813. usermodehelper_init();
  814. shmem_init();
  815. driver_init();
  816. init_irq_proc();
  817. do_ctors();
  818. usermodehelper_enable();
  819. do_initcalls();
  820. random_int_secret_init();
  821. }
  822. static void __init do_pre_smp_initcalls(void)
  823. {
  824. initcall_t *fn;
  825. for (fn = __initcall_start; fn < __initcall0_start; fn++)
  826. do_one_initcall(*fn);
  827. }
  828. static void run_init_process(const char *init_filename)
  829. {
  830. argv_init[0] = init_filename;
  831. kernel_execve(init_filename, argv_init, envp_init);
  832. }
  833. #ifdef CONFIG_DEFERRED_INITCALLS
  834. extern initcall_t __deferred_initcall_start[], __deferred_initcall_end[];
  835. /* call deferred init routines */
  836. void __ref do_deferred_initcalls(void)
  837. {
  838. initcall_t *call;
  839. static int already_run=0;
  840. if (already_run) {
  841. printk("do_deferred_initcalls() has already run\n");
  842. return;
  843. }
  844. already_run=1;
  845. printk("Running do_deferred_initcalls()\n");
  846. for(call = __deferred_initcall_start;
  847. call < __deferred_initcall_end; call++)
  848. do_one_initcall(*call);
  849. flush_scheduled_work();
  850. free_initmem();
  851. }
  852. #endif
  853. /* This is a non __init function. Force it to be noinline otherwise gcc
  854. * makes it inline to init() and it becomes part of init.text section
  855. */
  856. static noinline int init_post(void)
  857. {
  858. #ifdef CONFIG_SEC_GPIO_DVS
  859. /************************ Caution !!! ****************************/
  860. /* This function must be located in appropriate INIT position
  861. * in accordance with the specification of each BB vendor.
  862. */
  863. /************************ Caution !!! ****************************/
  864. gpio_dvs_check_initgpio();
  865. #endif
  866. /* need to finish all async __init code before freeing the memory */
  867. async_synchronize_full();
  868. #ifndef CONFIG_DEFERRED_INITCALLS
  869. free_initmem();
  870. #endif
  871. mark_rodata_ro();
  872. system_state = SYSTEM_RUNNING;
  873. numa_default_policy();
  874. current->signal->flags |= SIGNAL_UNKILLABLE;
  875. if (ramdisk_execute_command) {
  876. run_init_process(ramdisk_execute_command);
  877. printk(KERN_WARNING "Failed to execute %s\n",
  878. ramdisk_execute_command);
  879. }
  880. /*
  881. * We try each of these until one succeeds.
  882. *
  883. * The Bourne shell can be used instead of init if we are
  884. * trying to recover a really broken machine.
  885. */
  886. if (execute_command) {
  887. run_init_process(execute_command);
  888. printk(KERN_WARNING "Failed to execute %s. Attempting "
  889. "defaults...\n", execute_command);
  890. }
  891. run_init_process("/sbin/init");
  892. run_init_process("/etc/init");
  893. run_init_process("/bin/init");
  894. run_init_process("/bin/sh");
  895. panic("No init found. Try passing init= option to kernel. "
  896. "See Linux Documentation/init.txt for guidance.");
  897. }
  898. static int __init kernel_init(void * unused)
  899. {
  900. /*
  901. * Wait until kthreadd is all set-up.
  902. */
  903. wait_for_completion(&kthreadd_done);
  904. /* Now the scheduler is fully set up and can do blocking allocations */
  905. gfp_allowed_mask = __GFP_BITS_MASK;
  906. /*
  907. * init can allocate pages on any node
  908. */
  909. set_mems_allowed(node_states[N_HIGH_MEMORY]);
  910. /*
  911. * init can run on any cpu.
  912. */
  913. set_cpus_allowed_ptr(current, cpu_all_mask);
  914. cad_pid = task_pid(current);
  915. smp_prepare_cpus(setup_max_cpus);
  916. do_pre_smp_initcalls();
  917. lockup_detector_init();
  918. smp_init();
  919. sched_init_smp();
  920. do_basic_setup();
  921. /* Open the /dev/console on the rootfs, this should never fail */
  922. if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
  923. printk(KERN_WARNING "Warning: unable to open an initial console.\n");
  924. (void) sys_dup(0);
  925. (void) sys_dup(0);
  926. /*
  927. * check if there is an early userspace init. If yes, let it do all
  928. * the work
  929. */
  930. if (!ramdisk_execute_command)
  931. ramdisk_execute_command = "/init";
  932. if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
  933. ramdisk_execute_command = NULL;
  934. prepare_namespace();
  935. }
  936. /*
  937. * Ok, we have completed the initial bootup, and
  938. * we're essentially up and running. Get rid of the
  939. * initmem segments and start the user-mode stuff..
  940. */
  941. init_post();
  942. return 0;
  943. }