Linux 内核配置的格式化打印

Linux 内核配置的格式化打印

作为选项制作菜单配置使nconfig允许一种很好的方法来配置内核选项,有什么方法可以得到这个层次结构来打印它?

类似于“tree”命令输出的东西。

答案1

感谢 @jeff-schaller 的重播,我为 Kconfiglib 项目做出了贡献,现在有一个用于此任务的新示例脚本。以下是使用它的步骤:

在包含 linux 源代码的目录中,克隆存储库:

root@23e196045c6f:/usr/src/linux-source-4.9# git clone git://github.com/ulfalizer/Kconfiglib.git
Cloning into 'Kconfiglib'...
remote: Counting objects: 3367, done.
remote: Compressing objects: 100% (57/57), done.
remote: Total 3367 (delta 64), reused 89 (delta 50), pack-reused 3259
Receiving objects: 100% (3367/3367), 1.25 MiB | 1.79 MiB/s, done.
Resolving deltas: 100% (2184/2184), done.

修补 makefile:

root@23e196045c6f:/usr/src/linux-source-4.9# patch -p1 < Kconfiglib/makefile.patch
patching file scripts/kconfig/Makefile

根据需要进行配置,基本上是为了获取 .config 文件:

root@23e196045c6f:/usr/src/linux-source-4.9# make menuconfig

使用配置文件运行脚本:

root@23e196045c6f:/usr/src/linux-source-4.9# make scriptconfig SCRIPT=Kconfiglib/examples/print_config_tree.py SCRIPT_ARG=.config

======== Linux/x86 4.9.65 Kernel Configuration ========

[*] 64-bit kernel (64BIT)
    General setup
        ()  Cross-compiler tool prefix (CROSS_COMPILE)
        [ ] Compile also drivers which will not load (COMPILE_TEST)
        ()  Local version - append to kernel release (LOCALVERSION)
        [ ] Automatically append version information to the version string (LOCALVERSION_AUTO)
        -*- Kernel compression mode
                --> Gzip (KERNEL_GZIP)
                    Bzip2 (KERNEL_BZIP2)
                    LZMA (KERNEL_LZMA)
...

但好处是可以传递不同的内核配置并轻松匹配更改:

root@23e196045c6f:/usr/src/linux-source-4.9# make scriptconfig SCRIPT=Kconfiglib/examples/print_config_tree.py SCRIPT_ARG=/tmp/config1 > config1-list.txt

root@23e196045c6f:/usr/src/linux-source-4.9# make scriptconfig SCRIPT=Kconfiglib/examples/print_config_tree.py SCRIPT_ARG=/tmp/config2 > config2-list.txt

最后现在有了 diff 工具:

Kconfiglib 与 print_config_tree.py

相关内容