make config解惑

一直对Linux内核编译的配置问题的理解模棱两可的,网上的说法也众说纷纭,尤其是配置工具的使用问题,大家的理解完全就不一致。找了几个比较官方的网站,总结了一下比较权威的解释。

Linux内核的配置系统由三个部分组成,分别是:
1. Makefile:分布在 Linux 内核源代码中的 Makefile,定义 Linux 内核的编译规则;
2. 配置文件(config.in):给用户提供配置选择的功能;
3. 配置工具:包括配置命令解释器(对配置脚本中使用的配置命令进行解释)和配置用户界面(提供基于字符界面、基于 Ncurses 图形界面以及基于 Xwindows 图形界面的用户配置界面,各自对应于Make config、Make menuconfig 和 make xconfig)。
这些配置工具都是使用脚本语言,如 Tcl/TK、Perl 编写的(也包含一些用 C 编写的代码):
配置命令                                             解释脚本
make config,make oldcofig                    scripts/Configure
make menuconfig                                 scripts/Menuconfig
make xconfig                                       scripts/tkparse
除非是配置系统的维护者,一般的内核开发者无须了解它们的原理,只需要知道如何编写 Makefile 和配置文件就可以。
以字符界面配置(make config)为例,顶层Makefile调用scripts/Configure,按照arch/$(ARCH)/config.in来进行配置。命令 执行完后产生文件.config,其中保存着配置信息。下一次再做make config将产生新的.config文件,原.config被改名为.config.old。


Linux 内核支持非常多的硬件平台,对于具体的硬件平台而言,有些配置就是必需的,有些配置就不是必需的。另外,新增加功能的正常运行往往也需要一定的先决条件,针对新功能,必须作相应的配

置。因此,特定硬件平台能够正常运行对应着一个最小的基本配置,这就是缺省配置。
Linux 内核中针对每个 ARCH 都会有一个缺省配置。在向内核代码增加了新的功能后,如果新功能对于这个 ARCH 是必需的,就要修改此 ARCH 的缺省配置。修改方法如下(在 Linux 内核根目录下):
1. 备份 .config 文件
2. cp arch/arm/deconfig .config
3. 修改 .config
4. cp .config arch/arm/deconfig
5. 恢复 .config
如果新增的功能适用于许多的 ARCH,只要针对具体的 ARCH,重复上面的步骤就可以了。

看看内核源码的README:
Do not skip this step even if you are only upgrading one minor version. New configuration options are added in each release, and odd problems will turn up if the configuration

files are not set up as expected. If you want to carry your existing configuration to a new version with minimal work, use "make oldconfig", which will only ask you for theanswers to new questions.

- Alternate configuration commands are:
"make config"      Plain text interface.
"make menuconfig" Text based color menus, radiolists & dialogs.
"make xconfig"     X windows (Qt) based configuration tool.
"make gconfig"     X windows (Gtk) based configuration tool.
"make oldconfig"   Default all questions based on the contents of your existing ./.config file and asking about new config symbols.
"make silentoldconfig"   Like above, but avoids cluttering the screen with questions already answered.
Additionally updates the dependencies.
"make defconfig"   Create a ./.config file by using the default symbol values from either arch/$ARCH/defconfig or arch/$ARCH/configs/${PLATFORM}_defconfig, depending on the architecture.
"make ${PLATFORM}_defconfig" Create a ./.config file by using the default symbol values from arch/$ARCH/configs/${PLATFORM}_defconfig.
Use "make help" to get a list of all available platforms of your architecture.
"make allyesconfig" Create a ./.config file by setting symbol values to 'y' as much as possible.
"make allmodconfig" Create a ./.config file by setting symbol values to 'm' as much as possible.
"make allnoconfig" Create a ./.config file by setting symbol values to 'n' as much as possible.
"make randconfig" Create a ./.config file by setting symbol
values to random values.
在网上搜到的一个解释:
1. 如果.config不存在,运行make config/menuconfig时的缺省设置由固化在各个Kconfig文件中各项目的缺省值决定。
2. 如果.config存在,运行make config/menuconfig时的缺省设置即是当前.config的设置,若对设置进行了修改,.config将被更新。
3. arch/arm/defconfig是一个缺省的配置文件,make defconfig时会根据这个文件生成当前的.config。
4. arch/arm/configs文件夹中有许多命名为xxx_defconfig的配置文件,如果运行make xxx_defconfig,当前.config文件会由xxx_defconfig文件生成。
5. make oldconfig的作用是备份当前.config文件为.config.old,如若make config/menuconfig设置不当可用于恢复先前的.config。

       总结了一下,平时编译内核时所采用的是先将当前版本内核的配置文件拷贝到源码目录下.config,然后采用 make oldconfig的方式只回答新内核中添加功能的问题,如果没有.config文件,配置工具基于的默认值是arch/$(ARCH)/Kconfig 里的缺省值。一般如果当前.config被配置工具改动了,那么就会在该目录下生成一个.config.old文件,这是改动之前配置文件的备份。 make config毫无疑问是最基本也是最繁琐的一种方式,它会问遍所有问题,然后创建.config文件,如果已有该文件,它会进行备份(文件名 为.config.old)。

      不过貌似现在内核的编译比较人性化,考虑到了配置时的可操作性,如果用户在终端执行make menuconfig或者make oldconfig,它会自动先将/boot目录下的配置文件写进.config文件中,新增加的功能也会写进去,不过采用的是注释的形式(所以它会比直 接拷贝来的.config文件要大一些)。

       有一点要说明的是,.config文件中记录的都是选择y或者m的配置选项,如果配置的时候选择了n,那么在配置文件中是不会有任何记录的;但是如果当初 配置时只是简单地按回车跳过,那么它也认为是选择了n,不过它在.config文件中会以注释的形式进行说明该选项还没进行配置。

http://blog.sina.com.cn/s/blog_693301190100xxuf.html
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值