如何编写make menuconfig脚本以自动化Linux内核构建配置?


10

我想自动化Linux构建,但最终到了我需要运行似乎很手动的步骤的地步:make menuconfig。这似乎在OS和内核配置之间同步配置?

cp git-tracked-config .config
make defconfig 
make menuconfig # <- how to automate/script this?
make V=s

基本上,如何删除对make menuconfig构建脚本的调用?

顺便说一句,这是对似乎在我从未调用过make menuconfig的情况下发生的构建错误的反应:

make[1]: *** No rule to make target `include/config/auto.conf', needed by `include/config/kernel.release'.  Stop.

可能是因为makefile本身不存在,或者makefile尚未生成/变形以包含该规则,但这是一个单独的问题,这可能是makefile中缺少规则的原因。

可能有一种更聪明的方法来共同解决这个问题。还有其他我没有跟踪但应该跟踪的配置(例如oldconfig)吗?


1
你测试了make olddefconfig吗?
jimmij 2015年

不,现在就读更多……这太痛苦了,因为任何小型实验都需要很长时间。
tarabyte

Answers:


8

Linux内核构建系统提供了许多构建目标,了解它的最好方法可能是make help

Configuration targets:
  config      - Update current config utilising a line-oriented program
  nconfig         - Update current config utilising a ncurses menu based program
  menuconfig      - Update current config utilising a menu based program
  xconfig     - Update current config utilising a QT based front-end
  gconfig     - Update current config utilising a GTK based front-end
  oldconfig   - Update current config utilising a provided .config as base
  localmodconfig  - Update current config disabling modules not loaded
  localyesconfig  - Update current config converting local mods to core
  silentoldconfig - Same as oldconfig, but quietly, additionally update deps
  defconfig   - New config with default from ARCH supplied defconfig
  savedefconfig   - Save current config as ./defconfig (minimal config)
  allnoconfig     - New config where all options are answered with no
  allyesconfig    - New config where all options are accepted with yes
  allmodconfig    - New config selecting modules when possible
  alldefconfig    - New config with all symbols set to default
  randconfig      - New config with random answer to all options
  listnewconfig   - List new options
  olddefconfig    - Same as silentoldconfig but sets new symbols to their default value
  kvmconfig   - Enable additional options for guest kernel support
  tinyconfig      - Configure the tiniest possible kernel

正如jimmij在评论中所说,有趣的部分在oldconfig相关的目标中。

就个人而言,我建议您继续使用silentoldconfig(如果.config文件中没有任何更改,或者使用新内核olddefconfig更新了.config文件)。


1
randconfig让我吃了一惊。大概用于通过生成不太可能的组合来测试构建?
conorsch

2
是的,这恰好用作配置文件的模糊测试。看到这个问题:编译Linux内核时,目的是make randconfig什么?(在“询问Ubuntu”网站上)。
perror

2

merge_config.sh 配置片段

$ cd linux
$ git checkout v4.9
$ make x86_64_defconfig
$ grep -E 'CONFIG_(DEBUG_INFO|GDB_SCRIPTS)[= ]' .config
# CONFIG_DEBUG_INFO is not set
$ # GDB_SCRIPTS depends on CONFIG_DEBUG_INFO in lib/Kconfig.debug.
$ cat <<EOF >.config-fragment
> CONFIG_DEBUG_INFO=y
> CONFIG_GDB_SCRIPTS=y
> EOF
$ # Order is important here. Must be first base config, then fragment.
$ ./scripts/kconfig/merge_config.sh .config .config-fragment
$ grep -E 'CONFIG_(DEBUG_INFO|GDB_SCRIPTS)[= ]' .config
CONFIG_DEBUG_INFO=y
CONFIG_GDB_SCRIPTS=y

不幸的是,进程替换无法正常工作:

./scripts/kconfig/merge_config.sh arch/x86/configs/x86_64_defconfig \
    <( printf 'CONFIG_DEBUG_INFO=y\nCONFIG_GDB_SCRIPTS=y\n' ) 

由于:https : //unix.stackexchange.com/a/164109/32558

merge_config.sh是目标的简单前端make alldefconfig

交叉编译时,ARCH必须在运行时导出merge_config.sh,例如:

export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-
make defconfig
./scripts/kconfig/merge_config.sh .config .config-fragment

可以使用KCONFIG_CONFIG环境变量显式指定合并的输出文件。否则,它只会覆盖.config

KCONFIG_CONFIG=some/path/.config ./scripts/kconfig/merge_config.sh .config .config-fragment

Buildroot使用BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES以下命令使其自动化:https : //stackoverflow.com/questions/1414968/how-do-i-configure-the-linux-kernel-within-buildroot

相关:https//stackoverflow.com/questions/7505164/how-do-you-non-interactively-turn-on-features-in-a-linux-kernel-config-file


0

我遇到了同样的问题,因为我想升级我的CentOS内核,并且需要在多台机器上进行升级。假设这里我的新CentOS内核树在/linux-5.1中(我已登录到root帐户)

  1. cd /linux-5.1
  2. 运行make menuconfig并进行更改并将其保存到.config
  3. /linux-5.1/.config文件复制到您的开发服务器
  4. 现在,为您的下一台计算机进行升级,您将.config文件从开发服务器复制到/linux-5.1/.config新计算机上。

希望这对陷入困境的人有所帮助。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.