Linux 内核的`make defconfig` 究竟做了什么? [英] What exactly does Linux kernel's `make defconfig` do?

查看:35
本文介绍了Linux 内核的`make defconfig` 究竟做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用以下命令根据自定义的基于 ARM 的板的指定架构默认值创建 Linux 内核 .config 文件:

I can use the following command to create a Linux kernel .config file based on a specified architecture default for a custom ARM-based board:

ARCH=arm make defconfig KBUILD_DEFCONFIG=var_som_mx6_android_defconfig

我认为这个命令或多或少地将 ./arch/arm/configs/var_som_mx6_android_defconfig 复制到 ./.config.然而,生成的 .config 文件并不完全是副本:

I thought that this command more or less copies ./arch/arm/configs/var_som_mx6_android_defconfig to ./.config. However the resulting .config file isn't exactly a copy:

$ diff --unified arch/arm/configs/var_som_mx6_android_defconfig  .config
--- arch/arm/configs/var_som_mx6_android_defconfig  2017-01-20 12:10:51.891515984 -0800
+++ .config 2017-01-26 15:31:29.000000000 -0800
@@ -407,6 +407,7 @@
 CONFIG_ARM_ERRATA_751472=y
 CONFIG_ARM_ERRATA_794072=y
 CONFIG_ARM_ERRATA_761320=y
+CONFIG_ARM_ERRATA_845369=y
 # CONFIG_ARM_ERRATA_753970 is not set
 CONFIG_ARM_ERRATA_754322=y
 # CONFIG_ARM_ERRATA_754327 is not set
@@ -2683,7 +2684,6 @@
 CONFIG_AUTOFS4_FS=y
 CONFIG_FUSE_FS=y
 # CONFIG_CUSE is not set
-CONFIG_AUFS_FS=y

 #
 # Caches
@@ -2759,6 +2759,21 @@
 # CONFIG_PSTORE is not set
 # CONFIG_SYSV_FS is not set
 # CONFIG_UFS_FS is not set
+CONFIG_AUFS_FS=y
+CONFIG_AUFS_BRANCH_MAX_127=y
+# CONFIG_AUFS_BRANCH_MAX_511 is not set
+# CONFIG_AUFS_BRANCH_MAX_1023 is not set
+# CONFIG_AUFS_BRANCH_MAX_32767 is not set
+CONFIG_AUFS_SBILIST=y
+# CONFIG_AUFS_HNOTIFY is not set
+# CONFIG_AUFS_RDU is not set
+# CONFIG_AUFS_PROC_MAP is not set
+# CONFIG_AUFS_SP_IATTR is not set
+# CONFIG_AUFS_SHWH is not set
+# CONFIG_AUFS_BR_RAMFS is not set
+# CONFIG_AUFS_BR_FUSE is not set
+CONFIG_AUFS_BDEV_LOOP=y
+# CONFIG_AUFS_DEBUG is not set
 CONFIG_NETWORK_FILESYSTEMS=y
 CONFIG_NFS_FS=y
 CONFIG_NFS_V3=y

我不明白多余的行是从哪里来的,而且我总是发现内核配置、makefile 和构建脚本的内部工作方式很难理解.谁能解释一下 .config 中的那些行可能来自哪里?

I don't understand where the extra lines are coming from, and I have always found the internal workings of the kernel configuration, makefiles, and build scripts to be difficult to understand. Can anyone explain where those lines in the .config might be coming from?

推荐答案

动机

.config 文件不是简单地从您的 defconfig 文件中复制的.以这种格式存储 defconfig 的动机是下一个:在 defconfig 中,我们只能指定具有非默认值的选项(即我们为我们的板更改的选项).这样我们就可以保持它小而清晰.每个新的内核版本都会带来一堆新选项,这样我们就不需要在每次内核发布时更新我们的 defconfig 文件.另外,应该提到的是,内核构建系统在 defconfig 文件中保留了非常具体的选项顺序,因此最好避免手动修改它.相反,您应该使用 make saveefconfig 规则.

Motivation

The .config file is not simply copied from your defconfig file. The motivation for storing defconfig in such a format is next: in defconfig we can specify only options with non-default values (i.e. options we changed for our board). This way we can keep it small and clear. Every new kernel version brings a bunch of new options, and this way we don't need to update our defconfig file each time the kernel releases. Also, it should be mentioned that kernel build system keeps very specific order of options in defconfig file, so it's better to avoid modifying it by hand. Instead you should use make savedefconfig rule.

