“make oldconfig”是什么意思? Linux内核makefile中到底做了什么?

发布于 2024-10-02 08:16:57 字数 85 浏览 4 评论 0原文

谁能解释一下目标“oldconfig”在 Linux 内核 makefile 中到底做了什么?我在一些构建文档中看到它被引用,但从未解释过它到底是做什么的。

Can anyone explain what the target "oldconfig" does exactly in the Linux kernel makefile? I see it referenced in some build documentation but never explained what it does exactly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

明明#如月 2024-10-09 08:16:57

它读取用于旧内核的现有 .config 文件,并提示用户输入当前内核源代码中未在该文件中找到的选项。当采用现有配置并将其移动到新内核时,这非常有用。

It reads the existing .config file that was used for an old kernel and prompts the user for options in the current kernel source that are not found in the file. This is useful when taking an existing configuration and moving it to a new kernel.

随梦而飞# 2024-10-09 08:16:57

摘要

正如 Ignacio所述,它会更新您的 .config更新内核源代码后,例如使用 git pull 。

它试图保留您现有的选项。

为此编写一个脚本很有帮助,因为:

  • 可能已添加新选项,或删除旧选项

  • 内核的 Kconfig 配置格式具有以下选项:

    • 通过选择相互暗示
    • 通过depends依赖另一个

    这些选项关系使手动配置解析变得更加困难。

让我们手动修改 .config 以了解它如何解析配置

首先使用以下命令生成默认配置:

make defconfig

现在手动编辑生成的 .config 文件以模拟内核更新并运行:

make oldconfig

以查看会发生什么。一些结论:

  1. 行类型:

    # CONFIG_XXX 未设置
    

    并非单纯的注释,而是实际表明该参数未设置。

    例如,如果我们删除该行:

    # CONFIG_DEBUG_INFO 未设置
    

    并运行make oldconfig,它会询问我们:

    使用调试信息 (DEBUG_INFO) 编译内核 [N/y/?](新)
    

    结束后,.config 文件将被更新。

    如果您更改该行的任何字符,例如更改为# CONFIG_DEBUG_INFO,则不算。

  2. 行类型:

    # CONFIG_XXX 未设置
    

    总是用于属性的否定,尽管:

    <前><代码>CONFIG_XXX=n

    也可以理解为否定。

    例如,如果您删除# CONFIG_DEBUG_INFO is not set并回答:

    使用调试信息 (DEBUG_INFO) 编译内核 [N/y/?](新)
    

    使用N,则输出文件包含:

    # CONFIG_DEBUG_INFO 未设置
    

    而不是:

    <前><代码>CONFIG_DEBUG_INFO=n

    此外,如果我们手动将该行修改为:

    <前><代码>CONFIG_DEBUG_INFO=n

    并运行make oldconfig,然后该行被修改为:

    # CONFIG_DEBUG_INFO 未设置
    

    没有 oldconfig 询问我们。

  3. 不满足依赖关系的配置不会出现在 .config 中。其他人都这样做。

    例如设置:

    CONFIG_DEBUG_INFO=y
    

    并运行make oldconfig。现在它会要求我们提供:DEBUG_INFO_REDUCEDDEBUG_INFO_SPLIT等配置。

    这些属性之前没有出现在 defconfig 中。

    如果我们在lib/Kconfig.debug下查看它们的定义位置,我们会发现它们依赖于DEBUG_INFO

    配置DEBUG_INFO_REDUCED
        bool "减少调试信息"
        取决于DEBUG_INFO
    

    因此,当 DEBUG_INFO 关闭时,它们根本不会显示。

  4. 通过打开的配置选择的配置会自动设置,无需询问用户。

    例如,如果CONFIG_X86=y并且我们删除该行:

    CONFIG_ARCH_MIGHT_HAVE_PC_PARPORT=y
    

    并运行make oldconfig,该行会在不询问我们的情况下重新创建,这与DEBUG_INFO不同。

    发生这种情况是因为 arch/x86/Kconfig 包含:

    <前><代码>配置X86
    def_bool y
    [...]
    选择 ARCH_MIGHT_HAVE_PC_PARPORT

    并选择强制该选项为真。另请参阅:https://unix.stackexchange.com/questions/117521/select -vs-depends-in-kernel-kconfig

  5. 要求不满足约束的配置。

    例如,defconfig已设置:

    <前><代码>CONFIG_64BIT=y
    CONFIG_RCU_FANOUT=64

    如果我们编辑:

    <前><代码>CONFIG_64BIT=n

    并运行make oldconfig,它会询问我们:

    基于树的分层 RCU 扇出值 (RCU_FANOUT) [32](新)
    

    这是因为 RCU_FANOUTinit/Kconfig 中定义为:

    配置 RCU_FANOUT
        int "基于树的分层 RCU 扇出值"
        如果是 64BIT,则范围 2 64
        范围 2 32 如果 !64BIT
    

    因此,如果没有 64BIT,最大值为 32,但我们在 .config 上设置了 64 >,这会使其不一致。

