Parsing of Linux Startup parameters imported by uboot

Source: Internet
Author: User

Interaction between Bootloader and Kernel
The interaction between Bootloader and the kernel is one-way. bootloader transmits various parameters to the kernel. Because they cannot run at the same time, there is only one way to pass: bootloader places the parameters in a specified place, then starts the kernel, and obtains the parameters from this place after the kernel is started.

In addition to specifying the address for storing parameters, you must specify the parameter structure. Linux 2.4.x and later kernels all expect to pass startup parameters in the form of tagged list. A tag is a data structure. A tag list is the multiple tags that are stored. Mark the list to start marking atag_core and end marking atag_none. The data structure of the tag is tag, which consists of a tag_header structure and a union. The tag_header structure indicates the tag type and length, for example, memory or command line parameters. Use different Union for different types of tags. For example, if tag_mem32 is used for memory, it indicates that
Tag_cmdline. The data structure tag and tag_header are defined in the include/ASM/setup. h header file of the Linux kernel source code:

Struct tag_header {

U32 size;

U32 tag;

};

<Br> struct tag {

Struct tag_header HDR;

Union {

Struct tag_corecore;

Struct tag_mem32mem;

Struct tag_videotextvideotext;

Struct tag_ramdiskramdisk;

Struct tag_initrdinitrd;

Struct tag_serialnrserialnr;

Struct tag_revisionrevision;

Struct tag_videolfbvideolfb;

Struct tag_cmdlinecmdline;

<Br> /*

* Acorn specific

*/

Struct tag_acornacorn;

<Br> /*

* Dc21285 specific

*/

Struct tag_memclkmemclk;

} U;

};

The following describes how to transfer parameters by setting the memory tag and command line Tag:

(1) set the flag atag_core.

Mark the list to mark atag_core. If the storage address of the Bootloader and kernel parameters is 0x30000100, you can set the tag atag_core with the following code:

Params = (struct tag *) 0x30000100;

<Br> Params-> HDR. Tag = atag_core;

Params-> HDR. size = tag_size (tag_core );

<Br> Params-> U. Core. Flags = 0;

Params-> U. Core. pagesize = 0;

Params-> U. Core. rootdev = 0;

<Br> Params = tag_next (Params); where tag_next is defined as follows and points to the end of the current Tag:

# Define tag_next (t) (struct tag *) (u32 *) (t) + (t)-> HDR. Size ))

(2) set the memory tag.

If the starting address of the memory used by the Development Board is 0x30000000 and the size is 0x4000000, the memory mark can be set as follows:

Params-> HDR. Tag = atag_mem;

Params-> HDR. size = tag_size (tag_mem32 );

Params-> U. mem. Start = 0x30000000;

Params-> U. mem. size = 0x4000000;

Params = tag_next (Params );

(3) set the command line mark.

A command line is a string that is used to control some kernel behaviors. For example, "root =/dev/mtdblock2 init ="/linuxrc "console =" ttysac0 "" indicates that the root file system is located in the mtd2 partition, the first program executed after the system is started is/linuxrc, And the console is ttysac0 (that is, the first serial port ).

The command line can be set through the command in bootloader, and then transmitted to the kernel using the following construction mark:

Char * P = "root =/dev/mtdblock2 init ="/linuxrc "console =" ttysac0 "";

Params-> HDR. Tag = atag_cmdline;

Params-> HDR. size = (sizeof (struct tag_header) + strlen (p) + 1 + 4)> 2;

Strcpy (Params-> U. marshline. marshline, P );

Params = tag_next (Params );

(4) set the flag atag_none.

The tag list ends with the tag atag_none. The settings are as follows:

Params-> HDR. Tag = atag_none;

Params-> HDR. size = 0;

In addition to specifying the address for storing parameters, you must specify the parameter structure. Linux 2.4.x and later kernels all expect to pass startup parameters in the form of tagged list. A tag is a data structure. A tag list is the multiple tags that are stored. Mark the list to start marking atag_core and end marking atag_none. The data structure of the tag is tag, which consists of a tag_header structure and a union. The tag_header structure indicates the tag type and length, for example, memory or command line parameters. Use different Union for different types of tags. For example, if tag_mem32 is used for memory, it indicates that
Tag_cmdline. The data structure tag and tag_header are defined in the include/ASM/setup. h header file of the Linux kernel source code:

Struct tag_header {

U32 size;

U32 tag;

};

<Br> struct tag {

Struct tag_header HDR;

Union {

Struct tag_corecore;

Struct tag_mem32mem;

Struct tag_videotextvideotext;

Struct tag_ramdiskramdisk;

Struct tag_initrdinitrd;

Struct tag_serialnrserialnr;

Struct tag_revisionrevision;

Struct tag_videolfbvideolfb;

Struct tag_cmdlinecmdline;

<Br> /*

* Acorn specific

*/

Struct tag_acornacorn;

<Br> /*

* Dc21285 specific

*/

Struct tag_memclkmemclk;

} U;

};

The following describes how to transfer parameters by setting the memory tag and command line Tag:

(1) set the flag atag_core.

Mark the list to mark atag_core. If the storage address of the Bootloader and kernel parameters is 0x30000100, you can set the tag atag_core with the following code:

Params = (struct tag *) 0x30000100;

<Br> Params-> HDR. Tag = atag_core;

Params-> HDR. size = tag_size (tag_core );

<Br> Params-> U. Core. Flags = 0;

Params-> U. Core. pagesize = 0;

Params-> U. Core. rootdev = 0;

<Br> Params = tag_next (Params); where tag_next is defined as follows and points to the end of the current Tag:

# Define tag_next (t) (struct tag *) (u32 *) (t) + (t)-> HDR. Size ))

(2) set the memory tag.

If the starting address of the memory used by the Development Board is 0x30000000 and the size is 0x4000000, the memory mark can be set as follows:

Params-> HDR. Tag = atag_mem;

Params-> HDR. size = tag_size (tag_mem32 );

Params-> U. mem. Start = 0x30000000;

Params-> U. mem. size = 0x4000000;

Params = tag_next (Params );

(3) set the command line mark.

A command line is a string that is used to control some kernel behaviors. For example, "root =/dev/mtdblock2 init ="/linuxrc "console =" ttysac0 "" indicates that the root file system is located in the mtd2 partition, the first program executed after the system is started is/linuxrc, And the console is ttysac0 (that is, the first serial port ).

The command line can be set through the command in bootloader, and then transmitted to the kernel using the following construction mark:

Char * P = "root =/dev/mtdblock2 init ="/linuxrc "console =" ttysac0 "";

Params-> HDR. Tag = atag_cmdline;

Params-> HDR. size = (sizeof (struct tag_header) + strlen (p) + 1 + 4)> 2;

Strcpy (Params-> U. marshline. marshline, P );

Params = tag_next (Params );

(4) set the flag atag_none.

The tag list ends with the tag atag_none. The settings are as follows:

Params-> HDR. Tag = atag_none;

Params-> HDR. size = 0;

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.