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

查看:1891
本文介绍了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 savedefconfig规则.

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 only specify 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中未提及选项,则构建系统会使用在相应的Kconfig
  • 中指定的默认值将该选项放入.config.
  • 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

检查脚本/kconfig/Makefile 脚本/kconfig/conf.c文件以查看实际操作.

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

摘自Javier Martinez的"Kbuild:Linux内核构建系统" :

From "Kbuild: the Linux Kernel Build System" by Javier Martinez:

定义配置符号: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

使用以下命令查看可用的defconfig的完整列表:

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天全站免登陆