Should Know Something About Kernel Building

  • 配置内核最简单的方法是 make olddefconfig
  • 内核配置保存在 .config
  • 内核源码树里包含命令行修改 .config 的脚本 scripts/config
  • 内核构建依赖 flex, bison 词法分析程序

Build on Ubuntu 22.04

Environment

configuration version
distro Ubuntu 22.04 Jammy Jellyfish
gcc 11.2.0
original kernel 5.15.0-43-generic
building kernel v6.0

Compilation Errors

Errors Resolution
gelf.h: No such file or directory apt install libelf-dev
<openssl/opensslv.h>: No such file or directory apt install libssl-dev
No rule to make target ‘debian/canonical-certs.pem’ scripts/config –disable SYSTEM_TRUSTED_KEYS
No rule to make target ‘debian/canonical-revoked-certs.pem’ scripts/config –disable SYSTEM_REVOCATION_KEYS

Build on WSL2

Build Config

1
make KCONFIG_CONFIG=Microsoft/config-wsl

Compilation Errors

apt install -y dwarves

这是一个非常常见的依赖问题

1
2
3
4
5
6
7
8
  LD      vmlinux.o
MODPOST vmlinux.symvers
MODINFO modules.builtin.modinfo
GEN modules.builtin
BTF: .tmp_vmlinux.btf: pahole (pahole) is not available
Failed to generate BTF for vmlinux
Try to disable CONFIG_DEBUG_INFO_BTF
make: *** [Makefile:1218: vmlinux] Error 1

Direct WSL to the new vmlinux

新内核产生

1
2
3
4
5
6
7
8
9
  AS      arch/x86/boot/header.o
CC arch/x86/boot/version.o
LD arch/x86/boot/setup.elf
OBJCOPY arch/x86/boot/setup.bin
OBJCOPY arch/x86/boot/vmlinux.bin
BUILD arch/x86/boot/bzImage
Kernel: arch/x86/boot/bzImage is ready (#3)
MODPOST modules-only.symvers
GEN Module.symvers

新内核生效

  1. mv arch/x86/boot/bzImage /mnt/c/Users/luc/

  2. 编辑 /mnt/c/Users/luc/.wslconfig, 添加下面两行

1
2
[wsl2]
kernel=C:\\Users\\luc\\bzImage

NOTE: 如果以上两行添加进 /etc/wsl.conf 文件,不会有任何作用, 因为 /etc/wsl.conf 不支持 wsl2 Section

  1. 配置完成后,重启 WSL Ubuntu 20.04, 新编译的内核将生效。不要用 wsl --terminate.
1
wsl --shutdown Ubuntu-20.04

打开 CONFIG_DRM_VKMS

1
make nconfig

NOTE: 在 WSL 上不能将配置项置为 ‘M’, 而要 ‘Y’

配置更改后重新 make

Testing With IGT on WSL2

1
2
3
4
5
6
7
8
9
10
11
➜  tests git:(master) sudo ./kms_writeback --device "sys:/sys/devices/platform/vkms"
IGT-Version: 1.27.1-g45da871d (x86_64) (Linux: 5.15.90.1-microsoft-standard-WSL2+ x86_64)
(kms_writeback:9671) igt_kms-WARNING: Output Writeback-1 could not be assigned to a pipe
Starting subtest: writeback-pixel-formats
Subtest writeback-pixel-formats: SUCCESS (0.000s)
Starting subtest: writeback-invalid-parameters
Subtest writeback-invalid-parameters: SUCCESS (0.000s)
Starting subtest: writeback-fb-id
Subtest writeback-fb-id: SUCCESS (0.018s)
Starting subtest: writeback-check-output
Subtest writeback-check-output: SUCCESS (0.124s)
  • dmesg
1
2
3
4
5
6
[10893.662944] [IGT] kms_writeback: executing
[10893.673240] [IGT] kms_writeback: starting subtest writeback-pixel-formats
[10893.674026] [IGT] kms_writeback: starting subtest writeback-invalid-parameters
[10893.675055] [IGT] kms_writeback: starting subtest writeback-fb-id
[10893.693563] [IGT] kms_writeback: starting subtest writeback-check-output
[10893.826984] [IGT] kms_writeback: exiting, ret=0