当生成 .config 文件时,内核构建系统会检查所有 Kconfig 文件(来自所有子目录),检查那些 Kconfig 中的所有选项代码>文件:

When .config file is being generated, kernel build system goes through all Kconfig files (from all subdirs), checking all options in those Kconfig files:

  • 如果 defconfig 中提到了选项,构建系统将该选项放入 .config 中,并在 defconfig
  • 中选择值
  • 如果 defconfig 中没有提到选项,构建系统会将该选项放入 .config 使用其默认值,在相应的 Kconfig 中指定
  • if option is mentioned in defconfig, build system puts that option into .config with value chosen in defconfig
  • if option isn't mentioned in defconfig, build system puts that option into .config using its default value, specified in corresponding Kconfig

检查 scripts/kconfig/Makefilescripts/kconfig/conf.c 文件,看看它是如何实际完成的.

Check scripts/kconfig/Makefile and scripts/kconfig/conf.c files to see how it's actually done.

来自 Kbuild:Linux 内核构建系统"作者:哈维尔马丁内斯:

定义配置符号:Kconfig 文件

Defining Configuration Symbols: Kconfig Files

配置符号在称为 Kconfig 文件的文件中定义.每个Kconfig 文件可以描述任意数量的符号,也可以包含(源)其他Kconfig 文件.构建内核编译选项配置菜单的编译目标,如make menuconfig,读取这些文件以构建树状结构.内核中的每个目录都有一个 Kconfig,其中包含其子目录的 Kconfig 文件.在内核源代码目录的顶部,有一个 Kconfig 文件,它是选项树的根.menuconfig (scripts/kconfig/mconf)、gconfig (scripts/kconfig/gconf) 等编译目标调用从这个根 Kconfig 开始的程序,并递归地读取位于每个子目录中的 Kconfig 文件来构建它们的菜单.访问哪个子目录也是在每个Kconfig文件中定义的,也取决于用户选择的配置符号值.

Configuration symbols are defined in files known as Kconfig files. Each Kconfig file can describe an arbitrary number of symbols and can also include (source) other Kconfig files. Compilation targets that construct configuration menus of kernel compile options, such as make menuconfig, read these files to build the tree-like structure. Every directory in the kernel has one Kconfig that includes the Kconfig files of its subdirectories. On top of the kernel source code directory, there is a Kconfig file that is the root of the options tree. The menuconfig (scripts/kconfig/mconf), gconfig (scripts/kconfig/gconf) and other compile targets invoke programs that start at this root Kconfig and recursively read the Kconfig files located in each subdirectory to build their menus. Which subdirectory to visit also is defined in each Kconfig file and also depends on the config symbol values chosen by the user.

存储符号值:.config 文件

Storing Symbol Values: .config File

所有配置符号值都保存在一个名为 .config 的特殊文件中.每次要更改内核编译配置时,都会执行 make 目标,例如 menuconfigxconfig.它们读取 Kconfig 文件以创建菜单并使用 .config 文件中定义的值更新配置符号的值.此外,这些工具会使用您选择的新选项更新 .config 文件,如果之前不存在,也可以生成一个.

All config symbol values are saved in a special file called .config. Every time you want to change a kernel compile configuration, you execute a make target, such as menuconfig or xconfig. These read the Kconfig files to create the menus and update the config symbols' values using the values defined in the .config file. Additionally, these tools update the .config file with the new options you chose and also can generate one if it didn't exist before.

由于 .config 文件是纯文本文件,您也可以在不需要任何专门工具的情况下对其进行更改.保存和恢复之前的内核编译配置也很方便.

Because the .config file is plain text, you also can change it without needing any specialized tool. It is very convenient for saving and restoring previous kernel compilation configurations as well.

有用的命令

您可以为 make defconfig 使用更简单的语法,例如:

Useful commands

You can use simpler syntax for make defconfig, like:

$ make ARCH=arm your_board_defconfig

查看可用 defconfigs 的完整列表:

See the full list of available defconfigs with:

$ make ARCH=arm help | grep defconfig

如果你需要做反向操作(即从广泛的.config创建一个整洁的小defconfig),你可以使用savedefconfig规则:

If you need to do reverse action (i.e. create a neat small defconfig from extensive .config), you can use savedefconfig rule:

$ make ARCH=arm savedefconfig

此外,正如 0andriy 提到的,您可以使用 diffconfig 脚本查看从一个 .config 到另一个的更改:

Also, as 0andriy mentioned, you can use diffconfig script to see changes from one .config to another one:

$ scripts/diffconfig .config_old .config_new

这篇关于Linux 内核的`make defconfig` 究竟做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