内核参数,就是写在grub 的menu.lst里面或者通过其他地方,是传给内核的参数。由各种boot loader (grub ,lilo, pxeloader 等)负责复制到内存指定位置,然后linux内核通过boot loader传递过来的 一个指针(cmdline pointer)可以获取到。然后建立起/proc/cmdline文件,应用程序可以通过读取这个文件来得到参数。解释见Linux内核自带的文档Documentation/x86/boot.txt 。
http://lxr.linux.no/linux+v2.6.29/Documentation/x86/boot.txt
THE LINUX/x86 BOOT PROTOCOL
-----------------------------------------------------
0A0000 +------------------------+
| Reserved for BIOS | Do not use. Reserved for BIOS EBDA.
09A000 +------------------------+
| Command line | 参数在这里
| Stack/heap | For use by the kernel real-mode code.
098000 +------------------------+
| Kernel setup | The kernel real-mode code.
090200 +------------------------+
| Kernel boot sector | The kernel legacy boot sector.
090000 +------------------------+
| Protected-mode kernel | The bulk of the kernel image.
010000 +------------------------+
| Boot loader | <- Boot sector entry point 0000:7C00
001000 +------------------------+
| Reserved for MBR/BIOS |
000800 +------------------------+
| Typically used by MBR |
000600 +------------------------+
| BIOS use only |
000000 +------------------------+
http://lxr.linux.no/linux+v2.6.29/arch/x86/kernel/setup.c
654void __init setup_arch(char **cmdline_p)
655{
656#ifdef CONFIG_X86_32
657 memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
658 visws_early_detect();
659 pre_setup_arch_hook();
660#else
661 printk(KERN_INFO "Command line: %s\n", boot_command_line);
662#endif
http://lxr.linux.no/linux+v2.6.29/init/main.c
529
530asmlinkage void __init start_kernel(void)
531{
532 char * command_line;
533 extern struct kernel_param __start___param[], __stop___param[];
534
535 smp_setup_processor_id();
536
537 /*
538 * Need to run as early as possible, to initialize the
539 * lockdep hash:
540 */
541 lockdep_init();
542 debug_objects_early_init();
543 cgroup_init_early();
544
545 local_irq_disable();
546 early_boot_irqs_off();
547 early_init_irq_lock_class();
548
549/*
550 * Interrupts are still disabled. Do necessary setups, then
551 * enable them
552 */
553 lock_kernel();
554 tick_init();
555 boot_cpu_init();
556 page_address_init();
557 printk(KERN_NOTICE);
558 printk(linux_banner);
559 setup_arch(&command_line); **************初始化?******************
560 mm_init_owner(&init_mm, &init_task);
561 setup_command_line(command_line);
562 setup_per_cpu_areas();
563 setup_nr_cpu_ids();
564 smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
565
566 /*
567 * Set up the scheduler prior starting any interrupts (such as the
568 * timer interrupt). Full topology setup happens at smp_init()
569 * time - but meanwhile we still have a functioning scheduler.
570 */
571 sched_init();
572 /*
573 * Disable preemption - early bootup scheduling is extremely
574 * fragile until we cpu_idle() for the first time.
575 */
576 preempt_disable();
577 build_all_zonelists();
578 page_alloc_init();
579 printk(KERN_NOTICE "Kernel command line: %s\n", boot_command_line); 这里会打印出来
580 parse_early_param();
553 lock_kernel();
554 tick_init();
555 boot_cpu_init();
556 page_address_init();
557 printk(KERN_NOTICE);
558 printk(linux_banner);
559 setup_arch(&command_line);
在使用嵌入式linux系统开发产品的过程中,有时会使用console作为用户操作界面,这时就没必要看到linux系统的启动信息,需要将它去掉,现有方法如下:
在linux内核中的/kernel目录下printk.c文件中有一个函数:
CODE:
static void __call_console_drivers(unsigned long start, unsigned long end) { struct console *con; for (con = console_drivers; con; con = con->next) { if ((con->flags & CON_ENABLED) && con->write) con->write(con, &LOG_BUF(start), end - start); } } |