linux kernel: defconfig和.config

在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中,沒必要重複保存。
 
 
 
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章