Linux boot process

Source: Internet
Author: User

After bootloader copies the Linux kernel image to RAM, you can start the Linux kernel with the following example code:
Call_linux (0, Machine_type, kernel_params_base).

Where Machine_tpye is the processor type detected by bootloader, Kernel_params_base is the address of the boot parameter in RAM. In this way, the required parameters for Linux boot are passed from bootloader to the kernel.

The Linux kernel has two images: a non-compressed kernel called image, and the other is its compressed version, called Zimage. Depending on the kernel, the startup of the Linux kernel is different at the start stage. Zimage is a compressed image, so it is smaller than image. But in order to be able to use Zimage, you must add the extracted code at the beginning of the zimage to extract it before execution, so it executes slower than image. For ARM series processors, the Zimage entry program is Arch/arm/boot/compressed/head. S It does the following in turn: Open the MMU and cache, invoke Decompress_kernel () to extract the kernel, and finally enter the boot of the uncompressed kernel image by calling Call_kernel (). The following is a detailed analysis of the Linux kernel boot process after this.

1. Linux Kernel entry

The entry for the Linux uncompressed kernel is located in file/ARCH/ARM/KERNEL/HEAD-ARMV. The stext segment in S. The base address of the segment is the jump address of the compressed kernel after decompression. If the kernel loaded by the system is a uncompressed image, then bootloader copies the kernel from flash to ram and jumps directly to that address to start the Linux kernel. The entry files for Linux systems of different sizes are different, and because the file is related to the specific architecture, it is generally written in assembly language. For an ARM processor-based Linux system, this file is HEAD-ARMV. S The program calls the appropriate initialization function by looking for the processor kernel type and processor type, then establishes the page table, and finally jumps to the Start_kernel () function to start the kernel initialization work.

The assembly sub-function that detects the processor kernel type is completed in __lookup_processor_type, which can be called by the following code: BL __lookup_processor_type

When the __lookup_processor_type call finishes returning to the source program, the returned results are saved to the register. Where R8 holds the flag bit of the page table, R9 holds the processor ID number, R10 holds the processor-related struct proc_info_list structure address.

The detection processor type is done in assembly sub-function __lookup_architecture_type. Similar to __lookup_processor_type, it uses the code: "BL __lookup_processor_type" to make calls to it. When the function returns, the return structure is saved in the R5, R6, and R7 three registers. Where R5 holds the starting base address of the RAM, R6 saves the I/O base address, R7 the page table offset address where I/O is saved.

When the detection processor core and processor type end, the __create_page_tables child function will be called to establish the page table, it is to do the work is to start the RAM base of the 4M space to map the physical address to the beginning of the 0xC0000000 virtual address. For the author's s3c2410 Development Board, RAM is connected to the physical address 0x30000000, and 0x30000000 ~ 0x30400000 Physical Address is mapped to 0XC0000000~0XC04 when the call __create_page_tables ends 00000 at the virtual address.

When all initialization is complete, use the following code to jump to the C program's entry function Start_kernel (), starting with the kernel initialization work: b symbol_name (Start_kernel)

2. Start_kernel function

Start_kernel is the entry function of all Linux platforms after the initialization of the system kernel, it mainly completes the remaining hardware platform related initialization, after a series of kernel-related initialization, invokes the first user process init process and waits for the user process to execute. This will enable the entire Linux kernel to complete.

The function does this by calling the Setup_arch () function to perform the first initialization work related to architecture, which is defined differently for different architectures. For ARM platforms, this function is defined in the ARCH/ARM/KERNEL/SETUP.C

It first initializes the processor core through the detected processor type, then initializes the memory structure with the Bootmem_init () function based on the system-defined meminfo structure, and finally calls Paging_init () to open the MMU and create the kernel page table. Maps all the physical memory and IO space. Create exception vector table and initialize interrupt handler function, initialize system core process scheduler and clock interrupt processing mechanism, initialize serial port console (serial-console), create and initialize system cache, provide cache for various memory call mechanisms, including dynamic memory allocation, Virtual file systems (Virtualfile System) and page caching. Initializes memory management, detects memory size and memory consumed by the kernel, and initializes the interprocess communication mechanism (IPC) of the system;

When all of the above initialization work is complete, the Start_kernel () function calls the Rest_init () function for final initialization, including creating the first process of the system-init process to end the boot of the kernel.

The init process first carries out a series of hardware initializations and then mounts the root filesystem with the parameters passed by the command line. The final init process executes the user-specified command by executing the "init=" startup parameter passed by the user, or performs one of the following processes:
Execve ("/sbin/init", Argv_init,envp_init)
Execve ("/etc/init", Argv_init,envp_init)
Execve ("/bin/init", Argv_init,envp_init)
Execve ("/bin/sh", Argv_init,envp_init)
When all initialization is done, the Cpu_idle () function is called to leave the System idle (idle) and wait for the user program to execute. This completes the entire Linux kernel.

Linux boot process

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.