Linux kernel compilation instructions
1.Linux kernel source structure:
The following subdirectories are mainly included in the kernel source code:
Arch: Contains code related to architecture
Corresponding to each supported architecture, there is a corresponding sub-directory such as I386, ARM, Alpha, etc.
Each architecture subdirectory contains several major subdirectory:
KERNEL: Contains kernel code related to architecture
MM: Contains memory management code related to the architecture
LIB: Contains library code related to architecture
Documentation: Contains documents
Drivers: Contains device driver code. Each type of equipment has a corresponding subdirectory, such as char, block, net, etc.
fs: The code containing the file system. Each supported file system has a corresponding subdirectory, such as EXT2, PROC, etc.
Include: Nuclear head file, there is a corresponding subdirectory for each architecture.
Init: contains the core initialization code
LIB: Code containing the kernel
MM: Contains memory management code
KERNEL: Contains kernel management code
NET: The code containing the network part
2. The process of system boot
The system startup process on the PC:
After the system is powered up, BOIS is completed after the system completes the monitoring settings, and the control is handed over to the bootloader in the MBR on the hard disk, which is LILO or GRUB.
BootLoader Tumbs up the operating system code into memory and then handles control to the setup.s of Arch / i386 / boot.
SETUP.S This program is submitted to the system after 386 real mode to transfer control mode to HEAD.S.
Head.s creates a framework for memory management and interrupt management, and then call the start_kernel () function in init / main.c after start_kernel execution, the user can log in and use Linux. The Start_kernel () function is defined in init / main.c.
The main steps in the process of start_kernel:
Setup_arch (& Command_Line); initialization for the most basic hardware related part of the processor, memory, etc. Definition in Arch / I386 / Kernel / Setup.c;
PARSE_OPTIONS (Command_Line); separating the parameters obtained from the startup from the string of the command line and assigns the corresponding variable. Definition in init / main.c;
TRAP_INIT (); initialization of the interrupt vector table. Definition in Arch / I386 / Kernel / Trap.c;
INIT_IRQ (); Initialization related to the interrupt, defined in Arch / I386 / Kernel / I8259.c;
SCHED_INIT (); Process Scheduling Initialization. Definition in kernel / sched.c;
Softirq_init (); defined in Kernel / Softirq.c;
Time_init (); time part initialization. Definition in Arch / I386 / Kernel / Time.c;
Console_init (); initialization of terminals. Definition in drivers / char / tty_io.c;
Buffer_init (MEMPAGES); initialization of BUFF Free LIST used to indicate block cache. Definition in fs / buffer.c;
MEM_INIT (); Memory Management Initialization. Definitions in Arch / I386 / MM / INIT.C;
REST_INIT (); this function is called
Kernel_thread (init, null, clone_fs | clone_files | clone_signal) The init () function in init / main.c will establish DBFLUSH, KSWAPD two new kernel threads in the init () function. Initialize the TTY1 device. Look for / etc / init or / sbin / init or / bin / init to create an init process. The init process performs file system check according to the / etc / inittab file, and the launch system daemon is established to establish a getty process, execute the command file under / etc / rc.
Thereafter, getty will display the login prompt on the terminal to wait for the user to log in.
3. Establish the kernel using Make
1. Using the make metronfig command:
Use the following compilation options:
Processor Type and Features --->
(Pentium-Pro / Celeron / Pentium-II) Processor Family
(3GB) 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
Generate kernel BZIMAGE size is 309892 byte;
This core can successfully boot the system on the PC
This command generates a file .config defines the corresponding variables according to the selection you in MenuConfig. This file will be included in the Makefile file.
2. Establish dependencies using the Make DEP command.
3. Establish the kernel using the make bzimage command.
If the settings are correctly generated in the Arch / I386 / Boot / Directory, the kernel BZIMAGE file is generated.
4. Make Bzimage process brief description
When we use the make command, the Make program will first find the Makefile file in the current directory. Process according to the grammar of the Makefile file.
In the main Makefile file, the target BZImage is included in this file in this file:
BZIMAGE: VMLinux
@ $ (Makeboot) BZImage # This command will be explained as: make -c arch / i386 / boot bzimage
Now Make needs to create the target VMLinux and then execute the Make Bzimae under the Arch / i386 / boot / directory. We now assume that the VMLinux target has been generated, then the Make program under the Arch / i386 / boot directory will do the following:
Tools / build -b bbootsect bsetup compressed / bvmlinux.out ./ bzimage
It is about to compress the VMLinux with the Tools / Build tool to target the target file BZImage (in the process, Build programs will be built, converting VMLinux into bvmlinux.out, etc., refer to the Makefile file under Tools and Compressed directories).
Generate a VMLinux goal:
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 /
$ (More_files) /
$ (Drivers) /
$ (NetWorks) /
$ (LIBS) /
--end-group /
-o vmlinux # Born VMLinux
$ (Nm) VMLinux | grep -v / (compiled /) / | / (/. O $$ /) / | / ([AUW] /)/|/ (/.ng $$/ )/|// (Lash [RL] DI /) | Sort> System.map # This command generates system.map file according to VMLinux
This LD connection command is interpreted as:
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 / kernel.o Arch / i386 / mm / mm.o kernel / kernel.o mm / mm.o fs / fs.o IPC / IPC.O drivers / char / char. O drivers / block / block.o drivers / misc / misc.o drivers / net / net.o drivers / media / media.o drivers / IDE / IDEDRIVER.O Drivers / Video / Video.o Net / Network.o / Home /ar/linux/arch/i386/lib/lib.a /Home/arm/linux/lib/lib.a /Home/arm/linux/arch/i386/lib/lib.a - GROUP -O VMLinux
That is, the connection program LD connects each .o file into the target file VMLinux.
The respective .o file Make programs used in this command automatically generates according to the rules of the Makefile file, the following brief introduction, generates the IPC.o process by the IPC directory:
The contents of the Makefile file in its IPC directory are as follows:
O_target: = ipc.o
Obj-y: = util.o
Obj - $ (config_sysvipc) = msg.o sem.o shm.o
Include $ (TOPDIR) /Rules.make # contains universal rules in the rules.make file;
If we select the sysviPC option when Make MenuConfig, the .config file will define the variable config_sysvipc = Y;, OBJ-Y is equal to util.o msg.o sem.o shm.o; four in rules.make. The C file is compiled into .o file. Then the four .o files are connected to IPC.o files. No sysvipc is selected in our current settings; will only use Util.o file to generate target ipc.o; but Util.o is generated by util.c.
When all the needs .o file generation, connect it to the VMLinux file by LD, then compress it into the kernel file Bzimage we need. The Make program is finished.
September 13, 2002