Five EmbedDev logo Five EmbedDev

An Embedded RISC-V Blog

Note to self: When compiling the riscv-toolchain for embedded systems, set the configure options!

The toolchain can be cloned from the RISC-V official github. Once the dependencies are installed it’s straight forward to compile.

$ git clone --recursive  https://github.com/riscv-collab/riscv-gnu-toolchain.git

GCC itself can generate code for any RISC-V variant, however the support libraries must be compiled for a known target.

You have a choice to compile for just one architecture, or build the multilib support for a predefined set of architectures. I’m interested in 32 bit embedded, so have compiled for targets such as rv32imac or rv32ec.

The options for --march and --mabi are in the GCC documentation. Those need to be passed to the configure script to get the correct library.

./configure \
    --prefix=/opt/riscv \
    --with-tune=size \
    --with-arch=rv32imac \
    --with-abi=ilp32

Or with multilib (longer build).

./configure \
    --prefix=/opt/riscv \
    --with-tune=size \
    --with-multilib-generator

Currently looking at configure.ac these are supported for multilib:

(Where: (A)=all libs, (G)=glibc, (N)=newlib.)

After configure make will build and INSTALL, hence the --prefix directory should be writable to your user.

make -j 6