Learn some of the information on the Internet, I tried to find out a bit, to sort out this article.
Improper, but also ask everyone to criticize correct. Thank you.
Important references are:
Http://raspberrypi.stackexchange.com/questions/192/how-do-i-cross-compile-the-kernel-on-a-ubuntu-host
http://blog.csdn.net/xdw1985829/article/details/6833319
OK, let's get down to the chase.
First, the preparatory work
How to prepare the work, here is not said.
A) First of all, you have to have a PC (this is no nonsense ^_^), installed Linux.
b) Install GCC (this refers to the host GCC, which is used to compile and build the machine running on the PC program), make, ncurses and other tools.
c) Download a pure Linux kernel source package and unzip it well.
D) If you are porting Linux to an embedded system, then install the cross-compilation toolchain. For example, your target board CPU might be a CPU such as ARM or MIPS, then install the appropriate cross-compilation toolchain. After installation, you need to add the tool chain path to the PATH environment variable. For example, if you are installing an arm toolchain, then you execute a command similar to the following in the shell, and if you have a similar output, you are ready to install it.
[Email protected] linux-2.6.33.i686]# ARM-LINUX-GCC--version
ARM-LINUX-GCC (buildroot 2010.11) 4.3.5
Copyright (C) Free Software Foundation, Inc.
This was free software; See the source for copying conditions. There is NO
Warranty Not even to merchantability or FITNESS for A particular PURPOSE.
Second, set the compilation target
Before configuring or compiling the kernel, first determine the target CPU architecture and what toolchain to use at compile time. This is the most basic information, first of all to determine.
If you are compiling the kernel for the PC you are currently using, you do not need to set it. Otherwise, you need to set it clearly.
Here, take arm as an example to illustrate.
There are two ways to set up ():
A) Modify Makefile
Open the kernel source root directory makefile, modify the following two makefile variables and save.
ARCH: = Arm
Cross_compile: = arm-linux-
b) Each time the make command is executed, the information is passed through the command line arguments.
This is actually the value of the variable specified by the Make tool's command-line arguments.
For example
When configuring the kernel, use the
Make Arch=arm cross_compile=arm-linux-menuconfig
Use when compiling the kernel
Make Arch=arm cross_compile=arm-linux-
Third, configure the kernel
There are so many functions of the kernel, what parts we need, what form each part compiles into (the kernel or the module), and the working parameters of each part, which can be configured. So before we start compiling, we need to build a configuration checklist, put it in the kernel source root, name the. config file, and compile the kernel we need based on this. config file.
However, there are too many kernel configuration items, one for one, too much trouble. Also, different CPU architectures can be configured with a set of configuration items that are not the same. For example, a configuration item that is not supported by one of the features of a CPU is a configuration item that is related to the CPU architecture. Therefore, the kernel provides a simple configuration method.
Take arm as an example, as described below.
a) According to our target CPU architecture, from the kernel source Arch/arm/configs directory, find a configuration item closest to the target system, and copy it to the kernel source root directory, named. config. If your target system is a popular standard system, and you have no special requirements, then this step is done, it is the configuration has been completed. Otherwise, perform the following step to make some custom modifications to the configuration.
b) Perform make menuconfig some necessary modifications to this configuration, and select Save on exit to update the new configuration to the. config file.
Note that when we do this, the kernel opens a set of configuration items that let us configure. This set of configuration items is determined by the CPU architecture we set up earlier. To be more detailed, configure the system to open the Arch/arm/kconfig file, which also contains the other kernel subsystem of the Kconfig file (the file name may be another name), the other subsystems of the Kconfig file, and then layer contains the underlying kconfig file, This generates the entire collection of configuration items. For each configuration item, the current set value (for example, whether it is a kernel, compiled into a module, or possibly a parameter) is generated by a. config file under the kernel source root directory.
third, compile the kernel
The compilation itself is simple, and the following command is done.
Make
We might as well take some time to understand the kernel compilation mechanism.
A) How the kernel uses the config file
The. config file was generated earlier, and this is a text file, all of which are similar to the following:
Config_yenta_ene_tune=y
Config_yenta_toshiba=y
Config_pd6729=m
Config_i82092=m
config_mtdram_erase_size=128
As you can see, some of them are set up to compile a feature into the kernel, some of which are set up to compile a feature into a module, and some are some of the parameters that set a feature.
The syntax of this file is actually the syntax for defining the makefile variable. Yes, this is makefile.
When we execute make to start compiling the kernel, the compilation system also generates another config file, which is include/config/auto.conf. The content inside is similar to the. config, except that the content is less.
When the kernel is compiled, the top-level makefile (located under the source root) will contain the config file above.
This gives you the appropriate makefile variable to know how to compile the various parts of the kernel.
From the top-level makefile, you can see the following code:
Ifeq ($ (dot-config), 1)
# Read in config
-include include/config/auto.conf
However, the relationship between the two config files, which will be included in the end, is not clear. Have clear, also hope enlighten:)
b) in the kernel code, how to know if a function is configured, what form
When we execute make to start compiling the kernel, the compilation system also generates a C-language header file include/generated/autoconf.h
This file is similar to the following:
#define CONFIG_DM9000 1
#define CONFIG_DM9000_DEBUGLEVEL 4
#define CONFIG_SND_RAWMIDI_SEQ_MODULE 1
The first line indicates that the user has chosen to DM9000 the driver into the kernel, and the second line is a parameter of this driver. If the user chooses to compile DM9000 into a module, the contents of the first line become the following form.
#define CONFIG_DM9000_MODULE 1
With this header file, a. c file of a kernel source can be used to know the configuration of the user if it contains the header file.
Well, the kernel compilation mechanism, under the understanding is also very limited, first write this.
Linux Kernel compilation detailed