GNU/Linux - Kconfig Language - 1

Introduction

配置数据库是以树形结构组织的配置选项集合:

The configuration database is a collection of configuration options organized in a tree structure:

+- 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

+- ...

每个条目都有自己的依赖关系。这些依赖关系用于确定条目的可见性。任何子条目只有在其父条目也可见时才可见。

Every entry has its own dependencies. These dependencies are used to determine the visibility of an entry. Any child entry is only visible if its parent entry is also visible.

Menu entries | 菜单条目

大多数条目都定义了一个配置选项;所有其他条目都有助于组织这些选项。单个配置选项的定义如下

Most entries define a config option; all other entries help to organize them. A single configuration option is defined like this:

config MODVERSIONS

      bool "Set version information on all module symbols"

      depends on MODULES

      help

        Usually, modules have to be recompiled whenever you switch to a new

        kernel.  ...

每一行都以一个关键词开头,后面可以跟多个参数。"config "开始一个新的配置项。下面几行定义了该配置选项的属性。属性可以是配置选项的类型、输入提示、依赖关系、帮助文本和默认值。一个配置选项可以用相同的名称定义多次,但每次定义只能有一个输入提示,且类型不得冲突。

Every line starts with a key word and can be followed by multiple arguments. “config” starts a new config entry. The following lines define attributes for this config option. Attributes can be the type of the config option, input prompt, dependencies, help text and default values. A config option can be defined multiple times with the same name, but every definition can have only a single input prompt and the type must not conflict.

Menu attributes | 菜单属性

菜单条目可以有多种属性。并非所有属性都适用于所有地方(参见语法)。

A menu entry can have a number of attributes. Not all of them are applicable everywhere (see syntax).

  • type definition: "bool"/ "tristate"/ "string"/ "hex"/ "int"

每个配置选项都必须有一个类型。只有两种基本类型:三态和字符串;其他类型以这两种类型为基础。类型定义可选择接受输入提示,因此这两个示例是等价的:

Every config option must have a type. There are only two basic types: tristate and string; the other types are based on these two. The type definition optionally accepts an input prompt, so these two examples are equivalent:

bool "Networking support"

and:

bool

prompt "Networking support"

  • input prompt: "prompt" <prompt> ["if" <expr>]

每个菜单项最多只能有一个提示,用于向用户显示。可以用 "if "添加仅适用于该提示的依赖项。

Every menu entry can have at most one prompt, which is used to display to the user. Optionally dependencies only for this prompt can be added with “if”.

  • default value: "default" <expr> ["if" <expr>]

一个配置选项可以有任意多个默认值。如果可以看到多个默认值,则只有第一个定义的默认值有效。默认值并不局限于定义默认值的菜单项。这意味着默认值可以在其他地方定义,也可以被先前的定义覆盖。只有在用户没有设置其他值的情况下(通过上述输入提示),默认值才会分配给配置符号。如果输入提示可见,默认值就会显示给用户,用户可以自行更改。可以选择使用 "if "添加仅适用于该默认值的依赖关系。

A config option can have any number of default values. If multiple default values are visible, only the first defined one is active. Default values are not limited to the menu entry where they are defined. This means the default can be defined somewhere else or be overridden by an earlier definition. The default value is only assigned to the config symbol if no other value was set by the user (via the input prompt above). If an input prompt is visible the default value is presented to the user and can be overridden by him. Optionally, dependencies only for this default value can be added with “if”.

默认值特意设置为 "n",以避免编译过程臃肿。除少数例外情况外,新的配置选项不应改变默认值。make oldconfig "的目的是尽可能少地从一个版本添加到另一个版本的配置中。

The default value deliberately defaults to ‘n’ in order to avoid bloating the build. With few exceptions, new config options should not change this. The intent is for “make oldconfig” to add as little as possible to the config from release to release.

注意:

值得使用 "default y/m "的内容包括

1, 一个新的 Kconfig 选项,如果过去总是内置的,则应使用 "default y"。

2, 隐藏/显示其他 Kconfig 选项(但自身不生成任何代码)的新把关 Kconfig 选项应为 "default y",这样人们就能看到其他选项。

