How to configure kconfig in the kernel

Source: Internet
Author: User
Tags alphanumeric characters

2.6 The source code tree directory of the kernel usually contains two files: kconfig and makefile. Kconfig distributed in various directories forms a distributed Kernel configuration database. Each kconfig describes the Kernel configuration menus related to the directory source files. When you configure make menuconfig (or xconfig) in the kernel, read the configuration menu from kconfig and save it to. config (generated in the top-level directory) after the configuration is complete. When the kernel is compiled, the main makefile calls this. config and you will be able to understand the Kernel configuration.

The preceding content indicates that 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 add the configuration menu for our driver. In this way, you can choose our driver, if you want to compile the driver, you must modify the makefile in the directory where the driver is located.

Therefore, there are two types of files to be modified when a new driver is added (note not only two files)

* Kconfig
* Makefile

To know how to modify these two types of files, you must know the syntax structure of the two types of documents.

First: kconfig

 

Each menu item has a keyword identifier, and the most common one is config.

Syntax:
Config symbol

Options
<! -- [If! Supportlinebreaknewline] -->
<! -- [Endif] -->

Symbol is a new menu item. options is the attributes and options under this new menu item.

The options section includes:

1. Type Definition:
Each config menu item must have a type definition, bool: boolean type, tristate three states: built-in, module, remove, string: String, HEX: hexadecimal, integer: 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
Whether the appearance of this menu 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. That is, the menu is visible (configurable) only when arch_pxa is selected ).

3. Definition of help
Just add the help keyword help or --- help ---
<! -- [If! Supportlinebreaknewline] -->
<! -- [Endif] -->

For more detailed kconfigconfig syntax, refer:

Second: 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)

In the linux2.6.x/documentation/kbuild directory, you can learn more about Kernel makefile.

The last example is as follows:
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.

Bytes --------------------------------------------------------------------------------------------------------------------
Kconfig Syntax of linux2.6.x configuration file

 

 

In Linux 2.6 and later versions, the configuration file is changed from the original config. In to kconfig. The kconfig syntax is described in detail in/documentation/kbuild/kconfig-language.txt. here, the Chinese version of kconfig-language.txt is provided.
Introduction
----

The configuration options in the configuration database are organized in the form of a tree:

+-Code maturity level options
| +-Prompt for development and/or incomplete code/Drivers
+-General setup
| +-Networking Support
| +-System V IPC
| +-BSD process accounting
| +-Sysctl support
+-Loadable module support
| +-Enable loadable module support
| +-Set version information on all module symbols
| +-Kernel module Loader
+ -...

Each option has its own dependency. These dependencies determine whether the options are visible. The parent option is visible, and the Child option is visible.

Menu Options
--------

Most options define a configuration option, and other options help to organize them. (Original article: Most entries define
A config option, all other entries help to organize them.) A configuration option definition can be as follows:
Format:

Config modversions
Bool "set version information on all module symbols"
Depends modules
Help
Usually, modules have to be recompiled whenever you switch to a new
Kernel ....

Each line starts with a keyword and can be connected to multiple parameters. "Config" defines a new configuration option. The following lines define the configuration
Option. Attribute can be the type of the configuration option, input prompt (input prompt), dependency, help information, and default value. I
Configuration options can be defined multiple times with the same name, but each definition can only have one input prompt and the type cannot conflict.

Menu Properties
--------

One menu option can have multiple attributes. These attributes are not required to be used anywhere (see syntax ).

-Type Definition: "bool"/"tristate"/"string"/"hex"/"int"
The type must be specified for each configuration option. There are two basic types: Tristate and string. Other types are based on these two basic types.
Type. You can use the input prompt to define the type, so the two examples below are equivalent:

Bool "Networking support"
And
Bool
Prompt "Networking support"

-Input prompt: "prompt" <prompt> ["if" <expr>]
Each menu option can have only one input prompt displayed to the user. You can use "if" to indicate the dependency of the prompt. Of course this is
Optional.

-Default value: "default" <expr> ["if" <expr>]
One configuration option can have any number of default values. If multiple default values exist, only the first defined value is available. Default Value and
It is not limited to defining their menu options for applications. This means that the default value can be defined anywhere or earlier.
If you have not set the value (as prompted by the preceding input), the value of the configuration option is the default value. If the input prompt is displayed
The default value is displayed to the user and can be modified by the user.
You can use "if" to add the default dependency. (Optional)

-Dependency: "depends on"/"requires" <expr>
Define dependencies for the menu options. If multiple dependencies are defined, separate them. Dependencies can also be applied
All other options in this menu (the same if expression is accepted), so the following two examples are equivalent:

Bool "foo" If bar
Default y if Bar
And
Depends on bar
Bool "foo"
Default y

-Reverse dependency: "select" <symbol> ["if" <expr>]
Although normal dependency can reduce the upper limit of one option, reverse dependency can lower this limit. The value of the current menu option is symbol.
. If the symbol is selected multiple times, the upper limit is the maximum value.
The reverse dependency can only be used on the Boolean OR tristate options.

-Data range: "range" <symbol> ["if" <expr>]
The input value range is acceptable for int and hex options. The user can only enter equal to or greater than the first symbol, less than or equal to the second
The value of the symbol.

