The configuration mechanism of Linux kernel and its compiling process

Source: Internet
Author: User

The configuration mechanism of Linux kernel and its compiling process

First day of the country embedded in the third section: the configuration of the kernel on the X86 platform, the installation process, the production of their own Linux system, and dual-system boot.

"Linux System porting" chapter fourth

http://blog.csdn.net/zhengmeifu/article/details/7682373

The Linux kernel is customizable, with the following steps: The basic structure of the 1.1.1 configuration system

The Linux kernel configuration system consists of three parts, namely:

1, Makefile: Distributed in the Linux kernel source code root directory and each layer directory, define the Linux kernel compilation rules;

2. Configuration file (config.in (2.4 kernel, 2.6 kernel)): Provide the user with the function of configuration selection;

3, configuration tools: including configuration command interpreter (interpretation of configuration commands used in configuration scripts) and configuration user interface (provide a character-based interface, based on the ncurses graphical interface and Xwindows graphical interface based on the user Configuration interface, each corresponding to make config, make Menuconfig and make Xconfig).

These configuration tools are written using scripting languages, such as TCL/TK, Perl (and some code written in C). This article does not analyze the configuration system itself, but rather describes how to use the configuration system. So, unless the maintainer of the configuration system, the general kernel developers do not need to understand their principles, just need to know how to write makefile and configuration files can be. 1.1.2 Clears temporary files, intermediate files, and configuration files.

L Make Clean

Remove most generated files but keep the Config

Simply delete the generated. o File retention configuration

L Make Mrproper

Remove all generated files + config files

L Make Distclean

Mrproper + Remove editor backup and patch files

Determine the hardware and software configuration of the target system, such as the type of CPU, the model of the network card, the network protocol needed to support. 1.1.3 Configure the kernel with the following command:

A) make config: Interactive configuration based on text mode.

b) Make Menuconfig: menu-based configuration in text mode. (Recommended use)

c) Make Oldconfig: Use an existing configuration file (. config), but ask for additional configuration options.

d) Make Xconfig: Graphical configuration (requires the installation of a graphical system).

Make Menuconfig is the most commonly used kernel configuration method, using the following methods:

1. Use the arrow keys to move between the options;

2. Use "Enter" key to enter the next level menu; the highlighted letter on each option is a keyboard shortcut that allows you to quickly reach the selected item you want to set.

3. Press "Y" in parentheses to compile the project into the kernel, press "M" to compile as a module, press "N" for not selected (press the SPACEBAR can also be compiled into the kernel, compiled into the module and do not compile the three), press "H" will display the Help information of this option, press "ESC" key will return to the upper menu

Operation: Download kernel https://www.kernel.org/linux-2.6.29 on official website

This command must be done in the root directory of the kernel: /.. /linux-x.x.x

[email protected] linux-2.6.29]# make Distclean

Clear all previously compiled files, kernel operation below, can be displayed with text, or can be displayed as a menu.

[email protected] linux-2.6.29]# make Menuconfig

The following error 1 may occur:

Your display is too small to run menuconfig!

It must is at least lines by columns.

MAKE[1]: * * [Menuconfig] Error 1

Make: * * [Menuconfig] Error 2

Cause: The terminal window is too small for maximum resolution.

The following error 2 may occur:

 
 

Workaround: Installing Ncurses-devel

Enter the command:

The Kernel configuration box pops up after the problem is resolved. Click on the space to change the selection.

How to use:

Press "Y" in parentheses to compile the project into the kernel. Press "M" to compile the module, press "N" is not selected (press the SPACEBAR can also be compiled into the kernel, compiled into a module and do not compile the three), press "H" will display the Help information of this option, press "ESC" key will return to the upper menu select y (ie * The corresponding A.C file becomes A.O and the final link is generated into the uimage (kernel), and the corresponding A.C becomes the A.O module after selecting M.

Without any action, save kernel exit, input ls-a (-a Show hidden file) command shows more. config file, this is the result of our configuration.

[Email protected] linux-2.6.29]# ls-a

Then you can configure it, so how do you choose to configure the menu? 1.1.4 Makefile Menuconfig Process Explained

What exactly did the system do for us when we executed the make Menuconfig command?

There's a couple of papers involved in this, and we're here to explain one by one.

? Scripts folder under the Linux kernel root directory

? arch/$ARCH/kconfig files, kconfig files in each layer directory

? Makefile files in the root directory of the Linux kernel, makefile files under each layer directory

