Kconfig, Makefile, And. config in Linux Kernel

Source: Internet
Author: User

This article reference article address: http://hi.baidu.com/donghaozheng/blog/item/02e1b231f0df64a25fdf0eea.html

For more information, see the MICRO2440 user manual.

Mao learned how to install and uninstall the driver module. During this process, Mao found that many Kconfig and Makefile files are in the kernel directory, but Mao does not know why these files are needed, what are these files used. Next we will study the role of these documents with Tao Mao.
First, let's learn what Makefile, What Is Kconfig, and what is. config.
Makefile: a text file that contains rules to tell make which files to compile and how to compile them.

Kconfig: a text file that is used as a configuration option during Kernel configuration.

. Config: The file is a reference file for Kernel compilation generated after configuration during Kernel configuration.

Kconfig

1. First understand the Kconfig Syntax:
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
The content contained in menu/endmenu is a sub-menu of Network device support. Each sub-menu item is defined by config. The bool, depends on, default, and help attributes under congfig are config attributes used to define the type, dependency, default value, and help information of the menu item.
2. Add the following types:
Each config menu item must have a bool boolean type, tristate three-state (built-in, module, remove), string, hex hexadecimal, and integer type.
For example:
Config HELLO_MODULE
Bool "hello test module"
The bool type can only be selected or not selected, and is displayed as []; the tristate type menu items include the option to compile to the kernel module, which is displayed as <>. If you choose to compile to the kernel module, in. generate a CONFIG_HELLO_MODULE = m configuration in config. If the built-in configuration is selected, it is directly compiled into the kernel. generate a CONFIG_HELLO_MODULE = y configuration in config. hex hexadecimal type is displayed ().

3. Directory level Iteration
Similar statement in Kconfig: source "drivers/usb/Kconfig"
It is used to include (or nest) New Kconfig files, so that each directory can manage its own configuration content, so that you do not have to write those configurations in the same file for ease of modification and management.

Bytes ----------------------------------------------------------------------------------------------

Makefile
The 2.6 kernel Makefile consists of five components:
1. The top-level Makefile
2. The. config configuration file of the kernel
3. Makefile related to the architecture under the arch/$ (ARCH) Directory
4. The Makefile. * file under the s directory is a general rule for some makefiles.
5. About 500 kbuild Makefile files under directories at different levels

The Makefile on the top layer reads the content of the. config file, and is responsible for building the kernel and module. Arch Makefile provides supplementary information about the architecture. The Makefile in the s directory contains all the definitions and rules required to build the kernel based on the kbuild Makefile.

Kbuild Makefile
There are some different syntax rules for different components of Makefiles. The targets are also different. For most developers and users of kernel modules or device drivers, kbuild Makefile files based on the kbuild architecture under the directories of different layers are most commonly exposed. The core content of Kbuild Makefile mainly includes:
1. Target Definition
The target definition is used to define the content to be compiled as a module and the content to be compiled and linked to the kernel. For example:

Obj-y + = foo. o

It indicates that foo. o needs to be compiled by the foo. c or foo. s file and linked to the kernel, while obj-m indicates that the file should be compiled as a module. Objects in the obj-x format except y and m will not be compiled. The more common practice is to determine the file Compilation Method Based on the config _ variable of the. CONFIG file (for how the variable works, see the link of another article at the end of this Article), such:
Obj-$ (CONFIG_EXT2) + = ext2.o

In addition to objects in the obj-format, there are also targets such as lib-y library and hostprogs-y Host Program, but they are basically applied in specific directories and scenarios.

Example:

The following example describes the functions of these files.

Step 1: edit the configuration file Kconfig and add the driver option so that it appears when make menuconfig
Open the linux-2.6.32.2/drivers/char/Kconfig file and add:

Save and exit, then run make menuconfig in the linux-2.6.32.2 directory
The options added in the Drivers Character devices menu are displayed. Press the Space key and select <M>,
This means to compile this option into a module mode, and press a space to change to <*>, which means to compile this option into the kernel,
Here we select <M>,

Step 2: Through the previous step, although we can select the kernel during Kernel configuration, we still cannot compile mini2440_hello_module.c during kernel compilation, you also need to link the Kernel configuration options with the real source code in Makefile, open the linux-2.6.32.2/drivers/char/Makefile, add and save and exit:

 

Step 3: Return to the linux-2.6.32.2 source code root directory location, execute make modules, we can generate the kernel module File mini2440_hello_module.ko, so far, we have completed the module driver compilation.

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.