[Deven] kernel image composition analysis in Linux kernel makefile

Source: Internet
Author: User
Tags dio gz file network function
######################################## ###
# Compile and generate the file relationship on which zimage depends

1. kernel image composition
1.1 zimage File
The kernel image is the zimage file generated in the $ (topdir)/ARCH/$ (ARCH)/boot/directory. Analysis $ (topdir)/ARCH/$ (ARCH)/boot/makefile: The file is merged by bootsect setup compressed/vmlinux using the build tool.

1.2 compressed/vmlinux files
Further analysis of $ (topdir)/ARCH/$ (ARCH)/boot/compressed/makefile: Compressed/vmlinux is determined by head. o, MISC. o, piggy. O these three files are connected by LD and the starting address of the code segment is 0x1000 or 0x100000 with the "-ttext $ (zimage_offset)" parameter.

1.3 piggy. o file
Piggy. O is not compiled from the source file. Continue to analyze $ (topdir)/ARCH/$ (ARCH)/boot/compressed/makefile and learn that it is caused by $ (topdir) /For vmlinux, use the "gzip-F-9 <$ (topdir)/vmlinux> unzip tmppiggy.gz command to compress the variable tmppiggy.gz file, and then use" $ (LD)-R-o piggy. o-B binary ‑encoded tmppiggy.gz-B elf32-i386-T $ tmppiggy. lnk is linked to Piggy. o. A simple understanding is to compress $ (topdir)/vmlinux and then link it to Piggy. O.

