4

I've been trying to get U-Boot to work in QEMU for the sifive_u machine. I've tried using both the built in OpenSBI 'BIOS' and building my own OpenSBI, but I keep running into the same issue.

I'm building U-Boot using the riscv64 toolchain from the Arch repos:

➜  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

I've tried to run this as follows:

➜  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 ###

I've also tried bundling U-Boot as a payload into my own build of 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 ###

I've tried looking at the offending instruction (which I presume is at 0x8023cbdc) based on the error message:

➜  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)

It's a store, so it's plausible that this is indeed accessing an invalid location; I'm trying to get GDB working so I can examine what's actually happening in more detail, but that's causing issues of its own...

Has anyone had any success with this?

UPDATE

I've managed to fix this specific error by changing the amount of memory with -M 2G; I presume the address it's trying to access lies outside the 256M range, but I'm not sure what it's doing that requires this much RAM.

Now I'm getting the following error:

➜  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

Again it's similar (although a load this time); interestingly, the address fffadbd6 isn't part of U-Boot so I've no idea what's happening here; I very much doubt it's running off the end, because then I would expect undefined behaviour as opposed to consistently getting the same bad load.

p0llard
  • 439
  • 6
  • 17
  • 1
    Its too bad the exception handler doesn't show the `mtval` (the address of attempted access). (Also, not sure why they think `ra` is more relevant here than `mtval`??) – Erik Eidt Jan 22 '20 at 00:48
  • @ErikEidt Indeed, I tried to use GDB to observe which address is being accessed, but I'm having problems with that too (https://stackoverflow.com/questions/59828618/remote-debugging-hifive-unleashed-in-qemu); I actually managed to fix this error, but I've run into another very similar one, I'll update the question. – p0llard Jan 22 '20 at 14:11
  • @ErikEidt I might try hacking the exception handler to dump `mtval` too. – p0llard Jan 22 '20 at 14:17
  • Are you still seeing the issue? Btw there was a recent patch in U-Boot to dump all register on exception. Not sure if that is from you or somebody else. https://patchwork.ozlabs.org/patch/1215339/ – alex Feb 27 '20 at 23:54
  • @alex sadly other work has got in the way (ihtfp). Not my patch, but I'm planning to return to this. – p0llard Feb 28 '20 at 02:59
  • @p0llard sure. Let me know if you still see the issue. I run OpenSBI + U-Boot + Linux in Qemu very often. I may be able to help – alex Mar 04 '20 at 01:35
  • @alex just wondering which toolchain you're using for cross-compiling U-Bboot? – p0llard Mar 30 '20 at 21:49
  • From bootlin https://toolchains.bootlin.com/ – alex Apr 01 '20 at 00:04
  • I voted to close this question because SO is a programming Q&A platform and this question is not about programming. [What topics can I ask about here?](https://stackoverflow.com/help/on-topic) Please delete this. – Rob Jul 13 '23 at 13:29

1 Answers1

0

I built U-Boot 2023.07 with gcc 12.3.0-6ubuntu1 as follows:

export OPENSBI=../opensbi/build/platform/generic/firmware/fw_dynamic.bin
export CROSS_COMPILE=riscv64-linux-gnu-
make sifive_unleashed_defconfig
make -j$(nproc)

I am using QEMU 8.0 which provides OpenSBI as default firmware. The following command starts U-Boot successfully:

/usr/bin/qemu-system-riscv64 -M sifive_u -m 8G -nographic \
-kernel u-boot.bin

To use my own OpenSBI the following works:

/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 has to be built with

export CROSS_COMPILE=riscv64-linux-gnu-
make PLATFORM=generic
Xypron
  • 2,215
  • 1
  • 12
  • 24
  • The reason this question has not had any answers in over three years, till now, is because it is off topic. Do not answer off topic questions. [answer] Vote to close instead. – Rob Jul 13 '23 at 13:30