使用 u-boot 从 qemu (ARM) 中的 SD 启动内核

rfx*_*rfx 5 linux arm qemu embedded-linux u-boot

我对嵌入式系统很陌生,我正在 qemu 上使用 ARM。因此,我在使用 cpu cortex-a9 的多功能 Express 上从模拟 SD 启动 Linux 内核映像时遇到了问题。

我按以下顺序准备了所有内容:首先,我使用适当的 ARM 工具链构建了内核vexpress_defconfig。然后我用 构建了 u-boot vexpress_ca9x4_defconfig。一切都很顺利。我使用的 Linux 内核源代码是 4.13 版本(来自 git 的最新稳定版)。U-boot版本为2017.09-00100。然后我准备了一张标清图像:

dd if=/dev/zero of=sd.img bs=4096 count=4096
mkfs.vfat sd.img
mount sd.img /mnt/tmp -o loop,rw
cp kernel/arch/arm/boot/zImage /mnt/tmp
umount /mnt/tmp
Run Code Online (Sandbox Code Playgroud)

接下来我尝试按如下方式运行 qemu:

qemu-system-arm -machine vexpress-a9 -cpu cortex-a9 -m 128M -dtb kernel/arch/arm/boot/dts/vexpress-v2p-ca9.dtb -kernel uboot/u-boot -sd sd.img -nographic
Run Code Online (Sandbox Code Playgroud)

U-boot 加载成功并给出命令提示符。SD 确实存在并附加:

=> mmcinfo
Device: MMC
Manufacturer ID: aa
OEM: 5859
Name: QEMU! 
Tran Speed: 25000000
Rd Block Len: 512
SD version 1.0
High Capacity: No
Capacity: 16 MiB
Bus Width: 1-bit
Erase Group Size: 512 Bytes
Run Code Online (Sandbox Code Playgroud)

我尝试将压缩图像从 SD 加载到内存中并启动它:

fatload mmc 0:0 0x4000000 zImage
Run Code Online (Sandbox Code Playgroud)

一切看起来都很好

=> fatload mmc 0:0 0x4000000 zImage
reading zImage
3378968 bytes read in 1004 ms (3.2 MiB/s)
Run Code Online (Sandbox Code Playgroud)

但后来我想启动内核并收到错误:

=> bootz 0x4000000
Bad Linux ARM zImage magic!
Run Code Online (Sandbox Code Playgroud)

我还尝试了使用 u-boot 制作的 U-boot 映像mkimage,如下例所示:

uboot/tools/mkimage -A arm -C none -O linux -T kernel -d kernel/arch/arm/boot/Image -a 0x00010000 -e 0x00010000 uImage
Run Code Online (Sandbox Code Playgroud)

还尝试了-C gzip不同zImage的加载/入口地址,但无济于事。图像被复制到sd.img. 当我使用fatload图像并检查它时iminfo,无论我尝试哪个选项,我都会不断收到错误:

=> iminfo 0x4000000

## Checking Image at 04000000 ...
Unknown image format!
Run Code Online (Sandbox Code Playgroud)

我完全困惑了,这个问题让我发疯,而互联网上关于这个主题的信息相当稀缺。请提示我做错了什么并重定向到正确的方向。

使用的 qemu 是QEMU emulator version 2.9.0.