How to Run Linux on RISC-V with QEMU Emulator

RISC-V open source architecture is starting to become more and more interesting thanks the growing RISC-V hardware & software ecosystem, and with the recent release of HiFive Unleashed, we even have a board capable of running Linux. The only problem: it costs $999.

But luckily, it’s possible to experiment with Linux on RISC-V without extra hardware, just using your current PC. Imperas offers a commercial solution working on both Windows and Linux that relies on busybear-linux RISC-V Linux root filesystem comprised of busybox and dropbear SSH server. The rootfs also works with QEMU, so I tried it in Ubuntu 16.04.

The instructions on Github are quite easy to follow. My computer is powered by an AMD FX8350 processor coupled with 16GB RAM, and the whole process took around 2 hours, so better use the fastest computer possible. It also requires around 26 GB of storage on your build machine.

First, let’s create a working directory, and retrieve the RISC-V toolchain:


Now we can now build the RISC-V newlib & Linux toolchains) after installing some dependencies:


We’ll also need to build qemu for RISC-V


The next three steps will build the rootfs, Linux 4.14 kernel, and the bootloader, but there are optional since you could just as well as download the binary releases.

  • Build busybear-linux

  • Build RISC-V Linux

  • Build BBL (Berkeley Boot Loader):


If we’re going to use the release files instead:


You’d normally want to setup Linux bridged networking, and I tried, but failed and ran out of time. I added the following lines to /etc/network/interfaces in my computer:


and create two scripts in the current directory

  • ifup

  • ifdown


But I did not get it to work in a reasonable time. Studying QEMU Networking page on Arch Linux in details should help. [Update: See comments’ section for SSH access using the Fedora RISC-V image instead]

Nevertheless I could still run Linux on RISC-V with QEMU using the following command:


The boot takes just over one second to our minimal rootfs. Here’s the boot log:


We can login with root using password “busybear” without quote.


Type halt to turn off Linux and QEMU:

Support CNX Software - Donate via PayPal or cryptocurrencies, become a Patron on Patreon, or buy review samples
Subscribe
Notify of
guest
11 Comments
oldest
newest most voted
Advertisements