Toolchain for RISC-V (CH32V series)

As a next step for building OpenOCD, I tried to set up the cross-toolchain for RISC-V on the Ubuntu 20.04.
I used Crosstool-NG to do this. Initially, I tried Crosstool-NG Release 1.24.0, but this version doesn’t have an option to build the Newlib-nano library as a companion library. So I cloned the latest source code from a GitHub repository directly (The git commit SHA-1 hash was 7e21141).
The following is the record of my trial on Ubuntu 20.04.

sudo apt install git make texinfo libtool libtool-bin libmpc-dev zlib1g-dev gawk build-essential bison flex gperf patchutils help2man libncurses-dev curl device-tree-compiler libexpat-dev libusb-1.0-0-dev
git clone https://github.com/crosstool-ng/crosstool-ng
cd crosstool-ng
./bootstrap
./configure
make
sudo make install
sudo ct-ng update-samples

Then I built the cross-toolchain using the Crosstool-NG as follows.

mkdir build<br>cd build<br>ct-ng riscv32-unknown-elf<br>ct-ng menuconfig

For the ct-ng menuconfig command, I changed the following options from the default.

  • In the Target options menu, I enabled the Build a multilib toolchain.
  • In the C-library menu, I selected the newlib as the C library.
  • In the Companion libraries menu, I selected the newlib-nano and enabled the Additionally install newlib-nano libs into TARGET dir option for the newlib-nano.

After saving the changes to the .config file, I initiated the toolchain build by the following command.

ct-ng build

The toolchain build took about 30mins with my machine, and I finally got the toolchain binaries under ~/x-tools/riscv32-unknown-elf.