ARM Linux from bootloader, kernel to filesystem boot process __linux

Source: Internet
Author: User

The ARM Linux boot process is roughly:bootloader ---->kernel---->root filesystem. Bootloader is a power to get the control of the CPU, and bootloader to achieve the initialization of the hardware. Bootloader became the "first crab-eating" code after power on.

When it comes to this, you have to think about how the hardware mechanism satisfies this function. CPUs are generally integrated into small-capacity SRAM (also known as stapping Stone, stepping stone), when the system on the power, NAND controler automatically copy NAND flash in the front content into the stepping stone, and the PC The pointer points to the starting address 0x00000000 of the stepping stone. This part of the code can be implemented. So, this part of the code is the bootloader part, that a power bootloader can be run. Indeed, in embedded Linux software systems, the first part of Nandflash code is often bootloader, then kernel, then the root file system.

Said so much, as if not to start the process Ah, do not worry, I slowly talk about the so-called Maito well.

To say that the START process, if it is simply introduced from where to where, who did what, the results may be just know that they do not know why. Personally feel the CPU with the PC pointer, follow the footsteps of the code can be clear, when the code to find the implementation of the process, and then analyze the code, nature knows which part of the completed what, more importantly for the code of the transplant lay a solid foundation. Naturally this process is painful and boring, even look at the code for a few days did not understand, but this is a kind of exercise. Bootloder

Said earlier, bootloader on the power to get the right to use the CPU, it certainly has to do some initialization of the work Ah, such as the shutdown watchdog, set the CPU operating mode, set up the stack and so the more urgent things. Of course, some of the motherboard's other hardware for simple initialization, such as external DDR memory, network card, display, NAND flash, and so on initialization work, and finally responsible for the Linux kernel loaded into memory. The so-called responsibility and power are coexisting, you get the rights, of course, you have to pay. When Bootloader completes its mission, the right to use the CPU will be handed to the next part of the code: kernel. Kernel

Before discussing how kernel is started, understand the structure of kernel and how it came about. The following diagram shows the information that will be displayed at the end of the kernel compilation:

The following diagram illustrates the above compilation process,

As you can see, when the kernel source files are compiled and linked into vmlinux files, several modules are compiled and linked. where (1) vmlinux is an object file in the elf format, this file is only the source code after the connection to the file, and can not run on the arm platform. (2) After objcopy This tool transformation, obtains the binary format file Image,image file compared to the Vmlinux file, in addition to the format dissimilarity, also has been removed many annotation and the debugging information. (3) Image file after compression has been piggy.gz, this file is only the image of the compressed version, and no other difference. (4) Then compile and generate several other module files MISC.O, BIG_ENDIAN.O, HEAD.O, HEAD-XSCALE.O, these files constitute a component called Bootstrap loader , also called the bootstrapper . Compiles the generated piggy.o file. (5) The final piggy.o file and bootstrap loader constitute a bootable kernel Image file (bootable file).

You can see that the final executable file is the rightmost one on the top, and this is the last image we wrote to the Development Board. Where PIGGY.O is the kernel image, and the remaining few files form the bootstrapper.

Let's start by discussing the process of CPU flow, or using a diagram to show:

As can be seen from the above picture, the system begins to execute bootloader as soon as it is on. When the bootloader is finished, the control is given to the start label in the HEAD.O file of the bootstrapper, and when the bootstrapper completes the boot process, the control is transferred to the start label in the HEAD.O file of the real kernel. This is the entry point of the kernel, and the head.o of the kernel will control the MAIN.O start_kernel function. This way, you can see exactly what the code is doing by looking at the appropriate code. Here we can find the appropriate code to analyze and see what they are accomplishing. Here's my analysis: The bootstrapper:

HEAD.O takes control from Bootloader and completes the following tasks: Make it i/d caches, turn off interrupts, establish a C-run environment (that is, set up the stack), complete the decompression and relocation code by HEAD.O and HEAD-XSCAL.O, and complete other hardware related by MISC.O settings, such as BIG.ENDIAN.O to set the big-endian mode for the CPU

Kernel entry point: Take control from the bootstrapper, complete the following tasks check for valid CPU and CPU Information Create initialization page table entry enables MMU detection errors and reports jumps to the kernel itself main.c file Start_kernel () function kernel boot:

Take control from Kernel's HEAD.O and start the kernel, where initialization of the kernel is done, such as the initialization of each subsystem of the kernel. Root filesystem

To this end, kernel completed the system hardware detection and hardware-driven initialization, the kernel space related work has been completed, began to user space transfer, the kernel space through an indirect initrd (a virtual file system) to the user space over, and then began to mount with the file system, the process: INITRD ----> /sbin/init ----> /etc/inittab.

INITRD is a virtual file system, which has lib, bin, sbin, usr, proc, sys, VAR, dev, boot and some other directories, its directory is a bit like true/, so we call it the virtual root file system, The role is to connect kernel with the real root file system, allowing kernel to initrd the driver needed to load the root file system and mount the root file system in a read-write manner, allowing the first process init of the executing user.

After Init executes, the/etc/inittab file in the system will be launched to complete the initialization of the system.

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.