Linux system start-up process on ARM platform

Source: Internet
Author: User

Start learning embedded development has been using the Linux system as a learning platform, and now whether the PC or ARM Development Board has been able to successfully run the Linux system, but the Linux startup process is still not well understood. So began a variety of Baidu Google, of course, saw the way the great God wrote the introduction. In general: bootloader---->kernel---->root filesystem, and of course describes which stage of the work is done. For example, Bootloader is a power to get the control of the CPU, and bootloader to achieve 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. Take s3c2440 this chip (my hardware platform is to take this chip as the main chip), the CPU internal integration of a capacity of 4KB SRAM (also known as stapping stone stepping stone), when the system is a power, NAND controler automatically to the NAND The top 4K content in Flash is copied into the stepping stone, while the PC pointer is on the power-up point to the starting address of the stepping stone, 0x00000000. This part of the code can then be executed. Can you imagine that if this part of the code is part of the bootloader, then the 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. All right, come on, get to the subject now.

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 NIC, 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. Where Vmlinux is an object file in the ELF format, which is a file that is only obtained after each source code is connected and cannot be run on an arm platform. 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. Image file has been compressed after the piggy.gz, this file is only the compressed version of image, and no other difference. Then compile and generate several additional module files MISC.O big_endian.o head.o head-xscale.o, which make up a component called Bootstrap loader, also known as the bootloader. Compile the build piggy.o file. The last piggy.o file and 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.

The following is a discussion of the CPU flow process:

Or a graph to show:

As can be seen, the system starts to execute bootloader when the bootloader executes, the control is handed to the start label in the HEAD.O file of the boot program, and the control is transferred to the real kernel HEAD.O after the boot process completes the boot work. The start label in the file. 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:

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

1. Enable I/D caches, shut down interrupts, establish C run environment (that is, set stack) completed by HEAD.O and HEAD-XSCAL.O

2. Unzip and reposition the code, completed by MISC.O

3. Other hardware-related settings, such as BIG.ENDIAN.O for the CPU to set the big-endian mode

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

1. Check for valid CPU and CPU information

2. Create 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.

 

Linux system start-up process on ARM platform

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.