Absurd: RISC-V Toolchain for M1 Macintosh

20220625

In the Spring of 2017, I built a very impressive workstation that saw active use until 2022. This machine was a Ryzen ThreadRipper 1950X (16 cores, 32 threads), 32GB of DDR4 RAM, a Vega 64 GPU, 500GB NVMe SSD (later another 1TB was added), 802.11 AC Wi PCIe card was in there, and I’d added serial and parallel via PCIe cards as well. This is just old enough that I also had a multi-card reader, SATA BluRay burner, and the like. Four 8TB HDDs were in a RAID 10 in this machine for bulk data. To power all of this ridiculous hardware, the computer had a 1kw modular PSU made by GSkill. This was all in a Nanoxia deep silence 6 tower. This machine was enabled by Slackware 14.2 with a newer kernel build I did, then later by Slackware current when I needed more current software (beyond just the kernel). This machine was parted out and those parts sold (except for the HDDs) earlier this year. It was replaced by an entry level M1 Mac Mini (8/8/16 cores, 8GB RAM, 256GB SSD, WiFi 6), this new machine is consumes only 150W at max draw, cost a fraction of the TR machine, and was purchased with proceeds from the sale of the TR machine (with a decent amount of cash left over).

The Ryzen Threadripper machine was used for primarily to run virtual machines, to do software compiles, and to play the occasional video game. At the time, I was a system admin/engineer at a web hosting company, and having the ability to model a server setup or compile a bunch of software in very short time spans was quite useful. It also served my needs to tinker.

The Mac Mini is used for a bunch of office applications, an occasional software compile, an occasional single virtual machine, and naturally for an occasional video game. The bulk storage I used to have is now handled via that previously mentioned 1TB NVMe SSD in a thunderbolt sled, and those 8TB HDDs are now living in a Synology NAS. Access to serial, parallel, SATA, IDE, optical media, SD and CF cards, and other ports/media is handled via adapters and dongles plugged into a CalDigit.

Why do I bring all of this up?

This Mini surprised me. It impressed me. It made me love it. In my most recent prior article, I talked about a RISC-V machine. That machine needs some new software. I no longer have a Linux machine with beefy hardware, and I don’t have a more powerful RISC-V machine to host those compiles either. My Mac Mini must be made to suffce. It handles the job admirably. The performance is spectacular. I thought I was going to hate compiling on this thing, but instead, it offers that same breathtakingly quick turn around I experienced on ThreadRipper. Now, this is just M1, and not M1 Pro or M1 Max. The ThreadRipper obviously has advantages in several areas, but the M1 is very close. Additionally, the M1 remains completely usable during compiles while any Linux machine I have ever used will nearly freeze during any demanding task unless the user/admin specifically nices various processes.

When the M1 rst came out, I tested one from my employer. It was the entry level M1 MacBook Pro. I wasn’t impressed. To be honest, USB-C I/O performance was terrible. The dongle life was terrible. Accessing storage over a network was terrible. The thing’s performance with on-system, native applications was phenomenal, but in every other way the thing was just bad. This early experiment also showed me that HomeBrew was bad, and that MacPorts was better.

The Mac Mini benefits from coming into my hands much later, and as it is mine, I am a bit more willing to play around. The ecosystem is much more mature now as well.

I had been using MacPorts (as my earlier experience taught me), and the MacPorts repos lack cross compilers and such. I then tried building all of the software myself. Initially that was successful. Building the cross compiler was super speedy, and it seemed to work quite well. It ceased to work well when I attempted to build the Linux kernel. There were myriad issues, and I quickly decided that I would need to nd another route as maintaining the cross compiler environment as well as a full Linux system (on my own) was going to be more work than I really want.

UTM is awesome. If you have an M1 and you have not installed UTM, stop reading this and go install UTM (and then immediately come back and keep consuming my content). A quick download of Ubuntu Server ARM64, and the spin up of a virtual machine, and I was able to then install pre-built Linux arm64-to-RISCV toolchains with zero problems. This environment is still installed and I can use it, but there is a performance penalty involved despite not emulating the CPU. So, while UTM is freaking awesome, I still wanted something truly native.

First, you need to get the Xcode tools.

xcode-select -install

Next you need to install HomeBrew.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Then you need to enable the RISC-V toolchain repository.

brew tap riscv-software-src/riscv

Then you just need to install the toolchain.

brew install riscv-tools
brew install --build-from-source --with-NOmultilib riscv-gnu-toolchain

Assuming that all went well, you should now be able to do things like... compile a Linux kernel for the Clockwork Pi DevTerm R-01.

ARCH=riscv CROSS_COMPILE=riscv64-unknown-elf- make menuconfig

RISC-V, Linux make menuconfig

⇠ back

© MMXXV, Abort Retry Fail LLC
Licentiam Absurdum