3, 子驱动程序行为或驱动程序的类似选项应为 "default n"。这样可以提供合理的默认值。

4, 大家都期望使用的硬件或基础架构,如 CONFIG_NET 或 CONFIG_BLOCK。这些都是罕见的例外情况。

Note:

Things that merit “default y/m” include:

1. A new Kconfig option for something that used to always be built should be “default y”.

2. A new gatekeeping Kconfig option that hides/shows other Kconfig options (but does not generate any code of its own), should be “default y” so people will see those other options.

3. Sub-driver behavior or similar options for a driver that is “default n”. This allows you to provide sane defaults.

4. Hardware or infrastructure that everybody expects, such as CONFIG_NET or CONFIG_BLOCK. These are rare exceptions.

  • type definition + default value:

"def_bool" / "def_tristate" <expr> ["if" <expr>]

这是一个类型定义加上一个值的速记符号。可以选择用 "if "来添加该默认值的依赖关系。

This is a shorthand notation for a type definition plus a value. Optionally dependencies for this default value can be added with “if”.

  • dependencies: “depends on” <expr>

这就为该菜单条目定义了一个依赖项。如果定义了多个依赖项,则用"&&"将它们连接起来。依赖关系适用于该菜单项中的所有其他选项(这些选项也接受 "if "表达式),因此这两个示例是等价的:

This defines a dependency for this menu entry. If multiple dependencies are defined, they are connected with ‘&&’. Dependencies are applied to all other options within this menu entry (which also accept an “if” expression), so these two examples are equivalent:

bool "foo" if BAR

default y if BAR

and:

depends on BAR

bool "foo"

default y

  • reverse dependencies: “select” <symbol> [“if” <expr>]  

    反向依赖

正常从属关系会降低一个符号的上限(见下文),而反向从属关系则可用于强制降低另一个符号的上限。当前菜单符号的值被用作 <symbol> 可以设置的最小值。如果 <symbol> 被多次选择,则限制将设置为最大选择。反向依赖关系只能用于布尔或三态符号。

While normal dependencies reduce the upper limit of a symbol (see below), reverse dependencies can be used to force a lower limit of another symbol. The value of the current menu symbol is used as the minimal value <symbol> can be set to. If <symbol> is selected multiple times, the limit is set to the largest selection. Reverse dependencies can only be used with boolean or tristate symbols.

注意:

select会在不访问依赖关系的情况下将一个符号强制设为一个值。通过滥用 select,即使 FOO 依赖于未设置的 BAR,也能选择符号 FOO。一般来说,select 只用于不可见的符号(没有提示)和没有依赖关系的符号。这将限制其实用性,但另一方面也避免了到处都是的非法配置。

如果在 "select"<symbol>后面加上 "if"<expr>,<symbol> 将根据当前菜单符号值和 <expr> 的逻辑 AND 值进行选择。这意味着,由于 "if"<expr> 的存在,下限可以降级。这种行为可能看起来很奇怪,但我们依赖它。(该行为的未来尚未确定)。

Note:

select should be used with care. select will force a symbol to a value without visiting the dependencies. By abusing select you are able to select a symbol FOO even if FOO depends on BAR that is not set. In general use select only for non-visible symbols (no prompts anywhere) and for symbols with no dependencies. That will limit the usefulness but on the other hand avoid the illegal configurations all over.

If “select” <symbol> is followed by “if” <expr>, <symbol> will be selected by the logical AND of the value of the current menu symbol and <expr>. This means, the lower limit can be downgraded due to the presence of “if” <expr>. This behavior may seem weird, but we rely on it. (The future of this behavior is undecided.)

  • weak reverse dependencies: “imply” <symbol> [“if” <expr>]

这与 "select" 类似,因为它对另一个符号强制执行下限,但 "implied"符号的值仍可通过直接依赖关系或可见提示设置为 n。

This is similar to “select” as it enforces a lower limit on another symbol except that the “implied” symbol’s value may still be set to n from a direct dependency or with a visible prompt.

举例如下:

Given the following example:

config FOO

    tristate "foo"

    imply BAZ

config BAZ

    tristate "baz"

    depends on BAR

The following values are possible:

