Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GCC toolchain builder. Update README and .gitignore accordingly. #1415

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ __pycache__
.bender/
Bender.lock
/tools/
/util/gcc-toolchain-builder/src/
/util/gcc-toolchain-builder/build/
35 changes: 19 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,31 @@ There are README files in each directory with additional information.
#### Prerequisites
To execute tests on CVA6 core, you need a RISC-V toolchain.

Be aware that only gcc 11.1.0 or newer are supported in core-v-verif repository.
To build and install riscv gcc compiler in local, you can use the following commands :
To build and install RISC-V GCC compiler locally, you can use the toolchain generation scripts
located under `util/gcc-toolchain-builder`.

```sh
git clone https://github.com/riscv-collab/riscv-gnu-toolchain
cd riscv-gnu-toolchain
git clone https://github.com/gcc-mirror/gcc -b releases/gcc-13 gcc-13
./configure –prefix:/path/to/installation/directory --with-multilib-generator="rv32e-ilp32e--;rv32i-ilp32--;rv32im-ilp32--;rv32iac-ilp32--;rv32imac-ilp32--;rv32imafc-ilp32f--;rv32imafdc-ilp32d--;rv64i-lp64--;rv64ic-lp64--;rv64iac-lp64--;rv64imac-lp64--;rv64imafdc-lp64d--;rv64im-lp64--;" --with-gcc-src=`pwd`/gcc-13
make –j32
```
# Set environment variables. The toolchain can be installed
# in any user-writable directory.
export RISCV=/path/to/toolchain/installation/directory
export CV_SW_PREFIX=riscv-none-elf-
export RISCV_PREFIX=$RISCV/bin/$CW_SW_PREFIX
export RISCV_GCC=$RISCV_PREFIXgcc

These commands will install the riscv gcc 13.1.0 compiler which is the latest version.
Once running the previous commands, your environment must be updated with :
# Get the source code of toolchain components from public repositiories.
cd util/gcc-toolchain-builder
bash ./get-toolchain.sh

```sh
export RISCV=/path/to/installation/directory
export RISCV_PREFIX=$RISCV/bin/riscv-none-
export RISCV_GCC=$RISCV_PREFIXgcc
export CV_SW_PREFIX=riscv-none-elf-
# For the build prerequisites, see the local README.md.

# Build and install the GCC toolchain.
bash ./build-toolchain.sh $RISCV

# Return to the toplevel CVA6 directory.
cd -
```

This 4 variables will ensure you use correctly the new gcc compiler you have just installed.
These four variables will ensure you use correctly the new gcc compiler you have just installed.
You will now be able to run the test scripts.

#### Environent setup
Expand Down
156 changes: 156 additions & 0 deletions util/gcc-toolchain-builder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# `gcc-toolchain-builder`: Basic scripts for building a RISC-V GCC compiler toolchain

## Overview

This directory contains basic scripts for building local instances of CORE-V GCC toolchains.
The scripts provide the means of fetching the source code and building the executables
and libraries for well-defined toolchain configurations. The intention is to
simplify the processs of building such toolchains and make it as "push-button"
(and as accessible to CORE-V users) as reasonably possible.

Currently, the scripts support only 'bare metal' toolchain configurations
intended for hardware verification of 32- and 64-bit RISC-V targets.
These configurations are deliberately lightweight and consist of:

* `binutils-gdb`: assembler, linker, GDB debugger, and object file utilities
* `GCC`: the GNU GCC compiler configured for C only
* `newlib`: an open-source C library suitable for embedded applications.

Several extensions are envisioned:

* Explicit selection of GDB version
* Addition of LLVM/Clang compilers
* Support for Linux-based target environments
* Addition of full-featured C library implementations

## Getting started

