This is a detailed explanation of kernel compilation.
Source: Internet
Author: User
Article title: this is a detailed explanation of kernel compilation. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
1. Linux kernel source code structure: The kernel source code mainly contains the following sub-directories:
Arch: contains the code related to the architecture
Each supported architecture has a subdirectory such as i386, arm, and alpha.
Each of its architecture subdirectories contains several main subdirectories:
Kernel: contains kernel code related to the architecture
Mm: Contains memory management code related to the architecture
Lib: contains the library code related to the architecture
Documentation: contains the Kernel documentation.
Drivers: contains the device driver code. Each type of device has its own subdirectories, such as char, block, and net.
Fs: contains the code of the file system. Each supported file system has corresponding subdirectories, such as ext2 and proc.
Include: the kernel header file, which has corresponding subdirectories for each architecture.
Init: contains the kernel initialization code.
Lib: contains the library code of the kernel.
Mm: Contains memory management code.
Kernel: contains the kernel management code
Net: code that contains the network.
2. System guidance process System startup process on PC:
After the system is powered on, the bois completes the monitoring settings for the system and then delivers the control to the BootLoader in the MBR on the hard disk. here it is lilo or grub.
BootLoader transfers the operating system code to the memory, and then gives the control to the Setup. S program in arch/i386/boot.
Setup. S this program performs basic detection and settings on the system in 386 real-time mode, and then transfers the control to Head. S in protection mode.
After Head. S establishes a framework for memory management and interrupt management, call the start_kernel () function in init/main. c to log on to and use linux after start_kernel is executed. The Start_kernel () function is defined in init/main. c.
The main steps in the Start_kernel process are as follows:
Setup_arch (& command_line) is used to initialize the most basic hardware-related parts such as the processor and memory. Defined in arch/i386/kernel/setup. c;
Parse_options (command_line); separates the parameters obtained at startup from the command line string and assigns them to the corresponding variables. Defined in init/main. c;
Trap_init (); initializes the interrupt vector table. Defined in arch/i386/kernel/trap. c;
Init_IRQ (); interrupt-related initialization, defined in arch/i386/kernel/i8259.c;
Sched_init (); process scheduling initialization. Defined in kernel/sched. c;
Softirq_init (); defined in kernel/softirq. c;
Time_init (); initialize the time part. Defined in arch/i386/kernel/time. c;
Lele_init (); initialize the terminal. Defined in drivers/char/tty_io.c;
Buffer_init (mempages); initialize the buff free list used to indicate the block cache. Defined in fs/buffer. c;
Mem_init (); memory management initialization. Defined in arch/i386/mm/init. c;
Rest_init (); called in this function
Kernel_thread (init, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGNAL) function calls init/main. the init () function in c will create two new kernel threads, dbflush and kswapd, in the init () function. Initialize the tty1 device. Find/etc/init or/sbin/init or/bin/init to create an init process.
The Init process checks the file system according to the/etc/inittab file, starts the system daemon process, establishes the getty process for the online terminal, and executes the command file under/etc/rc.
After that, getty will display a login prompt on the terminal to wait for the user to log on.
3. use make to build the kernel 1. run the make menuconfig command:
Use the following compilation options:
Processor type and features --->
(Pentium-Pro/celeon/Pentium-II) Processor family
(3 GB) Maximum Virtual Memory
General setup --->
(ELF) Kernel core (/proc/kcore) format
[*] Kernel support for ELF binaries
File systems --->
[*]/Proc file system support
[*] Second extended fs support
ATA/IDE/MFM/RLL support --->
[*] ATA/IDE/MFM/RLL support
[*] Enhanced IDE/MFM/RLL disk/cdrom/tape/floppy support
[*] Include IDE/ATA-2 DISK support
Character devices --->
[*] Virtual terminal
Console drivers --->
[*] VGA text console
The size of the generated kernel bzImage is 309892 bytes;
This kernel can successfully boot the system on the pc
This command is used to generate a file. config which defines the corresponding variables according to your selection in menuconfig. This file will be included in the Makefile.
2. use the make dep command to establish the dependency.
3. run the make bzImage command to create the kernel.
If the settings are correct, the kernel bzImage file will be generated in the arch/i386/boot/directory.
4. a brief description of the make bzImage process
When we use the make command, the make program will first find the Makefile file in the current directory. Process according to the Makefile syntax.
The main Makefile contains arch/i386/Makefile. the target bzImage of make is determined in this file:
BzImage: vmlinux
@ $ (MAKEBOOT) bzImage # This command will be interpreted as: make-C arch/i386/boot bzImage
Now make needs to first create the target vmlinux and then execute make bzImae in the arch/i386/boot/directory. Now, assuming that the vmlinux target has been generated, the make program under the arch/i386/boot directory will perform the following operations:
Tools/build-B bbootsect bsetup compressed/bvmlinux. out./bzImage
Compress vmlinux with tools/build tools into the target file bzImage (in this process, a build program will be built to convert vmlinux to bvmlinux. for more information, see Makefile files in the tools and compressed directories ).
Generate vmlinux targets:
The vmlinux generation rules in the Makefile file in the main directory are as follows:
Vmlinux: $ (CONFIGURATION) init/main. o init/version. o linuxsubdirs
$ (LD) $ (LINKFLAGS) $ (HEAD) init/main. o init/version. o -- start-group $ (CORE_FILES) $ (DRIVERS) $ (NETWORKS) $ (LIBS) -- end-group-o vmlinux # generate vmlinux
$ (NM) vmlinux | grep? V \ (compiled \) \ | \(\. o $ \) \ | \ ([aUw] \) \ | \(\. \. ng $ \) \ | \ (LASH [RL] DI \) | sort> System. map # This command generates System based on vmlinux. map file
In the current settings, this ld connection command is interpreted: Ld-m elf_i386-T/home/arm/linux/arch/i386/vmlinux. lds-e stext arch/i386/kernel/head. o arch/i386/kernel/init_task.o init/main. o init/version. o -- start-group arch/i386/kernel. o arch/i386/mm. o kernel/kernel. o mm/mm. o fs/fs. o ipc/ipc. o drivers/char. o drivers/block. o drivers/misc. o drivers/net. o drivers/media. o drivers/ide/idedriver. o drivers/video. o net/network. o/home/arm/linux/arch/i386/lib. a/home/arm/linux/lib. a/home/arm/linux/arch/i386/lib. a -- end-group-o vmlinux
That is, the connection program ld connects each. o file to the target file vmlinux.
The. o file make program used in this command will be automatically generated according to the rules of the Makefile file. the following briefly introduces the process of generating ipc. o from the ipc Directory:
The content of Makefile in the ipc directory is as follows:
O_TARGET: = ipc. o
Obj-y: = util. o
Obj-$ (CONFIG_SYSVIPC) + = msg. o sem. o shm. o
Include $ (TOPDIR)/Rules. make # The contained Rules. make file contains general Rules;
For example, if the SYSVIPC option is selected during make menuconfig. the config file defines the variable CONFIG_SYSVIPC = y; then obj-y is equal to util. o msg. o sem. o shm. o; according to Rules. make adds four. the c file is compiled. o file. Connect the four. o files to the ipc. o file. In our current settings, no SYSVIPC is selected. Only one util. o file is used to generate the target ipc. o, and util. o is generated by util. c.
After all the required. o files are generated, ld will connect them to generate the vmlinux file, and then compress it into the required kernel file bzImage. The Make program is finished.
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.