Skip to content

Commit

Permalink
Streamline installation process.
Browse files Browse the repository at this point in the history
* README.md (Prerequisites): Update.
* verif/regress/install-cva6.sh (CV_SW_PREFIX): Add comment on value auto-
  detection.
  (RISCV_GCC): Ditto.
  (RISCV_OBJCOPY): Ditto.
  (SPIKE_ROOT): Replace with SPIKE_INSTALL_DIR.
* verif/regress/install-riscv-dv.sh (SPIKE_ROOT): Ditto.
* verif/regress/install-spike.sh (ROOT_PROJECT): Set automatically from
  script path at all times.
  (SPIKE_ROOT): Phase out.
  (build+install procedure): Update log messages.
* verif/sim/cva6.py (main): Replace SPIKE_ROOT with SPIKE_INSTALL_DIR.
  • Loading branch information
zchamski committed Sep 22, 2023
1 parent fbe79ab commit 0e1a2be
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 23 deletions.
45 changes: 35 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,44 @@ This BSP is used by both `core` testbench and `uvmt_cva6` UVM verification envir
There are README files in each directory with additional information.

#### Prerequisites
To execute tests on CVA6 core, you need a RISC-V toolchain.

To build and install RISC-V GCC compiler locally, you can use the toolchain generation scripts
located under `util/gcc-toolchain-builder`.
In brief, you will need:
- a native C/C++ development environment to build simulation tools and models;
- a RISC-V toolchain to build the CVA6 test programs;
- optionally, an EDA tool that supports building and running simulation models of designs expressed in SystemVerilog.

To build the open-source tools used by CVA6 and to run CVA6 simulations, you will need
a native compilation toolchain for C and C++. Such toolchains are available on virtually
all Linux distributions as pre-installed or optional packages. If unsure, ask your system
administrator to install one on your system.

To build test programs for the CVA6 core, you need a RISC-V toolchain.
For GCC-based toolchains, only GCC versions above 11.1.0 are supported;
it is recommended to use GCC 13.1.0 or above.

You can use a pre-built toolchain (available for most common Linux/macOS
distributions from a variety of providers) or build one from scratch using
publicly available source code repositiores. The second approach may prove
necessary on older or unsupported Linux installations.

To use a pre-built RISC-V toolchain, download and install the package(s) for your
Linux distribution as per instructions from the toolchain provider, and set the
`RISCV` environment variable to the installation location of the toolchain:

```sh
# Set environment variable RISCV to the location of the installed toolchain.
export RISCV=/path/to/toolchain/installation/directory
```

To build and install RISC-V GCC toolchain locally, you can use the toolchain generation scripts
located under `util/gcc-toolchain-builder`. Please make sure beforehand that you have
installed all the required *toolchain build* dependencies (see
[the toolchain README file](file:util/gcc-toolchain-builder/README.md).)

```sh
# Set environment variables. The toolchain can be installed
# in any user-writable directory.
# Set environment variable RISCV to the desired installation location.
# 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
Expand All @@ -155,8 +181,7 @@ bash ./build-toolchain.sh $RISCV
cd -
```

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.
You will now be able to run the CVA6 test scripts.

#### Environent setup

Expand Down
7 changes: 5 additions & 2 deletions verif/regress/install-cva6.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ if [ -z "$RISCV" ]; then
return
fi

# Auto-detect RISC-V tool name prefix if not explicitly given.
if [ -z "$CV_SW_PREFIX" ]; then
export CV_SW_PREFIX="$(ls -1 -r $RISCV/bin/riscv*-gcc | head -n 1| grep gcc | rev | cut -d '/' -f 1 | cut -d '-' -f 2- | rev)-"
fi

# Default to auto-detected GCC name if not explicitly given.
if [ -z "$RISCV_GCC" ]; then
export RISCV_GCC=$RISCV/bin/${CV_SW_PREFIX}gcc
fi

# Default to auto-detected OBJCOPY name if not explicitly given.
if [ -z "$RISCV_OBJCOPY" ]; then
export RISCV_OBJCOPY=$RISCV/bin/${CV_SW_PREFIX}objcopy
fi
Expand Down Expand Up @@ -76,7 +79,7 @@ echo $CVA6_HASH
echo $CVA6_PATCH

