A few months ago, we wrote that Western Digital was working on Linux & BusyBox RISC-V NOMMU, and managed to boot a minimal Linux OS on Kendryte K210 powered Sipeed Maix Go board.
RISC-V NOMMU support was scheduled for Linux 5.5, and now that the new kernel has been released, Damien Le Moal has pushed the code allowing to build Linux and a busybox based roofs for RISC-V 64-bit NOMMU platforms using buildroot.
I could start the build following the instructions on Github, but it failed as a Linux 5.6 RC1 tarball was missing. But I noticed “Vowstart” picked up on Damien’s work, and wrote detailed instructions. So let’s try the build out using a machine running Ubuntu 18.04.
We’ll have to make sure dependencies are installed first:
sudo apt install build-essential device-tree-compiler bison \
flex file git curl wget cpio python unzip rsync bc texinfo
Then we can retrieve the source code and do some preparations (e.g. extract Linux 5.6 RC1 tarball):
git clone https://github.com/vowstar/k210-linux-nommu.git
The next step is to build the toolchain. It will take a long while because there’s a lot of code to build and download from the Internet:
This ended successfully with:
mkdir -p /home/jaufranc/edev/Kendryte/k210-linux-nommu/riscv64-nommu-buildroot/output/target/etc
echo "NAME=Buildroot"; \
echo "VERSION=2020.02-git-g6cb52b1e6"; \
echo "ID=buildroot"; \
echo "VERSION_ID=2020.02-git"; \
echo "PRETTY_NAME=\"Buildroot 2020.02-git\"" \
) > /home/jaufranc/edev/Kendryte/k210-linux-nommu/riscv64-nommu-buildroot/output/target/usr/lib/os-release
ln -sf ../usr/lib/os-release /home/jaufranc/edev/Kendryte/k210-linux-nommu/riscv64-nommu-buildroot/output/target/etc
>>> Sanitizing RPATH in target tree
PER_PACKAGE_DIR=/home/jaufranc/edev/Kendryte/k210-linux-nommu/riscv64-nommu-buildroot/output/per-package /home/jaufranc/edev/Kendryte/k210-linux-nommu/riscv64-nommu-buildroot/support/scripts/fix-rpath target
We can now install the RISCV64 toolchain which will use for cross-compilation:
sudo cp -r output/host /opt/riscv64-uclibc
Next up is buildroot build for Kendryte K210 NOMMU processor:
make SKIP_STRIP=y install
The last step copies the file into
They also decided to build the Tiny C Compiler in order to be able to build code on the board itself. It’s not really necessary, as on such low-end hardware most people would likely prefer to cross-compile their code instead, but let’s go ahead anyway:
./configure --prefix=/usr --cross-prefix=riscv64-linux- --cpu=riscv64 --extra-cflags="-DCONFIG_TCC_STATIC=1" --extra-ldflags=-Wl,-elf2flt=-r
make DESTDIR=../rootfs_k210 install
They also made a script to setup and copy k210 rootfs CPIO image into
<span class="pl-c1">cd</span> <span class="pl-smi">$PROJ_ROOT</span>
We can now finally build the Linux 5.6-RC1 kernel:
make ARCH=riscv CROSS_COMPILE=riscv64-linux- nommu_k210_defconfig
make ARCH=riscv CROSS_COMPILE=riscv64-linux- -j
I don’t have a Sipeed MAIX board on hand, so I have not tried that part, but you can flash the resulting image as follows assuming your board is connected over /dev/ttyUSB:
sudo usermod -a -G uucp $(whoami)
sudo usermod -a -G dialout $(whoami)
sudo python3 -m pip install kflash
kflash -B dan -b 3000000 -p /dev/ttyUSB0 arch/riscv/boot/loader.bin
python3 -m serial.tools.miniterm --raw --filter colorize /dev/ttyUSB0 115200
The first two lines are to add the current user to dialout group to get access to /dev/ttyUSB0 without having to be root. The third one installs kflash utility, followed by the command that does dump the image to the internal flash, and the last one is to get terminal access to the board.
That means you can now run Linux on low-cost RISC-V hardware such as the Sipeed MAIX Bit sold for around $14 and up. Note that’s technically uCLinux, you’d have to work with just 8MB RAM and handle stack overflow issues commonly experienced in processors without a memory management unit.
Jean-Luc started CNX Software in 2010 as a part-time endeavor, before quitting his job as a software engineering manager, and starting to write daily news, and reviews full time later in 2011.
|Support CNX Software - Donate via PayPal, become a Patron on Patreon, or buy review samples|