[U-Boot] RISC-V: Crashes with OpenSBI+U-Boot on the qemu "virt" machine

Anup Patel anup at brainfault.org
Sat May 4 03:07:13 UTC 2019


Hi Karsten,

First of all, the 2GB case where U-Boot crashes shows that U-Boot is
trying to access memory close to 0x80000000 where OpenSBI firmware
is running hence it gets ACCESS fault. The OpenSBI protects firmware
using PMP configuration whereas BBL does not. In fact, it is very easy
to corrupt BBL from S-mode.

In fact, the U-Boot crashes with OpenSBI implies that issue in U-Boot
which OpenSBI is helping us detect by injecting ACCESS fault to S-mode.

I tries vanilla U-Boot-2019.07-rc1 (without booti support) and OpenSBI
at commit f9643f34. It worked fine for me. Here's the boot log:

anup at anup-ubuntu64:~/Work/riscv-test$ qemu-system-riscv64 -nographic
-machine virt -m 2G \
> -kernel opensbi/build/platform/qemu/virt/firmware/fw_jump.elf \
> -device loader,file=u-boot/u-boot.bin,addr=0x80200000 \
> -object rng-random,filename=/dev/urandom,id=rng0 \
> -device virtio-rng-device,rng=rng0 \
> -append "console=ttyS0 rw root=/dev/vda1" \
> -device virtio-blk-device,drive=hd0 \
> -drive file=./rootfs_riscv64.ext2,format=raw,id=hd0 \
> -device virtio-net-device,netdev=usernet \
> -netdev user,id=usernet,hostfwd=tcp::22222-:22

OpenSBI v0.3 (May  4 2019 08:27:41)
   ____                    _____ ____ _____
  / __ \                  / ____|  _ \_   _|
 | |  | |_ __   ___ _ __ | (___ | |_) || |
 | |  | | '_ \ / _ \ '_ \ \___ \|  _ < | |
 | |__| | |_) |  __/ | | |____) | |_) || |_
  \____/| .__/ \___|_| |_|_____/|____/_____|
        | |
        |_|

Platform Name          : QEMU Virt Machine
Platform HART Features : RV64ACDFIMSU
Platform Max HARTs     : 8
Current Hart           : 0
Firmware Base          : 0x80000000
Firmware Size          : 100 KB
Runtime SBI Version    : 0.1

PMP0: 0x0000000080000000-0x000000008001ffff (A)
PMP1: 0x0000000000000000-0xffffffffffffffff (A,R,W,X)


U-Boot 2019.07-rc1 (May 04 2019 - 07:50:53 +0530)

CPU:   rv64imafdcsu
Model: riscv-virtio,qemu
DRAM:  2 GiB
In:    uart at 10000000
Out:   uart at 10000000
Err:   uart at 10000000
Net:
Warning: virtio-net#2 using MAC address from ROM
eth0: virtio-net#2
Hit any key to stop autoboot:  0
=>
=> setenv ipaddr 10.0.2.1
=> ping 10.0.2.2
Using virtio-net#2 device
host 10.0.2.2 is alive
=>
Using virtio-net#2 device
host 10.0.2.2 is alive
=>
Using virtio-net#2 device
host 10.0.2.2 is alive
=>
Using virtio-net#2 device
host 10.0.2.2 is alive
=> <INTERRUPT>
=> QEMU 3.1.92 monitor - type 'help' for more information
(qemu) q


I also tried OpenSBI fail cases you reported but using bootm
and this worked for me as well.

Create temp.bin:
./u-boot/tools/mkimage -A riscv -O linux -T kernel -C none -a
0x80200000 -e 0x80200000 -n Linux -d
build-riscv64/arch/riscv/boot/Image
build-riscv64/arch/riscv/boot/uImage
./u-boot/tools/mkimage -A riscv -O linux -T ramdisk -C none -a
0x00000000 -n "Linux RootFS" -d rootfs_riscv64.img uRamdisk
dd if=/dev/zero of=./temp.bin bs=1M count=1
dd if=./build-riscv64/arch/riscv/boot/uImage of=./temp.bin bs=1M
seek=1 conv=nocreat,notrunc
dd if=./uRamdisk of=./temp.bin bs=1M seek=33 conv=nocreat,notrunc

