Linux 2.6 kernel startup and command line Transfer Process Analysis

Source: Internet
Author: User

The kernel can pass a string command line at startup to control the kernel startup process, for example:

"Console = ttyS2, 115200 mem = 64M @ 0xA0000000"

The console is specified as the serial port 2, the baud rate is 115200, the memory size is 64 MB, and the physical base address is 0xA0000000.

In addition, we can define some global variables in the kernel and use these global variables to control the Kernel configuration, for example, the usb driver defines

Static int nousb;/* Disable USB when built into kernel image */

If this variable is 1, the entire usb driver is not initialized. If you want to set it to 1, you can add nousb = 1 to the string command line.

Before you operate the variable, you need to let the system know the variable:

     
      
_ Module_param_call ("", nousb, param_set_bool, param_get_bool, & nousb, 0444) ;__ module_param_call this macro is defined in kernel \ include \ linux \ moduleparam. h
     

The prototype is as follows:

     
      #define __module_param_call(prefix, name, set, get, arg, perm)  \ static char __param_str_##name[] = prefix #name;  \ static struct kernel_param const __param_##name   \ __attribute_used__      \    __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \ = { __param_str_##name, perm, set, get, arg }
     

It defines a variable of the kernel_param type, which is put into the _ param,

The kernel_param struct is defined as follows:

     
      
Struct kernel_param {const char * name; unsigned int perm; param_set_fn set; param_get_fn get; void * arg ;};__ param /.. /.. /vmlinux. lds. s, while most platforms are placed in kernel \ include \ asm-generic \ vmlinux. lds. h: _ param: AT (ADDR (_ param)-LOAD_OFFSET) {\ VMLINUX_SYMBOL (_ start ___ param) = .; \ * (_ param) \ VMLINUX_SYMBOL (_ stop ___ param) = .; \}
     

When the kernel is started, the string command will be parsed. In kernel \ init \ main. c, the kernel startup function start_kernel

The external array is declared:

     
      extern struct kernel_param __start___param[], __stop___param[];
     

Then call the parse_args function to parse the array:

     
      parse_args("Booting kernel", command_line, __start___param,__stop___param - __start___param,&unknown_bootoption);
     

Command_line is the string command line to be parsed, and unknown_bootoption is the function pointer, which is used to obtain the = value on the right of the specified parameter.

Parse_args finds the kernel_param variable with the same name as nousb in the array and calls its set function to pay for it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.