TQ2440 Study Notes—— 34. Porting the Linux Kernel [Makefile Analysis]

Publisher:sjjawx831Latest update time:2022-04-18 Source: eefocusKeywords:TQ2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Linux Makefile Analysis


(1) The role of Makefile


a. Decide which files to compile


b. How to compile these files


c. How to connect these files, and most importantly, what is their order


There are many Makefile files in the Linux kernel. The following are the five major categories of Makefile files:

a. Decide which files to compile.


The compilation process of the Linux kernel starts with the top-level Makefile, and then recursively enters each level of subdirectory to call their Makefiles. It is divided into three steps.


1. The top-level Makefile determines which subdirectories under the kernel root directory will be compiled into the kernel.


2. arch/$(ARCH)/Makefile determines which files and directories under the arch/$(ARCH) directory will be compiled into the kernel.


3. The Makefile in each subdirectory determines which files in the directory will be compiled into the kernel, which files will be compiled into modules (ie, drivers), and which subdirectories will be entered to continue calling their Makefiles.


Let's look at step 1 first. In the top-level Makefile, we can see:

As can be seen above, the top-level Makefile divides these 13 subdirectories into 5 categories: init-y, drivers-y, net-y, libs-y and core-y. There is also an arch that is included into the kernel in arch/$(ARCH)/Makefile.

For non-x86 platforms, you also need to specify cross-compilation tools.

For arch/$(ARCH)/Makefile in step 2, taking the ARM system as an example, you can see the following content in arch/arm/Makefile:

Line 94: In addition to the previous 5 types, another type of head-y appears, but it appears directly as a question mark. MMUEXT is defined in the front of arch/arm/Makefile. For processors without MMU, the value of MMUEXT is -nommu, and the file head-nommu.S is used; for processors with MMU, the value of MMUEXT is empty, and the file head.S is used.


In arch/arm/Makefile, lines 171, 172, and 173 further expand the contents of core-y, and line 191 expands the contents of libs-y. These are architecture-related directories. CONFIG_ARCH_S3C2410 in lines 173 to 175 is defined when configuring the kernel. It has three values: y, m, or empty. y means compiled into the kernel, m means compiled as a module, and empty means not used.

When compiling the kernel, the directories listed in init-y, core-y, libs-y, drivers-y, and net-y will be entered in turn to execute their Makefiles. Each subdirectory will generate a built-in.o (a lib.a file may be generated in the directory listed in libs-y). Finally, the file represented by head-y will be compiled with these built-in.o


, lib.a together into the kernel image file vmlinux.


For step 3:


When configuring the kernel, a configuration file .config is generated. The kernel top-level Makefile uses the following statement to indirectly include the .config file, and then decides which files to compile based on the variables defined in .config. The so-called "indirect" inclusion is because it includes the include/config/auto.conf file, which only removes the comments in the .config file and adds some variables based on the variables defined in the top-level Makefile.

In the include/config/auto.conf file, there are two main types of variable values: "y" and "m". The Makefiles of each subdirectory use these variables to decide which files are compiled into the kernel, which files are compiled into modules, and which subdirectories to enter for further compilation. This is determined by the following 4 methods (obj-y, obj-m, lib-y are variables in Makefile).


obj-y is used to define which files are compiled into the kernel (built-in)


obj-m is used to define which files are compiled into loadable modules.


lib-y is used to define which files are compiled into library files

obj-y and obj-m can also be used to specify the next subdirectory to enter.


(2) How to compile these files


That is, what are the compile options and link options. These options are divided into three categories: global, applicable to the entire kernel source tree; local, applicable only to all files in a Makefile; individual, applicable only to a certain file.


(3) How to connect these files and what is their order


Keywords:TQ2440 Reference address:TQ2440 Study Notes—— 34. Porting the Linux Kernel [Makefile Analysis]

Previous article:TQ2440 Study Notes - 7. NOR Flash and NAND Flash
Next article:TQ2440 uses Jlink-Flasher to burn u-boot or program

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号