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

Recommended ReadingLatest update time:2024-11-15 07:31

OK6410A development board (VIII) 30 linux-5.11 OK6410A process-related registers
We know that when Linux is running, it is actually the running of each process. Although, there are several states 1. Switching between different processes 2. Switching between different states of the process But overall, when the system is running, it is actually a collection of different processes running. Pro
[Microcontroller]
[JZ2440] Use tftp to burn kernel and file system
1. Use the tftp tool to download the file to the specified address of mini2440 SDRAM.   1. Configure the IP of the Windows host. Here, the IP of my Windows host is configured as 192.168.1.5.   2. Set up a Windows host tftp server.   The Windows host runs the tftp server software. The server IP defaults to the Wi
[Microcontroller]
[JZ2440] Use tftp to burn kernel and file system
TQ2440 uboot---6. Run hello_world.c in the examples directory of U-boot
Today I accidentally discovered that there is an examples directory in u-boot. After compiling u-boot, I found several test programs, such as hello_world. At the same time, there is an option in the bootloader of tq2440 to download the program to sdram and run it. Download Program (uCOS-II or TQ2440_Test) to SDRAM an
[Microcontroller]
Linux serial terminal driver - s3c6410 platform (Part 2)
1. Terminal equipment In Linux system, terminal is a character device, which has many types. Usually tty is used to refer to various types of terminal devices. TTY is the abbreviation of Teletype, which is the earliest terminal device, much like a teletypewriter, produced by Teletype. Linux includes the following ty
[Microcontroller]
Linux serial terminal driver - s3c6410 platform (Part 2)
IIC bare metal and linux communication, bare metal series - S3C2440IIC communication
After about a week, I finally got IIC almost done. I can only say that every program should be taken seriously, and every program written is a kind of progress. For IIC, I feel that I knew this thing when I was working on the microcontroller, but I didn't adjust it. Now RAM bare metal programming is a good opportunity
[Microcontroller]
Linux 2.6.24.4 and root file system porting on S3C2410 (using 4.3.2 compiler to support eabi) (based on GEC2410)
Previously, I ported linux-2.6.24.4 and the root file system (created using busybox-1.10.1) to run on the GEC2410 platform. Please refer to the previous notes: Kernel configuration: http://blog.csdn.net/shevsten/archive/2010/05/17/5599790.aspx Root file system: http://blog.csdn.net/shevsten/archive/2010/05/26/562513
[Microcontroller]
OK6410A development board (eight) 75 linux-5.11 OK6410A linux kernel synchronization mechanism read-write lock implementation
accomplish read_lock read_unlock include/linux/rwlock.h  71 #define read_lock(lock)     _raw_read_lock(lock) include/linux/rwlock_api_smp.h  44 #define _raw_read_lock(lock) __raw_read_lock(lock) include/linux/rwlock_api_smp.h 146 static inline void __raw_read_lock(rwlock_t *lock)                                147
[Microcontroller]
Transplantation of Linux frame buffer device driver framework and graphical interface GUI
Hardware Platform S3C2410X is Samsung's S3C2410X chip based on ARM920T. S3C2410X integrates an LCD controller (supports STN and TFT LCD screens with touch screen), SDRAM, touch screen, USB, SPI, SD and MMC controllers, 4 timers with PWM function and 1 internal clock, 8-channel 10-bit ADC, 117-bit general I/O po
[Microcontroller]
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号