? The. config file, arm/$ARCH/config file under the root directory of the Linux kernel

? Include/generated/autoconf.h files in the root directory of the Linux kernel

Overall flow: Make menuconfig----make zimage (generate Zimage)----make modules----make Modules_install----init RAMDisk

1) Scripts folder is a file that is related to the graphical drawing of Make Menuconfig configuration interface, we as the user need not care about the contents of this folder

2) When we execute the make Menuconfig command to appear above the blue Configuration interface, the system has done the following work for us:

First the system reads the Kconfig file from the arch/$ARCH/directory to generate the entire Configuration Interface option (Kconfig is the core of the entire Linux configuration mechanism), so what is the value of the ARCH environment variable?

It is determined by the makefile file in the root directory of the Linux kernel and is defined under makefile with this environment variable:

or by the Make Arch=arm menuconfig command to generate the configuration interface, the default generated interface is that all parameters are not values.

For example, the academic office to carry out examinations, the number of examinations may have foreign languages, languages, mathematics and other subjects, here is equivalent to our Choice ARM branch can take the exam, the system will read the Arm/arm/kconfig file generation configuration options (selected arm section of the paper), the system also provides the x86 section, Milps and other 10 subjects of the examination questions.

3) menu configuration is cumbersome, kernel configuration is usually based on an existing configuration file, modified to obtain a new configuration file The Linux kernel provides a series of reference kernel configuration files, located in/linux-2.6.28-omap/arch/$arm/configs

If the academic department compared "kindness", in order to fear some students do good test, we also prepared a reference answer (default configuration option), stored in arch/$ARCH/configs, for ARM section is Arch/arm/configs folder:

There are many options in this folder, which will be read by the system? The kernel defaults to reading the Linux kernel root directory. config file as the default option for the kernel (the reference answer to the question), we will generally choose from the Development Board type of the closest to our Development Board series to the root of the Linux kernel (select a closest reference answer).

#根目录下操作

#cp arch/arm/configs/s3c2410_defconfig. config

4). config

Assuming that the academic office has left simpleton, the reference answer he provided is not entirely correct (the. config file does not exactly match our board), then we can choose to modify the. config file directly and then execute the make Menuconfig command to read the new options

But generally we do not take this approach, we choose to configure the interface through the space, ESC, enter select some options selected or unchecked, and finally save the exit, The Linux kernel updates the new option (the correct reference answer) to the. config, at which point we can rename the. config to a different file to save (when you do Distclean when the system will delete the. config file, we will not need to go to Arch/arm/configs to obtain the corresponding files in the future when we configure the kernel, save the trouble of reconfiguration, directly copy the saved. config file to. config.

5) After the above two steps, we can correctly read and configure the interface we need

So how do they build a compilation relationship with makefile files?

When you save the Make Menuconfig option, the system will also save all options in the form of a macro, in addition to automatically updating. config.

Under the Linux kernel root directory under the Include/generated/autoconf.h file

The source code in the kernel will contain the above. h file, with the definition of a macro conditional compilation.

When we need to select a file as a whole, such as whether or not to compile, we also need to modify the corresponding makefile file, for example:

We choose whether to compile s3c2410_ts.c this file, makefile will be based on config_touchscreen_s3c2410 to decide is to compile this file, this macro is defined in the Kconfig file, when we configure the completion, will appear in. config and autconf, so we have completed the entire Linux kernel compilation process.

Finally, we will find that throughout the Linux kernel configuration process, the interface left to the user is actually only the layers of kconfig, makefile files and corresponding source files.

For example, if we want to add a function to the kernel and control its claim process through make menuconfig.

The first thing to do is: modify the corresponding directory of the Kconfig file, according to the Kconfig syntax to add the corresponding options;

Next execute make Menuconfig choose to compile into the kernel or not compile into the kernel, or compile into a module, the. config file and the autoconf.h file will be generated automatically;

Finally modify the corresponding directory of the makefile file to complete the compilation options to add;

Finally the final execute make bzimage command is compiled. 1.2 Description of kernel configuration options

Because s6410 and 6400 of the resources are similar, the main frequency and peripheral a little difference, so in board/samsung/under the establishment of their own Development Board project, named Smdk6410. and copy all the files in the smdk6400 to smdk6410, enter the smdk6410 folder to rename smdk6400.c to Smdk6410.c, and open this file to change the inside of 6400 all to 6410. Open the Makfile and change the 6400 inside to 6410.

The configuration mechanism of Linux kernel and its compiling process

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.