Setting up RISC-V Toolchain - Ubuntu

This is the recommended method.

1. Install RISC-V Toolchain

First, we need to install the following dependencies.

sudo apt install autoconf automake autotools-dev curl python3 python3-pip libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev ninja-build git cmake libglib2.0-dev

Clone the RISC-V GNU Toolchain repo.

cd ~/Downloads/
git clone https://github.com/riscv-collab/riscv-gnu-toolchain.git
cd ~/Downloads/riscv-gnu-toolchain/

Run configuration. The prefix is where we want to install the toolchain. Here, we will be installing under the riscv64-unknown-toolchain directory.

We can specify which architecture we want to build into the toolchain with the --with-multilib-generator= flag. We add support for the most common ones here.

./configure --prefix=/home/tk/Documents/RISCV/riscv64-unknown-toolchain/ --with-multilib-generator="rv32i-ilp32--;rv32im-ilp32--;rv32iac-ilp32--;rv32imac-ilp32--;rv32imafc-ilp32f--;rv64imac-lp64--;rv64imafdc-lp64d--"

Build the toolchain

make -j8

To check which architecture the toolchain supports, run the following command

riscv64-unknown-elf-gcc --print-multi-lib
$ riscv64-unknown-elf-gcc --print-multi-lib
.;
rv32i/ilp32;@march=rv32i@mabi=ilp32
rv32im/ilp32;@march=rv32im@mabi=ilp32
rv32iac/ilp32;@march=rv32iac@mabi=ilp32
rv32imac/ilp32;@march=rv32imac@mabi=ilp32
rv32imafc/ilp32f;@march=rv32imafc@mabi=ilp32f
rv64imac/lp64;@march=rv64imac@mabi=lp64
rv64imafdc/lp64d;@march=rv64imafdc@mabi=lp64d

Finally, add the RISCV toolchain to PATH in ~/.bashrc

...

# RISCV
export RISCV="/home/tk/Documents/RISCV/"
export PATH="${RISCV}riscv64-unknown-toolchain/bin/:$PATH"

...

2. Install OpenOCD

First, we need to install the following dependencies.

sudo apt install libtool pkg-config
sudo apt install libusb-1.0-0-dev
sudo apt install libftdi-dev

Clone the RISC-V OpenOCD repo

cd ~/Documents/RISCV/
git clone https://github.com/riscv/riscv-openocd.git
cd ~/Documents/RISCV/riscv-openocd/

Run the following command to generate the necessary configuration and build files for OpenOCD.

./bootstrap

Configure the build process according to the current system and settings by running the following command.

./configure

Finally, compile and install the software

make
sudo make install

Also add OpenOCD to PATH

...

# RISCV
export RISCV="/home/tk/Documents/RISCV/"
export PATH="${RISCV}riscv64-unknown-toolchain/bin/:$PATH"
export PATH="${RISCV}riscv-openocd/:$PATH"

...

Common Error

libtool: Version mismatch error when building openocd

Last updated