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

Glossary

  • PoC: Proof of Concept, 概念验证
  • Chisel: tExtended on Scala
  • GDSII: 版图
  • RTL: Register-Transfer Level, RTL 语言包括 SystemVerilog, Verilog, VHDL等
  • FIRRTL: Chisel 的“翻译器”, Chisel -> Verilog
  • shift left: 把验证和调试放在 tape in 阶段
  • GEM5: C Simulator for GPU
  • PPA: Power, Performance, Area, used in deciding how to optimize semiconductor designs
Read more »

LLVM & llvm-project

LLVM 是 Low-Level Virtual Machine 的简写,但事实上它与虚拟机关系不大。我们更熟悉它是一套工具链,包括 clang /'klæŋ/, lld, lldb 等等。接触 LLVM 是因为 Mesa llvmpipe 使用 LLVM, 还有 AMDGPU 和 Radeon 的编译器后端都使用 LLVM IR,所以要编译 Mesa 的 -Dgallium-drivers=llvmpipe,radeonsi 都依赖于 LLVM 的诸多组件, 构建 Linux 内核的 eBPF 程序也依赖 LLVM, 构建 perfetto 也依赖 LLVM。这里主要记录 LLVM 的构建和使用的一些问题。

Read more »

Regular Expressions

GNU Extensions

Shorthand Classes

shorthand equivalence
\w [[:alnum:]_]
\W [^[:alnum:]_]
\s [[:space:]]
\S [^[:space:]]

Word Boundaries

