All of lore.kernel.org
 help / color / mirror / Atom feed
* Booting Linux from U-Boot in qemu-system-riscv64?
@ 2020-12-02  7:21 Michael Opdenacker
  2020-12-02 14:28 ` [sw-dev] " Anup Patel
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Opdenacker @ 2020-12-02  7:21 UTC (permalink / raw)
  To: u-boot

Greetings,

To prepare an embedded Linux demo (on RiscV), I'm trying to boot Linux
from U-Boot in qemu-system-riscv64, using the "virt" emulated machine...
Note that I'm using QEMU 5.0.

The well documented way to boot Linux works:

In Linux master:
CROSS_COMPILE=riscv64-linux-gnu- (toolchain built by Buildroot)
ARCH=riscv
make defconfig
make

In opensbi:
make PLATFORM=generic FW_PAYLOAD_PATH=../linux/arch/riscv/boot/Image

Running QEMU:
qemu-system-riscv64 -nographic? -machine virt -kernel
opensbi/build/platform/generic/firmware/fw_payload.elf -append
"console=ttyS0"

I can also boot U-Boot, but cannot manage to boot the Linux kernel with it:

In U-Boot mainline:

CROSS_COMPILE=riscv64-linux-gnu-
make qemu-riscv64_smode_defconfig
Modify the environment:
- Unset CONFIG_ENV_IS_NOWHERE
- CONFIG_ENV_IS_IN_FAT=y
- CONFIG_ENV_FAT_INTERFACE="virtio"
- CONFIG_ENV_FAT_DEVICE_AND_PART="0:1"
- CONFIG_ENV_FAT_FILE="uboot.env"
make

Note that having U-Boot in "S" mode seems to be required to boot Linux.
If U-Boot is in "M" mode, it works, but there are faults (as expected)
when trying to execute Linux.

In opensbi:
make PLATFORM=generic FW_PAYLOAD_PATH=../u-boot/u-boot.bin

I then prepared a disk.img image with a first FAT partition containing:
- A "dtb" file captured from the first Linux boot (from /sys/firmware/fdt)
- A "uImage" file made from the command:
mkimage -A riscv -O linux -C none? -T kernel -a 80200000 -e 80200000 -n
"Linux" -d arch/riscv/boot/Image uImage

Then I'm starting QEMU as follows:

qemu-system-riscv64 -m 1G -nographic? -machine virt -bios
opensbi/build/platform/generic/firmware/fw_payload.bin -device
virtio-blk-device,drive=hd0 -drive file=disk.img,format=raw,id=hd0

OpenSBI v0.8-58-g781cafd
?? ____??????????????????? _____ ____ _____
? / __ \????????????????? / ____|? _ \_?? _|
?| |? | |_ __?? ___ _ __ | (___ | |_) || |
?| |? | | '_ \ / _ \ '_ \ \___ \|? _ < | |
?| |__| | |_) |? __/ | | |____) | |_) || |_
? \____/| .__/ \___|_| |_|_____/|____/_____|
??????? | |
??????? |_|

Platform Name???????????? : riscv-virtio,qemu
Platform Features???????? : timer,mfdeleg
Platform HART Count?????? : 1
Firmware Base???????????? : 0x80000000
Firmware Size???????????? : 104 KB
Runtime SBI Version?????? : 0.2

Domain0 Name????????????? : root
Domain0 Boot HART???????? : 0
Domain0 HARTs???????????? : 0*
Domain0 Region00????????? : 0x0000000080000000-0x000000008001ffff ()
Domain0 Region01????????? : 0x0000000000000000-0xffffffffffffffff (R,W,X)
Domain0 Next Address????? : 0x0000000080200000
Domain0 Next Arg1???????? : 0x0000000082200000
Domain0 Next Mode???????? : S-mode
Domain0 SysReset????????? : yes

Boot HART ID????????????? : 0
Boot HART Domain????????? : root
Boot HART ISA???????????? : rv64imafdcsu
Boot HART Features??????? : scounteren,mcounteren,time
Boot HART PMP Count?????? : 16
Boot HART PMP Granularity : 4
Boot HART PMP Address Bits: 54
Boot HART MHPM Count????? : 0
Boot HART MHPM Count????? : 0
Boot HART MIDELEG???????? : 0x0000000000000222
Boot HART MEDELEG???????? : 0x000000000000b109


U-Boot 2021.01-rc2-00161-gf6cf78dc6a (Dec 02 2020 - 07:05:39 +0100)

CPU:?? rv64imafdcsu
Model: riscv-virtio,qemu
DRAM:? 1 GiB
Loading Environment from FAT... OK
In:??? uart at 10000000
Out:?? uart at 10000000
Err:?? uart at 10000000
Net:?? No ethernet found.
Hit any key to stop autoboot:? 0
bootcmd=printenv bootcmd; fatload virtio 0:1 0x84000000 uImage; fatload
virtio 0:1 0x88000000 dtb; bootm 0x84000000 - 0x88000000
17704512 bytes read in 39 ms (432.9 MiB/s)
3618 bytes read in 1 ms (3.5 MiB/s)
## Booting kernel from Legacy Image at 84000000 ...
?? Image Name:?? Linux
?? Image Type:?? RISC-V Linux Kernel Image (uncompressed)
?? Data Size:??? 17704448 Bytes = 16.9 MiB
?? Load Address: 80200000
?? Entry Point:? 80200000
?? Verifying Checksum ... OK
## Flattened Device Tree blob at 88000000
?? Booting using the fdt blob at 0x88000000
?? Loading Kernel Image
?? Using Device Tree in place@0000000088000000, end 0000000088003e21

Starting kernel ...


... and that's all I get, no further output. I'm not sure my dtb file is
suitable though. I'm surprised there is no DTS file for the riscv64
"virt" board emulated by QEMU in the Linux kernel sources, as U-Boot
will refuse to boot Linux without one.

Note that in U-Boot, the bootargs environment is set to:
bootargs=console=ttyS0

I'll be interested in your advise, if you already managed to do
something like this.

Cheers,

Michael.

-- 
Michael Opdenacker, CEO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-02 14:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-02  7:21 Booting Linux from U-Boot in qemu-system-riscv64? Michael Opdenacker
2020-12-02 14:28 ` [sw-dev] " Anup Patel
2020-12-02 14:53   ` Michael Opdenacker

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.