linux-2.6.22.6 Kernel boot Analysis makefile file

Source: Internet
Author: User

Learning Goals

Analyze the makefile file to see which files in the kernel are compiled, how they are compiled, and how the order of connections is determined!

Linux kernel source code contains a lot of makefile files, these makefile files contain other files, such as configuration information, general rules and so on. We can divide the makefile file in the kernel into 5 classes, as shown in the following table:

Top Floor Makefile The core of all makefile files, from the overall control of the kernel compilation, connection
. config

configuration file, which is generated when the configuration command is executed. All makefile files are based on. config to determine which files to use

arch/$ (ARCH)/makefile A makefile file corresponding to the CPU architecture that determines which architecture-related files participate in the kernel generation and provides rules for generating a specific format kernel image
Kbuild Makefile Sub-directories at all levels of the makefile, relatively simple, the previous level of makefile is used to compile files in the current directory
Script/makefile.* Makefile common rules and scripts

The kernel is eventually compiled when the make Uimage command is executed, so it is most appropriate to analyze the kernel makefile file relationships and target Uimage as the starting point for the analysis. Open the top-level makefile file, find the dependency of the target uimage in the top-level makefile file, and find that the target uimage dependency cannot be directly found in the top-level makefile file. Although the dependency of the target uimage is not directly found in the top-level makefile file, the kernel is compiled when we execute the make Uimage command, so we can speculate that the target uimage is definitely defined in makefile in the other directory, and the makefile file in this directory is contained by the top-level makefile file. Locate the makefile file in the other directory, and finally find the dependency of the target uimage in the makefile file in the Arch/arm directory, as follows:

227 zimage Image xipimage bootpimage uimage:vmlinux                            #来源于arch/arm file makefile      $ (Q) $ (make ) $ (build) =$ (boot) machine=$ (machine) $ (boot)/[email protected]

To verify that the above inference is correct, we searched the "include" character in the top-level makefile to find all the included files in the top-level makefile. After filtering, find the code shown below:

413 include $ (srctree)/arch/$ (arch)/Makefile                                    #来源于顶层Makefile中文件 414Export Kbuild _defconfig ..... 185 #ARCH        ? = $ (subarch)186 ARCH        ? = arm187 Cross_compile    ? = arm-linux-

The above code $ (Srctree) = Source root directory,$ (arch) =arm,include $ (srctree)/arch/$ (Arch)/ Makefile indicates that the top layer makefile contains makefile in the Arch/arm directory, which shows that our speculation is correct.

As you can see from the above 227 lines of code, the target uimage depends on Vmlinux. The Uimage file has two parts, the head and the true kernel part, to obtain the Uimage file must first compile the kernel, that is, the Vmlinux file, and finally generate uimage files according to the Vmlinux file. Here we also find vmlinux dependencies, in the top-level makefile to find the Vmlinux dependencies, the following code:

745 vmlinux: $ (vmlinux-lds) $ (vmlinux-init) $ (vmlinux-main) $ (KALLSYMS.O) Force                             #来源于顶层的Makefile

It can be seen that the vmlinux generated depends on $ (vmlinux-lds) $ (vmlinux-init) $ (vmlinux-main) $ (KALLSYMS.O), so for further analysis we are going to find out $ (vmlinux-lds) $ ( Vmlinux-init) $ (vmlinux-main) $ (KALLSYMS.O) variable represents the content and expands on what the variable represents.

608 Vmlinux-init: = $ (head-y) $ (init-y)                                           #来源于顶层Makefile文件 94  head-y: = arch/arm/ kernel/head$ (mmuext). o arch/arm/kernel/init_task.o         makefile file under the/arm directory #来源于arch
443 init-y : = init/ #来源于顶层Makefile文件
573 init-y : = $ (patsubst%/,%/BUILT-IN.O, $ (init-y)) #来源于顶层Makefile文件

Line 94th $ (mmuext) content is empty, head$ (mmuext). O is head.o, head-y: = ARCH/ARM/KERNEL/HEAD.O ARCH/ARM/KERNEL/INIT_TASK.O

Line No. 573 $ (Patsubst <pattern>,<replacement>,<text>) is a makefile function that finds whether the word in <text> matches the pattern < Pattern>, if matched, is replaced with <replacement>. Here,<pattern> can include the wildcard "%", which represents any length of string. If <replacement> also contains "%", then the "%" in the,<replacement> will be the string represented by the "%" in <pattern>. Init-y: =INIT/BUILT-IN.O

Line No. 608 $ (head-y) $ (init-y) replaced with 94 rows and 573 rows of analysis results, you can get vmlinux-init: =ARCH/ARM/KERNEL/HEAD.O arch/arm/kernel/init_ TASK.O INIT/BUILT-IN.O

