如何以非交互方式打开 Linux 内核 .config 文件中的功能?
我遇到过这样的情况:我们的软件需要与几个不同的 Linux 内核发行版/内核树一起工作。 (包括 Android 分支)
在尝试自动化我们的构建过程时,我发现我们需要支持的特定构建的一些 defconfig
文件不包含我们依赖的内核模块。
例如,假设我的 .config
中需要一个名为 XXX
的选项。对于某些依赖项,我可以这样做:
sed -i 's/# CONFIG_XXX is not set/CONFIG_XXX=m/' .config
对于其他依赖项,这并不容易,因为依赖项可能跨越多行 .config
语句。
是否有更受支持的方式以非交互方式执行此操作,或者我是否一直在编写更复杂的搜索和替换脚本?
I have a situation where our software needs to work with several different Linux kernel distributions / kernel trees. (including Android forks)
In trying to automate our build process, I am finding that some of the defconfig
files for particular builds we need to support do not include the kernel modules we depend on.
For example, let's imagine I need an option called XXX
in my .config
. For some dependencies, I can do something like this:
sed -i 's/# CONFIG_XXX is not set/CONFIG_XXX=m/' .config
For others, it's not so easy since the dependency may span multiple lines of .config
statements.
Is there a more supported way to do this non-interactively, or am I stuck writing a more complex search-and-replace script?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
内核有一个工具(./scripts/config)来更改.config 上的特定选项。这是一个示例:
尽管如此,它不会检查 .config 文件的有效性。
The kernel has a tool (./scripts/config) to change specific options on .config. Here is an example:
Although, it doesn't check the validity of the .config file.
merge_config.sh
配置片段不幸的是,进程替换无法工作:
因为:https://unix.stackexchange.com/a/164109/32558
merge_config.sh
是make alldefconfig
目标的简单前端。交叉编译时,运行
merge_config.sh
时必须导出ARCH
,eg:合并后的输出文件可以通过
KCONFIG_CONFIG
环境显式指定多变的;否则它只会覆盖.config
:Buildroot 使用
BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES
实现自动化:如何在 Buildroot 中配置 Linux 内核?相关:https://unix.stackexchange.com/questions/19905/ how-to-non-interactively-configure-the-linux-kernel-build 提前 20 天迁移:-)
merge_config.sh
config fragmentsProcess substitution does not work unfortunately:
because of: https://unix.stackexchange.com/a/164109/32558
merge_config.sh
is a simple front-end for themake alldefconfig
target.When cross compiling,
ARCH
must be exported when you runmerge_config.sh
, e.g.:The merged output file can be specified explicitly with the
KCONFIG_CONFIG
environment variable; otherwise it just overwrites.config
:Buildroot automates it with
BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES
: How do I configure the Linux kernel within Buildroot?Related: https://unix.stackexchange.com/questions/19905/how-to-non-interactively-configure-the-linux-kernel-build Migrated 20 days earlier :-)
是的,某些配置选项在版本之间会更改名称,有时作为微妙语义变化的指示。
我编写了 python 类来将一组配置片段合并到基本内核配置文件中。不过,这对你来说有点过分了;你可以做与 sed 脚本相同的事情;你并不局限于一句台词。
或者甚至创建一个单独的脚本。假设 config.sed 包含以下行:
然后您可以运行
希望有帮助!
Yes, some config options change names between releases, sometimes as an indication of subtle semantic changes.
I have written python classes to merge together a set of configuration fragments into base kernel configuration files. That's overkill for you, though; you can do the same thing as a sed script; you aren't limited to one-liners.
Or even create a separate script. Say, config.sed that contains the lines:
Then you can run
Hope that helps!
要在更新任何和所有配置依赖项时对单个配置进行一系列简单的翻转:
单选项方法
多文件合并方法
如果您有几个想要的
.config-*
文件小片段有选择地合并到主.config
文件中,执行:References
To do a series of simple flipping of a single config while updating any and all config dependencies:
Single Option approach
Multiple-File Merge approach
If you have several small snippets of
.config-*
files that you want to selectively merge into the main.config
file, execute:References
与 aarch64 跨链:
cross-chain with aarch64: