Migrate Alpine Linux to RISC-V

Original author: Drew DeVault
  • Transfer
After several painful months of waiting, I recently received my HiFive Unleashed , and this is incredibly cool. For those who are not up to date, HiFive Unleashed is the first consumer-oriented single - player RISC-V with Linux support. If it's not clear yet, RISC-V is an open , free instruction set architecture , and HiFive is an open processor that implements it. And here he is at my dinner table:


The board is really cool . Over the coming months, I will try to prepare everything necessary for the continuous integration service builds.sr.ht , through which the rest of the Alpine Linux transfer will be automated, as well as installing any other operating systems (including non-Linux) and user programs that you want port to RISC-V. I am quite sure that this will be the first such project on RISC-V equipment, open to the public.

There are two stages of porting the operating system to a new architecture: boot (bootstrapping) and ... actually, porting. For lack of a better term. For the initial load, we need a cross-compiler, we need to port libc and cross-compile the basic elements. Booting is completed when the system is capable of self-hosting , that is, it can compile itself. The “porting” process involves compiling all the packages available for your operating system. The process can take a long time and is generally automated.

First cross-compiler. RISC-V support appeared in binutils 2.28 and gcc 7.1 a few releases ago, you can not worry about it. It is enough to build both compilers with the parameter--target=riscv64-linux-musl. Another important part is the standard C or libc library. Unlike the C compiler, this step required some effort on my part, since Alpine Linux is based on musl libc, and its port for RISC-V is not yet complete and is not included in the mainline.

But there is a patch to support RISC-V, although it has never been tested on such a scale. Accordingly, I encountered several bugs for which I wrote several patches ( 1 , 2 , 3 ). Having a working distribution based on the RISC-V port is a convincing argument in favor of the maturity of the ported version, so I'm glad I caught these bugs. Until that time, I had to manually add the port and my patches to the Alpine Linux musl package.

The C compiler and the libc implementation open the doors for transferring a huge amount of software to your platform. The next step is to identify and transfer the necessary packages for the self-hosting system. Here in Alpine there is an excellent script that prepares the cross-compiler and builds the base system. Many (if not most) of these packages required corrections, customization, and manual intervention — this is not a complete solution, but an incredibly useful tool. The most important packages at this stage are native tools (that is, the compiler not only compiles, but also works itself under RISC-V), the password manager itself, and various other useful things, such as tar, patch, openssl, and so on.

Once the necessary packages have been assembled and the system can compile itself, the lengthy transfer process begins. Here it is usually wise to abandon the cross-compiler and proceed to the native build if the hardware is fast enough. This is a compromise, because the RISC-V system is somewhat slower than my x86_64 boot machine, but many packages require a lot of manual configuration and fixes for cross-compiling. The time saved saves the slower build (although I’m actually very impressed with HiFive Unleashed speed. The main bottleneck is the mmcblk driver, but as soon as the files get into the kernel cache, everything becomes very fast and pleasant).

There are thousands of packages, so the next step for me (and everyone who is working on the transfer) is automating the rest of the process. For me, an intermediate step is integration with the builds.sr.ht service to organize my own work and make the cycles available to other people interested in RISC-V. Not all packages will be ported automatically - but many will! As soon as you port programming languages ​​- C, Python, Perl, Ruby (I already did it!), Etc. - most open source programs are quite portable on different architectures. One of my main goals in sr.ht is to encourage the distribution of portable software!

If any reader has his own RISC-V hardware or he wants to try it with qemu, here is the Alpine Linux repository for RISC-V. Something like this would install it in / mnt:

apk add \
    -X https://mirror.sr.ht/alpine/main/ \
    --allow-untrusted \
    --arch=riscv64 \
    --root=/mnt \
    alpine-base alpine-sdk vim chrony

Run /bin/busybox --installand the apk fixfirst time you boot. The work is still ongoing, so setting up the rest is an exercise for the reader, until I clear the process and complete the normal installation script. Good luck!



In conclusion: thank you so much for helping the members of the #riscv community on Freenode, as well as the Debian and Fedora developers, who largely cleared the way and released patches for many programs! But I got all the joy of carrying musl, so the road was not completely clear :)

Also popular now: