Compiling the Android Linux kernel goldfish

Source: Internet
Author: User
Tags builtin

Https://source.android.com/source/building-kernels.html

$ Export Path=/home/hzh/oldhome/learn/android-4.2.2/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin:${path}

$ Export Arch=arm

$ Export Subarch=arm

$ Export cross_compile=arm-eabi-

$ make Arch=arm Goldfish_armv7_defconfig

$ make



Kernel Makefiles is part of the Kbuild system, documented in various places on the Web, for example HTTP://LWN.NET/ARTICL es/21835/. The relevant excerpt is here:

---3.1 Goal definitions

GOAL definitions is the main part (heart) of the Kbuild Makefile. These lines define the files to being built, any special compilation options, and any subdirectories to be entered Recursivel Y.

The most simple kbuild makefile contains one line:

Example:obj-y + = foo.o

This, kbuild, there is one object in that directory named FOO.O. FOO.O'll is build from FOO.C or foo. S.

If foo.o shall be built as a module, the variable obj-m is used. Therefore The following pattern is often used:

example:obj-$ (config_foo) + = FOO.O

$ (Config_foo) evaluates to either Y (for built-in) or M (for module). If Config_foo is neither y nor m, then the file would not be compiled nor linked.

So m means module, y means built-in (stands for Yes on the kernel config process), and $ (config_foo) pulls the right answe R from the normal config process.

The organization structure of the makefile of Linux kernel (RPM)
Background knowledge:
Background knowledge One: Kconfig Introduction:
When #make menuconfig, the menu list displayed is made up of kconfig of each layer.
The bottom Kconfig are stored in the ~/arch/i386/kconfig. With this as the head, it uses the source layer to add the keconfig of the various directories that need to be added recently.
Example: Source "Drivers/kconfig"
The ~/drivers/kconfig is added to the menu list.

Background knowledge Two: Kconfig write French meaning:
Config HID
TriState "Generic HID support"
Depends on INPUT
Default Y
The explanations are as follows:
Config HID: Indicates that this entry corresponds to Config-hid. Config-hid will be used in the makefile.

TriState the contents of the "Generic HID support" Quotation mark are displayed in the menu list. TriState says the item is tri-state.

Depends on input: dependent on input. If input is not selected, the menu list does not display this item.

Default y: Defaults are selected.



Background Knowledge Three: BUILT-IN.O
Vmlinux is an uncompressed kernel compiled by Linux source code, vmlinux by ARCH/I386/KERNEL/HEAD.O and Arch/i386/kernel/init_ TASK.O, as well as the BUILT-IN.O links in each of the related sub-directories.


Background knowledge Four: Kernel Makefile
Kernel makefile system and how to compile, in fact, Sam has been smattering.
Among them, the makefile in the kernel directory is called the underlying makefile.
A. config file is generated when the kernel is configured successfully using a similar #make menuconfig.
In other words: When make menuconfig, makefile reads kconfig from ~/arch/i386/kconfig. Then according to the user's choice. Generates a. config file.
For example: in Drivers/hid/kconfig:
Config HID
TriState "Generic HID support"
If the user selects Y, it is reflected in the. config:
Config_hid=y
You can see in the ~/drivers/makefile:
obj-$ (config_hid) + = Hid/
Indicates: If Config_hid is Y, the HID directory is added to the directory to be compiled.
Go to the/driver/hid directory and see:
HID-OBJS: = HID-CORE.O HID-INPUT.O
Indicates that these two. o files are bound to be compiled.
obj-$ (config_hid) + = HID.O
Indicates that if Config_hid is Y, then HID.O will be compiled. and built-in.
If it is =m, then HID.O is compiled, but finally made modules (KO)

Background Knowledge V: Kbuild make:
The makefile of the Linux kernel differs from the makefile we normally write, and it consists of five parts:
1.Makefile: Top layer Makefile.
2.. config:kernel configuration file.
3. Arch/xxx/makefile: Makefile of the specific architecture.
4. SCRIPTS/MAKEFILE.XXX: General rules.
5. Kbuild Makefile: There are about hundreds of such documents throughout the kernel.

After #make menuconfig, generate the kernel configuration file:. config.
The top-level makefile reads. config.
The top-level Makefile determines the Kbuild Makefile in which directories to recursively access by parsing. config.
In this process, Kbuild makefile will add a list of files to be used for the final compilation, by setting the. config.
The simplest kbuild makefile are as follows:
Obj-y + = foo.o
Indicates: Kbuild in this directory, there is a target file named FOO.O. FOO.O will be compiled from the FOO.C or Foo.s files. And it will be wrapped in built-in.
All the target files that are compiled into the kernel exist in the $ (obj-y) list. These lists depend on the configuration of the kernel. Kbuild compiles all the $ (obj-y) files. Then, call "$ (LD)-R" to merge them into a single BUILD-IN.O file. Later, the BUILD-IN.O is joined to the Vmlinux by its parent makefile.

