RISC-V on Ubuntu

Images

SiFive HiFive Unmatched & QEMU

One can boot riscv64+unmatched image on any system with qemu-system, or on bare-metal SiFive HiFive Unmatched board.

SiFive HiFive Unleashed & QEMU

One can boot riscv64 & riscv64+unleashed images on any system with qemu-system, or on bare-metal SiFive HiFive Unleashed board.

Forums

You can discuss Ubuntu on RISC-V in the comments, or by creating a new topic over on the Ubuntu Server forums.

Booting with qemu

Prerequisites:

sudo apt install qemu-system-misc opensbi u-boot-qemu qemu-utils

Hirsute’s version of u-boot-qemu is required at the moment to boot hirsute images.

After installing the above prerequisites, one can use any of the above images to boot virtually. First unpack the image

xz -dk focal-preinstalled-server-riscv64.img.xz

Optionally, if you want larger disk, you can expand the disk (filesystem will be automatically):

qemu-img resize -f raw focal-preinstalled-server-riscv64.img +5G

Next use OpenSBI bootloader & u-boot-qemu to boot the virtual machine. A working example with all the options is:

qemu-system-riscv64 \ -machine virt -nographic -m 2048 -smp 4 \ -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf \ -kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf \ -device virtio-net-device,netdev=eth0 -netdev user,id=eth0 \ -drive file=focal-preinstalled-server-riscv64.img,format=raw,if=virtio

The important options to use are:

  • Machine type virt aka -machine virt
  • Bios is OpenSBI -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf
  • “kernel” is qemu smode uboot -kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf

One can use pass through networking, adjust memory (-m) & cpu counts (-smp) as needed. Then, switch to the serial console, wait for cloud-init to complete, and login using ubuntu:ubuntu. See the cloud-init section below to further customise the first boot behaviour with cloud-init.

Booting on SiFive HiFive Unmatched board

The above image has U-Boot SPL loader as well as SiFive U-Boot to boot on the board.

Set jumpers to boot from the microSD by setting MSEL=1011 (MSEL2 to the outside of the board, the rest to the inside).

You can then use “Gnome Disks” app to restore img.xz image onto the microSD card, plug it into the board and boot.

You can also use cmdline to extract the image and dd it:

xz -dk focal-preinstalled-server-riscv64+unmatched.img.xz dd if=focal-preinstalled-server-riscv64+unmatched.img of=/dev/disk/by-id/<TAB><TAB>complete-to-sdcard-device

Monitor the serial console, wait for cloud-init to complete, then login using ubuntu:ubuntu. See the cloud-init section below to further customise the first boot behaviour with cloud-init.

Booting on SiFive HiFive Unleashed board

The above image has U-Boot SPL loader as well as SiFive U-Boot to boot on the board.

Set jumpers to boot from the microSD by setting MSEL=1011 (MSEL2 to the outside of the board, the rest to the inside).

You can then use “Gnome Disks” app to restore img.xz image onto the microSD card, plug it into the board and boot.

You can also use cmdline to extract the image and dd it.

xz -dk focal-preinstalled-server-riscv64+unleashed.img.xz dd if=focal-preinstalled-server-riscv64+unleashed.img of=/dev/disk/by-id/<TAB><TAB>complete-to-sdcard-device

Monitor the serial console, wait for cloud-init to complete, then login using ubuntu:ubuntu. See the cloud-init section below to further customise the first boot behaviour with cloud-init.

cloud-init integration

The image has a fallback cloud-init datasource that configures sudo user ubuntu with password ubuntu and DHCP networking. You will be asked to change the password on first login.

The image has CIDATA partition which can be used as a valid datasource to adjust cloud-config metadata. If you wish to customize user password, networking information, add ssh keys, etc. Please mount CIDATA partition rename meta-data and user-data files and adjust them to taste. You can use network-info to configure networking if something more sophisticated than just DHCP is desired.

For example ssh keys, disabling interactive login, and so on. See https://cloudinit.readthedocs.io/en/latest

1 Like

Hello,
I’m trying to boot the Ubuntu 21.04 Unmatched image from https://cdimage.ubuntu.com/releases/21.04/release/
I’m using Unmatched Version 2 board with assembly number HF-105-ASSY-2AO.
I’m connected to the board via serial console only.
I don’t see any output on the console past "U-Boot SPL 2021.01+dfsg-3ubuntu9 (Apr 21 2021 - 17:05:00 +0000)
"
The same board with the original OpenEmbedded image boots correctly.
Please advise.

That’s the same Assembly number I have and that image seems to be booting fine for me. I also have the same version of u-boot-sifive (2021.01+dfsg-3ubuntu9).

A few simple things to look at before we dive deeper: Are you booting from the SD card? Is there an NVME drive connected? Did you verify the sha256sum of the downloaded image before flashing it?

Hi Jawn,
Here is the info:
Booting from SD card.
No NVME.
sha256sum verified.

Thanks for the info! I double checked my own board and realized I was incorrect earlier, my revision ends in 3A0. I’m poking around now to see what the difference is between those two.

Thanks for the update, I’m trying to understand the differences also.

@jawn-smith There is a difference in memory size 3A is 16GB 2A is 8GB.

I just heard back from one of my coworkers that we don’t support the 2A0 unfortunately. It also seems that those 2A0 boards with 8GB of RAM were not supposed to go to end users. It may be possible to contact SiFive to get a Rev 3 board.

