将内核配置变量映射到模块

时间:2022-09-11 23:46:19

In general, how do I know what set of kernel config options are necessary to have some .ko file built?

一般来说,我如何知道构建.ko文件需要哪些内核配置选项?

For example, I need 'xt_conntrack.ko'. What resources are there that let me know whether or not enabling CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m in my kernel config is necessary or even sufficient to result in my built .ko file? How do I find the full set of kconfig options required to yield a kernel module?

例如,我需要'xt_conntrack.ko'。有什么资源可以让我知道在内核配置中启用CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m是必要的,还是足以生成.ko文件?如何找到生成内核模块所需的完整kconfig选项集?

http://cateee.net/lkddb/web-lkddb/NETFILTER_XT_MATCH_CONNTRACK.html indicates it will build "xt_conntrack", but I am not seeing it when I =m it and all of its dependencies. On the other side, there is no set of kconfig flags visible here (http://modules.libres.ch/browse/linux/v3.0/x86_64/xt_conntrack/)

http://cateee.net/lkddb/web- lddb/netfilter_xt_match_conntrack.html表明它将构建“xt_conntrack”,但当我=m它及其所有依赖项时,我看不到它。另一方面,这里没有可见的kconfig标志集(http://modules.libres.ch/browse/linux/v3.0/x86_64/xt_conntrack/)

1 个解决方案

#1


2  

How do I find the full set of kconfig options required to yield a kernel module?

如何找到生成内核模块所需的完整kconfig选项集?

In general, determining set of options for building a kernel module is complex process. Steps described below may guide in that process.

通常,确定构建内核模块的选项集是一个复杂的过程。下面描述的步骤可以指导这一过程。

1. Find a Makefile

Find a Makefile which builds a kernel module. This file is located in the same directory, where .ko file is produced; this directory usually coincides with a directory of module's source files. This Makefile contains a line which builds a module:

查找构建内核模块的Makefile。此文件位于.ko文件生成的同一目录中;这个目录通常与模块源文件的目录一致。此Makefile包含构建模块的行:

obj-${CONFIG_...} := <module_name>.o

Example:

例子:

A module xt_conntrack.ko is built by the line

一个模块xt_conntrack。ko是由直线建造的

obj-$(CONFIG_NETFILTER_XT_MATCH_CONNTRACK) += xt_conntrack.o

in file net/netfilter/Makefile.

在文件net/netfilter/Makefile。

2. Determine final option

There are several ways how configuration options may affect on building a module.

配置选项如何影响构建模块有几种方式。

  1. The option is used directly in the line, produced the module:

    该选项可直接在直线上使用,生成模块:

    obj-${CONFIG_X} := <module_name>.o
    

    means that option CONFIG_X should be set for the module to be built.

    意味着应该为将要构建的模块设置CONFIG_X选项。

  2. Given Makefile is conditionally included into the upper one:

    假设Makefile被有条件地包含在上面的一个中:

    obj-${CONFIG_Y} := <dir>/
    
  3. The line produced the module is guarded by "if" clause:

    该模块的生产线由“if”条款保护:

    ifeq ($(CONFIG_F),y)
    obj-m := <module_name>.o
    endif
    

    Alternatively, guard may protect inclusion of the Makefile from the upper one:

    另一种方法是,保护程序可以从上一层保护Makefile:

    ifeq ($(CONFIG_F),y)
    obj-m := <dir>/
    endif
    

Example:

例子:

A module xt_conntrack depends by rule 1 from CONFIG_NETFILTER_XT_MATCH_CONNTRACK option.

模块xt_conntrack依赖于CONFIG_NETFILTER_XT_MATCH_CONNTRACK选项中的规则1。

Also it depends by rule 2 from CONFIG_NETFILTER option, because outer net/Makefile includes net/netfilter/Makefile via

它还依赖于CONFIG_NETFILTER选项中的规则2,因为外部net/Makefile包含net/netfilter/Makefile via

obj-$(CONFIG_NETFILTER) += netfilter/

3. Find definition of the option and determine its availability

Note: This is the most complicated step, mainly because availability of the option is expressed in terms of other options. It is recommended to use ready-made tools for that. E.g., make menuconfig tool may search options and show their definition.

注意:这是最复杂的步骤,主要是因为选项的可用性是用其他选项表示的。建议使用现成的工具。例如,make menuconfig工具可以搜索选项并显示它们的定义。

Every configuration option is defined in one of Kconfig files.

每个配置选项都在一个Kconfig文件中定义。

Definition determines:

确定定义:

  • availability of the option (when the option can be used),

    可获得的选项(当选项可用时),

  • possible values of the option (y/n - boolean, y/m/n - tristate, etc.),

    选项的可能值(y/n - boolean, y/m/n - tristate等),

  • whether the option can be set by a user.

    选项是否可以由用户设置。

Example:

例子:

Option NETFILTER_XT_MATCH_CONNTRACK is defined in net/netfilter/Kconfig as

选项NETFILTER_XT_MATCH_CONNTRACK是在net/netfilter/Kconfig中定义的。