If FOO.O is to be compiled into a module, it will be used obj-m. The following form is used:
Obj-m + = foo.o



Example one:
In ~/driver/hid/hid-core.c, there is the following statement, the kernel Insmod interface hid_init.
Module_init (Hid_init);
In other words, Kernel automatically calls Hid_init when this module is Buildin or as module INSMOD.
Then look at the ~/driver/hid/makefile and discover
HID-OBJS: = HID-CORE.O HID-INPUT.O
Indicates that the HID-CORE.O will be generated as long as the HID directory is added.
Had to look at how a layer of directories would go into the HID directory:
obj-$ (config_hid) + = Hid/
Indicates that the HID directory is added as long as config_hid=y,m.
But what did the user do, the HID directory was added to compile it? Then look at ~/drivers/hid/kconfig.
Config HID
TriState "Generic HID support"
As long as this is selected in Make Menuconfig, HID-CORE.O is compiled.


Example 2:
Sam wants to study USB Keyboard & Mouse driver. When make menuconfig, you need to select:
Config Usb_hid
TriState "USB Human Interface Device (full HID) support"
Then view the makefile. Discover that only Config_usb_hid is selected. The USB_HID.O is compiled
But there is no usbhid.c in the ~/drivers/hid/usbhid directory. How did the USBHID.O build it?
In the Drivers/hid/usbhid directory, there is a. usbhid.o.cmd file.

_______________________________________________________________________________________________


Linux kernel Makefile
Describe the organizational structure of Linux kernel makefile, what is Linux kernel and makefile needless to say.

1. Overview

The makefile of kernel is divided into 5 parts:

Makefile, the outermost Makefile.
configuration file for. config kernel
arch/$ (ARCH)/makefile Makefile of different architecture CPUs

scripts/makefile.* Rule File

Kbuild makefiles 500 + makefile Files

Take a look at the construction rule definitions for the Kbuild makefile file. The Kbuild file is the file that organizes the kernel options. You will see that kbuild and makefile exist in a directory in general.

Target definition:

This definition is generally used, and the purpose of this line is to compile the foo.o file, and the source file is the default foo.c or Foo.s. The source file is in the sibling directory of the Kbuild file.

Obj-y + = foo.o

If you want to compile this into a module, you need to use OJB-M. If you want to pass this parameter through the kernel configuration, you need to write the following.

obj-$ (config_foo) + = FOO.O

(Config_foo) is what you configure in the kernel option, if you do not select built-in or module, then this variable is the other value of Y or M, the file will not be compiled.


Built-in target file:

When you obj-y, they will compile all the obj-y files into a large BUILT-IN.O target file. Thereafter, a kernel image is linked to the topmost makefile.


#drivers/isdn/i4l/makefile # Makefile for the kernel ISDN subsystem and device drivers. # Each configuration option enables a list of files. obj-$ (config_isdn) + = ISDN.O obj-$ (config_isdn_ppp_bsdcomp) + = ISDN_BSDCOMP.O
It is important to note that you need to be aware of the order of these target files.
Because some functions such as (Module_init ()/__initcall) are called in the order in which they appear.

Ojb-m Target:

This is meant to be compiled into modules. A module can consist of one source file or multiple components.
Linux/2.6.20.6/make Menuconfig


When "Make Menuconfig" is executed in the top-level directory, the rules for the top makefile No. 415 row are executed

Config%config:scripts_basic outputmakefile force
$ (Q) mkdir-p include/linux include/config
$ (Q) $ (make) $ (build) =scripts/kconfig [email protected]

Here "Menuconfig" matches the pattern "%config". So the rules for its execution are as follows:

Menuconfig:scripts_basic outputmakefile Force
$ (Q) mkdir-p include/linux include/config
$ (Q) $ (make) $ (build) =scripts/kconfig Menuconfig

This rule has three dependencies: Scripts_basic, Outputmakefile, force. Take a look at these three dependencies:

1. Force

First Analyze this dependency, its rules are defined in line 1485:

Phony + = Force
Force:

This rule has no command or dependency, and its target is not an existing file name. When this rule is executed, the target force is always considered up-to-date. So when it is dependent on other rules, because the dependencies are always considered to be updated, the commands defined in that rule are always executed.

2, Scripts_basic

This dependent rule is defined in 347 rows:

Scripts_basic:
$ (Q) $ (make) $ (build) =scripts/basic

The build variable defines the 114 lines in the Scripts/kbuild.include:

Build: =-F $ (if $ (KBUILD_SRC), $ (srctree)/) Scripts/makefile.build obj

So the above rules can be written in the following form:

Scripts_basic:
$ (Q) $ (make)-F $ (if $ (KBUILD_SRC), $ (srctree)/) Scripts/makefile.build Obj=scripts/basic

