我一直在尝试让 U-Boot 在 QEMU 中为sifive_u
机器工作。我尝试使用内置的OpenSBI"BIOS"和构建自己的OpenSBI,但我一直遇到同样的问题。
我正在使用 Arch 存储库中的 riscv64 工具链构建 U-Boot:
➜ u-boot git:(0b0c6af387) riscv64-linux-gnu-gcc --version
riscv64-linux-gnu-gcc (GCC) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
➜ u-boot git:(0b0c6af387) export CROSS_COMPILE=riscv64-linux-gnu-
➜ u-boot git:(0b0c6af387) export ARCH=riscv
➜ u-boot git:(0b0c6af387) make sifive_fu540_defconfig
...
➜ u-boot git:(0b0c6af387) make
我尝试按如下方式运行它:
➜ opensbi git:(master) ✗ qemu-system-riscv64 -M sifive_u -m 256M -bios default -display none -serial stdio -device loader,addr=0x80200000,file=../u-boot/u-boot.bin
OpenSBI v0.5 (Oct 9 2019 12:03:04)
____ _____ ____ _____
/ __ / ____| _ _ _|
| | | |_ __ ___ _ __ | (___ | |_) || |
| | | | '_ / _ '_ ___ | _ < | |
| |__| | |_) | __/ | | |____) | |_) || |_
____/| .__/ ___|_| |_|_____/|____/_____|
| |
|_|
Platform Name : SiFive Freedom U540
Platform HART Features : RV64ACDFIMSU
Platform Max HARTs : 5
Current Hart : 1
Firmware Base : 0x80000000
Firmware Size : 96 KB
Runtime SBI Version : 0.2
PMP0: 0x0000000080000000-0x000000008001ffff (A)
PMP1: 0x0000000000000000-0xffffffffffffffff (A,R,W,X)
U-Boot 2020.01 (Jan 20 2020 - 18:14:27 +0000)
CPU: rv64imafdc
Model: SiFive HiFive Unleashed A00
DRAM: exception code: 7 , Store/AMO access fault , epc 8023cbdc , ra 8020c670
### ERROR ### Please RESET the board ###
我还尝试将U-Boot作为有效负载捆绑到我自己的OpenSBI版本中:
➜ opensbi git:(master) ✗ export CROSS_COMPILE=riscv64-unknown-elf-
➜ opensbi git:(master) ✗ make PLATFORM=sifive/fu540 FW_PAYLOAD_PATH=../u-boot/u-boot.bin
➜ opensbi git:(master) ✗ qemu-system-riscv64 -M sifive_u -m 256M -bios none -display none -serial stdio -device loader,addr=0x80000000,file=./build/platform/sifive/fu540/firmware/fw_payload.bin
OpenSBI v0.5-32-gc0849cd
____ _____ ____ _____
/ __ / ____| _ _ _|
| | | |_ __ ___ _ __ | (___ | |_) || |
| | | | '_ / _ '_ ___ | _ < | |
| |__| | |_) | __/ | | |____) | |_) || |_
____/| .__/ ___|_| |_|_____/|____/_____|
| |
|_|
Platform Name : SiFive Freedom U540
Platform HART Features : RV64ACDFIMSU
Platform Max HARTs : 5
Current Hart : 1
Firmware Base : 0x80000000
Firmware Size : 100 KB
Runtime SBI Version : 0.2
PMP0: 0x0000000080000000-0x000000008001ffff (A)
PMP1: 0x0000000000000000-0xffffffffffffffff (A,R,W,X)
U-Boot 2020.01 (Jan 20 2020 - 18:14:27 +0000)
CPU: rv64imafdc
Model: SiFive HiFive Unleashed A00
DRAM: exception code: 7 , Store/AMO access fault , epc 8023cbdc , ra 8020c670
### ERROR ### Please RESET the board ###
我尝试根据错误消息查看有问题的指令(我认为0x8023cbdc
(:
➜ u-boot git:(0b0c6af387) riscv64-unknown-elf-objdump --start-address=0x8023cbdc -d ./u-boot | head -8
./u-boot: file format elf64-littleriscv
Disassembly of section .text_rest:
000000008023cbdc <memset+0x40>:
8023cbdc: fee7bc23 sd a4,-8(a5)
这是一家商店,因此这确实是访问无效位置是合理的;我正在尝试让 GDB 工作,以便我可以更详细地检查实际发生的事情,但这会导致它自己的问题......
有人在这方面取得了任何成功吗?
更新
我已经设法通过使用-M 2G
更改内存量来修复此特定错误;我认为它试图访问的地址在 256M 范围之外,但我不确定它正在做什么需要这么多 RAM。
现在我收到以下错误:
➜ opensbi git:(master) ✗ qemu-system-riscv64 -M sifive_u -m 8G -bios default -display none -serial stdio -device loader,addr=0x80200000,file=../u-boot/u-boot-dtb.bin
OpenSBI v0.5 (Oct 9 2019 12:03:04)
____ _____ ____ _____
/ __ / ____| _ _ _|
| | | |_ __ ___ _ __ | (___ | |_) || |
| | | | '_ / _ '_ ___ | _ < | |
| |__| | |_) | __/ | | |____) | |_) || |_
____/| .__/ ___|_| |_|_____/|____/_____|
| |
|_|
Platform Name : SiFive Freedom U540
Platform HART Features : RV64ACDFIMSU
Platform Max HARTs : 5
Current Hart : 1
Firmware Base : 0x80000000
Firmware Size : 96 KB
Runtime SBI Version : 0.2
PMP0: 0x0000000080000000-0x000000008001ffff (A)
PMP1: 0x0000000000000000-0xffffffffffffffff (A,R,W,X)
U-Boot 2020.01 (Jan 20 2020 - 21:40:02 +0000)
CPU: rv64imafdc
Model: SiFive HiFive Unleashed A00
DRAM: 8 GiB
MMC: exception code: 5 , Load access fault , epc fffadbd6 , ra fffadbd2
### ERROR ### Please RESET the board ###
qemu-system-riscv64: terminating on signal 2
同样是相似的(尽管这次是负载(; 有趣的是,地址fffadbd6
不是 U-Boot 的一部分,所以我不知道这里发生了什么;我非常怀疑它是否在结束时运行,因为那样我就会期望未定义的行为,而不是始终获得相同的不良负载。
我使用 gcc 2023.0-6ubuntu1 构建了 U-Boot 12.3.07,如下所示:
export OPENSBI=../opensbi/build/platform/generic/firmware/fw_dynamic.bin
export CROSS_COMPILE=riscv64-linux-gnu-
make sifive_unleashed_defconfig
make -j$(nproc)
我正在使用 QEMU 8.0,它提供 OpenSBI 作为默认固件。以下命令成功启动 U-Boot:
/usr/bin/qemu-system-riscv64 -M sifive_u -m 8G -nographic
-kernel u-boot.bin
要使用我自己的OpenSBI,以下工作:
/usr/bin/qemu-system-riscv64 -M sifive_u -m 8G -nographic
-bios ../opensbi/build/platform/generic/firmware/fw_dynamic.bin
-kernel u-boot.bin
OpenSBI必须与
export CROSS_COMPILE=riscv64-linux-gnu-
make PLATFORM=generic