Do_bootm function and Do_bootm_linux function analysis of uboot transplantation

Source: Internet
Author: User

One: Do_bootm function

(1) when the kernel starts by Bootm 30008000来 boot the kernel, bootm this command corresponding function is DO_BOOTM.

(2)

#define Linux_zimage_magic 0x016f2818

Linux_zimage_magic is a magic number whose value is equal to 0x016f2818. In the Zimage header information, there is a specific bit of a magic number, the magic number is used to indicate that the image is zimage, during the boot process, by reading the header information of the special location and the magic number to compare, to determine whether the image is zimage.

(3)

    if  (argc < 2)  {         addr = load_addr;         debug  ("*  kernel: default image load address = 0x%0 8lx\n ",                 load_ addr);     } else {        addr =  simple_strtoul (argv[1], null, 16);    //converts a string to a number of unsigend long  types          debug  ("*  kernel: cmdline image  Address = 0x%08lx\n ",  img_addr);     } 

When we started the kernel with the Bootm 30008000 command, the command passed in two parameters so ARGC = 1 Argv[0] = Bootm argv[1] = 30008000, where 30008000 is the starting address of the kernel image in the DDR, by which you can know You can also start the kernel directly from the command Bootm, so that the starting address of the kernel image is hard-coded in x210.h.

(4)

if (* (ULONG *) (addr + 9*4) = = linux_zimage_magic) {printf ("Boot with zimage\n");

This statement shows that our magic number is stored at the beginning of the Zimage (addr) 36-39 bytes, because we get the zimage image is essentially a binary file, so you can see through the Binary View tool Winhex.

(5) Images

static bootm_headers_t images;

Images is a static global variable whose type is bootm_headers_t, which holds the header information of the mirror (including the length, type, start address, etc.) of the image, and this is the global variable that is populated for later use.

The above is mainly for the zimage mirror calibration.


Two: do_bootm_linux function analysis

The uboot is defined by the #ifdef config_zimage_boot to determine whether the initiated image is Zimage or uimage. As previously mentioned, Uboot supports zimage and uimage boot, where zimage is the boot image added later. Analysis of the contents of the DO_BOOTM function can be found Uboot also supports fit format startup

FIT: The way the device tree is passed to start the kernel. There is no analysis here (mostly not), here is the analysis of the boot of the uimage image. Next, we continue to analyze the DO_BOOTM function

(1)

OS_HDR = Boot_get_kernel (CMDTP, Flag, argc, argv, &images, &os_data, &os_len);

The Boot_get_kernel function is primarily used to get the start address of the kernel and the length of the kernel. It is important to note that this function passes through a number of pointers, the output type parameters, which are assigned to these pointer variables.

A large part of the next step is verifying the uimage image and writing the header information to the global variable image.

(2) The DO_BOOTM function is executed to After_header_check: the check of the enemy information is complete.

(3) The following switch (OS), case has a number of options, indicating that Uboot not only to start the Linux kernel image, but also to launch other kernels. We are using the Linux kernel, so we will execute the Do_bootm_linux function later.

(4) Do_bootm_linux function

if (images->legacy_hdr_valid) {EP = Image_get_ep (&images->legacy_hdr_os_copy); The entrance to the mirror

The abbreviation for Ep:entry Point is the entry of the program (similar to Mian), and the starting execution part of an image file is not at the beginning of the image (the image has n bytes of header information at the beginning), and the first code is executed at a byte in the middle of the mirror when the real image file executes.
The equivalent of a head is a certain amount of offsets. This offset is recorded in the header information.

(5)

Thekernel = (void (*) (int, int., UINT)) EP;

Assigning the EP to Thekernel, the function pointer points to the real entry address of the OS image loaded in memory (the code that executes the first sentence of the operating system).

(6)

printf ("\nstarting kernel ... \ n");

Uboot print the last piece of information, if uboot in the process of booting the kernel, see this message, it means that uboot is not a problem.

(7)

Thekernel (0, Machid, bd->bi_boot_params);

Before the Thekernel this function pointer to the EP, that is, the mirror's entrance, so here is the uboot try to start the kernel, but can start the kernel, uboot run to this end.

Three: The execution process of the mirror

The first step is to read the header information, and then at the specific address of the header information to find Magic_num, thus to determine the type of image, the second step to verify the image, the third step to read the header information, the specific address know the image of the various information (image length, image type, entry address) The fourth step is to go to the entrypoint to begin the image execution.

This article is from the "11664570" blog, please be sure to keep this source http://11674570.blog.51cto.com/11664570/1925509

Do_bootm function and Do_bootm_linux function analysis of uboot transplantation

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.