# 🛠️ Risc-V linux Build Setup
This project supports building to Risc-V for running in Linux on a tiny Risc-V device.
This is tested on the $5 Milk-V Duo product: https://milkv.io/
The build requires the Milk-V Duo toolchain.
Follow this description to download and install the toolchain.
You need to manually download the toolchain host-tools and extract it to the SDK root directory:
cd ~
wget https://sophon-file.sophon.cn/sophon-prod-s3/drive/23/03/07/16/host-tools.tar.gz
tar xvf host-tools.tar.gz
cd host tools
export PATH=$PATH:$(pwd)/gcc/riscv64-linux-musl-x86_64/bin
export PATH=$PATH:/home/<your-home>/milkv/host-tools/gcc/riscv64-linux-musl-x86_64/bin
To build for RISC-V:
make riscv
This will use the toolchain file riscv64-toolchain.cmake which is configured to use:
-march=rv64gc -mabi=lp64d -g -O0By default, the build uses these compiler flags:
-march=rv64gc: RISC-V 64-bit with general extensions and compressed instructions-mabi=lp64d: Long and pointer 64-bit, double-precision floating point ABI-g: Include debug symbols-O0: No optimization (makes debugging easier)Other compiler toolchains that has been tested to compile but is not the correct for the Milk-V Duo board (but maybe a better choice for other devices)
The RISC-V build includes DAP (Debug Adapter Protocol) support, enabling debugging with compatible tools. The build automatically:
For a custom build with different compiler flags or configuration:
# Example: Build with optimization level 2
mkdir -p build_riscv_opt
cd build_riscv_opt
PATH="$PATH:/home/ronny/milkv/host-tools/gcc/riscv64-linux-musl-x86_64/bin" \
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_RISCV=ON \
-DCMAKE_TOOLCHAIN_FILE=../riscv64-toolchain.cmake \
-DCMAKE_C_FLAGS="-march=rv64gc -mabi=lp64d -O2" ..
make -j$(nproc)
Getting started: https://milkv.io/docs/duo/getting-started
Documentation: https://milkv.io/docs
GitHub: https://github.com/milkv-duo
Example environment setup: https://github.com/milkv-duo/duo-examples/blob/main/envsetup.sh
Connect to the device:
ssh root@192.168.42.1
mkdir -p nd
Copy the executable and disk images:
scp build_riscv/bin/nd100x images/SMD0.IMG FLOPPY.IMG root@192.168.42.1:/root/nd
Or just update the executable:
scp build_riscv/bin/nd100x root@192.168.42.1:/root/nd
The Milk-V Duo with 64MB RAM seems to not like that I compiled nd100x using 16MB of RAM. It was killed of withing a few seconds.
The solution was to recompile the emulator to use only 8MB of RAM.
Check DMSG
| dmesg | tail -n 50 |
Look for lines like
Actual log: