The connection between menuconfig, kconfig, .config

1. How menuconfig works

1.1, menuconfig itself is supported by a set of software

(1) In order to realize the configuration of the graphical interface, linux provides a set of configuration tools menuconfig.
(2) The ncurses library is used in linux to implement a textual graphical interface. The ncurses library is used in the linux kernel to provide menuconfig
(3) Some c files in the scripts\kconfig\lxdialog directory are used to provide the program sources of menuconfig code.


1.2, menuconfig reads Kconfig file

(1) The software of menuconfig itself is only responsible for providing this set of logic for menuconfig work (for example, in menuconfig, the cursor is adjusted by the up, down, left, and right arrow keys, and the response of keys such as Enter ESC key is pressed), and it is not responsible for providing content (menu items in).
(2) The menu content displayed by menuconfig (on the one hand, the directory structure of the menu, on the other hand, the details of each menu item) is supported by the Kconfig files in each directory of the kernel source tree. The Kconfig file contains one configuration item after another in a certain format, and each configuration item will become a menu item in make menuconfig. And the menu directory structure displayed in menuconfig is the same as that of Kconfig in the source directory.
(3) Delete a config item in the corresponding Kconfig file, and the item will no longer be visible when making menuconfig again.


1.3, menuconfig read/write .config file

(1) It has been known that the menu content of menuconfig comes from the Kconfig file, but the selection results (Y, N, M) of each menu are not saved in the Kconfig file. The Kconfig file is unchanged. The Kconfig file only decides whether there is this menu item or not, regardless of the selection result of this menu item.
(2) When menuconfig is working, when we open make menuconfig, it will read the .config file, and use the configuration selection result in the .config file to initialize the selection value of each menu item in menuconfig.


Summary: The item content of the menu item comes from the Kconfig file, and the selection value of the menu item comes from the .config file


(3) When we exit make menuconfig each time, the menuconfig mechanism will first check whether we have changed the value of some configuration items, If we have not changed the value of any configuration item this time, exit directly; if we have changed the value of the configuration item, we will be prompted whether to save. At this point, if you click Save, the changed configuration will be rewritten into the .config file to record. The next time you open make menuconfig again, .config will be loaded again, and the linker in .config will be considered when compiling the kernel. Configuration values ​​guide the entire compilation and linking process.


Summary: The main content of this lesson is to talk about: the relationship between menuconfig and Kconfig and .config.




2. Detailed explanation of Kconfig file 1

2.1, Kconfig format

(1)Kconfig按照一定的格式来书写,menuconfig程序可以识别这种格式,然后从中提取出有效信息组成menuconfig中的菜单项。
(2)将来在做驱动移植等工作时,有时需要自己添加Kconfig中的一个配置项来将某个设备驱动添加到内核的配置项目中,这时候就需要对Kconfig的配置项格式有所了解,否则就不会添加。
(3)#开头的行是注释行
(4)menuconfig表示菜单(本身属于一个菜单中的项目,但是他又有子菜单项目)、config表示菜单中的一个配置项(本身并没有子菜单下的项目)。
(5)menuconfig或者config后面空格隔开的大写字母表示的类似于 NETDEVICES 的就是这个配置项的配置项名字,这个字符串前面添加CONFIG_后就构成了.config中的配置项名字。
(6)一个menuconfig后面跟着的所有config项就是这个menuconfig的子菜单。这就是Kconfig中表示的目录关系。
(7)内核源码目录树中每一个Kconfig都会source引入其所有子目录下的Kconfig,从而保证了所有的Kconfig项目都被包含进menuconfig中。这个也告诉我们:如果你自己在linux内核中添加了一个文件夹,一定要在这个文件夹下创建一个Kconfig文件,然后在这个文件夹的上一层目录的Kconfig中source引入这个文件夹下的Kconfig文件。


2.2、tristate和bool的含义

(1)tristate意思是三态(3种状态,对应Y、N、M三种选择方式),bool是要么真要么假(对应Y和N)。所以tristate的意思就是这个配置项可以被三种选择,bool的意思是这个配置项只能被2种选择。




3.Kconfig文件详解2

3.1、depends的含义

(1)depends中文意思是“取决于”或者“依赖于”,所以depends在这里的意思是:本配置项依赖于另一个配置项。如果那个依赖的配置项为Y或者M,则本配置项才有意义;如果依赖的哪个配置项本身被设置为N,则本配置项根本没有意义。
(2)depends项目会导致make menuconfig的时候找不到一些配置项。所以你在menuconfig中如果找不到一个选项,但是这个选项在Kconfig中却是有的,则可能的原因就是这个配置项依赖的一个配置项是不成立的。
(3)depends并不要求依赖的配置项一定是一个,可以是多个,而且还可以有逻辑运算。这种时候只要依赖项目运算式子的裸机结果为真则依赖就成立。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325858249&siteId=291194637