Here's the log:
anup at anup-ubuntu64:~/Work/riscv-test$ qemu-system-riscv64 -nographic
-smp 2 -machine virt -m 1.9G -kernel
opensbi/build/platform/qemu/virt/firmware/fw_payload.elf -device
loader,file=./temp.bin,addr=0x80500000 -object
rng-random,filename=/dev/urandom,id=rng0 -device
virtio-rng-device,rng=rng0 -append "console=ttyS0 rw root=/dev/vda"
-device virtio-blk-device,drive=hd0 -drive
file=./rootfs_riscv64.ext2,format=raw,id=hd0 -device
virtio-net-device,netdev=usernet -netdev
user,id=usernet,hostfwd=tcp::22222-:22

OpenSBI v0.3 (May  4 2019 08:27:41)
   ____                    _____ ____ _____
  / __ \                  / ____|  _ \_   _|
 | |  | |_ __   ___ _ __ | (___ | |_) || |
 | |  | | '_ \ / _ \ '_ \ \___ \|  _ < | |
 | |__| | |_) |  __/ | | |____) | |_) || |_
  \____/| .__/ \___|_| |_|_____/|____/_____|
        | |
        |_|

Platform Name          : QEMU Virt Machine
Platform HART Features : RV64ACDFIMSU
Platform Max HARTs     : 8
Current Hart           : 0
Firmware Base          : 0x80000000
Firmware Size          : 104 KB
Runtime SBI Version    : 0.1

PMP0: 0x0000000080000000-0x000000008001ffff (A)
PMP1: 0x0000000000000000-0xffffffffffffffff (A,R,W,X)


U-Boot 2019.07-rc1 (May 04 2019 - 07:50:53 +0530)

CPU:   rv64imafdcsu
Model: riscv-virtio,qemu
DRAM:  1.9 GiB
In:    uart at 10000000
Out:   uart at 10000000
Err:   uart at 10000000
Net:
Warning: virtio-net#2 using MAC address from ROM
eth0: virtio-net#2
Hit any key to stop autoboot:  0

Device 0: QEMU VirtIO Block Device
            Type: Hard Disk
            Capacity: 32.0 MB = 0.0 GB (65536 x 512)
... is now current device
** No partition table - virtio 0 **
BOOTP broadcast 1
DHCP client bound to address 10.0.2.15 (6 ms)
Using virtio-net#2 device
TFTP from server 10.0.2.2; our IP address is 10.0.2.15
Filename 'boot.scr.uimg'.
Load address: 0x82100000
Loading: *
TFTP error: 'Access violation' (2)
Not retrying...
BOOTP broadcast 1
DHCP client bound to address 10.0.2.15 (0 ms)
Using virtio-net#2 device
TFTP from server 10.0.2.2; our IP address is 10.0.2.15
Filename 'boot.scr.uimg'.
Load address: 0x81000000
Loading: *
TFTP error: 'Access violation' (2)
Not retrying...
=> bootm 0x80600000 - ${fdtcontroladdr}
## Booting kernel from Legacy Image at 80600000 ...
   Image Name:   Linux
   Image Type:   RISC-V Linux Kernel Image (uncompressed)
   Data Size:    8433868 Bytes = 8 MiB
   Load Address: 80200000
   Entry Point:  80200000
   Verifying Checksum ... OK
## Flattened Device Tree blob at f9136f90
   Booting using the fdt blob at 0xf9136f90
   Loading Kernel Image ... OK
   Using Device Tree in place at 00000000f9136f90, end 00000000f913ad9d

Starting kernel ...

