~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/init/main.c

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 
 12 #define __KERNEL_SYSCALLS__
 13 
 14 #include <linux/config.h>
 15 #include <linux/proc_fs.h>
 16 #include <linux/devfs_fs_kernel.h>
 17 #include <linux/unistd.h>
 18 #include <linux/string.h>
 19 #include <linux/ctype.h>
 20 #include <linux/delay.h>
 21 #include <linux/utsname.h>
 22 #include <linux/ioport.h>
 23 #include <linux/init.h>
 24 #include <linux/raid/md.h>
 25 #include <linux/smp_lock.h>
 26 #include <linux/blk.h>
 27 #include <linux/hdreg.h>
 28 #include <linux/iobuf.h>
 29 #include <linux/bootmem.h>
 30 
 31 #include <asm/io.h>
 32 #include <asm/bugs.h>
 33 
 34 #ifdef CONFIG_PCI
 35 #include <linux/pci.h>
 36 #endif
 37 
 38 #ifdef CONFIG_DIO
 39 #include <linux/dio.h>
 40 #endif
 41 
 42 #ifdef CONFIG_ZORRO
 43 #include <linux/zorro.h>
 44 #endif
 45 
 46 #ifdef CONFIG_MTRR
 47 #  include <asm/mtrr.h>
 48 #endif
 49 
 50 #ifdef CONFIG_3215_CONSOLE
 51 extern int con3215_activate(void);
 52 #endif
 53 
 54 #ifdef CONFIG_NUBUS
 55 #include <linux/nubus.h>
 56 #endif
 57 
 58 #ifdef CONFIG_ISAPNP
 59 #include <linux/isapnp.h>
 60 #endif
 61 
 62 #ifdef CONFIG_IRDA
 63 #include <net/irda/irda_device.h>
 64 #endif
 65 
 66 #ifdef CONFIG_X86_IO_APIC
 67 #include <asm/smp.h>
 68 #endif
 69 
 70 /*
 71  * Versions of gcc older than that listed below may actually compile
 72  * and link okay, but the end product can have subtle run time bugs.
 73  * To avoid associated bogus bug reports, we flatly refuse to compile
 74  * with a gcc that is known to be too old from the very beginning.
 75  */
 76 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 91)
 77 #error Sorry, your GCC is too old. It builds incorrect kernels.
 78 #endif
 79 
 80 extern char _stext, _etext;
 81 extern char *linux_banner;
 82 
 83 static int init(void *);
 84 
 85 extern void init_IRQ(void);
 86 extern void init_modules(void);
 87 extern void sock_init(void);
 88 extern void fork_init(unsigned long);
 89 extern void mca_init(void);
 90 extern void sbus_init(void);
 91 extern void ppc_init(void);
 92 extern void sysctl_init(void);
 93 extern void signals_init(void);
 94 extern void bdev_init(void);
 95 extern int init_pcmcia_ds(void);
 96 extern void net_notifier_init(void);
 97 
 98 extern void free_initmem(void);
 99 extern void filesystem_setup(void);
