# Based on v2.6.26 Kernel
Compiling and generating kernel target files using Linux kernel makefile
Directly execute the make compilation process
- 1. First find the entry point (Entry Point Problem)
# Compile the kernel line502 and directly execute make to compile all: vmlinux # compile the module line1037 by default. If you select the compilation module, this will be the case. There are also many other all: Target instances, why is all: vmlinux executed by default? ALL: modules
- 2. Continue to find the vmlinux target
# Vmlinux image-including updated kernel symbols # vmlinux targets at line806 vmlinux: $ (vmlinux-LDS) $ (vmlinux-init) $ (vmlinux-Main) vmlinux. o $ (kallsyms. o) force # force is a pseudo-target. Make assumes that the time stamp of the pseudo-target is always the latest, that is, it is always modified, therefore, the "target" and "vmlinux" with it as "dependency" are compiled every time you make.
- 3. Understand the functions of $ (vmlinux-LDS) $ (vmlinux-init) $ (vmlinux-Main ).
# Line656 vmlinux-init: = $ (Head-y) $ (init-y) #-y indicates that if yes is configured, the kernel is added, and-M indicates that the module is configured, -N indicates that no kernel is added to vmlinux-Main :=$ (core-y) $ (libs-y) $ (drivers-y) $ (net-y) vmlinux-All :=$ (vmlinux-init) $ (vmlinux-Main) vmlinux-LDS: = ARCH/$ (srcarch)/kernel/vmlinux. LDS # srcarch is the architecture name. Here we use x86
Generated vmlinux. the target file of LDS is the link description file LD script for generating the vmlinux image. From this file, we can see that the head of the vmlinux image is $ (Head-Y) $ (init-y). The main part of the vmlinux image is $ (core-y) $ (libs-y) $ (drivers-y) $ (net-Y. for details, we can carefully study lD.
Script to make i386 Linux kernel.
Vmlinux image ###################################### ##################$ (Head-y) # $ (core-y) $ (libs-y) ##$ (init-y) # $ (drivers-y) $ (net-y), etc. ######################################## ################
- Find the files contained in $ (vmlinux-init) or $ (Head-y) $ (init-y)
Find init-y first, and easily solve the problem as follows:
# Line452 init-Y: = init/# line621 init-Y: = $ (patsubst %/, %/built-in.o, $ (init-y )) # Replace "/" in the $ (init-y) list with "/built-in.o", that is, the final init-y = init/built-in.o
The init/built-in.o target is generated under the init Directory, which contains the start_kernel function, which is a point from the startup code to the Linux kernel.
We cannot find the head-y definition in the MAKEFILE file in the root directory, so head-y must be in a file that is included. by searching include, we found that head-y may be in/ARCH/x86/makefile.
# line431 include $(srctree)/arch/$(SRCARCH)/Makefile
Sure enough, find head-y in/ARCH/x86/makefile,
# Line161 head-Y: = ARCH/x86/kernel/head _ $ (BITs ). O ## bits is the definition of the number of BITs processed by the CPU. We use a 32-bit CPU, which is directly replaced by 32 here, the file is head_32.o head-y + = ARCH/x86/kernel/head $ (BITs ). O # head32.o head-y + = ARCH/x86/kernel/init_task.o
- Summary of general rules for vmlinux Image Generation
Through the above analysis path
all --> vmlinux --> $(vmlinux-lds) $(vmlinux-init) --> $(head-y) $(init-y) -- --> built-in.o head32.o head_32.o init_task.o --> *.c *.S
We can have a general concept, that is, through Kernel configuration information, we have a XXXX-y target list, which is generated in sequence through deep traversal, and finally generate the vmlinux.
As for how the Kernel configuration information maps with the target list of XXXX-Y and the remaining directory files, it also needs to be analyzed more carefully.
- Bzimage-subsequent processing of vmlinux Images
We can also find the subsequent processing of the vmlinux image in/ARCH/x86/makefile. The bzimage will be
bzimage #################################################### # # # # # Setup # uncompress code # compressed vmlinux # # # # # ####################################################
Next, let's take a look at the makefile for subsequent processing of the vmlinux image. First, we need to find the starting point:
# Line200 of/ARCH/x86/makefile #### Boot Loader support. several targets are kept for legacy purposes boot: = ARCH/x86/boot phony + = zimage bzimage compressed zlilo bzlilo \ zdisk bzdisk fdimage fdimage144 upgrade isoimage install # default kernel to build all: bzimage # kbuild_image Specify target image being built kbuild_image :=$ (BOOT)/bzimage zimage zlilo zdisk: kbuild_image: = ARCH/x86/boot/zimage bzimage: vmlinux $ (q) $ (make) $ (build) = $ (BOOT) $ (kbuild_image) # Run The makefile in the arch/x86/boot directory $ (q) mkdir-p $ (objtree) /ARCH/$ (uts_machine)/boot $ (q) ln-FSN .. /.. /x86/boot/bzimage $ (objtree)/ARCH/$ (uts_machine)/boot/bzimage compressed: zimage