Hackster's FPGAdventures: Linux on RISC-V with the Microchip PolarFire SoC Icicle Kit

For those finding the default minimalist Linux build a little spartan, have a go at building your own — or experiment with AMP.

Gareth Halfacree
4 days agoFPGAs

The recently production-qualified PolarFire SoC is a powerful yet efficient field-programmable gate array (FPGA) with a range of features, but that's only half its promise: it's also a fully-functional system-on-chip (SoC), capable of running Linux on four RISC-V cores — which is where our FPGAdventures take us next.

When we first unboxed the Icicle Kit, a single-board computer built around the PolarFire SoC and designed for development and testing, four months ago the Linux experience left a lot to be desired. The most recent operating system image available at the time cut the board's 2GB of RAM in half, leaving only 1GB for the user; the root partition took up only 1GB of the 8GB on-board eMMC and was almost completely full on first boot; and the bare-bones package list made it near-impossible to compile software on-device.

It may have only been four months, but Microchip has spent its time wisely: Linux on the Icicle Kit is now a considerably more pleasant experience.

The Yocto BSP

Microchip is constantly releasing updates for the PolarFire SoC family in general and the Icicle Kit specifically. At the time of writing, the most recent software release was less than a month old. For those who like a little more control, though, the company doesn't just release pre-compiled updates but everything you need to make your own — courtesy of the Yocto Project.

The PolarFire SoC board support package (BSP) for Yocto provides an easy way to build your own Linux distribution, which will boot on the Icicle Kit — either from the full-size SD Card slot, from the on-board 8GB eMMC storage, or via an external eMMC connected to the Raspberry Pi-style general-purpose input/output (GPIO) header near the board's twin Ethernet ports.

Microchip's video guides make a friendly alternative to GitHub-hosted documentation. (📹: Microchip)

Using the BSP, and a suitable Linux host machine, you can build a Linux distribution from source in a surprisingly few commands — the bulk of which are simply installing prerequisites. In October last year Microchip published a video walk-through of the process, which stands alongside a detailed — though slightly outdated, and focused on Ubuntu 18.04 — text tutorial on the BSP's GitHub repository.

In addition to either Ubuntu or, if you're willing to think through the changes you'll need to make to prerequisite installation, another Linux distribution, you're going to need quite a hefty machine: Ignoring the prerequisites, the initialized repository took up 433MB of storage space that ballooned to 115GB following compilation — despite the finished disk image being a mere 7.3GB, in order to squeeze onto the Icicle Kit's 8GB eMMC.

On top of that, you'll need either patience or a fairly recent multi-core CPU with the RAM to back it up: On our test system, an eight-core 16-thread AMD Ryzen with 32GB of RAM and a high-performance SSD, the Bitbake-managed build took around three hours to complete — leaving the host system just about usable for lightweight desktop multitasking.

Flashing the OS

Compilation leaves you with the aforementioned 7.3GB disk image and a handy cross-compilation environment, which dramatically cuts down on the time it takes to compile software for the PolarFire SoC's Icicle cores compared to doing so on-device.

To actually use the OS, you'll need to flash it to eMMC or SD Card — for which Microchip recommends bmaptool, pointing out that it's faster than dd or other methods by dint of skipping empty blocks. Either way, it takes a few minutes — writing to the on-board eMMC as a USB device, which requires you to interrupt the Icicle Kit boot process and issue a mode-change command via the first UART bus, isn't terrifically fast.

You're not done there, though. The Yocto BSP for the PolarFire SoC is tied to the gateware running on the FPGA — in particular the Hart Software Services (HSS). If you've downloaded a fresh copy of the BSP but haven't updated HSS in a while, the flash will go fine but you'll encounter an error on boot.

Updating the HSS is a little more involved. First, you may need to update either Libero SoC or the Program & Debug bundle, which includes FlashPro Express. In either case, updating is a misnomer: Microchip doesn't support in-place upgrades, for reasons of backwards compatibility, and will instead install a second copy of the software alongside the original - doubling the disk usage, until and unless you manually delete the old version.

Once updated, simply download the release archive from the reference design GitHub repository and feed the job file it contains into FlashPro Express. As the Icicle Kit has a built-in FlashPro 6 device, it only takes a single cable and a couple of minutes until you're running the latest HSS.

Tooling around

In our original look at running Linux on the Icicle Kit, our biggest complaint — bigger even than only having access to half the RAM — was the bare-bones software load-out. With key packages entirely absent, any attempts to work directly on-device were hampered.

Having built an OS using the latest BSP, that's no longer the case. Now, not only does the root filesystem take up the entire 8GB eMMC but it's filled with 4.5GB of files — more than four times the size of the originally-tested root partition. There's almost everything you could need on there: vim, git, gzip, bzip2, curl, wget, even pretty system monitor htop is pre-installed and ready to run.

As a result, it's easier than ever before to find software you want to test on RISC-V, download it to the eMMC, and compile it right there on-device. If you're impatient, though, the BSP also sets up a cross-compilation environment — allowing you to take advantage of your, presumably, much more powerful desktop or laptop to do the heavy lifting then simply transfer the binary across to the Icicle Kit via USB or Ethernet.

For the programmers, Microchip has also included a selection of sample applications, with source code, which demonstrate the flexibility of the PolarFire SoC's hybrid SoC-FPGA design: One uses direct memory access to an area of RAM shared between the FPGA and the SoC, while another allows for reading and writing memory-mapped LSRAM in the FPGA fabric from within user-space Linux.

Other samples offer a look at using the GPIO header, running an HTTP server that reads power statistics from the Icicle Kit's on-board voltage/current sensor, reading a stream of data from the true random number generator (TRNG), and using CAN via User Input/Output (UIO).

Asymmetrically interesting

The mpfs-dev-cli image used above isn't the only thing the BSP can build, however. For the minimalists, there's the core-image-minimal-dev image — a lot closer to the bare-bones version we first reviewed, and ideal for those with pre-compiled software looking to make the most of the 8GB eMMC. There's mpfs-initramfs-image, an even smaller image that packs its root filesystem into RAM. And there's the icicle-kit-es-amp image.

This latter image truly showcases the flexibility of the PolarFire SoC. Once built, flashed, and booted, it literally splits the device in two, running the real-time FreeRTOS on one half and a minimalist Linux on the other. The two are effectively running on different logical machines, with the build configuration assigning one or more of the PolarFire SoC's SiFive U54 application cores to one and the remainder to the other.

It's not just the processor cores that can be split: running in asymmetric multiprocessing (AMP) mode, the Icicle Kit's resources can be assigned to either of the software contexts. Physical regions of memory can be assigned to one OS or the other, along with any desired peripherals — and a sample application demonstrates inter-hart communication between the two.

For those digging deeper, the icicle-kit-es-amp includes a second demonstration mode in which Linux is run alongside a bare-metal configuration. There is, however, a limit to the flexibility. While the PolarFire SoC has four U54 cores, each with a hart managed by Hart Software Services running on the fifth E51 monitor core, you can only split the device in two — though you can choose to run Linux with either RTOS or bare-metal, RTOS with bare metal, RTOS with RTOS, or bare metal with bare metal. You can't, however, run Linux with Linux.

Join us next month as our FPGAdventures take us on a deeper dive into those code samples and how communication between the Linux side and the FPGA works in practice.

More information on the PolarFire SoC Icicle Kit is available on the Microchip websiteand can be found on Avnet's product page as well.

Read the whole series:

Gareth Halfacree
Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire: freelance@halfacree.co.uk.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles