From 0e1a2be4d5987e4c82ed7ae0a24fd3490134faf0 Mon Sep 17 00:00:00 2001 From: Zbigniew Chamski Date: Fri, 22 Sep 2023 10:10:16 +0200 Subject: [PATCH] Streamline installation process. * 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. --- README.md | 45 ++++++++++++++++++++++++------- verif/regress/install-cva6.sh | 7 +++-- verif/regress/install-riscv-dv.sh | 2 +- verif/regress/install-spike.sh | 17 ++++++------ verif/sim/cva6.py | 2 +- 5 files changed, 50 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 63fe3ce5a0..ad20a296a4 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/verif/regress/install-cva6.sh b/verif/regress/install-cva6.sh index f403c1e33b..b7af9964db 100755 --- a/verif/regress/install-cva6.sh +++ b/verif/regress/install-cva6.sh @@ -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 @@ -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 diff --git a/verif/regress/install-riscv-dv.sh b/verif/regress/install-riscv-dv.sh index 7e34d04159..76cdd4257a 100755 --- a/verif/regress/install-riscv-dv.sh +++ b/verif/regress/install-riscv-dv.sh @@ -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 diff --git a/verif/regress/install-spike.sh b/verif/regress/install-spike.sh index 328504a4e8..3bc95f20d6 100755 --- a/verif/regress/install-spike.sh +++ b/verif/regress/install-spike.sh @@ -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. @@ -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). @@ -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 diff --git a/verif/sim/cva6.py b/verif/sim/cva6.py index 1b566c039d..6700f9da5f 100644 --- a/verif/sim/cva6.py +++ b/verif/sim/cva6.py @@ -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))