How to implement parameter passing between Uboot and Linux

Source: Internet
Author: User
Tags unique id

Reference http://cgxcn.blog.163.com/blog/static/132312422009101133251202/

Reference:http://blog.chinaunix.net/uid-14833587-id-76499.html

Reference:http://lixuefeng26.blog.sohu.com/204383842.html

The principle is:uboot the parameters to be passed, save to a specified physical location, and then Linux obtains the data from that physical location

1. First take a look at the parameter passing process of Uboot:

A The first two structures are described:

Boot/u-boot/include/asm-mips

typedef struct GLOBAL_DATA {

bd_t *BD;

unsigned long flags;

unsigned long baudrate;

unsigned long have_console; /* Serial_init () was called */

unsigned long ram_size; /* RAM Size */

unsigned long reloc_off; /* Relocation Offset */

unsigned long env_addr; /* Address of environment struct */

unsigned long env_valid; /* Checksum of environment valid? */

void **jt; /* Jump Table */

} gd_t

And

Boot/u-boot/include/asm-mips

typedef struct BD_INFO {

int bi_baudrate; /* Serial console BaudRate */

unsigned long bi_ip_addr; /* IP Address */

unsigned char bi_enetaddr[6]; /* Ethernet adress */

unsigned long bi_arch_number; /* Unique ID for this board */

unsigned long bi_boot_params; /* Where this board expects params */

unsigned long bi_memstart; /* Start of DRAM memory */

unsigned long bi_memsize; /* Size of DRAM memory in bytes */

unsigned long bi_flashstart; /* Start of FLASH memory */

unsigned long bi_flashsize; /* Size of FLASH memory */

unsigned long bi_flashoffset; /* Reserved area for startup Monitor */

} bd_t;

B in do_bootm_linux(boot/u-boot/lib_mips/mips_linux.c), there are the following treatments:

Linux_params_init (Uncached_sdram (gd->bd->bi_boot_params), commandline); --- this function, the startup parameters indicated by commandline are stored in the Uncached_sdram (gd->bd- >bi_boot_params) is indicated by the physical address , and the global variable is used linux_argc,linux_argv,linux_env To indicate the total number of these parameters, their location, and the location of the environment variables, respectively

#if defined (config_ar7100) | | Defined (config_ar7240)

/* Pass The flash size as expected by current Linux kernel for AR7100 */

Flash_size_mbytes = gd->bd->bi_flashsize/(1024 * 1024);

Thekernel (LINUX_ARGC, LINUX_ARGV, linux_env, flash_size_mbytes); /* Start the kernel, that is, start from the address of Ntohl (HDR->IH_EP) (This is not a function call, but instead run the object directly on this address; specifically kernel_ Entry), whose passed parameters are linux_argc, LINUX_ARGV, Linux_env, flash_size_mbytes*/

#else

and in Linux/kernels/mips-linux-2.6.31/arch/mips/kernel/head. S , there are:

NESTED (Kernel_entry, SP)

long_s a0, fw_arg0 # Firmware arguments

long_s A1, Fw_arg1[xxx1]

long_s A2, Fw_arg2

long_s A3, Fw_arg3

........

J Start_kernel

These are the four parameters:linux_argc, LINUX_ARGV, linux_env, Flash_size_mbytes, respectively, passed to:fw_arg0,fw_arg1,fw_arg2, FW_ARG3, and eventually jumps to the Start_kernel function .

C in start_kernel(linux/kernels/init/main.c), there are:

->setup_arch (&command_line) (LINUX/KERNELS/ARCH/MIPS/KERNEL/SETUP.C) , respectively, call:

Prom_init (LINUX/KERNELS/ARCH/MIPS/XXX/PROM.C) [xxx2] ;

Arch_mem_init (cmdline_p); (LINUX/KERNELS/ARCH/MIPS/KERNEL/SETUP.C) [XXX3]

2. Then, if we are going to pass some of the parameters of the Uboot to the Linux kernel. How do I do that? Here, due to the work needs, I need to uboot a Bootpara structure parameter, passed to the Linux kernel. The implementation scenario is as follows:

²  the do_bootm function in Cmd_bootm.c , in:

Case IH_COMP_LZMA:

printf ("uncompressing%s ... ", name);

i = lzma_inflate ((unsigned char *) data, Len, (unsigned char*) Ntohl (hdr->ih_load), &unc_len);

if (i! = LZMA_RESULT_OK) {

printf ("LZMA ERROR%d-must RESET Board to recover\n", I);

Show_boot_progress (-6);

Udelay (100000);

Do_reset (CMDTP, Flag, argc, argv);

}

/* When the decompression kernel succeeds, it means that the Do_bootm_linux boot kernel is called later, so this time, the Boot_para information that is recorded under uboot is required , Storage to the specified location in memory;

and pass it to the Linux kernel;

The location of the selected storage, need to be placed in front of the kernel decompression address ( This leaves 1K space, storing bootpara parameters ) this will not affect the boot of the kernel.

#ifdef Config_xxx_boot

else {

unsigned int save_position = Ntohl (hdr->ih_load)-1024x768; [XXX4]

Save_bootpara (Save_position, &gbootpara);

}

#endif

Break

which

void Save_bootpara (unsigned int save_position, T_boot_para *ptbootpara) {

Memmove ((unsigned char *) save_position, Ptbootpara, sizeof (T_boot_para));

Return

}

²  PROM.C in the prom_init function, add:

#define KERNEL_LOAD_ADDR 0x80002000 [XXX5]

#ifdef Config_xxx_boot

Get_bootpara (kernel_load_addr-1024[xxx6], Ptbootpara);

#endif

which

int Get_bootpara (unsigned int load_position, T_boot_para *ptbootpara) {

Memmove (Ptbootpara, (unsigned char *) load_position, sizeof (T_boot_para)); [XXX7]

return 0;

}

[XXX1] A value that actually corresponds to the LINUX_ARGV, which is the address that points to the stored parameter

[XXX2] in prom_init , there is the use of FW_ARG0,FW_ARG1,FW_ARG2,FW_ARG3 processing, using these parameters to revert to global variables:arcs_cmdline The value

[XXX3] use arcs_cmdlineto get the values of command_line and boot_command_line

[XXX4] The hdr->ih_load is specifically 0x80002000, which is specified by Uboot's mkimages when making the kernel image. This is the address of an KSEG0 address space located in MIPS. The scope of the KSEG0 address space is 0x8000,0000--0x9fff,ffff. Thus, what can be exploited is the range from the 0x8000,0000--hdr->ih_load. Exactly, the author chooses 1K to be able to put down.
Here's Use Linux The memory of the kernel is decompressed before the address 1024x768 bytes of space to hold the arguments to be passed.

[XXX5] in Uboot , the memory address to which the Linux kernel is freed

[Xxx6] Store The address of the Bootpara parameter

[XXX7] gets the contents of the stored bootpara parameter

How to implement parameter passing between Uboot and Linux

Related Article

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.