修改Linux Kernel defconfig的标准方法

adtxl
2021-06-03 / 0 评论 / 6,447 阅读 / 正在检测是否收录...

我们在开发过程中,经常遇到需要打开Linux kernel的某项功能或者宏,这时就需要修改defconfig。如果不使用标准方法修改,可能会导致defconfig冗余且混乱,也有可能导致某项功能没有成功enable,所以建议大家使用标准的menuconfig进行修改。

menuconfig可以很清晰的看到各个模块之间的依赖关系,并且修改完成后会自动根据字母排序,减少defconfig内容的冗余和混乱。

具体方法如下:

source ./build/envsetup.sh
lunch xxx
进入kernel目录
make ARCH=arm xxx_defconfig  
make ARCH=arm menuconfig
修改需要打开或者关闭的功能,修改完成后保存并退出menuconfig
make ARCH=arm savedefconfig
至此,在kernel目录下面会生成一份defconfig,使用此defconfig和xxx_defconfig进行比较,讲defconfig中的修改merge到xxx_defconfig中结束
备注:

xxx_defconfig是编译kernel时会用到的配置文件,一定要选对
ARCH=arm 或者ARCH=arm64 是表示项目使用的kernel架构
修改完defconfig后,要把kernel目录下面的两个临时文件删除掉,避免影响编译,如下:
rm -rf .config
rm -rf include/config

一个不错的博文:

在Linux内核里,编译内核文件时,先要配置.config文件,然后Makefile在编译时通过读取.config文件的配置来选择要编译的文件,选择驱动的加载方式。

xxx_defconfig 一般在arch/arm64/configs/目录下,是一个没有展开的内核配置,需要配合Kconfig展开成.config
从defconfig到.config不是简单的复制操作,而是make ARCH=arm64 defconfig
.confg也不是直接拷贝成defconfig,而是使用make ARCH=arm64 savedefconfig

正确使用和保存deconfig的流程:
要修改在arch/arm/configs下的文件xxx_defconfig

  1. make ARCH=arm64 xxx_defconfig 会生成.config文件
  2. make ARCH=arm64 menuconfig 修改配置后保存
  3. make ARCH=arm64 savedefconfig 生成defconfg文件
  4. 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中,没必要重复保存。

配置menuconfig后查看config变化
diff .config .config.old
————————————————
版权声明:本文为CSDN博主「crazy_baoli」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u012247418/article/details/109586015

0

评论 (0)

取消