mirror of
https://github.com/openhwgroup/cva6.git
synced 2025-04-20 04:07:36 -04:00
Add GCC toolchain builder. Update README and .gitignore accordingly. (#1415)
This commit is contained in:
parent
5b37393a2e
commit
5c3e3d4545
7 changed files with 658 additions and 17 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -45,3 +45,5 @@ __pycache__
|
|||
.bender/
|
||||
Bender.lock
|
||||
/tools/
|
||||
/util/gcc-toolchain-builder/src/
|
||||
/util/gcc-toolchain-builder/build/
|
||||
|
|
37
README.md
37
README.md
|
@ -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
|
||||
```
|
||||
|
||||
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 :
|
||||
|
||||
```sh
|
||||
export RISCV=/path/to/installation/directory
|
||||
export RISCV_PREFIX=$RISCV/bin/riscv-none-
|
||||
export RISCV_GCC=$RISCV_PREFIXgcc
|
||||
# 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
|
||||
|
||||
# Get the source code of toolchain components from public repositiories.
|
||||
cd util/gcc-toolchain-builder
|
||||
bash ./get-toolchain.sh
|
||||
|
||||
# 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
|
||||
|
|
156
util/gcc-toolchain-builder/README.md
Normal file
156
util/gcc-toolchain-builder/README.md
Normal file
|
@ -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._
|
217
util/gcc-toolchain-builder/build-toolchain.sh
Normal file
217
util/gcc-toolchain-builder/build-toolchain.sh
Normal file
|
@ -0,0 +1,217 @@
|
|||
#!/bin/sh
|
||||
|
||||
#############################################################################
|
||||
#
|
||||
# Copyright 2020-2023 Thales
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
#############################################################################
|
||||
#
|
||||
# Original Author: Zbigniew CHAMSKI, Thales Silicon Security
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
# Paths in configuration files are relative to this directory.
|
||||
ROOT_DIR=$(dirname $(readlink -f $0))
|
||||
|
||||
# Assumptions:
|
||||
# - the required binutils source is in src/binutils-gdb
|
||||
# - the required GCC source is in src/gcc
|
||||
# - the required newlib is in src/newlib
|
||||
# - the user invoking this script has sufficient permissions
|
||||
# to create/populate the installation directory.
|
||||
# - there are no restrictions on the parallelism of the build process
|
||||
# ("make -j" without an explicit job limit causes no significant harm)
|
||||
#
|
||||
# Builds of individual tools are performed under the matching
|
||||
# build/... subdirectories
|
||||
|
||||
# Helper function to print usage information.
|
||||
print_usage()
|
||||
{
|
||||
echo Usage:
|
||||
echo " $SHELL $0 [-h|--help]"
|
||||
echo " $SHELL $0 [-f|--force] [CONFIG_NAME] INSTALL_PREFIX"
|
||||
echo ""
|
||||
echo " -h, --help Print this help message and exit."
|
||||
echo " -f, --force Rebuild toolchain from scratch (remove build dirs,"
|
||||
echo " configure and build again.)"
|
||||
echo " CONFIG_NAME Use configuration from file config/CONFIG_NAME.sh"
|
||||
echo " (default: '$CONFIG_NAME')"
|
||||
echo " INSTALL_PREFIX Path where the toolchain should be installed"
|
||||
echo " (relative paths will be converted to absolute ones,"
|
||||
echo " missing parent directories will be created as needed.)"
|
||||
}
|
||||
|
||||
# Helper function to parse the cmdline args.
|
||||
# Takes the complete list of positional args, drops them as they get parsed.
|
||||
parse_cmdline()
|
||||
{
|
||||
# Print help message and exit.
|
||||
if [ $# -ge 1 ]; then
|
||||
if [ $1 = "-h" -o $1 = "--help" ]; then
|
||||
print_usage
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# "Force rebuild" mode: try before any file/directory names.
|
||||
# Valid only with 2+ cmdline args.
|
||||
if [ $# -ge 2 ]; then
|
||||
if [ $1 = "-f" -o $1 = "--force" ]; then
|
||||
FORCE_REBUILD=yes
|
||||
shift
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check for the config name. Valid only with 2+ cmdline args left.
|
||||
if [ $# -ge 2 ]; then
|
||||
CONFIG_NAME=$1
|
||||
shift
|
||||
fi
|
||||
|
||||
# Check for the installation prefix. Must exist after dropping previous args.
|
||||
if [ $# -eq 1 ]; then
|
||||
# Resolve the path to an absolute one (it needs NOT to exist yet.)
|
||||
PREFIX=`readlink -m "$1"`
|
||||
shift
|
||||
fi
|
||||
|
||||
# Any remaining arg past the prefix means an error.
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "*** Excess arguments past INSTALL_PREFIX: please correct the command line!"
|
||||
echo ""
|
||||
print_usage
|
||||
exit 12
|
||||
fi
|
||||
}
|
||||
|
||||
# ======== Default settings: GCC 13.1.0 baremetal, no forced rebuild ========
|
||||
# - toolchain configuration.
|
||||
# NOTE: config/$CONFIG_NAME.sh can be a symbolic link.
|
||||
CONFIG_NAME="gcc-13.1.0-baremetal"
|
||||
|
||||
# - rebuild mode
|
||||
FORCE_REBUILD=no
|
||||
|
||||
# The INSTALL_PREFIX argument is required
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "*** Please specify the installation prefix of the toolchain!"
|
||||
echo ""
|
||||
print_usage;
|
||||
exit 11
|
||||
fi
|
||||
|
||||
# ======== Parse the command line. Drop each successfully parsed arg. ========
|
||||
echo "### Parsing the cmdline..."
|
||||
parse_cmdline "$@"
|
||||
|
||||
# ======== Check if config file exists, and load it if it does ========
|
||||
# Check for the presence of source code and build configuration.
|
||||
CONFIG_FILE="$ROOT_DIR/config/$CONFIG_NAME.sh"
|
||||
|
||||
if [ -f $CONFIG_FILE ]; then
|
||||
# File present: read the settings.
|
||||
. $CONFIG_FILE
|
||||
else
|
||||
echo "*** Configuration file '$CONFIG_FILE' missing!"
|
||||
echo ""
|
||||
print_usage
|
||||
exit 13
|
||||
fi
|
||||
|
||||
# ======== Actual build process ========
|
||||
|
||||
# Force rebuilding if asked to: remove all build directories.
|
||||
[ $FORCE_REBUILD = "yes" ] && rm -rf $ROOT_DIR/build/{binutils-gdb,gcc,newlib}
|
||||
|
||||
# Overall build policy: try to be as push-button as possible...
|
||||
# - If a Makefile already exists, do not configure again - just build+install.
|
||||
# - If there is no Makefile, run configure, then build and install.
|
||||
# - If the first configure attempt failed try making 'clean' and 'distclean'
|
||||
# targets.
|
||||
# - In case of build error in GCC once configured, remove the target-specific
|
||||
# build subdirectories and try making again.
|
||||
# - binutils and GCC are built with CFLAGS and CXXFLAGS set to "-O2"
|
||||
# ("production" mode: no debug, stripping disabled = 10x smaller binaries).
|
||||
# - CFLAGS and CXXFLAGS are left unset for newlib.
|
||||
|
||||
# Disable debug support to reduce size of executables and speed up their launching.
|
||||
export CFLAGS="-O2"
|
||||
export CXXFLAGS="-O2"
|
||||
|
||||
# Configure and build binutils (required by GCC).
|
||||
# Binutils 2.40 has an annoying bug caused by a missing 'gas/doc'
|
||||
# directory ==> create it prior to launching 'make'.
|
||||
[ -d $ROOT_DIR/build/binutils-gdb ] || mkdir -p $ROOT_DIR/build/binutils-gdb
|
||||
cd $ROOT_DIR/build/binutils-gdb
|
||||
[ -f Makefile ] || \
|
||||
../../$BINUTILS_DIR/configure $BINUTILS_CONFIGURE_OPTS || \
|
||||
{ [ -f Makefile ] && make clean && make distclean && \
|
||||
../../$BINUTILS_DIR/configure $BINUTILS_CONFIGURE_OPTS || \
|
||||
{ echo "Could not configure binutils-gdb, bailing out!" ; \
|
||||
exit 2 ; } ; } && \
|
||||
{ [ -d gas/doc ] || mkdir -p gas/doc; } && \
|
||||
make -j all && make install || \
|
||||
{ echo "*** Could not build binutils, bailing out!" ; exit 2; }
|
||||
cd -
|
||||
|
||||
# Configure and build GCC (required by newlib).
|
||||
# If an initial configure failed (e.g., due to a change in PREFIX),
|
||||
# try making 'distclean' target and configuring again.
|
||||
# The target-specific subdirectories configured during *build*
|
||||
# are simply removed in case of build error, and 'make all' is
|
||||
# then restarted.
|
||||
[ -d $ROOT_DIR/build/gcc ] || mkdir -p $ROOT_DIR/build/gcc
|
||||
cd $ROOT_DIR/build/gcc
|
||||
[ -f Makefile ] || \
|
||||
../../$GCC_DIR/configure $GCC_CONFIGURE_OPTS || \
|
||||
{ [ -f Makefile ] && make clean && make distclean && \
|
||||
make -C libcc1 distclean && \
|
||||
../../$GCC_DIR/configure $GCC_CONFIGURE_OPTS || \
|
||||
{ echo "Could not configure GCC, bailing out!" ; \
|
||||
exit 2 ; } ; } && \
|
||||
make -j all || { rm -rf $TARGET && \
|
||||
make -j all ; } && make install || \
|
||||
{ echo "*** Could not build GCC (even after removing target dirs), bailing out!" ; exit 2; }
|
||||
cd -
|
||||
|
||||
# Unset the variables forced for binutils and GCC builds.
|
||||
unset CFLAGS CXXFLAGS
|
||||
|
||||
# Configure and build newlib.
|
||||
|
||||
# We need the path to the newly installed tools
|
||||
# when running 'configure' and building newlib.
|
||||
[ -d $ROOT_DIR/build/newlib ] || mkdir -p $ROOT_DIR/build/newlib
|
||||
cd $ROOT_DIR/build/newlib
|
||||
export PATH="$PREFIX/bin:$PATH"
|
||||
|
||||
# Assume a fully capable code model (medium)
|
||||
export CFLAGS="-mcmodel=medium"
|
||||
|
||||
# If an initial configure failed, try making 'distclean' target
|
||||
# and configuring again.
|
||||
[ -f Makefile ] || \
|
||||
../../$NEWLIB_DIR/configure $NEWLIB_CONFIGURE_OPTS || \
|
||||
{ [ -f Makefile ] && make clean && make distclean && \
|
||||
../../$NEWLIB_DIR/configure $NEWLIB_CONFIGURE_OPTS || \
|
||||
{ echo "Could not configure newlib, bailing out!" ; \
|
||||
exit 2 ; } ; } && \
|
||||
make -j all && make install || \
|
||||
{ echo "*** Could not build newlib, bailing out!" ; exit 2; }
|
||||
cd -
|
||||
|
||||
# Exit happily.
|
||||
exit 0
|
61
util/gcc-toolchain-builder/config/gcc-13.1.0-baremetal.sh
Normal file
61
util/gcc-toolchain-builder/config/gcc-13.1.0-baremetal.sh
Normal file
|
@ -0,0 +1,61 @@
|
|||
#############################################################################
|
||||
#
|
||||
# Copyright 2020-2023 Thales
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
#############################################################################
|
||||
#
|
||||
# Original Author: Zbigniew CHAMSKI, Thales Silicon Security
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
# Name of the target to use for the toolchain.
|
||||
export TARGET=riscv-none-elf
|
||||
|
||||
# ======= Source code setup: path, repo, commit, configure options ========
|
||||
|
||||
# Each *_COMMIT variable can designate any valid 'commit-ish' entity:
|
||||
# typically a tag, a commit or the output of "git describe" of a Git tree.
|
||||
|
||||
# Binutils
|
||||
BINUTILS_DIR=src/binutils-gdb
|
||||
BINUTILS_REPO=https://sourceware.org/git/binutils-gdb.git
|
||||
BINUTILS_COMMIT=binutils-2_40
|
||||
BINUTILS_CONFIGURE_OPTS="\
|
||||
--prefix=$PREFIX \
|
||||
--target=$TARGET \
|
||||
--disable-nls \
|
||||
--disable-werror"
|
||||
|
||||
# GCC
|
||||
GCC_DIR=src/gcc
|
||||
GCC_REPO=https://github.com/gcc-mirror/gcc.git
|
||||
GCC_COMMIT=releases/gcc-13.1.0
|
||||
GCC_CONFIGURE_OPTS="\
|
||||
--prefix=$PREFIX \
|
||||
--target=$TARGET \
|
||||
--enable-languages=c \
|
||||
--disable-libssp \
|
||||
--disable-libgomp \
|
||||
--disable-libmudflap"
|
||||
|
||||
# newlib
|
||||
NEWLIB_DIR=src/newlib
|
||||
NEWLIB_REPO=https://sourceware.org/git/newlib-cygwin.git
|
||||
NEWLIB_COMMIT=newlib-4.3.0
|
||||
|
||||
NEWLIB_CONFIGURE_OPTS="\
|
||||
--prefix=$PREFIX \
|
||||
--target=$TARGET \
|
||||
--enable-multilib"
|
61
util/gcc-toolchain-builder/config/gcc-master-baremetal.sh
Normal file
61
util/gcc-toolchain-builder/config/gcc-master-baremetal.sh
Normal file
|
@ -0,0 +1,61 @@
|
|||
#############################################################################
|
||||
#
|
||||
# Copyright 2020-2023 Thales
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
#############################################################################
|
||||
#
|
||||
# Original Author: Zbigniew CHAMSKI, Thales Silicon Security
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
# Name of the target to use for the toolchain.
|
||||
export TARGET=riscv-none-elf
|
||||
|
||||
# ======= Source code setup: path, repo, commit, configure options ========
|
||||
|
||||
# Each *_COMMIT variable can designate any valid 'commit-ish' entity:
|
||||
# typically a tag, a commit or the output of "git describe" of a Git tree.
|
||||
|
||||
# Binutils
|
||||
BINUTILS_DIR=src/binutils-gdb
|
||||
BINUTILS_REPO=https://sourceware.org/git/binutils-gdb.git
|
||||
BINUTILS_COMMIT=binutils-2_41
|
||||
BINUTILS_CONFIGURE_OPTS="\
|
||||
--prefix=$PREFIX \
|
||||
--target=$TARGET \
|
||||
--disable-nls \
|
||||
--disable-werror"
|
||||
|
||||
# GCC
|
||||
GCC_DIR=src/gcc
|
||||
GCC_REPO=https://github.com/gcc-mirror/gcc.git
|
||||
GCC_COMMIT=master
|
||||
GCC_CONFIGURE_OPTS="\
|
||||
--prefix=$PREFIX \
|
||||
--target=$TARGET \
|
||||
--enable-languages=c \
|
||||
--disable-libssp \
|
||||
--disable-libgomp \
|
||||
--disable-libmudflap"
|
||||
|
||||
# newlib
|
||||
NEWLIB_DIR=src/newlib
|
||||
NEWLIB_REPO=https://sourceware.org/git/newlib-cygwin.git
|
||||
NEWLIB_COMMIT=newlib-4.3.0
|
||||
|
||||
NEWLIB_CONFIGURE_OPTS="\
|
||||
--prefix=$PREFIX \
|
||||
--target=$TARGET \
|
||||
--enable-multilib"
|
141
util/gcc-toolchain-builder/get-toolchain.sh
Normal file
141
util/gcc-toolchain-builder/get-toolchain.sh
Normal file
|
@ -0,0 +1,141 @@
|
|||
#!/bin/sh
|
||||
|
||||
#############################################################################
|
||||
#
|
||||
# Copyright 2020-2023 Thales
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
#############################################################################
|
||||
#
|
||||
# Original Author: Zbigniew CHAMSKI, Thales Silicon Security
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
# Prerequisites:
|
||||
#
|
||||
# - autotools
|
||||
# - GNU make
|
||||
# - flex
|
||||
# - bison
|
||||
# - isl
|
||||
# - gmp
|
||||
# - mpz
|
||||
# - mpc
|
||||
# - texinfo
|
||||
# - 5.5 GB of disk space
|
||||
|
||||
# Paths in config files are relative to this directory.
|
||||
ROOT_DIR=$(dirname $(readlink -f $0))
|
||||
|
||||
# Helper function to print usage information.
|
||||
print_usage()
|
||||
{
|
||||
echo Usage:
|
||||
echo " your-favorite-shell $0 [CONFIG_NAME]"
|
||||
echo ""
|
||||
echo " CONFIG_NAME Use configuration from file config/CONFIG_NAME.sh"
|
||||
}
|
||||
|
||||
# Helper function to parse the cmdline args.
|
||||
# Takes the complete list of positional args as input, drops them locally as they get parsed.
|
||||
parse_cmdline()
|
||||
{
|
||||
# There must be exactly one positional arg.
|
||||
if [ $# -gt 1 ]; then
|
||||
echo "*** Incorrect number of cmdline arguments ($#), exiting!"
|
||||
echo ""
|
||||
print_usage
|
||||
exit 11
|
||||
fi
|
||||
|
||||
# The only, optional arg is supposed to be the config name.
|
||||
if [ $# -eq 1 ]; then
|
||||
CONFIG_NAME=$1
|
||||
shift
|
||||
fi
|
||||
}
|
||||
|
||||
# ======== Default settings: GCC 13.1.0 baremetal ========
|
||||
# - toolchain configuration
|
||||
# NOTE: config/$CONFIG_NAME.sh can be a symbolic link.
|
||||
CONFIG_NAME="gcc-13.1.0-baremetal"
|
||||
|
||||
# ======== Parse the command line ========
|
||||
parse_cmdline "$@"
|
||||
|
||||
# ======== Read configuration information =========
|
||||
# Check for the presence of source code and build configuration file.
|
||||
|
||||
CONFIG_FILE="$ROOT_DIR/config/$CONFIG_NAME.sh"
|
||||
|
||||
if [ -f $CONFIG_FILE ]; then
|
||||
# File present: read the settings.
|
||||
. $CONFIG_FILE
|
||||
else
|
||||
echo "*** Configuration file '$CONFIG_FILE' missing, bailing out!"
|
||||
echo ""
|
||||
print_usage
|
||||
exit 12
|
||||
fi
|
||||
# ========= Populate/update the directories =========
|
||||
|
||||
# Hook for the future tarball-only option
|
||||
# if [ $# -lt 2 -o $1 == "git"]; then
|
||||
# # populate directories from Git
|
||||
# else
|
||||
# # populate directories from tarballs
|
||||
# fi
|
||||
|
||||
# Overall directory infrastructure: make sure `pwd`/src exists.
|
||||
[ ! -d $ROOT_DIR/src ] && mkdir $ROOT_DIR/src
|
||||
|
||||
# All Git-based source trees are handled in the same way.
|
||||
# Positional args:
|
||||
# - $1: the Git repository to use
|
||||
# - $2: the local directory for the source code
|
||||
# - $3: the actual commit to check out (SHA1, tag, etc.)
|
||||
setup_sources_from_git()
|
||||
{
|
||||
# make sure the source directory exists and is populated
|
||||
# with Git information. If a stale non-Git directory exits,
|
||||
# remove it unless it is write-protected.
|
||||
[ -d $ROOT_DIR/$2 -a -d $ROOT_DIR/$2/.git ] || \
|
||||
{ rm -rf $ROOT_DIR/$2 && \
|
||||
git clone --depth=1 --branch="$3" $1 $ROOT_DIR/$2 ; }
|
||||
|
||||
# Check out the required revision as local branch (the shallow clone
|
||||
# leaves a "detached HEAD" state.)
|
||||
cd $ROOT_DIR/$2
|
||||
LOCAL_BRANCH="${3}-local"
|
||||
{ git branch | grep -q "$LOCAL_BRANCH" ; } || git checkout -b "$LOCAL_BRANCH"
|
||||
git checkout "$LOCAL_BRANCH"
|
||||
# Pull any updates available upstream (useful for 'master' branches).
|
||||
git pull origin "$3"
|
||||
cd -
|
||||
}
|
||||
|
||||
# Binutils
|
||||
echo "# Step 1: Obtaining sources of binutils-gdb..."
|
||||
setup_sources_from_git $BINUTILS_REPO $BINUTILS_DIR $BINUTILS_COMMIT
|
||||
|
||||
# GCC
|
||||
echo "# Step 2: Obtaining sources of GCC..."
|
||||
setup_sources_from_git $GCC_REPO $GCC_DIR $GCC_COMMIT
|
||||
|
||||
# Newlib
|
||||
echo "# Step 3: Obtaining sources of newlib..."
|
||||
setup_sources_from_git $NEWLIB_REPO $NEWLIB_DIR $NEWLIB_COMMIT
|
||||
|
||||
# Exit happily.
|
||||
exit 0
|
Loading…
Add table
Add a link
Reference in a new issue