Yep, thank you.
The one I have is an early access one.
Waiting for my Rev 3 to arrive.
Will report once arrived and booting Ubuntu :slight_smile:

1 Like

Rev 3 board arrived and booting Ubuntu 21.04 as expected ! :sunglasses:

1 Like

I’m having trouble booting the Unmatched image on QEMU. I’ve tried increasing the memory to the full 16 GiB the original board provides, but I get the same error. Both Unmatched and Unleashed images give the same error.

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

Platform Name       : riscv-virtio,qemu
Platform Features   : timer,mfdeleg
Platform HART Count : 4
Boot HART ID        : 0
Boot HART ISA       : rv64imafdcsu
BOOT HART Features  : pmp,scounteren,mcounteren
BOOT HART PMP Count : 16
Firmware Base       : 0x80000000
Firmware Size       : 116 KB
Runtime SBI Version : 0.2

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


U-Boot 2020.10+dfsg-1ubuntu0~20.04.2 (Jan 08 2021 - 13:03:11 +0000)

CPU:   rv64imafdcsu
Model: riscv-virtio,qemu
DRAM:  8 GiB
In:    uart@10000000
Out:   uart@10000000
Err:   uart@10000000
Net:   eth0: virtio-net#0
Hit any key to stop autoboot:  0 

Device 0: 1af4 VirtIO Block Device
            Type: Hard Disk
            Capacity: 8704.0 MB = 8.5 GB (17825792 x 512)
... is now current device
Scanning virtio 0:1...
Found /boot/extlinux/extlinux.conf
Retrieving file: /boot/extlinux/extlinux.conf
743 bytes read in 2 ms (362.3 KiB/s)
U-Boot menu
1:	Ubuntu 21.04 5.11.0-1007-generic
2:	Ubuntu 21.04 5.11.0-1007-generic (rescue target)
Enter choice: 1
1:	Ubuntu 21.04 5.11.0-1007-generic
Retrieving file: /boot/initrd.img-5.11.0-1007-generic
182268553 bytes read in 64 ms (2.7 GiB/s)
Retrieving file: /boot/vmlinuz-5.11.0-1007-generic
27355136 bytes read in 9 ms (2.8 GiB/s)
append: root=LABEL=cloudimg-rootfs ro earlycon
Unhandled exception: Load access fault
EPC: 00000000fffb6b26 RA: 00000000fff74b14 TVAL: 0000000000000000
EPC: 0000000080249b26 RA: 0000000080207b14 reloc adjusted

### ERROR ### Please RESET the board ###

Could you please post the full command you’re running? It looks like potentially an issue with the fdt, could you also please double check that the sha256 hash is correct on the image you’re trying to boot?

Hashes checked out. Here’s the command I ran:

qemu-system-riscv64 \
-machine virt -nographic -m 8G -smp 4 \
-bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf \
-kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf \
-device virtio-net-device,netdev=eth0 -netdev user,id=eth0 \
-drive file=ubuntu-21.04-preinstalled-server-riscv64+unmatched.img,format=raw,if=virtio

Ah I see the problem! You’re on 20.04, correct? You need the hirsute version of u-boot-qemu in order to boot a hirsute image. We’re working on that functionality in the focal u-boot package, but it’s not there yet. You’ll either need to install the hirsute version of u-boot-qemu or just upgrade your system to hirsute in order for this to work.

Yep, I’m on 20.04. So I’ll just grab the older image for now. Thanks for the help!

1 Like

There actually is no focal image for the unmatched yet. We’re working on that for the August 20.04.3 release. It should be pretty simple to install u-boot-qemu from hirsute though. This guide about apt-pinning covers how to install certain packages from future releases of Ubuntu: https://help.ubuntu.com/community/PinningHowto

I installed this release on my Unmatched and while it works nicely while alive, it crashes when attempting to shutdown via shutdown, shutdown -r, reboot, etc.

It prints the following over serial (https://hastebin.com/raw/naqoxuzuke).

journalctl doesn’t seem to show much of interest - I can see https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1922485 happening, and warnings about missing permissions during shutdown like:

Jun 24 01:52:41 acidburn systemd[1]: Failed to create compat systemd cgroup /system.slice/systemd-networkd-wait-online.service: Read-only file system
Jun 24 01:52:41 acidburn systemd[1]: Failed to attach 1086 to compat systemd cgroup /system.slice/systemd-networkd-wait-online.service: No such file or directory
Jun 24 01:52:41 acidburn systemd[1086]: Failed to attach 1086 to compat systemd cgroup /system.slice/systemd-networkd-wait-online.service: No such file or directory

and I see one real error in journalctl:

Jun 24 01:35:50 acidburn systemd[1]: Failed to trim compat systemd cgroup /dev-hugepages.mount: Read-only file system
Jun 24 01:35:50 acidburn systemd[1]: proc-sys-fs-binfmt_misc.automount: Got hangup/error on autofs pipe from kernel. Likely our automount point has been unmounted by someone or something else?
Jun 24 01:35:50 acidburn systemd[1]: proc-sys-fs-binfmt_misc.automount: Failed with result 'unmounted'.

What other debugging info can I gather to figure out what’s going on? Any ideas from just this stuff?

Thanks,
- nasamuffin

1 Like

Unfortunately there are some known issues with with openSBI/RISC-V Shutting down. You can keep an eye on https://github.com/riscv/meta-riscv/issues/245 and https://forums.sifive.com/t/reboot-command/4721/5

1 Like