例如,如果多个驱动程序都希望表明自己有能力连接到辅助子系统,而允许用户在配置该子系统时无需同时取消设置这些驱动程序,那么这种方法就非常有用。

This is useful e.g. with multiple drivers that want to indicate their ability to hook into a secondary subsystem while allowing the user to configure that subsystem out without also having to unset these drivers.

注意:如果 FOO=y 和 BAZ=m 的组合会导致链接错误,可以使用 IS_REACHABLE() 来保护函数调用:

Note: If the combination of FOO=y and BAZ=m causes a link error, you can guard the function call with IS_REACHABLE():

foo_init()

{

        if (IS_REACHABLE(CONFIG_BAZ))

                baz_register(&foo);

        ...

}

注:如果 BAZ 提供的功能是 FOO 非常需要的,则 FOO 不仅要暗示 BAZ,还要暗示其依赖关系 BAR:

Note: If the feature provided by BAZ is highly desirable for FOO, FOO should imply not only BAZ, but also its dependency BAR:

config FOO

    tristate "foo"

    imply BAR

    imply BAZ

注意:如果 "imply"<symbol> 后跟 "if"<expr>,<symbol> 的默认值将是当前菜单符号值和 <expr> 的逻辑 AND 值。(这种行为的未来还未确定)。

Note: If “imply” <symbol> is followed by “if” <expr>, the default of <symbol> will be the logical AND of the value of the current menu symbol and <expr>. (The future of this behavior is undecided.)

  • limiting menu display: “visible if” <expr>

该属性仅适用于菜单块,如果条件为假,则菜单块不会显示给用户(但其中包含的符号仍可被其他符号选择)。它类似于单个菜单项的条件 "prompt" 属性。"visible" 的默认值为 true。

This attribute is only applicable to menu blocks, if the condition is false, the menu block is not displayed to the user (the symbols contained there can still be selected by other symbols, though). It is similar to a conditional “prompt” attribute for individual menu entries. Default value of “visible” is true.

  • numerical ranges: “range” <symbol> <symbol> [“if” <expr>]

这样可以限制 int 和十六进制符号的可能输入值范围。用户只能输入大于或等于第一个符号、小于或等于第二个符号的值。

This allows to limit the range of possible input values for int and hex symbols. The user can only input a value which is larger than or equal to the first symbol and smaller than or equal to the second symbol.

  • help text: “help”

这定义了一个帮助文本。帮助文本的结尾由缩进级别决定,这意味着它在缩进比帮助文本的第一行小的行结束。

This defines a help text. The end of the help text is determined by the indentation level, this means it ends at the first line which has a smaller indentation than the first line of the help text.

  • module attribute

("modules") 此项声明将该符号用作 MODULES 符号,从而使所有配置符号都处于第三模块状态。最多只能有一个符号设置了 "modules "选项。

“modules” This declares the symbol to be used as the MODULES symbol, which enables the third modular state for all config symbols. At most one symbol may have the “modules” option set.

Menu dependencies

依赖关系定义了菜单项的可见性,也可以缩小三态符号的输入范围。表达式中使用的三态逻辑比普通布尔逻辑多使用一种状态来表达模块状态。依赖关系表达式的语法如下:

Dependencies define the visibility of a menu entry and can also reduce the input range of tristate symbols. The tristate logic used in the expressions uses one more state than normal boolean logic to express the module state. Dependency expressions have the following syntax:

         <expr> ::= <symbol>                  (1)

         <symbol> '=' <symbol>                (2)

         <symbol> '!=' <symbol>               (3)

         <symbol1> '<' <symbol2>              (4)

         <symbol1> '>' <symbol2>              (4)

         <symbol1> '<=' <symbol2>             (4)

         <symbol1> '>=' <symbol2>             (4)

         '(' <expr> ')'                       (5)

         '!' <expr>                           (6)

         <expr> '&&' <expr>                   (7)

         <expr> '||' <expr>                   (8)

表达式按优先级递减顺序排列。

1. 将符号转换为表达式。布尔和三态符号只需转换为相应的表达式值。所有其他符号类型的结果都是 "n"。

2. 如果两个符号的值相等,则返回 "y",否则返回 "n"。

3. 如果两个符号的值相等,则返回 "n",否则返回 "y"。

