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/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
--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:
- rv32i-ilp32 (N)
- rv32iac-ilp32 (N)
- rv32im-ilp32 (N)
- rv32imac-ilp32 (A)
- rv32imafdc-ilp32d (G)
- rv32imafc-ilp32f (N)
- rv64imac-lp64 (A)
- rv64imafdc-lp64d (A)
(Where: (A)=all libs, (G)=glibc, (N)=newlib.)
make will build and INSTALL, hence the
--prefix directory should be writable to your user.
make -j 6