100 
101 #ifdef CONFIG_TC
102 extern void tc_init(void);
103 #endif
104 
105 extern void ecard_init(void);
106 
107 #if defined(CONFIG_SYSVIPC)
108 extern void ipc_init(void);
109 #endif
110 #if defined(CONFIG_QUOTA)
111 extern void dquot_init_hash(void);
112 #endif
113 
114 /*
115  * Boot command-line arguments
116  */
117 #define MAX_INIT_ARGS 8
118 #define MAX_INIT_ENVS 8
119 
120 extern void time_init(void);
121 extern void softirq_init(void);
122 
123 int rows, cols;
124 
125 #ifdef CONFIG_BLK_DEV_INITRD
126 kdev_t real_root_dev;
127 #endif
128 
129 int root_mountflags = MS_RDONLY;
130 char *execute_command;
131 char root_device_name[64];
132 
133 
134 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
135 static char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
136 
137 static int __init profile_setup(char *str)
138 {
139     int par;
140     if (get_option(&str,&par)) prof_shift = par;
141         return 1;
142 }
143 
144 __setup("profile=", profile_setup);
145 
146 
147 static struct dev_name_struct {
148         const char *name;
149         const int num;
150 } root_dev_names[] __initdata = {
151         { "nfs",     0x00ff },
152         { "hda",     0x0300 },
153         { "hdb",     0x0340 },
154         { "hdc",     0x1600 },
155         { "hdd",     0x1640 },
156         { "hde",     0x2100 },
157         { "hdf",     0x2140 },
158         { "hdg",     0x2200 },
159         { "hdh",     0x2240 },
160         { "hdi",     0x3800 },
161         { "hdj",     0x3840 },
162         { "hdk",     0x3900 },
163         { "hdl",     0x3940 },
164         { "hdm",     0x5800 },
165         { "hdn",     0x5840 },
166         { "hdo",     0x5900 },
167         { "hdp",     0x5940 },
168         { "hdq",     0x5A00 },
169         { "hdr",     0x5A40 },
170         { "hds",     0x5B00 },
171         { "hdt",     0x5B40 },
172         { "sda",     0x0800 },
173         { "sdb",     0x0810 },
174         { "sdc",     0x0820 },
175         { "sdd",     0x0830 },
176         { "sde",     0x0840 },
177         { "sdf",     0x0850 },
178         { "sdg",     0x0860 },
179         { "sdh",     0x0870 },
180         { "sdi",     0x0880 },
181         { "sdj",     0x0890 },
182         { "sdk",     0x08a0 },
183         { "sdl",     0x08b0 },
184         { "sdm",     0x08c0 },
185         { "sdn",     0x08d0 },
186         { "sdo",     0x08e0 },
187         { "sdp",     0x08f0 },
188         { "ada",     0x1c00 },
189         { "adb",     0x1c10 },
190         { "adc",     0x1c20 },
191         { "add",     0x1c30 },
192         { "ade",     0x1c40 },
193         { "fd",      0x0200 },
194         { "md",      0x0900 },       
195         { "xda",     0x0d00 },
196         { "xdb",     0x0d40 },
197         { "ram",     0x0100 },
198         { "scd",     0x0b00 },
199         { "mcd",     0x1700 },
200         { "cdu535",  0x1800 },
201         { "sonycd",  0x1800 },
202         { "aztcd",   0x1d00 },
203         { "cm206cd", 0x2000 },
204         { "gscd",    0x1000 },
205         { "sbpcd",   0x1900 },
206         { "eda",     0x2400 },
207         { "edb",     0x2440 },
208         { "pda",        0x2d00 },
209         { "pdb",        0x2d10 },
210         { "pdc",        0x2d20 },
211         { "pdd",        0x2d30 },
212         { "pcd",        0x2e00 },
213         { "pf",         0x2f00 },
214         { "apblock", APBLOCK_MAJOR << 8},
215         { "ddv", DDV_MAJOR << 8},
216         { "jsfd",    JSFD_MAJOR << 8},
217 #ifdef CONFIG_MDISK
218         { "mnda", (MDISK_MAJOR << MINORBITS)},
219         { "mndb", (MDISK_MAJOR << MINORBITS) + 1},
220         { "mndc", (MDISK_MAJOR << MINORBITS) + 2},
221         { "mndd", (MDISK_MAJOR << MINORBITS) + 3},
222         { "mnde", (MDISK_MAJOR << MINORBITS) + 4},
223         { "mndf", (MDISK_MAJOR << MINORBITS) + 5},
224         { "mndg", (MDISK_MAJOR << MINORBITS) + 6},
225         { "mndh", (MDISK_MAJOR << MINORBITS) + 7},
226 #endif
227 #ifdef CONFIG_DASD
228         { "dasda", (DASD_MAJOR << MINORBITS) },
229         { "dasdb", (DASD_MAJOR << MINORBITS) + (1 << 2) },
230         { "dasdc", (DASD_MAJOR << MINORBITS) + (2 << 2) },
231         { "dasdd", (DASD_MAJOR << MINORBITS) + (3 << 2) },
232         { "dasde", (DASD_MAJOR << MINORBITS) + (4 << 2) },
233         { "dasdf", (DASD_MAJOR << MINORBITS) + (5 << 2) },
234         { "dasdg", (DASD_MAJOR << MINORBITS) + (6 << 2) },
235         { "dasdh", (DASD_MAJOR << MINORBITS) + (7 << 2) },
236 #endif
237 #if defined(CONFIG_BLK_CPQ_DA) || defined(CONFIG_BLK_CPQ_DA_MODULE)
238         { "ida/c0d0p",0x4800 },
239         { "ida/c0d1p",0x4810 },
240         { "ida/c0d2p",0x4820 },
241         { "ida/c0d3p",0x4830 },
242         { "ida/c0d4p",0x4840 },
243         { "ida/c0d5p",0x4850 },
244         { "ida/c0d6p",0x4860 },
245         { "ida/c0d7p",0x4870 },
246         { "ida/c0d8p",0x4880 },
247         { "ida/c0d9p",0x4890 },
248         { "ida/c0d10p",0x48A0 },
249         { "ida/c0d11p",0x48B0 },
250         { "ida/c0d12p",0x48C0 },
251         { "ida/c0d13p",0x48D0 },
252         { "ida/c0d14p",0x48E0 },
253         { "ida/c0d15p",0x48F0 },
254 #endif
255 #if defined(CONFIG_BLK_CPQ_CISS_DA) || defined(CONFIG_BLK_CPQ_CISS_DA_MODULE)
256         { "cciss/c0d0p",0x6800 },
257         { "cciss/c0d1p",0x6810 },
258         { "cciss/c0d2p",0x6820 },
259         { "cciss/c0d3p",0x6830 },
260         { "cciss/c0d4p",0x6840 },
261         { "cciss/c0d5p",0x6850 },
262         { "cciss/c0d6p",0x6860 },
263         { "cciss/c0d7p",0x6870 },
264         { "cciss/c0d8p",0x6880 },
265         { "cciss/c0d9p",0x6890 },
266         { "cciss/c0d10p",0x68A0 },
267         { "cciss/c0d11p",0x68B0 },
268         { "cciss/c0d12p",0x68C0 },
269         { "cciss/c0d13p",0x68D0 },
270         { "cciss/c0d14p",0x68E0 },
271         { "cciss/c0d15p",0x68F0 },
272 #endif
273 #ifdef CONFIG_NFTL
274         { "nftla", 0x5d00 },
275 #endif
276         { NULL, 0 }
277 };
278 
279 kdev_t __init name_to_kdev_t(char *line)
280 {
281         int base = 0;
282 
283         if (strncmp(line,"/dev/",5) == 0) {
284                 struct dev_name_struct *dev = root_dev_names;
285                 line += 5;
286                 do {
287                         int len = strlen(dev->name);
288                         if (strncmp(line,dev->name,len) == 0) {
289                                 line += len;
290                                 base = dev->num;
291                                 break;
292                         }
293                         dev++;
294                 } while (dev->name);
295         }
296         return to_kdev_t(base + simple_strtoul(line,NULL,base?10:16));
297 }
298 
299 static int __init root_dev_setup(char *line)
300 {
301         int i;
302         char ch;
303 
304         ROOT_DEV = name_to_kdev_t(line);
305         memset (root_device_name, 0, sizeof root_device_name);
306         if (strncmp (line, "/dev/", 5) == 0) line += 5;
307         for (i = 0; i < sizeof root_device_name - 1; ++i)
308         {
309             ch = line[i];
310             if ( isspace (ch) || (ch == ',') || (ch == '\0') ) break;
311             root_device_name[i] = ch;
312         }
313         return 1;
314 }
315 
316 __setup("root=", root_dev_setup);
317 
318 static int __init checksetup(char *line)
319 {
320         struct kernel_param *p;
321 
322         p = &__setup_start;
323         do {
324                 int n = strlen(p->str);
325                 if (!strncmp(line,p->str,n)) {
326                         if (p->setup_func(line+n))
327                                 return 1;
328                 }
329                 p++;
330         } while (p < &__setup_end);
331         return 0;
332 }
333 
334 /* this should be approx 2 Bo*oMips to start (note initial shift), and will
335    still work even if initially too large, it will just take slightly longer */
336 unsigned long loops_per_jiffy = (1<<12);
337 
338 /* This is the number of bits of precision for the loops_per_jiffy.  Each
339    bit takes on average 1.5/HZ seconds.  This (like the original) is a little
340    better than 1% */
341 #define LPS_PREC 8
342 
343 void __init calibrate_delay(void)
344 {
345         unsigned long ticks, loopbit;
346         int lps_precision = LPS_PREC;
347 
348         loops_per_jiffy = (1<<12);
349 
350         printk("Calibrating delay loop... ");
351         while (loops_per_jiffy <<= 1) {
352                 /* wait for "start of" clock tick */
353                 ticks = jiffies;
354                 while (ticks == jiffies)
355                         /* nothing */;
356                 /* Go .. */
357                 ticks = jiffies;
358                 __delay(loops_per_jiffy);
359                 ticks = jiffies - ticks;
360                 if (ticks)
361                         break;
362         }
363 
364 /* Do a binary approximation to get loops_per_jiffy set to equal one clock
365    (up to lps_precision bits) */
366         loops_per_jiffy >>= 1;
367         loopbit = loops_per_jiffy;
368         while ( lps_precision-- && (loopbit >>= 1) ) {
369                 loops_per_jiffy |= loopbit;
370                 ticks = jiffies;
371                 while (ticks == jiffies);
372                 ticks = jiffies;
373                 __delay(loops_per_jiffy);
374                 if (jiffies != ticks)   /* longer than 1 tick */
375                         loops_per_jiffy &= ~loopbit;
376         }
377 
378 /* Round the value and print it */      
379         printk("%lu.%02lu BogoMIPS\n",
380                 loops_per_jiffy/(500000/HZ),
381                 (loops_per_jiffy/(5000/HZ)) % 100);
382 }
383 
384 static int __init readonly(char *str)
385 {
386         if (*str)
387                 return 0;
388         root_mountflags |= MS_RDONLY;
389         return 1;
390 }
391 
392 static int __init readwrite(char *str)
393 {
394         if (*str)
395                 return 0;
396         root_mountflags &= ~MS_RDONLY;
397         return 1;
398 }
399 
400 static int __init debug_kernel(char *str)
401 {
402         if (*str)
403                 return 0;
404         console_loglevel = 10;
405         return 1;
406 }
407 
408 static int __init quiet_kernel(char *str)
409 {
410         if (*str)
411                 return 0;
412         console_loglevel = 4;
413         return 1;
414 }
415 
416 __setup("ro", readonly);
417 __setup("rw", readwrite);
418 __setup("debug", debug_kernel);
419 __setup("quiet", quiet_kernel);
420 
421 /*
422  * This is a simple kernel command line parsing function: it parses
423  * the command line, and fills in the arguments/environment to init
424  * as appropriate. Any cmd-line option is taken to be an environment
425  * variable if it contains the character '='.
426  *
427  * This routine also checks for options meant for the kernel.
428  * These options are not given to init - they are for internal kernel use only.
429  */
430 static void __init parse_options(char *line)
431 {
432         char *next,*quote;
433         int args, envs;
434 
435         if (!*line)
436                 return;
437         args = 0;
438         envs = 1;       /* TERM is set to 'linux' by default */
439         next = line;
440         while ((line = next) != NULL) {
441                 quote = strchr(line,'"');
442                 next = strchr(line, ' ');
443                 while (next != NULL && quote != NULL && quote < next) {
444                         /* we found a left quote before the next blank
445                          * now we have to find the matching right quote
446                          */
447                         next = strchr(quote+1, '"');
448                         if (next != NULL) {
449                                 quote = strchr(next+1, '"');
450                                 next = strchr(next+1, ' ');
451                         }
452                 }
453                 if (next != NULL)
454                         *next++ = 0;
455                 if (!strncmp(line,"init=",5)) {
456                         line += 5;
457                         execute_command = line;
458                         /* In case LILO is going to boot us with default command line,
459                          * it prepends "auto" before the whole cmdline which makes
460                          * the shell think it should execute a script with such name.
461                          * So we ignore all arguments entered _before_ init=... [MJ]
462                          */
463                         args = 0;
464                         continue;
465                 }
466                 if (checksetup(line))
467                         continue;
468                 
469                 /*
470                  * Then check if it's an environment variable or
471                  * an option.
472                  */
473                 if (strchr(line,'=')) {
474                         if (envs >= MAX_INIT_ENVS)
475                                 break;
476                         envp_init[++envs] = line;
477                 } else {
478                         if (args >= MAX_INIT_ARGS)
479                                 break;
480                         if (*line)
481                                 argv_init[++args] = line;
482                 }
483         }
484         argv_init[args+1] = NULL;
485         envp_init[envs+1] = NULL;
486 }
487 
488 
489 extern void setup_arch(char **);
490 extern void cpu_idle(void);
491 
492 #ifndef CONFIG_SMP
493 
494 #ifdef CONFIG_X86_IO_APIC
495 static void __init smp_init(void)
496 {
497         IO_APIC_init_uniprocessor();
498 }
499 #else
500 #define smp_init()      do { } while (0)
501 #endif
502 
503 #else
504 
505 /* Called by boot processor to activate the rest. */
506 static void __init smp_init(void)
507 {
508         /* Get other processors into their bootup holding patterns. */
509         smp_boot_cpus();
510         smp_threads_ready=1;
511         smp_commence();
512 }               
513 
514 #endif
515 
516 /*
517  *      Activate the first processor.
518  */
519  
520 asmlinkage void __init start_kernel(void)
521 {
522         char * command_line;
523         unsigned long mempages;
524         extern char saved_command_line[];
525 /*
526  * Interrupts are still disabled. Do necessary setups, then
527  * enable them
528  */
529         lock_kernel();
530         printk(linux_banner);
531         setup_arch(&command_line);
532         printk("Kernel command line: %s\n", saved_command_line);
533         parse_options(command_line);
534         trap_init();
535         init_IRQ();
536         sched_init();
537         time_init();
538         softirq_init();
539 
540         /*
541          * HACK ALERT! This is early. We're enabling the console before
542          * we've done PCI setups etc, and console_init() must be aware of
543          * this. But we do want output early, in case something goes wrong.
544          */
545         console_init();
546 #ifdef CONFIG_MODULES
547         init_modules();
548 #endif
549         if (prof_shift) {
550                 unsigned int size;
551                 /* only text is profiled */
552                 prof_len = (unsigned long) &_etext - (unsigned long) &_stext;
553                 prof_len >>= prof_shift;
554                 
555                 size = prof_len * sizeof(unsigned int) + PAGE_SIZE-1;
556                 prof_buffer = (unsigned int *) alloc_bootmem(size);
557         }
558 
559         kmem_cache_init();
560         sti();
561         calibrate_delay();
562 #ifdef CONFIG_BLK_DEV_INITRD
563         if (initrd_start && !initrd_below_start_ok &&
564                         initrd_start < min_low_pfn << PAGE_SHIFT) {
565                 printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
566                     "disabling it.\n",initrd_start,min_low_pfn << PAGE_SHIFT);
567                 initrd_start = 0;
568         }
569 #endif
570         mem_init();
571         kmem_cache_sizes_init();
572 #ifdef CONFIG_3215_CONSOLE
573         con3215_activate();
574 #endif
575 #ifdef CONFIG_PROC_FS
576         proc_root_init();
577 #endif
578         mempages = num_physpages;
579 
580         fork_init(mempages);
581         proc_caches_init();
582         vfs_caches_init(mempages);
583         buffer_init(mempages);
584         page_cache_init(mempages);
585         kiobuf_setup();
586         signals_init();
587         bdev_init();
588         inode_init(mempages);
589 #if defined(CONFIG_SYSVIPC)
590         ipc_init();
591 #endif
592 #if defined(CONFIG_QUOTA)
593         dquot_init_hash();
594 #endif
595         check_bugs();
596         printk("POSIX conformance testing by UNIFIX\n");
597 
598         /* 
599          *      We count on the initial thread going ok 
600          *      Like idlers init is an unlocked kernel thread, which will
601          *      make syscalls (and thus be locked).
602          */
603         smp_init();
604         kernel_thread(init, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGNAL);
605         unlock_kernel();
606         current->need_resched = 1;
607         cpu_idle();
608 }
609 
610 #ifdef CONFIG_BLK_DEV_INITRD
611 static int do_linuxrc(void * shell)
612 {
613         static char *argv[] = { "linuxrc", NULL, };
614 
615         close(0);close(1);close(2);
616         setsid();
617         (void) open("/dev/console",O_RDWR,0);
618         (void) dup(0);
619         (void) dup(0);
620         return execve(shell, argv, envp_init);
621 }
622 
623 #endif
624 
625 struct task_struct *child_reaper = &init_task;
626 
627 static void __init do_initcalls(void)
628 {
629         initcall_t *call;
630 
631         call = &__initcall_start;
632         do {
633                 (*call)();
634                 call++;
635         } while (call < &__initcall_end);
636 
637         /* Make sure there is no pending stuff from the initcall sequence */
638         flush_scheduled_tasks();
639 }
640 
641 /*
642  * Ok, the machine is now initialized. None of the devices
643  * have been touched yet, but the CPU subsystem is up and
644  * running, and memory and process management works.
645  *
646  * Now we can finally start doing some real work..
647  */
648 static void __init do_basic_setup(void)
649 {
650 #ifdef CONFIG_BLK_DEV_INITRD
651         int real_root_mountflags;
652 #endif
653 
654         /*
655          * Tell the world that we're going to be the grim
656          * reaper of innocent orphaned children.
657          *
658          * We don't want people to have to make incorrect
659          * assumptions about where in the task array this
660          * can be found.
661          */
662         child_reaper = current;
663 
664 #if defined(CONFIG_MTRR)        /* Do this after SMP initialization */
665 /*
666  * We should probably create some architecture-dependent "fixup after
667  * everything is up" style function where this would belong better
668  * than in init/main.c..
669  */
670         mtrr_init();
671 #endif
672 
673 #ifdef CONFIG_SYSCTL
674         sysctl_init();
675 #endif
676 
677         /*
678          * Ok, at this point all CPU's should be initialized, so
679          * we can start looking into devices..
680          */
681 #ifdef CONFIG_PCI
682         pci_init();
683 #endif
684 #ifdef CONFIG_SBUS
685         sbus_init();
686 #endif
687 #if defined(CONFIG_PPC)
688         ppc_init();
689 #endif
690 #ifdef CONFIG_MCA
691         mca_init();
692 #endif
693 #ifdef CONFIG_ARCH_ACORN
694         ecard_init();
695 #endif
696 #ifdef CONFIG_ZORRO
697         zorro_init();
698 #endif
699 #ifdef CONFIG_DIO
700         dio_init();
701 #endif
702 #ifdef CONFIG_NUBUS
703         nubus_init();
704 #endif
705 #ifdef CONFIG_ISAPNP
706         isapnp_init();
707 #endif
708 #ifdef CONFIG_TC
709         tc_init();
710 #endif
711 
712         /* Networking initialization needs a process context */ 
713         sock_init();
714 
715 #ifdef CONFIG_BLK_DEV_INITRD
716         real_root_dev = ROOT_DEV;
717         real_root_mountflags = root_mountflags;
718         if (initrd_start && mount_initrd) root_mountflags &= ~MS_RDONLY;
719         else mount_initrd =0;
720 #endif
721 
722         start_context_thread();
723         do_initcalls();
724 
725         /* .. filesystems .. */
726         filesystem_setup();
727 
728 #ifdef CONFIG_IRDA
729         irda_device_init(); /* Must be done after protocol initialization */
730 #endif
731 #ifdef CONFIG_PCMCIA
732         init_pcmcia_ds();               /* Do this last */
733 #endif
734 
735         /* Mount the root filesystem.. */
736         mount_root();
737 
738         mount_devfs_fs ();
739 
740 #ifdef CONFIG_BLK_DEV_INITRD
741         root_mountflags = real_root_mountflags;
742         if (mount_initrd && ROOT_DEV != real_root_dev
743             && MAJOR(ROOT_DEV) == RAMDISK_MAJOR && MINOR(ROOT_DEV) == 0) {
744                 int error;
745                 int i, pid;
746 
747                 pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD);
748                 if (pid>0)
749                         while (pid != wait(&i));
750                 if (MAJOR(real_root_dev) != RAMDISK_MAJOR
751                      || MINOR(real_root_dev) != 0) {
752                         error = change_root(real_root_dev,"/initrd");
753                         if (error)
754                                 printk(KERN_ERR "Change root to /initrd: "
755                                     "error %d\n",error);
756                 }
757         }
758 #endif
759 }
760 
761 static int init(void * unused)
762 {
763         lock_kernel();
764         do_basic_setup();
765 
766         /*
767          * Ok, we have completed the initial bootup, and
768          * we're essentially up and running. Get rid of the
769          * initmem segments and start the user-mode stuff..
770          */
771         free_initmem();
772         unlock_kernel();
773 
774         if (open("/dev/console", O_RDWR, 0) < 0)
775                 printk("Warning: unable to open an initial console.\n");
776 
777         (void) dup(0);
778         (void) dup(0);
779         
780         /*
781          * We try each of these until one succeeds.
782          *
783          * The Bourne shell can be used instead of init if we are 
784          * trying to recover a really broken machine.
785          */
786 
787         if (execute_command)
788                 execve(execute_command,argv_init,envp_init);
789         execve("/sbin/init",argv_init,envp_init);
790         execve("/etc/init",argv_init,envp_init);
791         execve("/bin/init",argv_init,envp_init);
792         execve("/bin/sh",argv_init,envp_init);
793         panic("No init found.  Try passing init= option to kernel.");
794 }
795 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.