config NETFILTER_XT_MATCH_CONNTRACK
    tristate '"conntrack" connection tracking match support'
    depends on NF_CONNTRACK
    default m if NETFILTER_ADVANCED=n
    help
      This is a general conntrack match module, a superset of the state match.

      It allows matching on additional conntrack information, which is
      useful in complex configurations, such as NAT gateways with multiple
      internet links or tunnels.

      To compile it as a module, choose M here.  If unsure, say N.

That is, the option is available (can be set) only when NF_CONNTRACK option is set.

也就是说,只有当设置了NF_CONNTRACK选项时,该选项才可用(可以设置)。

Documentation for format of Kconfig files is located at Documentation/kbuild/kconfig-language.txt.

Kconfig文件格式的文档位于Documentation/kbuild/ Kconfig -language.txt文件中。

#1


2  

How do I find the full set of kconfig options required to yield a kernel module?

如何找到生成内核模块所需的完整kconfig选项集?

In general, determining set of options for building a kernel module is complex process. Steps described below may guide in that process.

通常,确定构建内核模块的选项集是一个复杂的过程。下面描述的步骤可以指导这一过程。

1. Find a Makefile

Find a Makefile which builds a kernel module. This file is located in the same directory, where .ko file is produced; this directory usually coincides with a directory of module's source files. This Makefile contains a line which builds a module:

查找构建内核模块的Makefile。此文件位于.ko文件生成的同一目录中;这个目录通常与模块源文件的目录一致。此Makefile包含构建模块的行:

obj-${CONFIG_...} := <module_name>.o

Example:

例子:

A module xt_conntrack.ko is built by the line

一个模块xt_conntrack。ko是由直线建造的

obj-$(CONFIG_NETFILTER_XT_MATCH_CONNTRACK) += xt_conntrack.o

in file net/netfilter/Makefile.

在文件net/netfilter/Makefile。

2. Determine final option

There are several ways how configuration options may affect on building a module.

配置选项如何影响构建模块有几种方式。

  1. The option is used directly in the line, produced the module:

    该选项可直接在直线上使用,生成模块:

    obj-${CONFIG_X} := <module_name>.o
    

    means that option CONFIG_X should be set for the module to be built.

    意味着应该为将要构建的模块设置CONFIG_X选项。

  2. Given Makefile is conditionally included into the upper one:

    假设Makefile被有条件地包含在上面的一个中:

    obj-${CONFIG_Y} := <dir>/
    
  3. The line produced the module is guarded by "if" clause:

    该模块的生产线由“if”条款保护:

    ifeq ($(CONFIG_F),y)
    obj-m := <module_name>.o
    endif
    

    Alternatively, guard may protect inclusion of the Makefile from the upper one:

    另一种方法是,保护程序可以从上一层保护Makefile:

    ifeq ($(CONFIG_F),y)
    obj-m := <dir>/
    endif
    

Example:

例子:

A module xt_conntrack depends by rule 1 from CONFIG_NETFILTER_XT_MATCH_CONNTRACK option.

模块xt_conntrack依赖于CONFIG_NETFILTER_XT_MATCH_CONNTRACK选项中的规则1。

Also it depends by rule 2 from CONFIG_NETFILTER option, because outer net/Makefile includes net/netfilter/Makefile via

它还依赖于CONFIG_NETFILTER选项中的规则2,因为外部net/Makefile包含net/netfilter/Makefile via

obj-$(CONFIG_NETFILTER) += netfilter/

3. Find definition of the option and determine its availability

Note: This is the most complicated step, mainly because availability of the option is expressed in terms of other options. It is recommended to use ready-made tools for that. E.g., make menuconfig tool may search options and show their definition.

注意:这是最复杂的步骤,主要是因为选项的可用性是用其他选项表示的。建议使用现成的工具。例如,make menuconfig工具可以搜索选项并显示它们的定义。

Every configuration option is defined in one of Kconfig files.

每个配置选项都在一个Kconfig文件中定义。

Definition determines:

确定定义:

  • availability of the option (when the option can be used),

    可获得的选项(当选项可用时),

  • possible values of the option (y/n - boolean, y/m/n - tristate, etc.),

    选项的可能值(y/n - boolean, y/m/n - tristate等),

  • whether the option can be set by a user.

    选项是否可以由用户设置。

Example:

例子:

Option NETFILTER_XT_MATCH_CONNTRACK is defined in net/netfilter/Kconfig as

选项NETFILTER_XT_MATCH_CONNTRACK是在net/netfilter/Kconfig中定义的。

config NETFILTER_XT_MATCH_CONNTRACK
    tristate '"conntrack" connection tracking match support'
    depends on NF_CONNTRACK
    default m if NETFILTER_ADVANCED=n
    help
      This is a general conntrack match module, a superset of the state match.

      It allows matching on additional conntrack information, which is
      useful in complex configurations, such as NAT gateways with multiple
      internet links or tunnels.

      To compile it as a module, choose M here.  If unsure, say N.

That is, the option is available (can be set) only when NF_CONNTRACK option is set.

也就是说,只有当设置了NF_CONNTRACK选项时,该选项才可用(可以设置)。

Documentation for format of Kconfig files is located at Documentation/kbuild/kconfig-language.txt.

Kconfig文件格式的文档位于Documentation/kbuild/ Kconfig -language.txt文件中。