- RISC-V Toolchain (32 or 64 bits, in this example I will use the 32 version)
- Here's a guide how to easily build the 32-bits version with the ISA of your choice
riscv32-unknown-elf-as exampleAsm.S -o exampleAsm.o
riscv32-unknown-elf-ld -o exampleAsm.elf -T asm.ld -m elf32lriscv -nostdlib --no-relax
riscv32-unknown-elf-gcc -r exampleC.c -o exampleC.o
riscv32-unknown-elf-ld -o exampleC.elf -T c_prog.ld -m elf32lriscv -nostdlib --no-relax
Trying to use multiplication or other advanced math operations with the rv32I arch? No problem, you just have to declare the path to the correct libgcc library on the loader step.
Watch out!, the path may change depending of how did you setup the multilib, just beware of choosing the libgcc.a corresponding to the rv32I.
riscv32-unknown-elf-ld -o exampleC2.elf -T bram.ld -m elf32lriscv -nostdlib --no-relax /(RVTOOLCHAIN_GCC_LIB_DIR)/libgcc.a
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