Linux on Scratch Is Proven Possible, Thanks to This Clever RISC-V Emulator Project

Running a Scratch port of Charles Lohr's RISC-V emulator, this clever project achieves the seemingly impossible.

Gareth Halfacree
1 year agoHW101

Pseudonymous developer "bilman66" has achieved the seemingly impossible by getting a Linux operating system to boot in the Scratch visual coding environment — by writing a Scratch RISC-V emulator.

"A real build of the Linux 6.1.14 kernel running in pure Scratch code," bilman66 writes of their creation, brought to our attention by Adafruit. "The Linux build comes with the usual programs like cat/echo and is fully capable of running shell scripts, but it also comes with Duktape (a JavaScript engine), as well as ed for text editing, and CoreMark for benchmarking."

While Scratch is a fully Turing-complete programming language, it was never designed for projects of this complexity — being tailored to appeal to beginners as an accessible visual coding language for educational purposes. As bilman66 has proven, though, that doesn't mean it can't be used — and its performance is surprising, taking a relatively speedy 40 seconds to boot on consumer hardware when paired with the TurboWarp Scratch mod.

The trick lies in how the code interacts with the Linux kernel: using Charles Lohr's 400-line emulator as a basis, bilman66 wrote a Scratch-based emulator which acts like a Linux-compatible RISC-V processor. This gets the operating system running, after which any Linux software compiled for RISC-V should work — given storage and memory constraints, anyway.

"I will release the toolchain and standard library soon that will allow you to compile and run your own C programs on the emulator," bilman66 promises to those looking to dive deeper than the bundled applications. "For now just use the ROM that's already included."

The project is now available on the Scratch website, though use without TurboWarp isn't recommended for reasons of performance.

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