奖励

make olddefconfig 将每个选项设置为默认值,无需交互询问。它会在 make 上自动运行,以确保 .config 保持一致,以防您像我们一样手动修改它。另请参阅:https://serverfault.com /questions/116299/automatically-answer-defaults-when-doing-make-oldconfig-on-a-kernel-tree

make alldefconfig 就像 make olddefconfig ,但它也接受要合并的配置片段。此目标由 merge_config.sh 脚本使用:https://stackoverflow.com/a/39440863/ 895245

如果你想自动修改.config,那就不太简单了:如何以非交互方式打开 Linux 内核 .config 文件中的功能?

Summary

As mentioned by Ignacio, it updates your .config for you after you update the kernel source, e.g. with git pull.

It tries to keep your existing options.

Having a script for that is helpful because:

  • new options may have been added, or old ones removed

  • the kernel's Kconfig configuration format has options that:

    • imply one another via select
    • depend on another via depends

    Those option relationships make manual config resolution even harder.

Let's modify .config manually to understand how it resolves configurations

First generate a default configuration with:

make defconfig

Now edit the generated .config file manually to emulate a kernel update and run:

make oldconfig

to see what happens. Some conclusions:

  1. Lines of type:

    # CONFIG_XXX is not set
    

    are not mere comments, but actually indicate that the parameter is not set.

    For example, if we remove the line:

    # CONFIG_DEBUG_INFO is not set
    

    and run make oldconfig, it will ask us:

    Compile the kernel with debug info (DEBUG_INFO) [N/y/?] (NEW)
    

    When it is over, the .config file will be updated.

    If you change any character of the line, e.g. to # CONFIG_DEBUG_INFO, it does not count.

  2. Lines of type:

    # CONFIG_XXX is not set
    

    are always used for the negation of a property, although:

    CONFIG_XXX=n
    

    is also understood as the negation.

    For example, if you remove # CONFIG_DEBUG_INFO is not set and answer:

    Compile the kernel with debug info (DEBUG_INFO) [N/y/?] (NEW)
    

    with N, then the output file contains:

    # CONFIG_DEBUG_INFO is not set
    

    and not:

    CONFIG_DEBUG_INFO=n
    

    Also, if we manually modify the line to:

    CONFIG_DEBUG_INFO=n
    

    and run make oldconfig, then the line gets modified to:

    # CONFIG_DEBUG_INFO is not set
    

    without oldconfig asking us.

  3. Configs whose dependencies are not met, do not appear on the .config. All others do.

    For example, set:

    CONFIG_DEBUG_INFO=y
    

    and run make oldconfig. It will now ask us for: DEBUG_INFO_REDUCED, DEBUG_INFO_SPLIT, etc. configs.

    Those properties did not appear on the defconfig before.

    If we look under lib/Kconfig.debug where they are defined, we see that they depend on DEBUG_INFO:

    config DEBUG_INFO_REDUCED
        bool "Reduce debugging information"
        depends on DEBUG_INFO
    

    So when DEBUG_INFO was off, they did not show up at all.

  4. Configs which are selected by turned on configs are automatically set without asking the user.

    For example, if CONFIG_X86=y and we remove the line:

    CONFIG_ARCH_MIGHT_HAVE_PC_PARPORT=y
    

    and run make oldconfig, the line gets recreated without asking us, unlike DEBUG_INFO.

    This happens because arch/x86/Kconfig contains:

    config X86
        def_bool y
        [...]
        select ARCH_MIGHT_HAVE_PC_PARPORT
    

    and select forces that option to be true. See also: https://unix.stackexchange.com/questions/117521/select-vs-depends-in-kernel-kconfig

  5. Configs whose constraints are not met are asked for.

    For example, defconfig had set:

    CONFIG_64BIT=y
    CONFIG_RCU_FANOUT=64
    

    If we edit:

    CONFIG_64BIT=n
    

    and run make oldconfig, it will ask us:

    Tree-based hierarchical RCU fanout value (RCU_FANOUT) [32] (NEW)
    

    This is because RCU_FANOUT is defined at init/Kconfig as:

    config RCU_FANOUT
        int "Tree-based hierarchical RCU fanout value"
        range 2 64 if 64BIT
        range 2 32 if !64BIT
    

    Therefore, without 64BIT, the maximum value is 32, but we had 64 set on the .config, which would make it inconsistent.

