Booting Linux from U-Boot in qemu-system-riscv64?

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@10000000 Out: uart@10000000 Err: uart@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 at 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.

Hi Michael,
Set bootargs to "root=/dev/vda2 rootwait console=ttyS0 earlycon=sbi" in U-Boot before doing bootm
Regards, Anup
On Wed, 2 Dec, 2020, 12:51 Michael Opdenacker, < michael.opdenacker@bootlin.com> wrote:
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@10000000 Out: uart@10000000 Err: uart@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 at 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
-- You received this message because you are subscribed to the Google Groups "RISC-V SW Dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to sw-dev+unsubscribe@groups.riscv.org. To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/6071db20-58af-55... .

Hi Anup,
On 12/2/20 3:28 PM, Anup Patel wrote:
root=/dev/vda2 rootwait console=ttyS0 earlycon=sbi
Many thanks for the "earlycon=sbi" tip. It doesn't solve the problem yet but definitely helps to get further details:
[ 0.000000] Linux version 5.10.0-rc5-00357-gaae5ab854e38 (mike@mike-laptop) (riscv64-linux-gnu-gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #11 SMP Tue Dec 1 07:13:44 CET 2020 [ 0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80200000 [ 0.000000] earlycon: sbi0 at I/O port 0x0 (options '') [ 0.000000] printk: bootconsole [sbi0] enabled [ 0.000000] efi: UEFI not found. [ 0.000000] Zone ranges: [ 0.000000] DMA32 [mem 0x0000000080200000-0x0000000081ffffff] [ 0.000000] Normal empty [ 0.000000] Movable zone start for each node [ 0.000000] Early memory node ranges [ 0.000000] node 0: [mem 0x0000000080200000-0x0000000081ffffff] [ 0.000000] Initmem setup node 0 [mem 0x0000000080200000-0x0000000081ffffff] [ 0.000000] Unable to handle kernel paging request at virtual address ffffffe007e00001 [ 0.000000] Oops [#1] [ 0.000000] Modules linked in: [ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 5.10.0-rc5-00357-gaae5ab854e38 #11 [ 0.000000] epc: ffffffe0004a8b38 ra : ffffffe000021cb8 sp : ffffffe001003f60 [ 0.000000] gp : ffffffe0010e1fb0 tp : ffffffe00100bd40 t0 : ffffffe001d8efc0 [ 0.000000] t1 : 0000000081f8efc0 t2 : 2d656b696d40656b s0 : ffffffe001003f80 [ 0.000000] s1 : ffffffe007e00000 a0 : ffffffe007e00000 a1 : ffffffe001d8ef80 [ 0.000000] a2 : 0000000000000000 a3 : 0000000000000000 a4 : 0000000000000000 [ 0.000000] a5 : ffffffdf7fe00000 a6 : ffffffe0010104b8 a7 : 0000000000000030 [ 0.000000] s2 : ffffffe0010e30a8 s3 : 0000000000000003 s4 : fffffffffffffff3 [ 0.000000] s5 : 00000000bffe1c70 s6 : 0000000000000000 s7 : 0000000000000000 [ 0.000000] s8 : 00000000bff6a042 s9 : 0000000080200000 s10: 0000000000000000 [ 0.000000] s11: 0000000000000000 t3 : 0000000000000018 t4 : 0000000000000001 [ 0.000000] t5 : 0000000000000018 t6 : 0000000001e00000 [ 0.000000] status: 0000000000000100 badaddr: ffffffe007e00001 cause: 000000000000000d [ 0.000000] random: get_random_bytes called from print_oops_end_marker+0x22/0x44 with crng_init=0 [ 0.000000] ---[ end trace 0000000000000000 ]--- [ 0.000000] Kernel panic - not syncing: Attempted to kill the idle task! [ 0.000000] ---[ end Kernel panic - not syncing: Attempted to kill the idle task! ]---
Now I guess I can compare with the run in which the kernel is directly started without U-Boot...
Suggestions welcome of course...
Thanks again,
Michael.
participants (2)
-
Anup Patel
-
Michael Opdenacker