An Ultra-Tiny RISC-V Emulator Turns the Raspberry Pi Pico Into a Functional, If Slow, Linux PC

Building on Charles Lohr's 400-line RISC-V emulator, this project puts Linux on Raspberry Pi's low-cost RP2040 microcontroller.

Gareth Halfacree
12 months agoHW101 / Productivity

Electronics engineering student Vlad Tomoiagă is looking to get the diminutive Raspberry Pi Pico and its RP2040 microcontroller to run a functional Linux-based operating system — by having its Arm Cortex-M0+ cores emulate a 32-bit RISC-V chip.

"On power-up, the Linux image will be copied into RAM," Tomoiagă explains of his creation. "After a few seconds, Linux kernel messages will start streaming on the console. The boot process takes about one and a half minute[s]. A prebuilt Linux kernel and filesystem image […] must be placed in the root of the SD Card."

It's now possible to run a slimline Linux distribution on the Raspberry Pi Pico — by emulating a RISC-V chip. (📹: Vlad Tomoiagă)

Booting Linux — and compiling C code on-device — is an impressive feat for a Raspberry Pi Pico, given that its processor is a dual-core Arm Cortex-M0+ microcontroller and it has a mere 264kB of RAM. Tomoiagă has a couple of tricks for getting around those issues, though — including adding 16MB of pseudo-static RAM (PSRAM) on an SPI bus and having the microcontroller emulate a cut-down 32-bit RISC-V microprocessor core.

The project builds on the work of electrical engineer Charles Lohr, who last year released a "really tiny" RISC-V emulator which takes up just 400 lines in a single C header file. "The reason I wanted to do this was I wanted to see if I could run Linux on it," Lohr explained at the time. "Something that was close to but not as simple as an ESP32-C3. And, well, the answer was yes. In fact, I was able to write a really tiny RISC-V emulator."

"The Linux image includes a fork of the c4 compiler/interpreter. To run the included hello world example, type c4 hello.c in the shell after the system has booted," Tomoiagă tells anyone interested in giving the project a go. "The source file of c4 can be found in /usr/src/c4.c. I have included it in the system image because this compiler is self-hosting and can run itself, which makes for a nice demo. You can use the vi editor to create or edit source files."

The project's source code is available on GitHub under a mixture of permissive MIT, BSD, and Apache 2.0 licenses.

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