一直对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
make menuconfig
make xconfig
除非是配置系统的维护者,一般的内核开发者无须了解它们的原理,只需要知道如何编写 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"
"make menuconfig" Text based color menus, radiolists & dialogs.
"make xconfig"
"make gconfig"
"make oldconfig"
"make silentoldconfig"
Additionally updates the dependencies.
"make defconfig"
"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。