曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 10008|回复: 0
打印 上一主题 下一主题

Kconfig 中的 tristate, depends on 与 if

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34397
跳转到指定楼层
楼主
发表于 2011-7-13 14:47:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Kconfig 对应内核版本:2.6.35.13

在 Kconfig 中, tristate 表示三态性,即:
"M" -- 以模块方式加载到内核
"y“ -- 直接编译进内核
"n" -- 不选。

下面看一个实例:
在 init/Kconfig 中看到:
433 config IKCONFIG
434         tristate "Kernel .config support"
435         ---help---
436           This option enables the complete Linux kernel ".config" file
437           contents to be saved in the kernel. It provides documentation
438           of which kernel options are used in a running kernel or in an
439           on-disk kernel.  This information can be extracted from the kernel
440           image file with the script scripts/extract-ikconfig and used as
441           input to rebuild the current kernel or to build another kernel.
442           It can also be extracted from a running kernel by reading
443           /proc/config.gz if enabled (below).
”Kernel .config support“ 这一行提示符会在 make menuconfig 产生的菜单的 General setup 栏里看到(由 init/Kconfig 的第 24 行的 menu "General setup" 可知):

因为 tristate "Kernel .config support" 没有对该选项做任何限定,所以默认时它是不选的,为 "n" 。

当连续按下空格键时,可以看到有 3 种状态循环显示,分别为:<> , <M>, <*> 。这就是该选项的三态性。注意到,当处于 <M> 或 <*> 两种状态时,底下会展开另一个选项:



为什么会这样?

在 init/Kconfig 的第 445 行看到:
445 config IKCONFIG_PROC
446         bool "Enable access to .config through /proc/config.gz"
447         depends on IKCONFIG && PROC_FS
448         ---help---
449           This option enables access to the kernel configuration file
450           through /proc/config.gz.
由上面的 depends on 知道,”Enable access to .config through /proc/config.gz“ 这一项依赖于  IKCONFIG 和 PROC_FS 。我们再在 make menuconfig 菜单里搜索 PROC_FS 选项:
Symbol: PROC_FS [=y]                                                                          
  │ Prompt: /proc file system support                                                              
  │   Defined at fs/proc/Kconfig:1                                                                 
  │   Depends on: EMBEDDED [=n]                                                                    
  │   Location:                                                                                    
  │     -> File systems                                                                            
  │       -> Pseudo filesystems  
知道 PROC_FS 该项已经默认为 y 。所以,综上可知,当在菜单中对 Kernel .config support 选择 <M> 或 <*> 时, IKCONFIG 项为真;当 IKCONFIG &&  PROC_FS 同时为真时依赖满足,因此 ”Enable access to .config through /proc/config.gz“ 该选项便可以显示出来。

最后还注意到,PROC_FS 还依赖于 EMBEDDED,但是由上面 Depends on: EMBEDDED [=n]  看到  EMBEDDED 项预设是 n ,那么按照上面所说,PROC_FS 项应该不能显示在菜单里才对,然而实际上它已经显示出来。这时,看 fs/proc/Kconfig 里:
1 config PROC_FS
  2         bool "/proc file system support" if EMBEDDED
  3         default y
EMBEDDED 前面是有 if 声明。"if" 表示这是提示性依赖关系(也是一种 depends on),当然这是可选的。既然是可选的提示性依赖,那么它即使预设为 "n" ,也不会影响该项显示出来。当然了,如果你将 if 去掉,并在底下改成 depends on EMBEDDED ,这样显式的声明依赖性,那么该项就不会在菜单中显示出来了。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2025-6-17 23:49 , Processed in 0.068450 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表