4. 如果 <symbol1> 的值分别比 <symbol2> 的值小、大、小或相等、大或相等,则返回'y',否则返回'n'。

5. 返回表达式的值。用于覆盖优先级。

6. 返回 (2-/expr/) 的结果。

7. 返回 min(/expr/, /expr/) 的结果。

8. 返回 max(/expr/, /expr/) 的结果。

Expressions are listed in decreasing order of precedence.

1. Convert the symbol into an expression. Boolean and tristate symbols are simply converted into the respective expression values. All other symbol types result in ‘n’.

2. If the values of both symbols are equal, it returns ‘y’, otherwise ‘n’.

3. If the values of both symbols are equal, it returns ‘n’, otherwise ‘y’.

4. If value of <symbol1> is respectively lower, greater, lower-or-equal, or greater-or-equal than value of <symbol2>, it returns ‘y’, otherwise ‘n’.

5. Returns the value of the expression. Used to override precedence.

6. Returns the result of (2-/expr/).

7. Returns the result of min(/expr/, /expr/).

8. Returns the result of max(/expr/, /expr/).

表达式的值可以是 "n"、"m "或 "y"(计算时分别为 0、1、2)。当表达式的值为 "m "或 "y "时,菜单条目才会显示。

An expression can have a value of ‘n’, ‘m’ or ‘y’ (or 0, 1, 2 respectively for calculations). A menu entry becomes visible when its expression evaluates to ‘m’ or ‘y’.

符号有两类:常量符号和非常量符号。非常数符号是最常见的符号,通过 "config "语句定义。非常数符号完全由字母数字字符或下划线组成。常量符号只是表达式的一部分。常量符号总是由单引号或双引号包围。在引号内,允许使用任何其他字符,引号可以用"'"转义。

There are two types of symbols: constant and non-constant symbols. Non-constant symbols are the most common ones and are defined with the ‘config’ statement. Non-constant symbols consist entirely of alphanumeric characters or underscores. Constant symbols are only part of expressions. Constant symbols are always surrounded by single or double quotes. Within the quote, any other character is allowed and the quotes can be escaped using "'".

Menu structure

菜单条目在树中的位置有两种确定方式。首先,可以明确指定:

The position of a menu entry in the tree is determined in two ways. First it can be specified explicitly:

menu "Network device support"

      depends on NET

config NETDEVICES

      ...

endmenu

"menu"... "endmenu"块中的所有条目都将成为 "Network device support"的子菜单。所有子菜单条目都将继承菜单条目的依赖关系,例如,这意味着 "NET "依赖关系将被添加到配置选项 NETDEVICES 的依赖关系列表中。

All entries within the “menu” ... “endmenu” block become a submenu of “Network device support”. All subentries inherit the dependencies from the menu entry, e.g. this means the dependency “NET” is added to the dependency list of the config option NETDEVICES.

生成菜单结构的另一种方法是分析依赖关系。如果一个菜单条目在某种程度上依赖于前一个条目,那么它就可以成为前一个条目的子菜单。首先,前一个(父)符号必须是依赖列表的一部分,然后这两个条件之一必须为真:

The other way to generate the menu structure is done by analyzing the dependencies. If a menu entry somehow depends on the previous entry, it can be made a submenu of it. First, the previous (parent) symbol must be part of the dependency list and then one of these two conditions must be true:

  • 如果父条目设置为 "n",子条目必须变为不可见

  • 子条目必须在父条目可见时才可见:

  • the child entry must become invisible, if the parent is set to ‘n’

  • the child entry must only be visible, if the parent is visible:

config MODULES

    bool "Enable loadable module support"

config MODVERSIONS

    bool "Set version information on all module symbols"

    depends on MODULES

comment "module support disabled"

    depends on !MODULES

MODVERSIONS 直接依赖于 MODULES,这意味着只有 MODULES 与 "n "不同时它才可见。另一方面,注释只有在 MODULES 设置为 "n"时才可见。

MODVERSIONS directly depends on MODULES, this means it’s only visible if MODULES is different from ‘n’. The comment on the other hand is only visible when MODULES is set to ‘n’.

参考:

Kconfig Language — The Linux Kernel documentation

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜流冰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值