[    0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80200000
[    0.000000] Linux version 5.1.0-rc7-00002-ge306aaec1303-dirty
(anup at anup-ubuntu64) (gcc version 8.2.0 (Buildroot
2018.11-rc2-00003-ga0787e9)) #21 SMP Thu May 2 10:02:14 IST 2019
[    0.000000] initrd not found or empty - disabling initrd
[    0.000000] Zone ranges:
[    0.000000]   DMA32    [mem 0x0000000080200000-0x00000000f9999fff]
[    0.000000]   Normal   empty
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000080200000-0x00000000f9999fff]
[    0.000000] Initmem setup node 0 [mem 0x0000000080200000-0x00000000f9999fff]
[    0.000000] software IO TLB: mapped [mem 0xf3694000-0xf7694000] (64MB)
[    0.000000] elf_hwcap is 0x112d
[    0.000000] percpu: Embedded 17 pages/cpu s29592 r8192 d31848 u69632
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 490759
[    0.000000] Kernel command line: console=ttyS0 rw root=/dev/vda
[    0.000000] Dentry cache hash table entries: 262144 (order: 9, 2097152 bytes)
[    0.000000] Inode-cache hash table entries: 131072 (order: 8, 1048576 bytes)
[    0.000000] Sorting __ex_table...
[    0.000000] Memory: 1881684K/1990248K available (5586K kernel code,
352K rwdata, 1774K rodata, 192K init, 313K bss, 108564K reserved, 0K
cma-reserved)
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=2, Nodes=1
[    0.000000] rcu: Hierarchical RCU implementation.
[    0.000000] rcu:     RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=2.
[    0.000000] rcu: RCU calculated value of scheduler-enlistment delay
is 25 jiffies.
[    0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=2
[    0.000000] NR_IRQS: 0, nr_irqs: 0, preallocated irqs: 0
[    0.000000] plic: mapped 53 interrupts with 2 handlers for 4 contexts.
[    0.000000] riscv_timer_init_dt: Registering clocksource cpuid [0] hartid [0]
[    0.000000] clocksource: riscv_clocksource: mask:
0xffffffffffffffff max_cycles: 0x24e6a1710, max_idle_ns: 440795202120
ns
[    0.000115] sched_clock: 64 bits at 10MHz, resolution 100ns, wraps
every 4398046511100ns
[    0.003035] Console: colour dummy device 80x25
[    0.004254] Calibrating delay loop (skipped), value calculated
using timer frequency.. 20.00 BogoMIPS (lpj=40000)
[    0.004400] pid_max: default: 32768 minimum: 301
[    0.008974] Mount-cache hash table entries: 4096 (order: 3, 32768 bytes)
[    0.009052] Mountpoint-cache hash table entries: 4096 (order: 3, 32768 bytes)
[    0.018034] *** VALIDATE proc ***
[    0.020619] *** VALIDATE cgroup1 ***
[    0.020677] *** VALIDATE cgroup2 ***
[    0.035733] rcu: Hierarchical SRCU implementation.
[    0.042693] smp: Bringing up secondary CPUs ...
[    0.053472] smp: Brought up 1 node, 2 CPUs
[    0.102787] devtmpfs: initialized
[    0.110755] random: get_random_u32 called from
bucket_table_alloc+0x74/0x17c with crng_init=0
[    0.114136] clocksource: jiffies: mask: 0xffffffff max_cycles:
0xffffffff, max_idle_ns: 7645041785100000 ns
[    0.114449] futex hash table entries: 512 (order: 3, 32768 bytes)
[    0.118349] NET: Registered protocol family 16
[    0.168031] vgaarb: loaded
[    0.168961] SCSI subsystem initialized
[    0.171377] usbcore: registered new interface driver usbfs
[    0.171717] usbcore: registered new interface driver hub
[    0.172038] usbcore: registered new device driver usb
[    0.181523] clocksource: Switched to clocksource riscv_clocksource
[    0.243791] NET: Registered protocol family 2
[    0.259646] tcp_listen_portaddr_hash hash table entries: 1024
(order: 2, 16384 bytes)
[    0.259818] TCP established hash table entries: 16384 (order: 5,
131072 bytes)
[    0.260272] TCP bind hash table entries: 16384 (order: 6, 262144 bytes)
[    0.260561] TCP: Hash tables configured (established 16384 bind 16384)
[    0.262454] UDP hash table entries: 1024 (order: 3, 32768 bytes)
[    0.262735] UDP-Lite hash table entries: 1024 (order: 3, 32768 bytes)
[    0.264072] NET: Registered protocol family 1
[    0.267631] RPC: Registered named UNIX socket transport module.
[    0.267705] RPC: Registered udp transport module.
[    0.267750] RPC: Registered tcp transport module.
[    0.267787] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.277637] workingset: timestamp_bits=62 max_order=19 bucket_order=0
[    0.289839] NFS: Registering the id_resolver key type
[    0.290564] Key type id_resolver registered
[    0.290630] Key type id_legacy registered
[    0.290801] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    0.319589] NET: Registered protocol family 38
[    0.320030] Block layer SCSI generic (bsg) driver version 0.4
loaded (major 254)
[    0.320161] io scheduler mq-deadline registered
[    0.320275] io scheduler kyber registered
[    0.323769] pci-host-generic 30000000.pci: host bridge
/soc/pci at 30000000 ranges:
[    0.324712] pci-host-generic 30000000.pci:    IO
0x03000000..0x0300ffff -> 0x00000000
[    0.325975] pci-host-generic 30000000.pci:   MEM
0x40000000..0x7fffffff -> 0x40000000
[    0.327555] pci-host-generic 30000000.pci: ECAM at [mem
0x30000000-0x3fffffff] for [bus 00-ff]
[    0.328515] pci-host-generic 30000000.pci: PCI host bridge to bus 0000:00
[    0.328705] pci_bus 0000:00: root bus resource [bus 00-ff]
[    0.328819] pci_bus 0000:00: root bus resource [io  0x0000-0xffff]
[    0.328864] pci_bus 0000:00: root bus resource [mem 0x40000000-0x7fffffff]
[    0.657734] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
[    0.670254] printk: console [ttyS0] disabled
[    0.674112] 10000000.uart: ttyS0 at MMIO 0x10000000 (irq = 10,
base_baud = 230400) is a 16550A
[    0.706583] printk: console [ttyS0] enabled
[    0.710175] [drm] radeon kernel modesetting enabled.
[    0.776626] loop: module loaded
[    0.796027] virtio_blk virtio1: [vda] 65536 512-byte logical blocks
(33.6 MB/32.0 MiB)
[    0.911186] libphy: Fixed MDIO Bus: probed
[    0.924288] e1000e: Intel(R) PRO/1000 Network Driver - 3.2.6-k
[    0.924673] e1000e: Copyright(c) 1999 - 2015 Intel Corporation.
[    0.926571] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    0.927187] ehci-pci: EHCI PCI platform driver
[    0.928301] ehci-platform: EHCI generic platform driver
[    0.929661] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[    0.930490] ohci-pci: OHCI PCI platform driver
[    0.931560] ohci-platform: OHCI generic platform driver
[    0.939057] usbcore: registered new interface driver uas
[    0.940342] usbcore: registered new interface driver usb-storage
[    0.952450] mousedev: PS/2 mouse device common for all mice
[    0.960830] usbcore: registered new interface driver usbhid
[    0.961346] usbhid: USB HID core driver
[    0.964999] NET: Registered protocol family 10
[    0.992632] Segment Routing with IPv6
[    0.994252] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[    1.011182] NET: Registered protocol family 17
[    1.012799] Key type dns_resolver registered
[    1.065211] EXT4-fs (vda): mounting ext2 file system using the ext4 subsystem
[    1.079749] EXT4-fs (vda): warning: mounting unchecked fs, running
e2fsck is recommended
[    1.096180] EXT4-fs (vda): mounted filesystem without journal. Opts: (null)
[    1.098008] VFS: Mounted root (ext2 filesystem) on device 254:0.
[    1.137019] Freeing unused kernel memory: 192K
[    1.137518] This architecture does not have kernel memory protection.
[    1.138165] Run /sbin/init as init process
           _  _
          | ||_|
          | | _ ____  _   _  _  _
          | || |  _ \| | | |\ \/ /
          | || | | | | |_| |/    \
          |_||_|_| |_|\____|\_/\_/

               Busybox Rootfs

Please press Enter to activate this console.
/ # cat /proc/interrupts
           CPU0       CPU1
  6:          0          0  SiFive PLIC   6  virtio2
  7:         45          0  SiFive PLIC   7  virtio1
 10:         58          0  SiFive PLIC  10  ttyS0
IPI0:       641        656  Rescheduling interrupts
IPI1:         0          6  Function call interrupts
IPI2:         0          0  CPU stop interrupts
/ # QEMU 3.1.92 monitor - type 'help' for more information
(qemu) q

Regards,
Anup


More information about the U-Boot mailing list