The purpose of this article is to help understand how to compile a version of the Linux kernel. Familiar with Kconfig kbuild tools. Whether you're modifying the Linux kernel yourself or doing embedded cross-compiling, there are some things that can help.
Kernel compilation system
If you have access to some open source software under Linux, you will know that they are configured and compiled using Autotools. Compile the ./config
source code by executing the make
make install
-----. The compilation of the Linux kernel also needs to be configured and recompiled. Configuration using Kconfig, compiled using Kbuild, these two tools support the Linux kernel compilation system, they are unified management in makefile to complete the configuration of the compilation work.
or first download a version of the kernel source code, easy to follow the instructions. You can download the kernel of your desired version to the Linux official website. Here take linux-2.6.29.tar.bz2 http://www.kernel.org/pub/linux/kernel/v2.6/as an example. Download unzip.
In the README, we have actually taught us how to configure, compile, and launch the new kernel. Here I follow the Reame file first give the configuration, compile the kernel process. Execute under the Linux kernel source code root directory:
Make Mrproper first clears the previous configuration.
Make O=/home/name/build/kernel Menuconfig uses Menuconfig to configure the kernel, the O variable is the build directory, or it can not be set.
Make O=/home/name/kbuild/kernel compiles the kernel according to the configuration information.
sudo make O=/home/name/kbuild/kernel modules_install install the module after compilation is complete. Write the compiled module to the/lib/modules/directory.
Perhaps you have compiled the kernel in the steps above. But there is still a need for a closer look.
Kconfig
Linux kernel source supports more than 20 architectures of processors, as well as a variety of drivers and other options. Therefore, the kernel source code must be configured on a specific platform before compiling. The Linux kernel has thousands of configuration options and is quite complex to configure. Therefore, the Linux kernel source code organizes a configuration system. You can use the following model diagram to understand how kconfig works.
In fact, it is very simple to parse the configuration file to generate the macro definition, so as to control the compilation of the code or makefile the module compilation or not. Here make menuconfig
, for example, illustrates the execution flow in the next makefile. First, look for the target in the makefile file at the root of the source code, as below,% for wildcard characters.
The command will then continue to execute $(Q)$(MAKE) $(build)=scripts/kconfig [email protected]
. where $ (build) is include
declared in a way.
Then open ./scripts/Kbuild.include
the file and look build
for the definition:
So the above command expansion is make -f scripts/Makefile.build obj=scripts/kconfig menuconfig
This command format is used by Linux Kbuild makefile Way. The final call is the scripts/kconfig
Makefile file under the directory. Then we continue to look up to scripts/kconfig/Makefile
find the menuconfig
following:
The command it relies on scripts/kconfig/mconf
for the final invocation is: scripts/kconfig/mconf arch/x86/Kconfig
take the x86 platform as an example. That is to use mconf this tool to parse the arch/x86/Kconfig
file, then we make the configuration, the configuration interface is as follows:
You can generate a configured. config file in the source code root directory. You can open the. config file to see what's inside.
Prepare for future compilation work. If interested students can also use the compiled Mconf tool to parse their own written Kconfig files. may be encountered in future projects. The syntax for the Kconfig configuration file can refer to/linux-2.6.29/documentation/kbuild$ vim kconfig-language.txt or the online information. No longer stated here.
The other way of configuring the principle is the same. But there are differences in the configuration and interface. A table is listed here and you can try it all.
How to configure |
function |
Config |
Updating the current configuration through a command-line program |
Menuconfig |
Updating the current configuration through a menu program |
Xconfig |
Updating the current configuration via the Qt graphical interface |
Gconfig |
Updating the current configuration via the GTK graphical interface |
Oldconfig |
Updating the current configuration through the provided. config file |
Randconfig |
Random configuration for all types of selection |
Defconfig |
Use default configuration for all types of selection |
Allmodconfig |
Select ' m ' for all types of selection possible |
Allyesconfig |
Select ' Y ' as much as possible for all options |
Allnoconfig |
Choose the minimum configuration of ' n ' for all selections possible |
Kbuild
After the Linux kernel has been configured, it can be compiled. Kbuild is compiled using a more general way of compiling. This part of the content is going to re-write an article to tidy up. This is a temporary skip.
Compilation process
So much to be able to compile the kernel. This is the example of compiling the Linux kernel under the x86 platform, and gives the process of graphic form.
Download and unzip the source code
Make clean make Mrproper
Configure the kernel, novice to kernel option is not familiar, here use Defconfig way. After a lot of experience, nature is ripe for these configuration options.
Compile the kernel and use a simple make
command.
Install the module! sudo make Modules_install install
If the compilation is correct, the new kernel is generated under the./arch/x86/boot folder.
Wrong row
The process of compiling the kernel will inevitably cause some errors. Go to Google or Baidu to find the answer Bai. Here are some of the errors and workarounds that occurred while compiling the kernel.
Gcc:error:elf_i386:No such file or directory http://blog.csdn.net/chenyu123123/article/details/8481772
This article explains the file format used by the kernel during the compilation process. such as vmlinux various image and so on. Http://www.cnblogs.com/hnrainll/archive/2011/06/10/2077961.html
Compiling the Linux kernel