609Vmlinux-main: = $ (core-y) $ (libs-y) $ (drivers-y) $ (net-y) #来源于顶层Makefile文件
438Core-y: = usr/#来源于顶层Makefile文件
562Core-y+ = kernel/mm/fs/ipc/security/crypto/block/#来源于顶层Makefile文件
574Core-y: = $ (patsubst%/,%/BUILT-IN.O, $ (core-y))#来源于顶层Makefile文件

437Libs-y: = lib/#来源于顶层Makefile文件
577Libs-y1: = $ (patsubst%/,%/LIB.A, $ (libs-y))#来源于顶层Makefile文件
578Libs-y2: = $ (patsubst%/,%/BUILT-IN.O, $ (libs-y))#来源于顶层Makefile文件
579Libs-y: = $ (libs-y1) $ (libs-y2)#来源于顶层Makefile文件

435Drivers-y: = drivers/sound/#来源于顶层Makefile文件
575Drivers-y: = $ (patsubst%/,%/BUILT-IN.O, $ (drivers-y))#来源于顶层Makefile文件

436Net-y: = net/#来源于顶层Makefile文件
576Net-y: = $ (patsubst%/,%/BUILT-IN.O, $ (net-y))#来源于顶层Makefile文件

Combine 438 rows and 562 rows, 574 lines, line No. 574 core-y: = kernel/built-in.o mm/built-in.o fs/ built-in.o ipc/built-in.o security/built-in.o crypto/ built-in.o block/built-in.o

Combined with 437 rows, 577 rows, and 578 rows, line No. 579 libs-y : = LIB/LIB.A LIB/BUILT-IN.O

Combined with 435 lines, line No. 575 drivers-y : = drivers/built-in.o SOUND/BUILT-IN.O

Combine 436 lines, line No. 576 net-y: =NET/BUILT-IN.O

Line No. 609 $ (core-y) $ (libs-y) $ (drivers-y) $ (net-y) replaced with 574 rows, 579 rows, 575 rows, and 576 analysis results to getVmlinux-main: =kernel/built-in.o mm/built-in.o fs/built-in.o ipc/built-in.o security/ BUILT-IN.O crypto/built-in.o block/built-in.o lib/lib.a lib/built-in.o drivers/built-in.o Sound /BUILT-IN.O NET/BUILT-IN.O

610 vmlinux-all  : = $ (vmlinux-init) $ (vmlinux-main)

Combined with 608 rows and 609 rows of analysis results, replace 610 lines $ (vmlinux-init) $ (vmlinux-main) to getVmlinux-all: =ARCH/ARM/KERNEL/HEAD.O arch/arm/kernel/init_task.o INIT/BUILT-IN.Okernel/built-in.omm/built-in.o fs/ Built-in.o ipc/built-in.o security/built-in.o  crypto/built-in.o  block/BUILT-IN.O&NBSP;LIB/LIB.A lib/built-in.o  DRIVERS/BUILT-IN.O sound/built-in.o net/built-in.o

The above describes the raw materials that make up the kernel, but how they are compiled, connected to the kernel, and we're going to look at the commands executed under the Vmlinux dependency file.

745 vmlinux: $ (vmlinux-lds) $ (vmlinux-init) $ (vmlinux-Main) $ (KALLSYMS.O) Force           #顶层Makefile文件 746 ifdef Config_headers_check 747     $ (Q) $ (make)-F $ (srctree)/Makefile headers_check748endif749    $ ( Call if_changed_rule,vmlinux__)759    $ (Q) $ (make)-F $ (srctree)/scripts/makefile.modpost [ Email protected]751    $ (Q) rm-f. old_version

We can analyze the above command to get the compilation process and some of the generated files, but the above command involves a lot of functions, scripts, is too large, not so much effort to do so. In this case, you can compile the kernel directly by using the RM vmlinux command to delete the vmlinux generated by make Uimage before executing the Create uimage v=1 To view a more detailed compilation process, connect the commands as shown:

In the diagram, the vmlinux is the connection output, the Arch/arm/kernel/vmlinux.lds is the connection script, and some of the following are the raw materials connected, and these raw materials correspond to the basic one by one of the raw materials we analyzed above.

Summarize:

1, the top makefile and arch/$ (arch)/makefile decide which subdirectories under the root directory, arch/$ (arch) directory which files and directories are compiled into the kernel, and finally, the sub-directory of all levels under the makefile decide which files in the directory will be compiled into the kernel, Which files are compiled into modules, and which subdirectories continue to invoke their makefile.

2, through the analysis to get the compiler kernel connection script is arch/arm/kernel/vmlinux.lds, the first file is Arch/arm/kernel/head. S, the first file arch/arm/kernel/head when the subsequent analysis kernel starts. S will be the starting point for the analysis.

linux-2.6.22.6 Kernel boot Analysis makefile file

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.