shorthand matches
\b position at a word boundary
\B position not at a word boundary
\< position at the start of a word
\> position at the end of a word
\` (backtick) position at the start of subject string
\' (single quote) position at the end of subject string

Bash Shell

Parameter Expansion

Use an alternate value

1
2
${var:+WORD}
${var+WORD}

如果 var 没有设置或为空,则这个变量展开为 Nothing (注意:不是空 empty, 是 nothing), 如果被设置了(不包括被设置成空),它展开为 + 后面的 WORD.

如果冒号被省略,则 var 即使被设置为空,它也展开为 + 后面的 WORD

Indirect

1
${!var}

如果 var 的值是 MESA_DEBUG, 那么这个形式展开后是变量 MESA_DEBUG 的值,例如 export MESA_DEBUG=1, var=MESA_DEBUG, 则最后的展开结果是 1

Quoted

1
${var@Q}

@Q 指变量展开后的值被单引号引起来,例如 export ABC=abc, echo "ABC=${ABC@Q}" 的结果是 ABC='abc'

Text Manipulation

Linux 下的文本处理三剑客: grep, sed, awk, 除了它们其实还有一些小巧的命令,如 tr, cut 也可以帮助我们快速处理和格式化文本。
下面以一个例子为例。

在 Linux 内核源码树里,搜索出目录 drivers/gpu/drm 下所有的 DRIVER_NAME 定义,并排序后格式化输出

命令如下:

1
rg '#define DRIVER_NAME' drivers/gpu/drm --no-heading | tr -s '\t' | tr '\t' ' ' | tr -s ' ' | awk -F':' '{printf("%-52s%-40s\n",$1,$2)}' | sort -k4 | xclip -i
  • rg (ripgrep) 比 grep 更快,更强大
  • tr 在不带任何选项时,默认执行替换,例子是中将 tab 替换成 空格, -s 表示 squeeze-repeats, 就是去重
  • awk 天生支持 C-Style printf

输出结果:

  • 格式化之前:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
drivers/gpu/drm/solomon/ssd130x.c:#define DRIVER_NAME	"ssd130x"
drivers/gpu/drm/solomon/ssd130x-i2c.c:#define DRIVER_NAME "ssd130x-i2c"
drivers/gpu/drm/solomon/ssd130x-spi.c:#define DRIVER_NAME "ssd130x-spi"
drivers/gpu/drm/exynos/exynos_drm_drv.c:#define DRIVER_NAME "exynos"
drivers/gpu/drm/bridge/imx/imx8qxp-pixel-link.c:#define DRIVER_NAME "imx8qxp-display-pixel-link"
drivers/gpu/drm/bridge/imx/imx8qxp-pxl2dpi.c:#define DRIVER_NAME "imx8qxp-pxl2dpi"
drivers/gpu/drm/bridge/imx/imx8qxp-pixel-combiner.c:#define DRIVER_NAME "imx8qxp-pixel-combiner"
drivers/gpu/drm/bridge/imx/imx8qxp-ldb-drv.c:#define DRIVER_NAME "imx8qxp-ldb"
drivers/gpu/drm/bridge/imx/imx8qm-ldb-drv.c:#define DRIVER_NAME "imx8qm-ldb"
drivers/gpu/drm/bridge/synopsys/dw-hdmi-gp-audio.c:#define DRIVER_NAME "dw-hdmi-gp-audio"
drivers/gpu/drm/bridge/synopsys/dw-hdmi-ahb-audio.c:#define DRIVER_NAME "dw-hdmi-ahb-audio"
drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c:#define DRIVER_NAME "dw-hdmi-i2s-audio"
drivers/gpu/drm/meson/meson_dw_hdmi.c:#define DRIVER_NAME "meson-dw-hdmi"
drivers/gpu/drm/meson/meson_drv.c:#define DRIVER_NAME "meson"
drivers/gpu/drm/omapdrm/omap_drv.c:#define DRIVER_NAME MODULE_NAME
drivers/gpu/drm/sprd/sprd_drm.c:#define DRIVER_NAME "sprd"
drivers/gpu/drm/savage/savage_drv.h:#define DRIVER_NAME "savage"
drivers/gpu/drm/i810/i810_drv.h:#define DRIVER_NAME "i810"
drivers/gpu/drm/mediatek/mtk_drm_drv.c:#define DRIVER_NAME "mediatek"
drivers/gpu/drm/mga/mga_drv.h:#define DRIVER_NAME "mga"
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.h:#define DRIVER_NAME "amdgpu"
drivers/gpu/drm/vboxvideo/vbox_drv.h:#define DRIVER_NAME "vboxvideo"
drivers/gpu/drm/vkms/vkms_drv.c:#define DRIVER_NAME "vkms"
drivers/gpu/drm/via/via_dri1.c:#define DRIVER_NAME "via"
drivers/gpu/drm/sti/sti_drv.c:#define DRIVER_NAME "sti"
drivers/gpu/drm/imx/ipuv3/imx-ldb.c:#define DRIVER_NAME "imx-ldb"
drivers/gpu/drm/udl/udl_drv.h:#define DRIVER_NAME "udl"
drivers/gpu/drm/nouveau/nouveau_drv.h:#define DRIVER_NAME "nouveau"
drivers/gpu/drm/mgag200/mgag200_drv.h:#define DRIVER_NAME "mgag200"
drivers/gpu/drm/vgem/vgem_drv.c:#define DRIVER_NAME "vgem"
drivers/gpu/drm/qxl/qxl_drv.h:#define DRIVER_NAME "qxl"
drivers/gpu/drm/radeon/radeon_drv.h:#define DRIVER_NAME "radeon"
drivers/gpu/drm/rockchip/rockchip_drm_drv.c:#define DRIVER_NAME "rockchip"
drivers/gpu/drm/virtio/virtgpu_drv.h:#define DRIVER_NAME "virtio_gpu"
drivers/gpu/drm/tiny/gm12u320.c:#define DRIVER_NAME "gm12u320"
drivers/gpu/drm/tiny/simpledrm.c:#define DRIVER_NAME "simpledrm"
drivers/gpu/drm/tiny/ofdrm.c:#define DRIVER_NAME "ofdrm"
drivers/gpu/drm/v3d/v3d_drv.c:#define DRIVER_NAME "v3d"
drivers/gpu/drm/gma500/psb_drv.h:#define DRIVER_NAME "gma500"
drivers/gpu/drm/hyperv/hyperv_drm_drv.c:#define DRIVER_NAME "hyperv_drm"
drivers/gpu/drm/sis/sis_drv.h:#define DRIVER_NAME "sis"
drivers/gpu/drm/tdfx/tdfx_drv.h:#define DRIVER_NAME "tdfx"
drivers/gpu/drm/i915/i915_driver.h:#define DRIVER_NAME "i915"
drivers/gpu/drm/r128/r128_drv.h:#define DRIVER_NAME "r128"
drivers/gpu/drm/tiny/cirrus.c:#define DRIVER_NAME "cirrus"
drivers/gpu/drm/tegra/drm.c:#define DRIVER_NAME "tegra"
drivers/gpu/drm/ast/ast_drv.h:#define DRIVER_NAME "ast"
drivers/gpu/drm/vc4/vc4_drv.c:#define DRIVER_NAME "vc4"
  • 格式化之后:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.h             #define DRIVER_NAME "amdgpu"            
drivers/gpu/drm/ast/ast_drv.h #define DRIVER_NAME "ast"
drivers/gpu/drm/tiny/cirrus.c #define DRIVER_NAME "cirrus"
drivers/gpu/drm/bridge/synopsys/dw-hdmi-ahb-audio.c #define DRIVER_NAME "dw-hdmi-ahb-audio"
drivers/gpu/drm/bridge/synopsys/dw-hdmi-gp-audio.c #define DRIVER_NAME "dw-hdmi-gp-audio"
drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c #define DRIVER_NAME "dw-hdmi-i2s-audio"
drivers/gpu/drm/exynos/exynos_drm_drv.c #define DRIVER_NAME "exynos"
drivers/gpu/drm/tiny/gm12u320.c #define DRIVER_NAME "gm12u320"
drivers/gpu/drm/gma500/psb_drv.h #define DRIVER_NAME "gma500"
drivers/gpu/drm/hyperv/hyperv_drm_drv.c #define DRIVER_NAME "hyperv_drm"
drivers/gpu/drm/i810/i810_drv.h #define DRIVER_NAME "i810"
drivers/gpu/drm/i915/i915_driver.h #define DRIVER_NAME "i915"
drivers/gpu/drm/imx/ipuv3/imx-ldb.c #define DRIVER_NAME "imx-ldb"
drivers/gpu/drm/bridge/imx/imx8qm-ldb-drv.c #define DRIVER_NAME "imx8qm-ldb"
drivers/gpu/drm/bridge/imx/imx8qxp-pixel-link.c #define DRIVER_NAME "imx8qxp-display-pixel-link"
drivers/gpu/drm/bridge/imx/imx8qxp-ldb-drv.c #define DRIVER_NAME "imx8qxp-ldb"
drivers/gpu/drm/bridge/imx/imx8qxp-pixel-combiner.c #define DRIVER_NAME "imx8qxp-pixel-combiner"
drivers/gpu/drm/bridge/imx/imx8qxp-pxl2dpi.c #define DRIVER_NAME "imx8qxp-pxl2dpi"
drivers/gpu/drm/mediatek/mtk_drm_drv.c #define DRIVER_NAME "mediatek"
drivers/gpu/drm/meson/meson_drv.c #define DRIVER_NAME "meson"
drivers/gpu/drm/meson/meson_dw_hdmi.c #define DRIVER_NAME "meson-dw-hdmi"
drivers/gpu/drm/mga/mga_drv.h #define DRIVER_NAME "mga"
drivers/gpu/drm/mgag200/mgag200_drv.h #define DRIVER_NAME "mgag200"
drivers/gpu/drm/nouveau/nouveau_drv.h #define DRIVER_NAME "nouveau"
drivers/gpu/drm/tiny/ofdrm.c #define DRIVER_NAME "ofdrm"
drivers/gpu/drm/qxl/qxl_drv.h #define DRIVER_NAME "qxl"
drivers/gpu/drm/r128/r128_drv.h #define DRIVER_NAME "r128"
drivers/gpu/drm/radeon/radeon_drv.h #define DRIVER_NAME "radeon"
drivers/gpu/drm/rockchip/rockchip_drm_drv.c #define DRIVER_NAME "rockchip"
drivers/gpu/drm/savage/savage_drv.h #define DRIVER_NAME "savage"
drivers/gpu/drm/tiny/simpledrm.c #define DRIVER_NAME "simpledrm"
drivers/gpu/drm/sis/sis_drv.h #define DRIVER_NAME "sis"
drivers/gpu/drm/sprd/sprd_drm.c #define DRIVER_NAME "sprd"
drivers/gpu/drm/solomon/ssd130x.c #define DRIVER_NAME "ssd130x"
drivers/gpu/drm/solomon/ssd130x-i2c.c #define DRIVER_NAME "ssd130x-i2c"
drivers/gpu/drm/solomon/ssd130x-spi.c #define DRIVER_NAME "ssd130x-spi"
drivers/gpu/drm/sti/sti_drv.c #define DRIVER_NAME "sti"
drivers/gpu/drm/tdfx/tdfx_drv.h #define DRIVER_NAME "tdfx"
drivers/gpu/drm/tegra/drm.c #define DRIVER_NAME "tegra"
drivers/gpu/drm/udl/udl_drv.h #define DRIVER_NAME "udl"
drivers/gpu/drm/v3d/v3d_drv.c #define DRIVER_NAME "v3d"
drivers/gpu/drm/vboxvideo/vbox_drv.h #define DRIVER_NAME "vboxvideo"
drivers/gpu/drm/vc4/vc4_drv.c #define DRIVER_NAME "vc4"
drivers/gpu/drm/vgem/vgem_drv.c #define DRIVER_NAME "vgem"
drivers/gpu/drm/via/via_dri1.c #define DRIVER_NAME "via"
drivers/gpu/drm/virtio/virtgpu_drv.h #define DRIVER_NAME "virtio_gpu"
drivers/gpu/drm/vkms/vkms_drv.c #define DRIVER_NAME "vkms"
drivers/gpu/drm/omapdrm/omap_drv.c #define DRIVER_NAME MODULE_NAME

Markdown to PDF

Highly recommended 3 utilities:

  • pandoc 标记语言转换领域的"瑞士军刀"
  • TexLive 开发最为活跃的 TeX 发行版之一
  • eisvogel 简洁的 pandoc LaTex 模板

eisvogel 要求一个完整的 TexLive 的安装环境,但通常像 CentOS 这样的 Linux 发行版自带的 TexLive 并不完整。

How to Install texlive.iso

Quick Install

将 TexLive 的镜像下载并挂载后,通过顶层目录下的 install-tl 这个 Perl 脚本程序安装,整个安装过程要注意以下几点。

mount ISO image

假设在 Linux 下,通过 root 用户或 sudo 挂载镜像文件

1
2
mkdir -p /mnt/iso
mount /path/to/texlive.iso /mnt/iso -o loop

run installer

TexLive 的 installer 是一个 perl script, 提供 text mode 和 GUI mode 两种安装模式.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
======================> TeX Live installation procedure <=====================

======> Letters/digits in <angle brackets> indicate <=======
======> menu items for actions or customizations <=======
= help> https://tug.org/texlive/doc/install-tl.html <=======

Detected platform: GNU/Linux on x86_64

<B> set binary platforms: 1 out of 6

<S> set installation scheme: scheme-full

<C> set installation collections:
40 collections out of 41, disk space required: 7262 MB (free: 168365 MB)

<D> set directories:
TEXDIR (the main TeX directory):
!! default location: /usr/local/texlive/2022
!! is not writable or not allowed, please select a different one!
TEXMFLOCAL (directory for site-wide local files):
/usr/local/texlive/texmf-local
TEXMFSYSVAR (directory for variable and automatically generated data):
/usr/local/texlive/2022/texmf-var
TEXMFSYSCONFIG (directory for local config):
/usr/local/texlive/2022/texmf-config
TEXMFVAR (personal directory for variable and automatically generated data):
~/.texlive2022/texmf-var
TEXMFCONFIG (personal directory for local config):
~/.texlive2022/texmf-config
TEXMFHOME (directory for user-specific files):
~/texmf

<O> options:
[ ] use letter size instead of A4 by default
[X] allow execution of restricted list of programs via \write18
[X] create all format files
[X] install macro/font doc tree
[X] install macro/font source tree
[ ] create symlinks to standard directories
[X] after install, set CTAN as source for package updates

<V> set up for portable installation

Actions:
<I> start installation to hard disk
<P> save installation profile to 'texlive.profile' and exit
<Q> quit

Enter command:
1
2
3
4
5
6
7
8
9
10
11
12
13
Options customization:

<P> use letter size instead of A4 by default: [ ]
<E> execution of restricted list of programs: [X]
<F> create all format files: [X]
<D> install font/macro doc tree: [X]
<S> install font/macro source tree: [X]
<L> create symlinks in standard directories: [X]
binaries to: /usr/bin
manpages to: /usr/man
info to: /usr/info
<Y> after install, set CTAN as source for package updates:
[X]

最好勾选此选项,避免使用 TexLive 时各种 Not Found, 原因是 TexLive 默认安装路径并不是标准 Linux 可执行程序的路径(如 /usr/bin), 而是 /usr/local/texlive, 如在 x86_64 安装 texlive2022.iso, 则可执行程序被安装在 /usr/local/texlive/2022/bin/x86_64-linux. 假如不想因为该路径没有在 PATH 里,最好就是在安装时直接在 /usr/bin 下创建相应符号链接。

texlive-full

在使用 xelatex, pdflatex 等 latex 程序时,可以常常遇到类似

! LaTeX Error: File 'fontawesome.sty' not found

xxx.sty 这样的报错,一般是缺少某个 texlive 包,但 texlive 的包太多了,如果懒得一个一个安装,可以

sudo apt install texlive-full

0%