The command of this rule eventually goes into the scripts directory, executes the Makefile.build file, and passes the parameter obj=scripts/basic.

The 5th line in Makefile.build is:

SRC: = $ (obj)

This assigns the value passed in to SRC, so

SRC: = scripts/basic

The two lines starting at line 16th include the makefile in SRC (that is, the Scripts/basic) directory (Kbuild if Kbuild is included)

Kbuild-dir: = $ (if $ (filter/%,$ (SRC)), $ (SRC), $ (srctree)/$ (SRC))
Include $ (if $ (wildcard $ (kbuild-dir)/kbuild), $ (Kbuild-dir)/kbuild, $ (kbuild-dir)/makefile)

The 19th line contains the scripts/makefile.lib come in,

In line 83rd of Makefile.build, the first goal that make has encountered in Makefile.build

__build: $ (if $ (kbuild_builtin), $ (builtin-target) $ (lib-target) $ (extra-y)) \
$ (if $ (kbuild_modules), $ (obj-m)) \
$ (SUBDIR-YM) $ (always)
@:

Kbuild_builtin in the No. 207 row of the top-level makefile definition

Kbuild_builtin: = 1

If "Make modules" is executed, it will be processed at the beginning of line 214

Ifeq ($ (makecmdgoals), modules)
Kbuild_builtin: = $ (if $ (config_modversions), 1)
endif

So here we are kbuild_builtin: =1

Kbuild_modules is defined in the No. 206 row of the top-level makefile,

Kbuild_modules: =

If you do any of the commands in "Make all", "Make _all," "Make modules," "Makes," then this variable will be processed at the beginning of line 222

Ifneq ($ (Filter all _all modules,$ (makecmdgoals)),)
Kbuild_modules: = 1
endif

Ifeq ($ (makecmdgoals),)
Kbuild_modules: = 1
endif

Therefore, we kbuild_modules here: =

After analyzing these two variables, the above rules can be re-written as

__build: $ (builtin-target) $ (lib-target) $ (extra-y)) $ (SUBDIR-YM) $ (always)
@:

That's through the rules.

Scripts_basic:
$ (Q) $ (make)-F $ (if $ (KBUILD_SRC), $ (srctree)/) Scripts/makefile.build Obj=scripts/basic

The first rule that executes in a scripts/makefile.build file,

The dependencies in the rule are represented by several variables $ (builtin-target) $ (lib-target) $ (extra-y)) $ (SUBDIR-YM) $ (always). The command of a rule is a colon command ":", a colon (:) command is a built-in command of Bash, which is usually treated as a true command. Bash's help explanation: No effect; The command does nothing. A Zero exit code is returned. (No effect, the command is an empty operation, the exit status is always 0).
__build: $ (builtin-target) $ (lib-target) $ (extra-y)) $ (SUBDIR-YM) $ (always)
@:

Build a number of dependent targets, which are primarily built with the target specified by the $ (always) variable. Other variables are not defined in Scripts/basic/makefile.

3, Outputmakefile

Go back to the top floor and see the rules makefile

Menuconfig:scripts_basic outputmakefile Force
$ (Q) mkdir-p include/linux include/config
$ (Q) $ (make) $ (build) =scripts/kconfig Menuconfig

The Outputmakefile parameter construction rules in the 357 line start definition

Outputmakefile:
Ifneq ($ (KBUILD_SRC),)
$ (Q) $ (Config_shell) $ (srctree)/scripts/mkmakefile \
$ (srctree) $ (objtree) $ (VERSION) $ (patchlevel)
endif

The command for this rule runs a shell script Scripts/mkmakefile, and passes four parameters. This script generates a makefile file primarily in the directory specified by the $ (objtree) parameter. Because the kbuild_src here is empty, this script is not executed

Go back and look at that rule.

Menuconfig:scripts_basic outputmakefile Force
$ (Q) mkdir-p include/linux include/config
$ (Q) $ (make) $ (build) =scripts/kconfig Menuconfig

After his dependency has been processed, the command to execute the rule begins. The first command creates two directories, and the second command expands to

$ (Q) $ (make)-F $ (if $ (KBUILD_SRC), $ (srctree)/) Scripts/makefile.build obj =scripts/kconfig menuconfig

This command is still executed scripts/makefile.build this Makefile file. and execute the rules of menuconfig inside it. Based on the above analysis, the Makefile.build will contain the Scripts/kconfig/makefile file. Then execute a rule that targets menuconfig, defined in line 13 of the Scripts/kconfig/makefile

Menuconfig: $ (obj)/mconf
$< arch/$ (Arch)/kconfig

As you can see from this command, you will eventually run the Arch/arm/kconfig script, which shows the configuration interface

Compiling the Android Linux kernel goldfish

Related Article

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.