Creating bare-metal toolchain for riscv32

Hi,

I’m new to riscv and want to compile a bare-metal toolchain
with latest binutils/gcc git tree. I have seen both upstream projects recently got support for riscv. Any plans to get newlib support upstream, too?

I added riscv support to my build system, but I get an internal compiler error:
Makefile:490: recipe for target ‘_multc3.o’ failed
make[8]: *** [_multc3.o] Error 1
make[8]: *** Waiting for unfinished jobs…
/home/wbx/riscv/toolchain_build_generic-riscv_newlib/w-gcc-git-1/gcc-git/libgcc/libgcc2.c: In function ‘__divtc3’:
/home/wbx/riscv/toolchain_build_generic-riscv_newlib/w-gcc-git-1/gcc-git/libgcc/libgcc2.c:2094:1: error: unable to generate reloads for:
}
^
(insn 2671 2822 1275 33 (set (reg:SI 1107)
(mem/c:SI (plus:SI (reg/f:SI 65 frame)
(const_int 4 [0x4])) [3 %sfp±188 S4 A32])) “/home/wbx/riscv/toolchain_build_generic-riscv_newlib/w-gcc-git-1/gcc-git/libgcc/libgcc2.c”:2082 132 {*movsi_internal}
(expr_list:REG_DEAD (reg:SI 1225)
(nil)))
/home/wbx/riscv/toolchain_build_generic-riscv_newlib/w-gcc-git-1/gcc-git/libgcc/libgcc2.c:2094:1: internal compiler error: in curr_insn_transform, at lra-constraints.c:3785
Please submit a full bug report,
with preprocessed source if appropriate.
See http://www.openadk.org/ for instructions.
Makefile:490: recipe for target ‘_divtc3.o’ failed
make[8]: *** [_divtc3.o] Error 1
Makefile:10886: recipe for target ‘all-target-libgcc’ failed
make[7]: *** [all-target-libgcc] Error 2
Makefile:872: recipe for target ‘all’ failed
make[6]: *** [all] Error 2

Full log of toolchain build:
https://debug.openadk.org/riscv/make.log

Thanks
Waldemar

I believe Kito is planning on upstreaming the RISC-V newlib port, there’s some progress here: https://github.com/riscv/riscv-newlib/commits/riscv-newlib-2.4.0 .

That error could very well be a bug in our GCC port. There’s one patch I have outstanding that might fix something similar but I haven’t verified it’s sane yet: https://github.com/riscv/riscv-gcc/commit/2c6af46afa0ffe94a9a7162b656ffddfdf5b4b31 .

If that patch doesn’t fix your bug, then I’ll need to be able to reproduce your error to help. Can you first verify that riscv-gnu-toolchain builds on your platform, and if it does can you attach a preprocessed source to a bug report on https://github.com/riscv/riscv-gcc/issues ?

Hi Palmer,

the patch works fine for newlib/glibc based toolchains :slight_smile:

./toolchain_generic-riscv_glibc/usr/bin/riscv32-openadk-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=./toolchain_generic-riscv_glibc/usr/bin/riscv32-openadk-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/home/wbx/riscv/toolchain_generic-riscv_glibc/usr/libexec/gcc/riscv32-openadk-linux-gnu/7.0.1/lto-wrapper
Target: riscv32-openadk-linux-gnu
Configured with: /home/wbx/riscv/toolchain_build_generic-riscv_glibc/w-gcc-git-1/gcc-git/configure --prefix=/home/wbx/riscv/toolchain_generic-riscv_glibc/usr --with-bugurl=http://www.openadk.org/ --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=riscv32-openadk-linux-gnu --with-gmp=/home/wbx/riscv/host_x86_64-linux-gnu/usr --with-mpfr=/home/wbx/riscv/host_x86_64-linux-gnu/usr --with-libelf=/home/wbx/riscv/host_x86_64-linux-gnu/usr --disable-__cxa_atexit --with-system-zlib --with-gnu-ld --with-gnu-as --disable-libsanitizer --disable-install-libiberty --disable-libitm --disable-libmudflap --disable-libgomp --disable-libcilkrts --disable-libquadmath --disable-libquadmath-support --disable-decimal-float --disable-libstdcxx-pch --disable-ppl-version-check --disable-cloog-version-check --without-ppl --without-cloog --without-isl --disable-werror --disable-nls --disable-lto --enable-tls --enable-threads --enable-libatomic --enable-shared --enable-cxx-flags=-fPIC --disable-libssp --disable-biarch --disable-multilib --enable-languages=c --with-build-sysroot=’/…/…/target_generic-riscv_glibc’ --with-sysroot=’/…/…/target_generic-riscv_glibc’
Thread model: posix
gcc version 7.0.1 20170311 (experimental) (GCC)

Thanks,
Waldemar

Hi Waldemar. I will definitely need your toolchain to bring up a bare metal system
on this chip. what is your eta?

later…dd

Hi,
the patch was added, you can play with the toolchain
https://openadk.org whenever you like.

ok, wow, very impressive…dd

You might also try GNU MCU Eclipse RISC-V Embedded GCC, it is a RISC-V toolchain intended for bare-metal embeded applications. It generates code for both riscv32 and riscv64.

Binary releases for all major platforms (32/64-bits) are available from GitHub.

It is the default toolchain for GNU MCU Eclipse.

1 Like