Let’s a lot of excitement around RISC-V open architecture, but a lot of work still needs to be done to bring the ecosystem to level with Arm or x86 architecture from the silicon to the software. Progress is made step-by-step and one of these steps is Canonical released Ubuntu 64-bit RISC-V (RISCV64) images for some of SiFive HiFive boards, as well as QEMU open-source emulator.
Specifically, Canonical released an Ubuntu 20.04.2 LTS image for HiFive Unleashed & QEMU, and an Ubuntu 21.04 image for HiFive Unleashed, HiFive Unmatched, and QEMU. Note those are only server images, and there’s no desktop image yet like for Ubuntu 21.04 on Raspberry Pi 2/3/4.
It’s been possible to run RISC-V Linux in QEMU for at least three years, but when I tried it was a minimal system based on Busybox, so let’s try again with Ubuntu 21.04 following the instructions provided on Discourse.
I have an AMD Ryzen laptop running Ubuntu 20.04, and I opened a terminal window to first install the dependencies.
1 |
sudo apt install qemu-system-misc opensbi u-boot-qemu qemu-utils |
then downloaded and extracted Ubuntu 21.04 image for HiFive Unmatched:
1 2 |
wget https://cdimage.ubuntu.com/releases/21.04/release/ubuntu-21.04-preinstalled-server-riscv64+unmatched.img.xz xz -dk ubuntu-21.04-preinstalled-server-riscv64+unmatched.img.xz |
We can now Ubuntu 21.04 RISCV64 in your machine:
1 |
qemu-system-riscv64 -machine virt -nographic -m 2048 -smp 1 -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 |
But it abruptly stops:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
OpenSBI v0.8 ____ _____ ____ _____ / __ \ / ____| _ \_ _| | | | |_ __ ___ _ __ | (___ | |_) || | | | | | '_ \ / _ \ '_ \ \___ \| _ < | | | |__| | |_) | __/ | | |____) | |_) || |_ \____/| .__/ \___|_| |_|_____/|____/_____| | | |_| Platform Name : riscv-virtio,qemu Platform Features : timer,mfdeleg Platform HART Count : 1 Boot HART ID : 0 Boot HART ISA : rv64imafdcsu BOOT HART Features : pmp,scounteren,mcounteren BOOT HART PMP Count : 16 Firmware Base : 0x80000000 Firmware Size : 92 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: 2 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: 3584.0 MB = 3.5 GB (7340032 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 5 ms (144.5 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 269 ms (646.2 MiB/s) Retrieving file: /boot/vmlinuz-5.11.0-1007-generic 27355136 bytes read in 50 ms (521.8 MiB/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 ### |
That’s because the Ubuntu 21.04 Hirsute cannot boot with the version of u-boot-qemu provided in Ubuntu 20.04 at this time, only the version in Ubuntu 21.04 is supported. So let’s try the Ubuntu 20.04 RISC-V image instead:
1 2 3 |
wget https://cdimage.ubuntu.com/releases/20.04.2/release/ubuntu-20.04.2-preinstalled-server-riscv64.img.xz xz -dk ubuntu-20.04.2-preinstalled-server-riscv64.img.xz qemu-system-riscv64 -machine virt -nographic -m 2048 -smp 2 -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-20.04.2-preinstalled-server-riscv64.img,format=raw,if=virtio |
Good! After a few minutes, we can access the command line using “ubuntu” username and password:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
OpenSBI v0.8 ____ _____ ____ _____ / __ \ / ____| _ \_ _| | | | |_ __ ___ _ __ | (___ | |_) || | | | | | '_ \ / _ \ '_ \ \___ \| _ < | | | |__| | |_) | __/ | | |____) | |_) || |_ \____/| .__/ \___|_| |_|_____/|____/_____| | | |_| Platform Name : riscv-virtio,qemu Platform Features : timer,mfdeleg Platform HART Count : 2 Boot HART ID : 1 Boot HART ISA : rv64imafdcsu BOOT HART Features : pmp,scounteren,mcounteren BOOT HART PMP Count : 16 Firmware Base : 0x80000000 Firmware Size : 100 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: 2 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: 3584.0 MB = 3.5 GB (7340032 x 512) ... is now current device Scanning virtio 0:1... Found /boot/extlinux/extlinux.conf Retrieving file: /boot/extlinux/extlinux.conf 631 bytes read in 2 ms (307.6 KiB/s) U-Boot menu 1: Ubuntu 20.04.2 LTS 5.8.0-14-generic 2: Ubuntu 20.04.2 LTS 5.8.0-14-generic (rescue target) Enter choice: 1 1: Ubuntu 20.04.2 LTS 5.8.0-14-generic Retrieving file: /boot/initrd.img-5.8.0-14-generic 160037936 bytes read in 250 ms (610.5 MiB/s) Retrieving file: /boot/vmlinuz-5.8.0-14-generic 20094612 bytes read in 47 ms (407.7 MiB/s) append: root=LABEL=cloudimg-rootfs ro earlycon Moving Image from 0x84000000 to 0x80200000, end=81622f80 ## Flattened Device Tree blob at ff74bea0 Booting using the fdt blob at 0xff74bea0 Using Device Tree in place at 00000000ff74bea0, end 00000000ff74fe1d Starting kernel ... ... -----END SSH HOST KEY KEYS----- [ 263.760272] cloud-init[665]: Cloud-init v. 20.4.1-0ubuntu1~20.04.1 running 'modules:final' at Mon, 28 Jun 2021 04:36:41 +0000. Up 257.45 seconds. [ 263.773658] cloud-init[665]: ci-info: no authorized SSH keys fingerprints found for user ubuntu. [ 263.782580] cloud-init[665]: Cloud-init v. 20.4.1-0ubuntu1~20.04.1 finished at Mon, 28 Jun 2021 04:36:47 +0000. Datasource DataSourceNoCloud [seed=/var/lib/cloud/seed/nocloud-net][dsmode=net]. Up 263.41 seconds Ubuntu 20.04.2 LTS ubuntu ttyS0 ubuntu login: ubuntu Password: You are required to change your password immediately (administrator enforced) Changing password for ubuntu. Current password: New password: Retype new password: Bad: new password is too simple New password: Retype new password: Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.8.0-14-generic riscv64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Mon Jun 28 04:37:40 UTC 2021 System load: 1.08 Usage of /: 76.8% of 3.22GB Memory usage: 8% Swap usage: 0% Processes: 90 Users logged in: 0 IPv4 address for eth0: 10.0.2.15 IPv6 address for eth0: fec0::5054:ff:fe12:3456 0 updates can be installed immediately. 0 of these updates are security updates. The list of available updates is more than a week old. To check for new updates run: sudo apt update The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. To run a command as administrator (user "root"), use "sudo <command>". See "man sudo_root" for details. ubuntu@ubuntu:~$ |
We are indeed in a dual-core 64-bit RISC-V system as I used “smp 2” option in the command line:
1 2 3 4 5 6 7 8 9 10 |
ubuntu@ubuntu:~$ cat /proc/cpuinfo processor : 0 hart : 1 isa : rv64imafdcsu mmu : sv48 processor : 1 hart : 0 isa : rv64imafdcsu mmu : sv48 |
We have Ethernet up and running properly:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
ip address 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 52:54:00:12:34:56 brd ff:ff:ff:ff:ff:ff inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic eth0 valid_lft 79022sec preferred_lft 79022sec inet6 fec0::5054:ff:fe12:3456/64 scope site dynamic mngtmpaddr noprefixroute valid_lft 86299sec preferred_lft 14299sec inet6 fe80::5054:ff:fe12:3456/64 scope link valid_lft forever preferred_lft forever |
So I could SSH to my host computer, but I could not SSH to the QEMU session. So I shut down the Ubuntu RISC-V instance, added a tcp redirect to enable SSH on port 2222, and restarted QEMU.
1 |
qemu-system-riscv64 -machine virt -nographic -m 2048 -smp 1 -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,hostfwd=tcp::2222-:22 -drive file=ubuntu-20.04.2-preinstalled-server-riscv64.img,format=raw,if=virtio |
I could login to QEMU over SSH as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
jaufranc@cnx-laptop-4:~/edev/sandbox/ubuntu-risc-v$ ssh -p 2222 ubuntu@localhost The authenticity of host '[localhost]:2222 ([127.0.0.1]:2222)' can't be established. ECDSA key fingerprint is SHA256:XvWsfVDD4C4qaH0g1VU1mY47+tcGx6E0GRVjX5mORvM. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '[localhost]:2222' (ECDSA) to the list of known hosts. ubuntu@localhost's password: Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.8.0-14-generic riscv64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Mon Jun 28 07:08:20 UTC 2021 System load: 0.18 Usage of /: 78.3% of 3.22GB Memory usage: 8% Swap usage: 0% Processes: 81 Users logged in: 1 IPv4 address for eth0: 10.0.2.15 IPv6 address for eth0: fec0::5054:ff:fe12:3456 0 updates can be installed immediately. 0 of these updates are security updates. The list of available updates is more than a week old. To check for new updates run: sudo apt update Last login: Mon Jun 28 07:05:11 2021 ubuntu@ubuntu:~$ |
So it’s possible to easily transfer files between QEMU and the host in either direction.
Jean-Luc started CNX Software in 2010 as a part-time endeavor, before quitting his job as a software engineering manager, and starting to write daily news, and reviews full time later in 2011.
Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress
HiFive Unleashed $999
HiFive Unmatched $679
… my hope is on affordable RISC-V mobo’s … around 150 USD … as for that money you can get a quite nice Celeron board ^H^^H^H^H barebone system.
Sadly still way too experimental to get good discounts on large orders. Allwinner D1 might reach that, but it’s still quite expensive for price/perf, and will take a while to mature.
There is the Beagleboard too par around 100€, but this is developer/integrators oriented, no GPU for now. The next version should have a GPU. Everything progress very fast in RISC-V world, on embedded world most (if not all) OS are ported several major linux distribution are ported, I’m pretty sure we will see basic and affordable complete RISC-V boards at the end of this year or beginning of next year. Don’t expect the same perfs with the same price, it will still be for people that want to help this architecture to progress faster. More I know it, more I… Read more »
Let’s wait a few years. 2023 maybe 🙂
If the Intel/SiFive collaboration comes to fruition, we might see motherboards that support either a Celeron or a Risc-V using a common socket.
Mad idea :
Retro Console system emulation and gaming has come along way on Arm SBC and Arm TV boxes. Can you emulate a powerful RISC-V system on a Arm SBC, Arm TV box?
It might be feasible as long the QEMU programs needed are available on Arm, and the host system has enough memory. Arm SBC’s and TV box are rather low-end. Ubuntu RISC-V takes about 5 minutes to boot in my AMD RYzen 7 2700U laptop with 16GB RAM. So provided it indeed can work on Arm SBC or TV box, I’d expect boot times to be much longer.
Also note that I had to type slower in QEMU, or some key presses will be missed…
ISO is generally slow to boot, try to install it on a raw format disk image, I used about the same settings with Debian Bullseye on a 2012 Core i7, with 8GB of ram, and giving 512M~1.5G to VM and 1 or 2 core and boot in less that 1 minute (on ArchLinux with qemu-6.0.0). The debian image is in qcow2 (10× slower) format but can be converted easily with qemu-img. I will try ubuntu, as packages are generally more recent, thanks for the information. i’ve only a very slow ARM board, with very old/slow SD card (I will try… Read more »
> Also note that I had to type slower in QEMU, or some key presses will be missed…
This is probably not related to emulation speed then, but to support for the virtualized hardware. E.g. some drivers might possibly not implement interrupts correctly and might miss some events, or rely on polling. The number of CPU cycles needed to echo keystrokes is ridiculously low. Just remember that an ESP8266 can easily emulate a PDP11 running BSD 🙂
Hi, this is incorrect. The default username and password ‘ubuntu’ does not work.
I went to check again on discourse and the username and password are ubuntu.
Got it working via SSH. Strangely, after the mandatory password change, logging in via the serial tty started functioning.
I try Ubuntu 21.04 image for HiFive Unmatched on Ubuntu 21.04 Intel Laptop with QEMU and it works.