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
Previous article:TQ2440 Study Notes - 7. NOR Flash and NAND Flash
Next article:TQ2440 uses Jlink-Flasher to burn u-boot or program
Recommended ReadingLatest update time:2024-11-15 07:31
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Create a new micropython container in docker
- 1
- The simplest FPGA multi-image loading solution
- Control of Brushless DC Motor Using DSP
- About Class D Amplifier Design
- EEWORLD University Hall ---- Single Avalanche Tolerance
- SparkRoad Evaluation (5)-Clock System and IP Resource Reference
- Qorvo Delivers 100 Million RF Devices for 5G Wireless Infrastructure
- 11 examples to teach you how to deal with servo motor jitter problems
- Low Power Consumption Design Strategy for Single Chip Microcomputer System