The role of Kconfig in Linux kernel-general Linux technology-Linux programming and kernel information. For more information, see the following section. The Directory of the kernel source code tree contains two documents: Kconfig (Config. in version 2.4) and Makefile. The Kconfig distributed to each directory constitutes a distributed Kernel configuration database. Each Kconfig describes the Kernel configuration menus related to the source document of the directory. When you configure make menuconfig (or xconfig) in the kernel, read the menu from Kconfig and save it to the Kernel configuration document of. config. When the kernel is compiled, the main Makefile calls this. config, and the user's choice is known.
As described above, Kconfig corresponds to the Kernel configuration menu. If you want to add a new driver to the kernel source code, you can modify Kconfig to select the driver. If you want to compile the driver, you need to modify the Makefile.
Therefore, there are two types of documents to be modified when adding a new driver (note not only two)
* Kconfig
* Makefile
To know how to modify these two documents, you must know the syntax structure of the two documents.
First: Kconfig
Each menu has a keyword identifier, and the most common one is config.
Syntax:
Config
Symbol is a new marked menu item. options is the attribute and option under this new menu item.
The options section includes:
1. Type Definition:
Each config menu item must have a type definition, Boolean bool type, tristate three states: Built-in, module, Remove string, hex hexadecimal, integer
For example, config HELLO_MODULE
Bool "hello test module"
The bool type can only be selected or not selected. The menu items of the tristate type have more options for compiling to the kernel module. If the option is compiled to the kernel module, it will be 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.
2. Dependency-defined depends on or requires
Indicates whether or not the menu appears depends on another definition.
Config HELLO_MODULE
Bool "hello test module"
Depends on ARCH_PXA
This example shows that the menu item HELLO_MODULE is only valid for the XScale processor.
3. Definition of help
Just add the help keyword help or --- help ---
Second: Kernel Makefile
In the linux2.6.x/Documentation/kbuild directory, have a detailed introduction to kernel makefile.
The kernel Makefile consists of five components:
Makefile at the top layer
The current configuration document of the. config kernel, which is compiled as part of the top-level Makefile.
Arch/$ (ARCH)/Makefile related to the architecture
S/Makefile. * some general Makefile rules
The kbuild Makefile directory contains about 500 documents. during compilation, the source code is compiled into modules or into the kernel based on the macro definition passed by the upper Makefile and other compilation rules.
The Makefile document at the top layer reads the content of the. config document and is generally responsible for building the kernel and module. Arch Makefile provides supplementary information about the architecture. The Makefile document under the s directory contains any definitions and rules required to build the kernel based on the kbuild Makefile.
(The content of. config is the result of Kconfig configuration in make menuconfig)
For example:
Suppose you want to load a flash Driver written by yourself into the project, and you can select this driver when configuring the kernel through menuconfig. What should I do? It can be divided into three steps:
1. Add the flashtest. c file you wrote to the/driver/mtd/maps/directory.
2. Modify the kconfig document in the/driver/mtd/maps directory:
Config MTD_flashtest
Tristate "ap71 flash"
In this way, the ap71 flash option will appear when you make menuconfig.
Third, modify the makefile document in this directory.
Add the following content: obj-$ (CONFIG_MTD_flashtest) + = flashtest. o
In this way, when you run make menucofnig, you will find the ap71 flash option, if you select this option. This option is saved in the. config document. When you compile the kernel, it will read. config file. When the ap71 flash option is yes, when the system calls makefile under/driver/mtd/maps/, the flashtest. o is added to the kernel. To achieve your purpose.
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