1.4 $ (topdir)/vmlinux File
$ (Topdir)/vmlinux is the real system, and some initialization code is linked with it. $ (Topdir)/vmlinux get through analysis $ (top)/makefile: it is obtained by the operating system core (kernel directory), Driver (DRIVERS directory), network system (net directory) C language library function implementation (lib directory. o file. Which. O files are determined by specific configuration.
$ (LD) $ (linkflags) $ (head) init/Main. O init/version. O/
-- Start-group/
$ (Core_files )/
$ (Drivers )/
$ (Networks )/
$ (Libs )/
-- End-group/
-O vmlinux
So far, we have explained the composition of kernel images.

2. What are the kernel images?
2.1 zimage File
Bootsect: compiled by boot/bootsect. S. This module is the boot program in the first sector of the disk. It moves itself to 0x9000: 0x0000, reads setup to 0x9000: 0x0200, reads the kernel to 0x1000: 0000, then jump to the Code 0x90200 of setup to execute.
Setup: compiled by setup. s and video. s under Boot. This module initializes some simple hardware, initializes IDT and gdt, and then enters the protection mode by saying "movw, % ax; lmsw % ax;". jmpi 0x100000, _ kernel_cs jumps to the kernel.
Compressed/vmlinux: from now on, it is pure 32-bit code and enters the protection mode.

2.2 compressed/vmlinux files
Head. O: compiled by boot/compressed/head. S. Clear the data segment, initialize the interrupt, copy the startup parameters and bios parameters, initialize the page, update gdt, IDT, segment register, and reserve the system stack, and finally execute start_kernel to transfer to pure C code.
Misc. O: compiled by boot/compressed/Misc. C and $ (topdir)/lib/inflate. C.
Piggy. O: Compressed by $ (topdir)/vmlinux.

2.4 $ (topdir)/vmlinux File
According to the specific configuration, we will not go into details.

Zimage (makefile;> ARCH/i386/makefile;-> ARCH/i386/boot/makefile zimage ;)
|-> Bootsect
|-> Bootsect. o
|-> Bootsect. s
|-> Setup
|-> Setup. o
|-> Setup. s
|-> Compressed/vmlinux (ARCH/i386/boot/compressed/makefile-C compressed vmlinux ;)
| -- $ (Topdir)/vmlinux
|-> Head. o
|-> Head. s
|-> Misc. o
|-> Misc. c
|-> Piggy. o
|-> $ (Topdir)/vmlinux (use objcopy to the local directory, compress it with gzip, and link LD to Piggy. O)
| -- $ (Configure) & tools/build

######################################
Vmlinux ($ (top)/makefile)
{
(Defined in arch/i386/makefile)
Head: = ARCH/i386/kernel/head. o arch/i386/kernel/init_task.o

(Defined in $ (top)/makefile)
Subdirs = kernel drivers mm FS net IPC lib
Core_files = kernel/kernel. O mm/mm. O fs/fs. o ipc/IPC. o
Networks = net/network. o
Libs = $ (topdir)/lib.

Drivers-N: =
Drivers-Y: =
Drivers-M: =
Drivers-: =

Drivers-$ (config_acpi) + = Drivers/ACPI. o
Drivers-$ (config_parport) + = Drivers/parport/driver. o
Drivers-y + = Drivers/Char. O/
Drivers/block. O/
Drivers/MISC/Misc. O/
Drivers/NET/net. O/
Drivers/Media/media. o
Drivers-$ (config_agp) + = Drivers/Char/AGP. o
Drivers-$ (config_drm_new) + = Drivers/Char/DRM. o
Drivers-$ (config_drm_old) + = Drivers/Char/drm-4.0/DRM. o
Drivers-$ (config_nubus) + = Drivers/nubus.
Drivers-$ (config_isdn) + = Drivers/ISDN.
Drivers-$ (config_net_fc) + = Drivers/NET/FC/Fc. o
Drivers-$ (config_appletalk) + = Drivers/NET/appletalk. o
Drivers-$ (config_tr) + = Drivers/NET/tokenring/tr. o
Drivers-$ (config_wan) + = drivers/NET/WAN. o
Drivers-$ (config_arcnet) + = Drivers/NET/ARCNET/arcnetdrv. o
Drivers-$ (config_atm) + = Drivers/ATM. o
Drivers-$ (config_ide) + = Drivers/IDE/idedriver. o
Drivers-$ (config_fc4) + = Drivers/FC4/fc4.a
Drivers-$ (config_scsi) + = Drivers/SCSI/scsidrv. o
Drivers-$ (config_fusion_boot) + = Drivers/message/fusion. o
Drivers-$ (config_ieee1394) + = Drivers/ieee1394/ieee1394drv. o

Ifneq ($ (config_cd_no_idescsi) $ (config_blk_dev_idecd) $ (config_blk_dev_sr) $ (config_paride_pcd ),)
Drivers-y + = Drivers/CDROM/driver. o
Endif

Drivers-$ (config_sound) + = Drivers/sound/sounddrivers. o
Drivers-$ (config_pci) + = Drivers/PCI/driver. o
Drivers-$ (config_mtd) + = Drivers/MTD/mtdlink. o
Drivers-$ (config_pcmcia) + = Drivers/PCMCIA. o
Drivers-$ (config_net_pcmcia) + = Drivers/NET/PCMCIA/pcmcia_net.o
Drivers-$ (config_net_wireless) + = Drivers/NET/wireless/wireless_net.o
Drivers-$ (config_pcmcia_chrdev) + = Drivers/Char/PCMCIA/pcmcia_char.o
Drivers-$ (config_dio) + = Drivers/Dio/dio.
Drivers-$ (config_sbus) + = Drivers/sbus/sbus_all.o
Drivers-$ (config_zorro) + = Drivers/Zorro/driver. o
Drivers-$ (config_fc4) + = Drivers/FC4/fc4.a
Drivers-$ (config_all_ppc) + = Drivers/Macintosh. o
Drivers-$ (config_mac) + = Drivers/Macintosh. o
Drivers-$ (config_isapnp) + = Drivers/PNP. o
Drivers-$ (config_sgi_ip22) + = Drivers/SGI.
Drivers-$ (config_vt) + = Drivers/Video/video. o
Drivers-$ (config_paride) + = Drivers/block/Paride.
Drivers-$ (config_hamradio) + = Drivers/NET/hamradio. o
Drivers-$ (config_tc) + = Drivers/TC.
Drivers-$ (config_usb) + = Drivers/usb drv. o
Drivers-$ (config_input) + = Drivers/input/inputdrv. o
Drivers-$ (config_i2o) + = Drivers/message/i2o/i2o. o
Drivers-$ (config_irda) + = Drivers/NET/IrDA/IRDA. o
Drivers-$ (config_i2c) + = Drivers/I2C/I2C. o
Drivers-$ (config_phone) + = Drivers/telephony. o
Drivers-$ (config_md) + = Drivers/MD/mddev. o
Drivers-$ (config_bluez) + = Drivers/Bluetooth. o
Drivers-$ (config_hotplug_pci) + = Drivers/hotplug/vmlinux-obj.o

Drivers: = $ (drivers-y)

Vmlinux: Include/Linux/version. h $ (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
$ (Nm) vmlinux | grep-V '/(Compiled/)/| /(/. o $/)/|/([auw]/)/| /(/. /. ng $/)/|/(lash [RL] di/) '| sort> system. map
}
|-> $ (Core_files) (Kernel File)
|-> $ (Drivers) (driver)
|-> $ (Networks) (network function)
|-> $ (Libs) (library file)

######################################## ##################
Make install

Zimage (makefile;> ARCH/i386/makefile;-> ARCH/i386/boot/makefile bootimage = bzimage install ;)
{
(ARCH/i386/makefile)
Kernelrelease = $ (Version). $ (patchlevel). $ (sublevel) $ (extraversion)
Kernelpath = kernel-$ (shell echo $ (kernelrelease) | sed-e "S //-// G ")

Install: $ (configure) $ (bootimage)
Sh-X./install. Sh $ (kernelrelease) $ (bootimage) $ (topdir)/system. Map "$ (install_path )"
}
|-> $ (Bootimage)
| -- $ (Configure)
| -- Vmlinux
 

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.