Linux Kernel Series 1: Introduction and kernel startup Overview

Source: Internet
Author: User

Preface

In the last few months, I have made a rough research on Linux kernel. Next I need to perform in-depth and detailed analysis. It mainly uses a Development Board of S3C2440 as the hardware entity. It includes the following content:

1 bootloader analysis, mainly uboot, combined with the specific situation of the Development Board. My goal is to explain how uboot works (to be honest, I don't want to be kidnapped by hardware during the analysis, but I need to use a practical example.

For analysis)

2. This is a lot of content. We plan to analyze the process starting with the kernel startup.

3 In addition to the kernel itself, there is still a lot of knowledge, such as LD input script analysis. Here we will introduce it together.

Kernel Startup Process Overview

I. kernel image composition 1 ES (embed system) when starting, CPU power-up, the first statement executed is bootloader, which is very similar to the BIOS on a PC. After BL loads the kernel, what is the first statement that the controller transfers to lk2 LK for execution? Vmlinux is a single kernel representation. According to the previous kernel compilation connection knowledge, the first statement is head. S (historical reasons, MD, there are many files called head. s) We need to re-analyze the composition of the kernel (here it is zimage). (The method is very simple. To study the implementation process of make, make v = 1 zimage can get almost all the information)
  • Vmlinux, which is a kernel module without compression and strip, elf Structure
  • Image: binary, uncompressed, but strip Kernel
  • Head. O: Arm-related. Bl transfers control to it. That is, the head. s generation mentioned above
  • Pigg.gz: gzip compression of the image file
  • Piggy. O: generated by piggy. S. This s file contains the image by using the include Bin method. Piggy means carrying and shoulders. Very good image?
  • Misc. O: From the above, it involves some decompression content, while MISC provides some auxiliary functions.
  • Vmlinux: this file is a vmlinux file consisting of head + PIgG + Misc. Is the name the same? Really confusing!
  • Zimage: Compressed from the above vmlinux
Figure 1 shows the process. Figure 1 The composition of the kernel 3 piggy's story piggy.s is very thoughtful, setting up a function, and marking the boundary of piggy.gz. Piggy corresponds to an image named Bootstrap. Note that Bootstrap is different from bootloader. It is a piece of code after BL to decompress the kernel and set the memory. It can also be called Second Stage boot. 4 what is the difference between bootloadre and bootstraploaderbl and BSL?
  • BL only initializes hardware, does not rely on Linux, does not process Linux
  • BSL is executed after BL and depends on Linux because Linux needs to be decompressed. Another important point is that BSL needs to establish an environment for Linux running.
BSL includes:
  • Head. O: Initialize CPU and other work
  • Misc. O: decompress and relocate (for example, moving the kernel to another location) decompress_kernel
  • Other jobs
Init/main. c: start_kernel start call figure 2. figure 2 start the call flow chart below to analyze the head in the START process 1 kernel. O analysis: Keep the CPU family as common as possible, such as arm cpu initialization. But how to initialize a specific Board (such as CPU + other hardware? This is done by the initialization function in the Mach directory. Therefore, kernel Initialization is divided into: Generic CPU initialization + specific Board initialization. Head. O after initialization, jump to main. O start_kernel, continue with the subsequent process 2 start_kernel :( init/main. c): start_kernel is transferred by head. o, but the code is generally included in the more general head_common.s and will be used for Kernel Analysis. Let's start with main. what does start_kernel do?
  • CPU-related initialization was just performed, while start_arch executes the CPU-related initialization.
3. Kernel Parameter Analysis: Kernel command line. Note: this parameter is passed to the kernel by BL, but who sets this parameter? Where does it exist? This line is placed in a global location. In addition, how does the kernel process these parameters? There is a better method, __set_up macro, which stores some parameters and corresponding function pointers in a special section, and then calls the functions in this section cyclically. (Similar to the driver module ). It is defined in init. h. The values of some special parameters are defined in arch/ARM/kernel/vmlinux. LDS. S. (You have to check the manual of LD later) the _ set_up macro also has a flags such as early, which indicates whether the processing stage is in early-stage. It indicates that the memory occupied by section _ init will be discarded.. 4 subsystem initialization: including interruption and so on .? Section nesting section? 5 kernel_init process: start_kernel finally fork a kernel_init process, and the original execution process becomes an idle process .. 6. user space INIT process: the kernel_init process finally completes 7 References through execve init. ELP is a great reference in this book ..

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.