Bonuses

make olddefconfig sets every option to their default value without asking interactively. It gets run automatically on make to ensure that the .config is consistent in case you've modified it manually like we did. See also: https://serverfault.com/questions/116299/automatically-answer-defaults-when-doing-make-oldconfig-on-a-kernel-tree

make alldefconfig is like make olddefconfig, but it also accepts a config fragment to merge. This target is used by the merge_config.sh script: https://stackoverflow.com/a/39440863/895245

And if you want to automate the .config modification, that is not too simple: How do you non-interactively turn on features in a Linux kernel .config file?

ゞ花落谁相伴 2024-10-09 08:16:57

在运行 make oldconfig 之前,您需要将旧内核中的内核配置文件复制到新内核的根目录中。

您可以在正在运行的系统上的 /boot/config-3.11.0 中找到旧内核配置文件的副本。或者,

如果您的内核源代码位于 /usr/src/linux,内核 源代码的配置位于 linux-3.11.0/arch/x86/configs/{i386_defconfig / x86_64_defconfig}代码>:

cd /usr/src/linux
cp /boot/config-3.9.6-gentoo .config
make oldconfig

Before you run make oldconfig, you need to copy a kernel configuration file from an older kernel into the root directory of the new kernel.

You can find a copy of the old kernel configuration file on a running system at /boot/config-3.11.0. Alternatively, kernel source code has configs in linux-3.11.0/arch/x86/configs/{i386_defconfig / x86_64_defconfig}

If your kernel source is located at /usr/src/linux:

cd /usr/src/linux
cp /boot/config-3.9.6-gentoo .config
make oldconfig
我纯我任性 2024-10-09 08:16:57

使用新的/更改的/删除的选项更新旧配置。

Updates an old config with new/changed/removed options.

难忘№最初的完美 2024-10-09 08:16:57

从这个页面

Make oldconfig 获取 .config 并通过以下规则运行它
Kconfig 文件并生成与以下一致的 .config
Kconfig 规则。如果缺少 CONFIG 值,则 make
oldconfig 会询问它们。

如果.config已经与Kconfig中找到的规则一致,
那么 make oldconfig 本质上是一个空操作。

如果您要运行 make oldconfig,然后运行 ​​make oldconfig a
第二次,第二次不会造成任何额外的变化
制作。

From this page:

Make oldconfig takes the .config and runs it through the rules of the
Kconfig files and produces a .config which is consistant with the
Kconfig rules. If there are CONFIG values which are missing, the make
oldconfig will ask for them.

If the .config is already consistant with the rules found in Kconfig,
then make oldconfig is essentially a no-op.

If you were to run make oldconfig, and then run make oldconfig a
second time, the second time won't cause any additional changes to be
made.

假装爱人 2024-10-09 08:16:57

这是一种折磨。它们不包含通用的conf 文件,而是让您按回车键9000 次才能生成一个文件。

It's torture. Instead of including a generic conf file, they make you hit return 9000 times to generate one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文