-Help: "Help" or "--- help ---"
Define help information. The end of the help information is determined by the indentation level, which means that the information is in the first line
The end of the line with a small indentation.
"--- Help ---" and "help" have no difference in implementation. "--- help ---" helps to compare the configuration logic in the file
Separate prompts for developers.

Menu dependency
------------

Dependency determines whether the menu options are visible or not. It can also reduce the input range of tristate. Tristate logic compared with Boolean logic in the table
More States are used to indicate the status of a module. The syntax of the dependency expression is as follows:

<Expr >::= <symbol> (1)
<Symbol> '=' <symbol> (2)
<Symbol> '! = '<Symbol> (3)
'(' <Expr> ')' (4)
'! '<Expr> (5)
<Expr> '&' <expr> (6)
<Expr> '|' <expr> (7)

Expressions are listed in descending order of priority.

(1) Assign the symbol to the expression. The Boolean and tristate types are directly assigned to the expression. All other types of Symbol
All are assigned 'n '.
(2) If two symbrs are equal, 'y' is returned; otherwise, 'n' is returned '.
(3) If two symbrs are equal, 'n' is returned; otherwise, 'y' is returned '.
(4) return the value of the expression. Used to change the priority.
(5) return the result of (2-/expr.
(6) return the results of min (/expr/,/expr.
(7) return the result of max (/expr/,/expr.

The value of an expression can be 'n', M', or 'y' (or the result 0, 1, 2 ). When the expression value is 'M' or 'y ',
A single item is visible.

There are two types of Symbol: immutable and mutable. The immutable symbol is the most common, defined by the 'config' statement and completely composed of numbers
Alphanumeric characters or underscores ).
Immutable symbol is only part of the expression. It is often enclosed in single or double quotation marks. Any character can be used in quotation marks.
Escape Character '/'.

Menu structure
--------

The menu position in the tree can be determined by two methods. The first method can be as follows:

Menu "network device support"
Depends net

Config netdevices
...

Endmenu

All sub-menus between "menu"... "endmenu" are "network device support. All sub-menu options
All inherit the dependency of the parent menu. For example, the dependency of "net" is added to the dependency list of the configuration option netdevices.

In addition, the menu structure is generated by analyzing dependencies. If the menu option depends on the previous option to a certain extent, it can become
Sub-menu. First, the preceding (parent) options must be part of the dependency list and must have options that meet the following two conditions:
-If the parent option is 'n', the sub-options must be invisible.
-If the parent option is visible, the Child option can be visible.

Config modules
Bool "enable loadable module support"

Config modversions
Bool "set version information on all module symbols"
Depends modules

Comment "module support disabled"
Depends! Modules

Modversions depends on modules directly, which means that this option is visible if modules is not 'n. In other words, when
When modules is visible, options are visible (the (null) Dependency of modules is also part of the Option dependency ).

Kconfig syntax
------------

The configuration file describes the menu options. Each line starts with a keyword (except the help information ). The following keyword ends a menu option:
-Config
-Menuconfig
-Choice/endchoice
-Comment
-Menu/endmenu
-If/endif
-Source
The first five can also be used at the beginning of the menu option definition.

Config:

"Config" <symbol>
<Config Options>

A configuration option <symbol> is defined and can accept any attribute described above.

Menuconfig:
"Menuconfig" <symbol>
<Config Options>

This keyword is similar to the previous keyword, but it requires that all sub-options be displayed as independent rows on the basis of the previous keyword. (This is
Similar to the simple config entry above, but it also gives a hint to front
Ends, that all suboptions shoshould be displayed as a separate list of options .)

Choices:

"Choice"
<Choice options>
<Choice block>
"Endchoice"

This keyword defines a set of selection items, and the options can be any attribute described above. Although Boolean allows only one configuration option,
Tristate can be set to 'M' for multiple configuration options, but the option can only be Boolean OR tristate type. This can be achieved through multiple
Only one driver is compiled into/loaded into the kernel, but all the drivers can be compiled into modules.
Another option that is acceptable is "optional", so that the option is set to 'n', not selected.

Comment:

"Comment" <prompt>
<Comment Options>

The comment displayed to the user during the configuration process is defined here and will be written into the output file. The only available option is dependency.

Menu:

"Menu" <prompt>
<Menu Options>
<Menu block>
"Endmenu"

A menu is defined here. For more information, see "menu structure ". The only available option is dependency.

If:

"If" <expr>
<If block>
"Endif"

The IF structure is defined here. Dependency <expr> is added to all menu options in if... endif.

 

 

Choice
Prompt "NAND Flash capacity select"
Depends on MTD
Help
Embedsky board NAND Flash capacity select

Config embedsky_64mb_nand
Boolean "64 mb nand for embedsky board"
Depends on MTD
Help
Set 64 mb nand parts

Config embedsky_128mb_nand
Boolean "128 mb nand for embedsky board"
Depends on MTD
Help
Set 128 mb nand parts

Config embedsky_more_than_256mb_nand
Boolean "256mb ~ 1 gb nand for embedsky board"
Depends on MTD
Help
Set 256mb ~ 1 gb nand parts

Endchoice

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.