Linux boot process

Source: Internet
Author: User

Processor is a general term, the internal generally contains CPU, on-chip memory, on-chip peripheral interface and other different hardware logic.
The Linux boot process is related to processor configuration, memory configuration, peripheral hardware configuration, and different processor and hardware systems adopt different policies, so the specific boot process will vary. However, regardless of the difference, from the computer system point of view, the startup process is generally divided into three steps. Power on and execute the bootloader program, initialize the operating system kernel, and execute the first application.
The first step is to power on the system, the hardware circuit will generate a deterministic reset timing, to ensure that the CPU is the last device to be reset. Why does the CPU have to be reset at last? Because if the first CPU is reset, when the CPU resets and starts running, the state of the registers inside other hardware may not be ready, such as a disk or memory, then a peripheral hardware initialization error may occur.
When the reset is completed correctly, the CPU starts executing the first instruction, and the memory address of the instruction is fixed, which is set by the CPU manufacturer. Different CPUs may get instructions from different addresses, but this address must be fixed, and the fixed address is often referred to as the "boot Program" (Bootloader), because its role is to load a real user program.
As for how to load, it is a policy problem, different CPUs will provide different loading methods, for example, some are through the common port memory, some are through the SD card, but also through the RS232 interface. Regardless of which interface is mounted on the hardware, the loading process must provide: where to read the user program? What is the length of the user program? Where should I jump after loading the user program, i.e. where is the user program's execution entrance? For ARM processors, when the reset is complete, the processor first executes a small piece of the program on its on-chip ROM. The size of this ROM is generally only a few KB, this program is the bootloader program, this program will be executed according to the processor on some of the high and low status of the pin, choose from the physical interface to load the user program, such as USB port, serial, SD card, and Flash and so on. Most real-world arm-based hardware systems will be loaded from the 0x00000000 address of the NAND flash chip in the same port. For some small embedded systems, the program in this address is the end of the user program to execute, and for Android, the address of the program is not an Android program, but a program called Uboot or FastBoot, its role is to initialize the hardware devices, such as the network port, sdram,rs232, and provide some debugging functions, such as to write new data in NAND Flash, which can be used in the development process of kernel burning, upgrading and so on. When Uboot (FastBoot) is loaded and starts to run, it will generally detect if the user has pressed some special keys, which are uboot pre-agreed at compile time for entering debug mode. If the user does not press these special keys, Uboot will load the Linux kernel from NAND flash, and the loaded address is pre-agreed when compiling uboot.
The second step is to execute the kernel program, the kernel program described here is the "user program" in the previous step. Because from the CPU point of view, all except Bootloader program is the user program, but from the software point of view, the user program is divided into kernel programs and applications. After the Linux kernel is loaded, the kernel initialization process begins. The operations that are performed when the kernel program is initialized include initializing various hardware, including memory, network interface, display, input device, and then establishing various internal data structures that will be used for multi-threaded scheduling and memory management. Boot steps for the Linux kernel:

Function name Source path of the kernel Describe
Start () ./arch/xxx/boot/head. S Assembly language, perform some configuration of the CPU registers, and call the Startup_32 () function
Startup_32 () ./arch/xxx/boot/compress/head. S assembly language, configuring the stack, and emptying the BSS segment
Decompress_kernel () ./arch/xxx/boot/compress/misc.c C language function, used to extract the kernel, the Linux kernel image file is a zlib compressed format of data, so you need to extract the first
Startup_32 () ./arch/xxx/kernel/head. S The CPU page table configuration, mainly for virtual memory, and detect whether the CPU has floating-point processing Unit (FPU) support, at this time the process is a system process, that is, process No. 0
Start_kernel () ./init/main.c The kernel internal data is initialized, the interrupt vector table is configured, the RAMDisk is mounted, and finally the Kernel_thread () method is called
Kernel_thread () ./arch/xxx/kernel/process.c The method will start a different application according to the configuration of a text file called Init.rc in RAMDisk, the first program to start is a user-level program
Cpu_idle () ./init/main.c At this point, the kernel can be scheduled according to the priority of the process, and when no other process is running, the method is called

The content format of init.rc is similar to a script, but it is not a standard Linux script, but a script that is only used for startup. When the kernel program is initialized, it starts running the specific application. In general, it is customary to refer to the first application as a "home program."
The third step is to run the home program, such as the Windows system's desktop is a typical home program. This is called the home program because it makes it easy to start other applications. While the traditional Linux system started, the first running program is generally a terminal, although it appears like a DOS interface, but it can also be called the Home program, because the goal of Home program is to provide a portal, users can launch other applications through the portal.

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.