Awesome
riscv-tools
This guide explains how to install riscv-tools on Ubuntu. These instructions might also work on other Linux variants, but we have only tested (and we only support) these instructions on Ubuntu 14.04 or higher.
Quickstart
$ git submodule update --init --recursive
$ export RISCV=/path/to/install/riscv/toolchain
$ ./build-rv32g.sh
Ubuntu packages needed:
$ sudo apt-get install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev
Note: This requires a compiler with C++11 support (e.g. GCC >= 4.8). To use a compiler different than the default, use:
$ CC=gcc-5 CXX=g++-5 ./build.sh
Note for OS X: It's very unlikly that you can build riscv-tools for RV32 on OS X. If you insist, we recommend using Homebrew to install the dependencies (gawk gnu-sed gmp mpfr libmpc isl wget
). This repo will build with Apple's command-line developer tools (clang) in addition to gcc.
The RISC-V GCC Toolchain Installation Manual
This document is adapted from the official Installation Manual which was authored by Quan Nguyen.
Introduction
The purpose of this page is to document a procedure through which an interested user can build the RISC-V GCC toolchain.
A project with a duration such as this requires adequate documentation to support future development and maintenance. This document is created with the hope of being useful; however, its accuracy is not guaranteed.
Table of Contents
- Introduction
- Table of Contents
- Meta-installation Notes
- Installing the Toolchain
- Testing Your Toolchain
Meta-installation Notes
Running Shell Commands
Instructive text will appear as this paragraph does. Any instruction to execute in your terminal will look like this:
$ echo "execute this"
If you will need to replace a bit of code that applies specifically to your situation, it will be surrounded by [square brackets].
Having Superuser Permissions
You will need root privileges to install the tools to directories like /usr/bin
. Otherwise, superuser privileges are not necessary.
GCC Version
Note: Building riscv-tools
requires GCC >= 4.8 for C++11 support (including thread_local). To use a compiler different than the default (for example on OS X), you'll need to do the following when the guide requires you to run build-rv32.sh
:
$ CC=gcc-5 CXX=g++-5 ./build-rv32.sh
Installing the Toolchain
Let's start with the directory in which we will install our tools. Change to the directory you want to install in, and then set the $TOP
environment variable accordingly:
$ export TOP=$(pwd)
Our instructions assume that TOP
is ~/Desktop
, but you may choose any directory.
Tour of the Sources
The toolchain consists of the following components:
riscv-gnu-toolchain
, a RISC-V cross-compilerriscv-fesvr
, a "front-end" server that services calls between the host and target processors on the Host-Target InterFace (HTIF) (it also provides a virtualized console and disk device)riscv-isa-sim
, the ISA simulator and "golden standard" of executionriscv-opcodes
, the enumeration of all RISC-V opcodes executable by the simulatorriscv-pk
, a proxy kernel that services system calls generated by code built and linked with the RISC-V Newlib port (this does not apply to Linux, as it handles the system calls)riscv-tests
, a set of assembly tests and benchmarks
Obtaining and Compiling the Sources
First, clone the tools from the riscv-tools
GitHub repository:
$ git clone https://github.com/ring00/riscv-tools.git
This command will bring in only references to the repositories that we will need. We rely on Git's submodule system to take care of resolving the references. Enter the newly-created riscv-tools directory and instruct Git to update its submodules.
$ cd $TOP/riscv-tools
$ git submodule update --init --recursive
To build GCC, we will need several other packages, including flex, bison, autotools, libmpc, libmpfr, and libgmp. Ubuntu distribution installations will require this command to be run. If you have not installed these things yet, then run this:
$ sudo apt-get install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc
Before we start installation, we need to set the $RISCV
environment variable. The variable is used throughout the build script process to identify where to install the new tools. (This value is used as the argument to the --prefix
configuration switch.)
$ export RISCV=$TOP/riscv
If your $PATH
variable does not contain the directory specified by $RISCV
, add it to the $PATH
environment variable now:
$ export PATH=$PATH:$RISCV/bin
The number of parallel compiler runs is set by $MAKEFLAGS
.
$ export MAKEFLAGS=-j8
With everything set up, run the build script. Recall that if you're using a new-version of gcc that isn't the default on your system, you'll need to precede the ./build-rv32.sh
with CC=gcc-5 CXX=g++-5
:
$ ./build-rv32.sh
Testing Your Toolchain
Now that you have a toolchain, it'd be a good idea to test it.
$ cd $TOP
$ echo -e '#include <stdio.h>\n int main(void) { printf("Hello world!\\n"); return 0; }' > hello.c
Then, build your program with riscv32-unknown-linux-gnu-gcc
.
$ riscv32-unknown-linux-gnu-gcc hello.c -o hello
Our "Hello world!" program involves a system call, which couldn't be handled by our host x86 system. We'll have to run the program within the proxy kernel, which itself is run by spike
, the RISC-V architectural simulator. Run this command to run your "Hello world!" program:
$ spike pk hello
The RISC-V architectural simulator, spike
, takes as its argument the path of the binary to run. This binary is pk
, and is located at $RISCV/riscv64-unknown-elf/bin/pk
. spike
finds this automatically. Then, riscv-pk
receives as its argument the name of the program you want to run.
Hopefully, if all's gone well, you'll have your program saying, "Hello world!".
References
-
Waterman, A., Lee, Y., Patterson, D., and Asanovic, K,. "The RISC-V Instruction Set Manual," vol. II, http://inst.eecs.berkeley.edu/~cs152/sp12/handouts/riscv-supervisor.pdf, 2012.
-
Bovet, D.P., and Cesati, M. Understanding the Linux Kernel, 3rd ed., O'Reilly, 2006.
-
Gorman, M. Understanding the Linux Virtual Memory Manager, http://www.csn.ul.ie/~mel/docs/vm/guide/pdf/understand.pdf, 2003.
-
Corbet, J., Rubini, A., and Kroah-Hartman, G. Linux Device Drivers, 3rd ed., O'Reilly, 2005.
-
Beekmans, G. Linux From Scratch, version 7.3, http://www.linuxfromscratch.org/lfs/view/stable/, 2013.