2020-06-11

RISC-V. Part 2: The GNU Toolchain

1 Download

There is a well maintained git repository with a RISC-V cross-gcc. It has been updated from gcc 9 to gcc 10 in the days just before 2020-06-11. Download the current toolchain from git:

git clone --recursive https://github.com/riscv/riscv-gnu-toolchain
Cloning into 'riscv-gnu-toolchain'...
remote: Enumerating objects: 1, done.        
remote: Counting objects: 100% (1/1), done.        
remote: Total 7704 (delta 0), reused 0 (delta 0), pack-reused 7703        
Receiving objects: 100% (7704/7704), 4.72 MiB | 1.07 MiB/s, done.
Resolving deltas: 100% (3903/3903), done.
Submodule 'qemu' (https://git.qemu.org/git/qemu.git) registered for path 'qemu'
Submodule 'riscv-binutils' (https://github.com/riscv/riscv-binutils-gdb.git) registered for path 'riscv-binutils'
Submodule 'riscv-dejagnu' (https://github.com/riscv/riscv-dejagnu.git) registered for path 'riscv-dejagnu'
Submodule 'riscv-gcc' (https://github.com/riscv/riscv-gcc.git) registered for path 'riscv-gcc'
Submodule 'riscv-gdb' (https://github.com/riscv/riscv-binutils-gdb.git) registered for path 'riscv-gdb'
Submodule 'riscv-glibc' (https://github.com/riscv/riscv-glibc.git) registered for path 'riscv-glibc'
Submodule 'riscv-newlib' (https://github.com/riscv/riscv-newlib.git) registered for path 'riscv-newlib'
Cloning into '/home/h/riscv/riscv-gnu-toolchain/qemu'...
⋮

git downloads 3.26 GB over a 12 Mbit/s DSL line within an hour.

2 Compile the Toolchain

I prefer to compile the toolchain in a dedicated directory. For that I create build, enter the working directory, and configure the compilation from there. The prefix-parameter sets the installation directory. The architecture is rv32imac because the GD32VF103 is a 32-bit MCU with a 32 GPR (General Purpose Register) file, integer multiply/divide, atomics, and compressed (16bit) ISA set.

cd riscv-gnu-toolchain/
mkdir build
cd build
../configure --prefix=/opt/riscv --with-arch=rv32imac --with-abi=ilp32
checking for gcc... /usr/local/gcc-9.2/bin/gcc-9.2
checking whether the C compiler works... yes
⋮
configure: creating ./config.status
config.status: creating Makefile
config.status: creating scripts/wrapper/awk/awk
config.status: creating scripts/wrapper/sed/sed

To install the toolchain type

make

An hour later the cross-compiler is installed at /opt/riscv/bin/riscv32-unknown-elf-gcc.

3 Next Steps

Developing embedded systems
GNU Toolchain Provided

The left branch (gcc and sim via elf) of the system is complete. To test it, we must provide input to gcc. This will be done in the next blog.

No comments:

Post a Comment