Once the prerequisites (see [below](#prerequisites)) are satisfied, you can fetch and build the
upstream GCC toolchain (default: 13.1.0) for bare-metal 32-bit and 64-bit applications in just three steps.

# 1. Select an installation location for the toolchain (here: the default RISC-V tooling directory $RISCV).
INSTALL_DIR=$RISCV

# 2. Fetch the source code of the toolchain (assumes Internet access.)
sh get-toolchain.sh

# 3. Build and install the toolchain (requires write+create permissions for $INSTALL_DIR.)
sh build-toolchain.sh $INSTALL_DIR

## File and directory structure

The base infrastructure for building compilation toolchains consists of two scripts
and a directory holding configuration files:

* `get-toolchain.sh`: script in charge of obtaining the source code and
extracting the correct code baselines.
* `build-toolchain.sh`: script in charge of building and installing the
different toolchain components in suitable order.
* `config/`: directory containing the configuration files for the various configurations.

In the process of building the toolchain, two new directory trees are created
under the current working directory:

* `src/`: Source code is fetched and checked out into subdirectories of `src` in
the current working directory.

* `build/`: The building of the various components of the toolchain occurs in
subdirectories of `build` in the current working directory.

This directory structure was chosen to keep the source and build directories
local to the user's workspace while supporting systematic out-of-source-tree
building of toolchain components.

## Prerequisites

**Disk space:** Approximately 3.5 GB of disk space are needed to build and install a bare-metal toolchain
from source code:

* 1.9 GB is occupied by source code (including Git history);
* 1.1 GB is needed for the build space;
* 0.5 GB is needed for the installed toolchain.

Several **standard packages** are needed to build the GCC-based compiler
toolchains. On Debian/Ubuntu, executing the following command should suffice:

$ sudo apt-get install autoconf automake autotools-dev curl git libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool bc zlib1g-dev

On Fedora/CentOS/RHEL OS, executing the following command should suffice:

$ sudo yum install autoconf automake git libmpc-devel mpfr-devel gmp-devel gawk bison flex texinfo gcc gcc-c++ zlib-devel

On macOS, you can use [Homebrew](http://brew.sh) to install the dependencies:

$ brew install gawk gnu-sed gmp mpfr libmpc isl zlib

## Building a bare-metal toolchain (Newlib-based)

In order to build a toolchain you need to select a _toolchain configuration_ and
an _installation location_ (an "install prefix"):

* the toolchain configuration name must match one of the predefined `config/CONFIG_NAME.sh`
files under `config` directory.

* the installation location can be an arbitrary path. It needs not to exist
yet: any missing directories will be created during the building process. _The user running the
`build-toolchain.sh` script must have sufficient permissions to create the
missing directories of the installation location._

Once a configuration name `CONFIG_NAME` and an installation location
`INSTALL_LOCATION` are chosen, use

sh get-toolchain.sh CONFIG_NAME
# E.g.,
# sh get-toolchain.sh gcc-10.2.0-baremetal

to fetch/update the source code and to check out the matching baseline of code.

If the name of the toolchain configuration is omitted, a default configuration
will be selected implicitly. _The default configuration is currently named
`gcc-13.1.0-baremetal`_ and builds a toolchain containing

* binutils v2.40 (official release baseline)
* gcc v.13.1.0 (official release baseline)
* newlib v4.3 (official release baseline).

To build the toolchain from the retrieved source baseline, use

sh build-toolchain.sh CONFIG_NAME INSTALL_DIR
# E.g.,
# sh build-toolchain.sh gcc-13.1.0-baremetal $RISCV

The `build-toolchain.sh` script incorporates fallbacks for several commonly encountered configuration and
build issues. However, it is not meant to auto-detect major reconfigurations of source
code such as a change of baseline configuration. _Whenever the source
configuration is changed, please use the `-f` (or `--force`)
option to forcibly rebuild the entire toolchain_:

sh build-toolchain.sh -f CONFIG_NAME INSTALL_DIR
# E.g.,
# sh build-toolchain.sh -f gcc-13.1.0-baremetal $RISCV

## Defining new configurations

Users involved with toolchain validation and development may be interested in
creating new configurations that cater for specific needs:

* use of local Git mirrors to enable toolchain development and to shorten
Git query times
* building of experimental toolchains combining specific versions of individual
components.

New configurations can be easily introduced by copying existing
configuration files in subdirectory `config/` under a different name and
adjusting the values of per-component variables. Taking `GCC` as an example:

* `GCC_DIR` defines the location of GCC source code.
* `GCC_REPO` selects the Git repository to fetch GCC code from.
* `GCC_COMMIT` identifies the revision of source code to use: a specific commit,
tag, or branch. \
_**NOTE:** If you set `GCC_COMMIT` to the name of a branch, the
`get-toolchain.sh` will update the local repository to the tip of the remote
branch at every invocation._

* `GCC_CONFIGURE_OPTS` is the list of options to pass to the configure script. \
_**NOTE:** Since `GCC_CONFIGURE_OPTS` is a Bourne shell variable, any double-quotes in
the option list must be duly escaped to be correctly handled by the shell._
Loading