main.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100
  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, NULL);
  569. page_alloc_init();
  570. printk(KERN_NOTICE "Kernel command line: %s\n", boot_command_line);
  571. /* parameters may set static keys */
  572. jump_label_init();
  573. parse_early_param();
  574. parse_args("Booting kernel", static_command_line, __start___param,
  575. __stop___param - __start___param,
  576. -1, -1, &unknown_bootoption);
  577. #ifdef CONFIG_CRYPTO_FIPS_OLD_INTEGRITY_CHECK
  578. /* change@ksingh.sra-dallas
  579. * marks the zImage copy area as reserve before mmu can clear it
  580. */
  581. integrity_mem_reserve();
  582. #endif // CONFIG_CRYPTO_FIPS_OLD_INTEGRITY_CHECK
  583. /*
  584. * These use large bootmem allocations and must precede
  585. * kmem_cache_init()
  586. */
  587. setup_log_buf(0);
  588. pidhash_init();
  589. vfs_caches_init_early();
  590. sort_main_extable();
  591. trap_init();
  592. mm_init();
  593. /*
  594. * Set up the scheduler prior starting any interrupts (such as the
  595. * timer interrupt). Full topology setup happens at smp_init()
  596. * time - but meanwhile we still have a functioning scheduler.
  597. */
  598. sched_init();
  599. /*
  600. * Disable preemption - early bootup scheduling is extremely
  601. * fragile until we cpu_idle() for the first time.
  602. */
  603. preempt_disable();
  604. if (!irqs_disabled()) {
  605. printk(KERN_WARNING "start_kernel(): bug: interrupts were "
  606. "enabled *very* early, fixing it\n");
  607. local_irq_disable();
  608. }
  609. idr_init_cache();
  610. perf_event_init();
  611. rcu_init();
  612. radix_tree_init();
  613. /* init some links before init_ISA_irqs() */
  614. early_irq_init();
  615. init_IRQ();
  616. prio_tree_init();
  617. init_timers();
  618. hrtimers_init();
  619. softirq_init();
  620. timekeeping_init();
  621. time_init();
  622. sched_clock_postinit();
  623. profile_init();
  624. call_function_init();
  625. if (!irqs_disabled())
  626. printk(KERN_CRIT "start_kernel(): bug: interrupts were "
  627. "enabled early\n");
  628. early_boot_irqs_disabled = false;
  629. local_irq_enable();
  630. kmem_cache_init_late();
  631. /*
  632. * HACK ALERT! This is early. We're enabling the console before
  633. * we've done PCI setups etc, and console_init() must be aware of
  634. * this. But we do want output early, in case something goes wrong.
  635. */
  636. console_init();
  637. if (panic_later)
  638. panic(panic_later, panic_param);
  639. lockdep_info();
  640. /*
  641. * Need to run this when irqs are enabled, because it wants
  642. * to self-test [hard/soft]-irqs on/off lock inversion bugs
  643. * too:
  644. */
  645. locking_selftest();
  646. #ifdef CONFIG_BLK_DEV_INITRD
  647. if (initrd_start && !initrd_below_start_ok &&
  648. page_to_pfn(virt_to_page((void *)initrd_start)) < min_low_pfn) {
  649. printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
  650. "disabling it.\n",
  651. page_to_pfn(virt_to_page((void *)initrd_start)),
  652. min_low_pfn);
  653. initrd_start = 0;
  654. }
  655. #endif
  656. page_cgroup_init();
  657. debug_objects_mem_init();
  658. kmemleak_init();
  659. setup_per_cpu_pageset();
  660. numa_policy_init();
  661. if (late_time_init)
  662. late_time_init();
  663. sched_clock_init();
  664. calibrate_delay();
  665. pidmap_init();
  666. anon_vma_init();
  667. #ifdef CONFIG_X86
  668. if (efi_enabled(EFI_RUNTIME_SERVICES))
  669. efi_enter_virtual_mode();
  670. #endif
  671. #ifdef CONFIG_X86_ESPFIX64
  672. /* Should be run before the first non-init thread is created */
  673. init_espfix_bsp();
  674. #endif
  675. thread_info_cache_init();
  676. cred_init();
  677. fork_init(totalram_pages);
  678. proc_caches_init();
  679. buffer_init();
  680. key_init();
  681. security_init();
  682. dbg_late_init();
  683. vfs_caches_init(totalram_pages);
  684. signals_init();
  685. /* rootfs populating might need page-writeback */
  686. page_writeback_init();
  687. #ifdef CONFIG_PROC_FS
  688. proc_root_init();
  689. #endif
  690. cgroup_init();
  691. cpuset_init();
  692. taskstats_init_early();
  693. delayacct_init();
  694. check_bugs();
  695. acpi_early_init(); /* before LAPIC and SMP init */
  696. sfi_init_late();
  697. if (efi_enabled(EFI_RUNTIME_SERVICES))
  698. efi_free_boot_services();
  699. ftrace_init();
  700. /* Do the rest non-__init'ed, we're now alive */
  701. rest_init();
  702. }
  703. /* Call all constructor functions linked into the kernel. */
  704. static void __init do_ctors(void)
  705. {
  706. #ifdef CONFIG_CONSTRUCTORS
  707. ctor_fn_t *fn = (ctor_fn_t *) __ctors_start;
  708. for (; fn < (ctor_fn_t *) __ctors_end; fn++)
  709. (*fn)();
  710. #endif
  711. }
  712. bool initcall_debug;
  713. core_param(initcall_debug, initcall_debug, bool, 0644);
  714. static char msgbuf[64];
  715. static int __init_or_module do_one_initcall_debug(initcall_t fn)
  716. {
  717. ktime_t calltime, delta, rettime;
  718. unsigned long long duration;
  719. int ret;
  720. printk(KERN_DEBUG "calling %pF @ %i\n", fn, task_pid_nr(current));
  721. calltime = ktime_get();
  722. ret = fn();
  723. rettime = ktime_get();
  724. delta = ktime_sub(rettime, calltime);
  725. duration = (unsigned long long) ktime_to_ns(delta) >> 10;
  726. printk(KERN_DEBUG "initcall %pF returned %d after %lld usecs\n", fn,
  727. ret, duration);
  728. return ret;
  729. }
  730. int __init_or_module do_one_initcall(initcall_t fn)
  731. {
  732. int count = preempt_count();
  733. int ret;
  734. if (initcall_debug)
  735. ret = do_one_initcall_debug(fn);
  736. else
  737. ret = fn();
  738. msgbuf[0] = 0;
  739. if (ret && ret != -ENODEV && initcall_debug)
  740. sprintf(msgbuf, "error code %d ", ret);
  741. if (preempt_count() != count) {
  742. strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
  743. preempt_count() = count;
  744. }
  745. if (irqs_disabled()) {
  746. strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
  747. local_irq_enable();
  748. }
  749. if (msgbuf[0]) {
  750. printk("initcall %pF returned with %s\n", fn, msgbuf);
  751. }
  752. return ret;
  753. }
  754. extern initcall_t __initcall_start[];
  755. extern initcall_t __initcall0_start[];
  756. extern initcall_t __initcall1_start[];
  757. extern initcall_t __initcall2_start[];
  758. extern initcall_t __initcall3_start[];
  759. extern initcall_t __initcall4_start[];
  760. extern initcall_t __initcall5_start[];
  761. extern initcall_t __initcall6_start[];
  762. extern initcall_t __initcall7_start[];
  763. extern initcall_t __initcall_end[];
  764. static initcall_t *initcall_levels[] __initdata = {
  765. __initcall0_start,
  766. __initcall1_start,
  767. __initcall2_start,
  768. __initcall3_start,
  769. __initcall4_start,
  770. __initcall5_start,
  771. __initcall6_start,
  772. __initcall7_start,
  773. __initcall_end,
  774. };
  775. /* Keep these in sync with initcalls in include/linux/init.h */
  776. static char *initcall_level_names[] __initdata = {
  777. "early parameters",
  778. "core parameters",
  779. "postcore parameters",
  780. "arch parameters",
  781. "subsys parameters",
  782. "fs parameters",
  783. "device parameters",
  784. "late parameters",
  785. };
  786. static void __init do_initcall_level(int level)
  787. {
  788. extern const struct kernel_param __start___param[], __stop___param[];
  789. initcall_t *fn;
  790. strcpy(static_command_line, saved_command_line);
  791. parse_args(initcall_level_names[level],
  792. static_command_line, __start___param,
  793. __stop___param - __start___param,
  794. level, level,
  795. repair_env_string);
  796. for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
  797. do_one_initcall(*fn);
  798. }
  799. static void __init do_initcalls(void)
  800. {
  801. int level;
  802. for (level = 0; level < ARRAY_SIZE(initcall_levels) - 1; level++)
  803. do_initcall_level(level);
  804. }
  805. /*
  806. * Ok, the machine is now initialized. None of the devices
  807. * have been touched yet, but the CPU subsystem is up and
  808. * running, and memory and process management works.
  809. *
  810. * Now we can finally start doing some real work..
  811. */
  812. static void __init do_basic_setup(void)
  813. {
  814. cpuset_init_smp();
  815. usermodehelper_init();
  816. shmem_init();
  817. driver_init();
  818. init_irq_proc();
  819. do_ctors();
  820. usermodehelper_enable();
  821. do_initcalls();
  822. random_int_secret_init();
  823. }
  824. static void __init do_pre_smp_initcalls(void)
  825. {
  826. initcall_t *fn;
  827. for (fn = __initcall_start; fn < __initcall0_start; fn++)
  828. do_one_initcall(*fn);
  829. }
  830. static void run_init_process(const char *init_filename)
  831. {
  832. argv_init[0] = init_filename;
  833. kernel_execve(init_filename, argv_init, envp_init);
  834. }
  835. #ifdef CONFIG_DEFERRED_INITCALLS
  836. extern initcall_t __deferred_initcall_start[], __deferred_initcall_end[];
  837. /* call deferred init routines */
  838. void __ref do_deferred_initcalls(void)
  839. {
  840. initcall_t *call;
  841. static int already_run=0;
  842. if (already_run) {
  843. printk("do_deferred_initcalls() has already run\n");
  844. return;
  845. }
  846. already_run=1;
  847. printk("Running do_deferred_initcalls()\n");
  848. for(call = __deferred_initcall_start;
  849. call < __deferred_initcall_end; call++)
  850. do_one_initcall(*call);
  851. flush_scheduled_work();
  852. free_initmem();
  853. }
  854. #endif
  855. /* This is a non __init function. Force it to be noinline otherwise gcc
  856. * makes it inline to init() and it becomes part of init.text section
  857. */
  858. static noinline int init_post(void)
  859. {
  860. #ifdef CONFIG_SEC_GPIO_DVS
  861. /************************ Caution !!! ****************************/
  862. /* This function must be located in appropriate INIT position
  863. * in accordance with the specification of each BB vendor.
  864. */
  865. /************************ Caution !!! ****************************/
  866. gpio_dvs_check_initgpio();
  867. #endif
  868. /* need to finish all async __init code before freeing the memory */
  869. async_synchronize_full();
  870. #ifndef CONFIG_DEFERRED_INITCALLS
  871. free_initmem();
  872. #endif
  873. mark_rodata_ro();
  874. system_state = SYSTEM_RUNNING;
  875. numa_default_policy();
  876. current->signal->flags |= SIGNAL_UNKILLABLE;
  877. if (ramdisk_execute_command) {
  878. run_init_process(ramdisk_execute_command);
  879. printk(KERN_WARNING "Failed to execute %s\n",
  880. ramdisk_execute_command);
  881. }
  882. /*
  883. * We try each of these until one succeeds.
  884. *
  885. * The Bourne shell can be used instead of init if we are
  886. * trying to recover a really broken machine.
  887. */
  888. if (execute_command) {
  889. run_init_process(execute_command);
  890. printk(KERN_WARNING "Failed to execute %s. Attempting "
  891. "defaults...\n", execute_command);
  892. }
  893. run_init_process("/sbin/init");
  894. run_init_process("/etc/init");
  895. run_init_process("/bin/init");
  896. run_init_process("/bin/sh");
  897. panic("No init found. Try passing init= option to kernel. "
  898. "See Linux Documentation/init.txt for guidance.");
  899. }
  900. static int __init kernel_init(void * unused)
  901. {
  902. /*
  903. * Wait until kthreadd is all set-up.
  904. */
  905. wait_for_completion(&kthreadd_done);
  906. /* Now the scheduler is fully set up and can do blocking allocations */
  907. gfp_allowed_mask = __GFP_BITS_MASK;
  908. /*
  909. * init can allocate pages on any node
  910. */
  911. set_mems_allowed(node_states[N_MEMORY]);
  912. /*
  913. * init can run on any cpu.
  914. */
  915. set_cpus_allowed_ptr(current, cpu_all_mask);
  916. cad_pid = task_pid(current);
  917. smp_prepare_cpus(setup_max_cpus);
  918. do_pre_smp_initcalls();
  919. lockup_detector_init();
  920. smp_init();
  921. sched_init_smp();
  922. do_basic_setup();
  923. /* Open the /dev/console on the rootfs, this should never fail */
  924. if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
  925. printk(KERN_WARNING "Warning: unable to open an initial console.\n");
  926. (void) sys_dup(0);
  927. (void) sys_dup(0);
  928. /*
  929. * check if there is an early userspace init. If yes, let it do all
  930. * the work
  931. */
  932. if (!ramdisk_execute_command)
  933. ramdisk_execute_command = "/init";
  934. if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
  935. ramdisk_execute_command = NULL;
  936. prepare_namespace();
  937. }
  938. /*
  939. * Ok, we have completed the initial bootup, and
  940. * we're essentially up and running. Get rid of the
  941. * initmem segments and start the user-mode stuff..
  942. */
  943. init_post();
  944. return 0;
  945. }