Kconfig, Makefile,. Config__linux in the Linux kernel

Source: Internet
Author: User
This article refers to the article address: http://hi.baidu.com/donghaozheng/blog/item/02e1b231f0df64a25fdf0eea.html

This article refers to the friendly arm of the MICRO2440 user manual

Fluffy students today learned the driver module installation and uninstall, in the process of fluffy found that the kernel of the directory there are many kconfig, makefile files, but Fluffy do not know why they need these files, these files are used to do what. Next we will be together with TAUMAUMAO students to learn what the role of these documents.
First we will learn what makefile, what is kconfig, and what is. config
Makefile: A text-form file that contains rules that tell make which files to compile and how to compile them.

Kconfig: A text-form file in which the primary role is to configure the kernel as a configuration option.

. config: A file is a kernel-configured kernel-compiled reference file when it is configured.

Kconfig

1. Learn the grammar of Kconfig first:
A typical kernel configuration menu is as follows:
Menu "Network device Support"
Config netdevices
BOOL "Enable Net Devices"
Depends on NET
Default Y
Help
This is help desciption.
...
Endmenu
Content contained in Menu/endmenu becomes a submenu of network device support. Every submenu item is defined by CONFIG. The properties of bool, depends on, default, and help, as config, below congfig to define the type, dependencies, defaults, assistance information, and so on for the menu item.
2. Add a description of the type definition section:
Each config menu item must have a type definition: bool Boolean type, TriState three state (Builtin, module, remove), string string, Hex 16, Integer int.
For example:
Config Hello_module
BOOL "Hello Test module"
type bool can only be selected or unchecked, displayed as []; TriState type of menu items are compiled into the kernel module options, shown as < >, if you choose to compile into a kernel module, you will generate a config_hello_module=m configuration in. CONFIG, if you choose to build, you directly compile into the kernel impact, A config_hello_module=y configuration is generated in. CONFIG. The hex hexadecimal type is displayed as ().

3. Directory Hierarchy iterations
There are similar statements in Kconfig: source "Drivers/usb/kconfig"
Used to include (or nest) new kconfig files so that each directory manages its own configuration, making it easier to modify and manage without having to write those configurations in the same file.

----------------------------------------------------------------------------------------------

Makefile
The makefile of the 2.6 kernel is divided into 5 components:
1. The top floor of the makefile
2. config profile of the kernel
3. Architecture-related Makefile in the arch/$ (ARCH) directory
4. The makefile.* file in the S directory is a common rule for some Makefile
5. Approximately 500 Kbuild makefile documents at all levels of the catalogue

The makefile file at the top level reads the contents of the. config file and is responsible for the build kernel and the module overall. Arch Makefile provides additional architecture-related information. The Makefile file in the S directory contains all the definitions and rules needed to build the kernel according to the Kbuild Makefile.

Kbuild Makefile
There are some different grammatical rules for the different parts of the makefiles. The objects are also different, and for most kernel modules or device-driven developers and users, the most common contact is the Kbuild makefile files based on the Kbuild architecture in each level of the directory. Kbuild Makefile Core content mainly includes:
1. Target definition
The goal definition is to define what content to be compiled for the module, and which to compile the link into the kernel. Such as:

Obj-y + + FOO.O

Represents the foo.o to be compiled by FOO.C or FOO.S files and linked into the kernel, while obj-m indicates that the file is to be compiled as a module. Targets in the form of obj-x other than y,m are not compiled. The more common approach is to determine how the file is compiled based on the config_ variable of the. config file (this variable works as a link to another article at the end of article), such as:
obj-$ (CONFIG_EXT2) + + EXT2.O

In addition to the obj-form of the goal, there are Lib-y library, hostprogs-y host programs and other goals, but the basic applications are in specific directories and occasions.

Example Description:

Let's take an example to illustrate the role of these files

STEP1: Edit the configuration file Kconfig and add the driver option to make Menuconfig
Open the Linux-2.6.32.2/drivers/char/kconfig file and add it as shown in the picture:

Save exit, then run the make Menuconfig at the linux-2.6.32.2 directory location in device
Drivers Character Devices menu to see the option just added, press the space bar will be selected as <m>
The idea is to compile the option into a modular way, and then press the space to become <*>, meaning to compile the option into the kernel,
Here we choose <m>, as shown in figure:

STEP2: In the last step, although we can choose to configure the kernel, but in fact, the implementation of the compiler at this time can not compile the mini2440_hello_module.c, but also in the makefile to the kernel configuration options and real source code, Open Linux-2.6.32.2/drivers/char/makefile, as shown in Figure Add and save exit:

STEP3: Then back to linux-2.6.32.2 source code root location, execute make modules, you can generate the kernel module file we need Mini2440_hello_module.ko, as shown: So far, we have completed the module-driven compilation.

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.