ARM Linux starts the process from bootloader, kernel to filesystem

Source: Internet
Author: User

Transferred from: http://www.veryarm.com/1491.html

The ARM Linux startup process is roughly:bootloader ---->kernel---->root filesystem. Bootloader is a power-up to get control of the CPU, and bootloader implements the initialization of the hardware. Bootloader has become the "first to eat crab" code after power on.

When it comes to this, you have to think about how the hardware mechanism fulfills this function. The CPU is generally integrated with small capacity SRAM (also known as stapping Stone, stepping stone), when the system is on,NAND controler automatically copies the former content of NAND flash into the stepping stone , while the PC When the pointer is on, it points to the starting address of the stepping stone, 0x00000000. This part of the code can then be executed. So, this part of the code is the bootloader part, that a power bootloader can not be run? This is true, in the embedded Linux software system, nandflash the front part of the code is often bootloader, then kernel, and then the root file system.

Said so much, as if they did not mention the start-up process ah, don't worry, we slowly talk, so-called AX.

To say that the start-up process, if only a simple introduction from where to where, who did what, the results may be just know it does not know why. Personally feel that with the CPU of the PC pointer, follow the code of the footsteps of the entire process clear, when the code to find the implementation process, and then analyze the code, naturally know which part of the completion of what things, more importantly, for the code to 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 it is also a kind of exercise.

Bootloder

Said before, bootloader a power on the use of the CPU, of course, it has to do some initialization work ah, such as the shutdown watchdog, set the CPU operating mode, set up the stack, and so 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, and finally responsible for loading the Linux kernel into memory. The so-called responsibility and Power are coexisting, you get the rights, of course, have to pay. When Bootloader completes its mission, it will hand over the use of the CPU to the next part of the code: kernel.

Kernel

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

The following diagram illustrates the compilation process above,

You can see that when the kernel source file is compiled and linked into a vmlinux file, several modules are compiled and linked. which

(1) Vmlinux is an object file in the ELF format, which is a file that is obtained after the connection of each source code and cannot be run on an arm platform .

(2) After objcopy This tool conversion, got the binary format file image,image file compared to the Vmlinux file, in addition to the format is different, but also removed a lot of comments and debugging information .

(3) Image file has been compressed after the piggy.gz, this file is only the compressed version of image, 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 form a component called Bootstrap loader , also known as the bootloader . Compile the build piggy.o file.

(5) The final piggy.o file and the bootstrap loader form a bootable kernel Image file (bootable file).

You can see that the last executable is the rightmost one, which is the last image we burn to the Development Board. Where PIGGY.O is the kernel image, and the remaining files make up the boot program.

Let's start with a discussion of the CPU flow, or a graph to show:

As you can see, the system starts to execute bootloader as soon as it is power on. When the bootloader executes, the control is given to the start label in the head.o file of the bootloader, and when the bootloader completes the boot process, the control is transferred to the start label in the HEAD.O file of the real kernel. This is the kernel entry point, and the last kernel HEAD.O will control the Start_kernel function to MAIN.O. This way, by looking at the code, you know exactly what the code is doing. Here we can find the corresponding code, analyze it, see what they have done. here is my analysis of the results :

Boot program:

HEAD.O took control from Bootloader and completed the following tasks:

    1. Enable I/D caches, shut down interrupts, establish C run environment (i.e. set stack) completed by HEAD.O and HEAD-XSCAL.O
    2. Unzip and reposition the code, done by MISC.O
    3. Other hardware-related settings, such as BIG.ENDIAN.O to set the big-endian mode for the CPU

Kernel entry point : Take control from the bootloader and complete the following tasks

    1. Check for valid CPU and CPU information
    2. Creating an initialization Page table entry
    3. Enable MMU
    4. Detect Errors and report
    5. Jump to the Start_kernel () function in the main.c file of the kernel itself
Kernel boot:

Take control from Kernel's HEAD.O, start the kernel startup, and complete the initialization of the kernel, 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 transfer to the user space, the kernel space through an indirect initrd (a virtual file system) to the user space over , and then began to mount the root filesystem , its process:initrd ----> /sbin/init ----> /etc/inittab.

INITRD is a virtual file system with Lib, bin, sbin, usr, proc, sys, VAR, dev, boot and other directories, the directory is a bit like real/, so we call it virtual root filesystem , The function is to establish an association relationship between the kernel and the true root filesystem, allowing kernel to load the driver required by the root filesystem in Initrd and mount the root filesystem in a read-write manner, and let the first process initof the user be executed.

When Init executes, the/etc/inittab file in the system is started to complete the initialization of the system system.

ARM Linux starts the process from bootloader, kernel to filesystem

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.