Linux on RISC-V

Posted on June 8, 2019

What’s RISC-V ?

RISC-V is a new type of CPU architecture.

If you’ve used a desktop or laptop computer, it’s almost certainly using Intel’s x86 architecture. If you’ve used a cell phone, it’s almost certainly using Advanced Research Machines’ ARM architecture.

In a nutshell, a CPU architecture is one way to answer “How do I describe work to be done?” as well as “How do I build a machine to cheaply and efficiently do the described work?”.

Both x86 and ARM are copyrighted, and have various restrictions on use. While Intel designs and builds their own CPUs, ARM designs but does not build.

ARM designs many different options that are easy to plug together so a licensee can choose any combination of trade-off between performance and cost.

How do I try it?

RISC-V takes the surprising approach of “We describe how the CPU should work, and you as a user can download one and try it out”.

Part of the surprise is that “reprogrammable chips” are now common, so you really can do this!

I purchased a BeagleWire because it has both a standalone Linux system and a daughterboard that includes an FPGA, the “reprogrammable chip”.

The FPGA on the BeagleWire is very small and can’t do much, but that also means it’s $8 USD instead of $20,000 USD that the high-end FPGAs cost.

While the smallest RISC-V can fit on the BeagleWire, I chose to buy one of the first batch of real RISC-V boards that could boot Linux, the HiFive Unleashed.

WHY are you doing this?

I want to get my favorite programming language, Haskell, to work on the RISC-V architecture!

How are you doing this?

My familiar development environment is a Linux system, preferably the Debian distribution so I can easily install packages I need.

When the board arrived, I booted it up and discovered it does have Linux, but only busybox and a very small set of tools.

The hardware is nice, it has 8 gigabytes of RAM and four RISC-V 64-bit cores. The board boots from an SD card, but the documentation says that SD card read/write speed is slow. If you’re willing to spend another $2,000 USD, you can get the expansion board that lets you connect a real disk drive, a screen, and even more RAM! I decided the thousand dollar base board would have to work for me, and I’d skip the extra two thousand dollars.

So you want to install a Real Linux?

Yes! I was hoping this would be as easy as 1990s Linux installs where I would download an image to write to an SD card, and the system would then boot into ‘real’ Linux!

But no, it’s not yet that easy.

I was a Unix sysadmin for a few years, and I’ve been a software developer for many more years, but this level of working with hardware is out of my comfort zone.

After much reading on the internet, I think I clone and build the freedom-u-sdk, and then install a Debian userland around that kernel?

That’s what I understand from reading the Debian RISC-V pages.

It’s not an emergency if you prepared for it

The first time I do something, it’s usually terrible. Thus I shall prepare for failure by making a backup copy of the SD card that came with the HiFive Unleashed.

I’ve used the utility dd to copy an image onto an sd card, perhaps it’s just as easy to copy an sd card to an image? Stackoverflow says yes?

Now I settle down to wait for dd if=/dev/sda of=/root/hifive.img to finish.

Frustration sets in

I spent several days fighting to mount the second partition on the SD card, always getting the most generic error possible.

wrong fs type, bad option, bad superblock on /dev/loop23p2, missing codepage or helper program, or other error

Nothing shows up in dmesg or other system logs, I just don’t know.

On the good side, I ran across the creator of Debian filesystem images on IRC, and they confirmed that I don’t have to do it this way! They used scp to dump the files onto the filesystem, and it will likely work for me. But at this point, I’ve had too much frustration and it’s time to do something else.

Next time I pick this up, I should be able to start from Debian RISC-V and jump in!