在Linux内核里,编译内核文件时,先要配置.config文件,然后Makefile在编译时通过读取.config文件的配置来选择要编译的文件,选择驱动的加载方式。
defconfig 一般在arch/arm64/configs/目录下,是一个没有展开的内核配置,需要配合Kconfig展开成.config
从defconfig到.config不是简单的复制操作,而是make ARCH=arm64 defconfig
.confg也不是直接拷贝成defconfig,而是使用make ARCH=arm64 savedefconfig
正确使用和保存deconfig的流程:
1. 要修改在arch/arm/configs下的文件xxx_defconfig
2. make ARCH=arm64 xxx_defconfig 会生成.config文件
3. make ARCH=arm64 menuconfig 修改配置后保存
4. make ARCH=arm64 savedefconfig 生成defconfg文件
5. cp defconfig arch/arm/configs/xxx_defconfig 保存
这样保存的defconfig文件,配置最小化,且日后能恢复成.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.
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.
deconfig
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.
When .config file is being generated, kernel build system goes through all Kconfig files (from all subdirs), checking all options in those Kconfig files:
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
根据上述描述,xxx_deconfig中只保存那些没有默认值的option(但被用户修改过的option除外,如config_xxx默认值为y,但是被用户修改为n,那么config_xxx将被保存进deconfig),因为有默认值的option保存在Kconfig中,没必要重复保存。