vimacs's personal siteWritten with Vim and Emacs

提取 U-Boot 驱动的方法

由于 U-Boot 使用大量自定义数据结构,提取里面的驱动比较麻烦。因此,我把所有的头文件都复制出来,然后用 make V=1 查看构建过程。

以 ext4 驱动为例,编译 ext4fs.c 的命令如下(此处省略部分参数):

gcc  -nostdinc -isystem /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include -Iinclude   -I./arch/sandbox/include -include ./include/linux/kconfig.h -D__KERNEL__ -D__UBOOT__ -Wall  -fno-builtin    -c -o /tmp/ext4fs.o fs/ext4/ext4fs.c

可以看出需要的头文件来自 include 和 arch/ARCH/include 目录下,还需要包含 kconfig.h, libgcc 的头文件。在 U-Boot 中,获取 libgcc 头文件路径的方式在以下 Makefile 语句中:

NOSTDINC_FLAGS = -nostdinc -isystem $(shell $(CC) -print-file-name=include)

于是我们可以把所需的源代码复制出来,利用 U-Boot 的头文件,制造一个独立于 U-Boot 的模块。