Tested on Ubuntu 24.04.1 (WSL2)
Kernel 6.6.87.2-microsoft-standard-WSL2
- RISC-V Toolchain (32 or 64 bits, in this example I will use the 32 version)
- This is the repository I used to install the toolchain, precisely tag 2026.01.01.
- Basically clone the repo, checkout the tag and install the Prerequisites for Ubuntu.
- Then configure the installation for baremetal Risc-V, 32 bits RV32I
sudo mkdir /opt/riscv sudo chown -R <your_ubuntu_username> /opt/riscv/ sudo chgrp -R <your_ubuntu_username> /opt/riscv/ ./configure --prefix=/opt/riscv --with-arch=rv32i --with-abi=ilp32 make
- The installation might take up around 1 hour. Verify it went successful by:
cd /opt/riscv/bin ./riscv32-unknown-elf-gcc --version - Add the riscv toolchain to PATH by adding this to the .bashrc:
export PATH=$PATH:/opt/riscv/bin
riscv32-unknown-elf-as exampleAsm.S -o exampleAsm.o
riscv32-unknown-elf-ld -o exampleAsm.elf -T asm.ld -m elf32lriscv -nostdlib --no-relaxriscv32-unknown-elf-gcc -c example.c -o example.o
riscv32-unknown-elf-gcc example.o -o example.elf -nostdlib -lgcc -T loader.ldTrying to use multiplication or other advanced math operations with the rv32I arch? No problem, by linking with
the flag -lgcc the compiler will use software multiplication by using libgcc.
riscv32-unknown-elf-objcopy -O binary exampleProg.elf exampleProg.bin
hexdump -e '"%08x\n"' exampleProg.bin > exampleProg.hex- A guide to install the elf2hex tool
riscv32-unknown-elf-elf2hex --bit-width 32 --input exampleProg.elf --output exampleProg.hex