# install Spike
if [ -z "$SPIKE_ROOT" ]; then
export SPIKE_ROOT=$TOP/spike/
if [ -z "$SPIKE_INSTALL_DIR" ]; then
export SPIKE_INSTALL_DIR=$TOP/spike/
fi
source verif/regress/install-spike.sh
2 changes: 1 addition & 1 deletion verif/regress/install-riscv-dv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fi
if [ -z "$RISCV_OBJCOPY" ]; then
export RISCV_OBJCOPY="$RISCV_TOOLCHAIN/bin/riscv-none-elf-objcopy"
fi
export SPIKE_PATH=$SPIKE_ROOT/bin
export SPIKE_PATH=$SPIKE_INSTALL_DIR/bin
export RTL_PATH=$ROOT_PROJECT/
export TB_PATH=$ROOT_PROJECT/verif/tb/core
export TESTS_PATH=$ROOT_PROJECT/verif/tests
Expand Down
17 changes: 8 additions & 9 deletions verif/regress/install-spike.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ if [ -z ${NUM_JOBS} ]; then
NUM_JOBS=1
fi

# Get the path to the top of the CVA6 installation. Assume we are located in CVA6_TOP/verif/regress.
ROOT_PROJECT=$(readlink -f $(dirname $0))/../..

# Set SPIKE_INSTALL_DIR to 'NO' to skip the installation/checks of Spike
# altogether.
# This is useful for CI jobs not depending on Spike in any way.
Expand All @@ -24,8 +27,7 @@ fi
if [ "$SPIKE_INSTALL_DIR" = "NO" ]; then
echo "NOTE: Skipping Spike setup on user's request (\$SPIKE_INSTALL_DIR = \"NO\")."
else
# Export the location of Spike source code. Assume we are located in CVA6_TOP/verif/regress.
ROOT_PROJECT=$(readlink -f $(dirname $0))/../..
# Export the location of Spike source code.
export SPIKE_SRC_DIR=$ROOT_PROJECT/vendor/riscv/riscv-isa-sim

# Check if a local copy of Spike should be built/used ($SPIKE_INSTALL_DIR non empty).
Expand All @@ -35,29 +37,26 @@ else
if [ "$SPIKE_INSTALL_DIR" = "__local__" ]; then
export SPIKE_INSTALL_DIR="$ROOT_PROJECT/tools/spike"
fi
# Override SPIKE_ROOT value with $SPIKE_INSTALL_DIR (the latter takes priority.)
# TODO: Remove the following two lines when SPIKE_ROOT is phased out.
echo "NOTE: Overriding SPIKE_ROOT value ('$SPIKE_ROOT') with \$SPIKE_INSTALL_DIR ('$SPIKE_INSTALL_DIR')."
export SPIKE_ROOT="$SPIKE_INSTALL_DIR"
# Do not clean up the destination directory: leave that to the user (real or CI job).
fi

# Rebuild Spike or reuse an existing Spike build.
if [ ! -d "$SPIKE_INSTALL_DIR" -o ! -f "$SPIKE_INSTALL_DIR/bin/spike" ]; then
echo "Installing Spike in '$SPIKE_INSTALL_DIR'..."
# Keep track of current working dir.
CALLER_DIR=$(readlink -f $(pwd))
# Enter the vendorized tree. It already captures the desired Spike config.
cd $SPIKE_SRC_DIR
echo "Building Spike sources in $SPIKE_SRC_DIR..."
# Build and install Spike (including extensions).
mkdir -p build
cd build
../configure --enable-commitlog --prefix="$SPIKE_INSTALL_DIR"
../configure --prefix="$SPIKE_INSTALL_DIR"
make -j${NUM_JOBS}
echo "Installing Spike in '$SPIKE_INSTALL_DIR'..."
make install
cd $CALLER_DIR
else
echo "Using Spike from cached directory '$SPIKE_INSTALL_DIR'."
echo "Using pre-installed Spike from '$SPIKE_INSTALL_DIR'."
fi
fi

2 changes: 1 addition & 1 deletion verif/sim/cva6.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ def main():
sys.exit(RET_FAIL)
#print environment softwares
logging.info("GCC Version : %s" % (gcc_version))
spike_version=get_env_var("SPIKE_ROOT")
spike_version=get_env_var("SPIKE_INSTALL_DIR")
logging.info("Spike Version : %s" % (spike_version))
verilator_version=run_cmd("verilator --version")
logging.info("Verilator Version : %s" % (verilator_version))
Expand Down

0 comments on commit 0e1a2be

Please sign in to comment.