2023-01-22 03:31:47 +00:00
|
|
|
|
#!/bin/bash
|
2023-01-22 18:53:23 +00:00
|
|
|
|
###########################################
|
2023-01-22 19:04:31 +00:00
|
|
|
|
## Tool chain install script.
|
2023-01-22 18:53:23 +00:00
|
|
|
|
##
|
|
|
|
|
## Written: Ross Thompson ross1728@gmail.com
|
|
|
|
|
## Created: 18 January 2023
|
|
|
|
|
## Modified: 22 January 2023
|
2023-03-23 14:20:35 +00:00
|
|
|
|
## Modified: 23 March 2023
|
2024-06-22 04:18:09 +00:00
|
|
|
|
## Modified: 21 June 2024, Jordan Carlin jcarlin@hmc.edu
|
2023-01-22 18:53:23 +00:00
|
|
|
|
##
|
|
|
|
|
## Purpose: Open source tool chain installation script
|
|
|
|
|
##
|
|
|
|
|
## A component of the CORE-V-WALLY configurable RISC-V project.
|
2024-01-29 13:38:11 +00:00
|
|
|
|
## https://github.com/openhwgroup/cvw
|
2023-01-22 18:53:23 +00:00
|
|
|
|
##
|
|
|
|
|
## Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University
|
|
|
|
|
##
|
|
|
|
|
## SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
|
|
|
|
|
##
|
|
|
|
|
## Licensed under the Solderpad Hardware License v 2.1 (the “License”); you may not use this file
|
|
|
|
|
## except in compliance with the License, or, at your option, the Apache License version 2.0. You
|
|
|
|
|
## may obtain a copy of the License at
|
|
|
|
|
##
|
|
|
|
|
## https:##solderpad.org/licenses/SHL-2.1/
|
|
|
|
|
##
|
|
|
|
|
## Unless required by applicable law or agreed to in writing, any work 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.
|
|
|
|
|
################################################################################################
|
2023-01-22 03:31:47 +00:00
|
|
|
|
|
2024-06-22 04:18:09 +00:00
|
|
|
|
# Check if root
|
|
|
|
|
ROOT=$( [ "${EUID:=$(id -u)}" = 0 ] && echo true || echo false);
|
|
|
|
|
|
|
|
|
|
# All tools will be installed under the $RISCV directory. By default, if run as root (with sudo)
|
|
|
|
|
# this is set to /opt/riscv. Otherwise, it is set to ~/riscv. This value can be changed if needed.
|
|
|
|
|
if [ "$ROOT" = true ]; then
|
|
|
|
|
export RISCV="${1:-/opt/riscv}"
|
|
|
|
|
else
|
|
|
|
|
export RISCV="${1:-$HOME/riscv}"
|
|
|
|
|
fi
|
|
|
|
|
|
2023-05-10 15:23:55 +00:00
|
|
|
|
export PATH=$PATH:$RISCV/bin:/usr/bin
|
2023-01-21 20:03:30 +00:00
|
|
|
|
|
2023-01-22 00:00:14 +00:00
|
|
|
|
set -e # break on error
|
|
|
|
|
|
2023-03-23 14:20:35 +00:00
|
|
|
|
# Modify accordingly for your machine
|
2023-03-23 16:05:37 +00:00
|
|
|
|
# Increasing NUM_THREADS will speed up parallel compilation of the tools
|
2023-03-24 00:24:58 +00:00
|
|
|
|
#NUM_THREADS=2 # for low memory machines > 16GiB
|
|
|
|
|
NUM_THREADS=8 # for >= 32GiB
|
2023-01-22 03:23:23 +00:00
|
|
|
|
#NUM_THREADS=16 # for >= 64GiB
|
2023-01-21 20:03:30 +00:00
|
|
|
|
|
2024-06-22 04:18:09 +00:00
|
|
|
|
mkdir -p "$RISCV"
|
2023-01-21 23:32:44 +00:00
|
|
|
|
|
2024-06-22 04:18:09 +00:00
|
|
|
|
echo -e "\n*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "Installing Dependencies from Package Manager"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************\n"
|
2023-03-23 16:05:37 +00:00
|
|
|
|
# Update and Upgrade tools (see https://itsfoss.com/apt-update-vs-upgrade/)
|
2023-05-10 15:23:55 +00:00
|
|
|
|
sudo apt update -y
|
|
|
|
|
sudo apt upgrade -y
|
2024-06-22 04:18:09 +00:00
|
|
|
|
|
2024-06-22 19:18:38 +00:00
|
|
|
|
# Packages are grouped by which tool requires them, split by line.
|
|
|
|
|
# If mutltipole tools need a package, it is included in the first tool only
|
|
|
|
|
# General/Wally specific, riscv-gnu-toolchain, qemu, spike, verilator, sail
|
|
|
|
|
sudo apt install -y git make cmake python3 python3-pip python3-venv curl wget ftp tar pkg-config dialog mutt ssmtp \
|
|
|
|
|
autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat1-dev ninja-build libglib2.0-dev libslirp-dev \
|
|
|
|
|
libfdt-dev libpixman-1-dev \
|
|
|
|
|
device-tree-compiler libboost-regex-dev libboost-system-dev \
|
|
|
|
|
help2man perl g++ clang ccache libgoogle-perftools-dev numactl mold perl-doc libfl2 libfl-dev zlib1g \
|
|
|
|
|
opam z3
|
2024-06-22 04:18:09 +00:00
|
|
|
|
|
|
|
|
|
echo -e "\n*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "Setting up Python Environment"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************\n"
|
2023-03-23 16:31:17 +00:00
|
|
|
|
# Other python libraries used through the book.
|
2024-06-22 04:18:09 +00:00
|
|
|
|
cd "$RISCV"
|
|
|
|
|
if [ ! -e "$RISCV"/riscv-python/bin/activate ]; then
|
|
|
|
|
python3 -m venv riscv-python
|
2023-01-22 03:29:37 +00:00
|
|
|
|
fi
|
2024-06-22 04:18:09 +00:00
|
|
|
|
source "$RISCV"/riscv-python/bin/activate
|
|
|
|
|
pip install -U pip
|
2024-06-22 19:18:38 +00:00
|
|
|
|
pip install -U sphinx sphinx_rtd_theme matplotlib scipy scikit-learn adjustText lief markdown pyyaml testresources riscv_config
|
2024-06-22 04:18:09 +00:00
|
|
|
|
pip install -U riscv_isac # to generate new tests, such as quads with fp_dataset.py
|
|
|
|
|
source "$RISCV"/riscv-python/bin/activate
|
2023-01-21 20:03:30 +00:00
|
|
|
|
|
2023-03-23 14:20:35 +00:00
|
|
|
|
# gcc cross-compiler (https://github.com/riscv-collab/riscv-gnu-toolchain)
|
2023-03-23 16:05:37 +00:00
|
|
|
|
# To install GCC from source can take hours to compile.
|
2023-05-14 10:41:35 +00:00
|
|
|
|
# This configuration enables multilib to target many flavors of RISC-V.
|
2024-03-24 22:19:36 +00:00
|
|
|
|
# This book is tested with GCC 13.2.0
|
2024-06-22 04:18:09 +00:00
|
|
|
|
echo -e "\n*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "Installing RISC-V GNU Toolchain"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************\n"
|
|
|
|
|
cd "$RISCV"
|
|
|
|
|
if [[ ((! -e riscv-gnu-toolchain) && ($(git clone https://github.com/riscv/riscv-gnu-toolchain) || true)) || ($(cd riscv-gnu-toolchain; git fetch; git rev-parse HEAD) != $(cd riscv-gnu-toolchain; git rev-parse master)) || (! -e $RISCV/riscv-gnu-toolchain/stamps/build-gcc-newlib-stage2) ]]; then
|
|
|
|
|
cd riscv-gnu-toolchain
|
|
|
|
|
git checkout master
|
|
|
|
|
git pull
|
|
|
|
|
./configure --prefix="${RISCV}" --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--;"
|
|
|
|
|
make -j ${NUM_THREADS}
|
|
|
|
|
fi
|
2023-01-21 20:03:30 +00:00
|
|
|
|
|
2023-03-23 14:20:35 +00:00
|
|
|
|
# elf2hex (https://github.com/sifive/elf2hex)
|
2023-03-23 16:31:17 +00:00
|
|
|
|
#The elf2hex utility to converts executable files into hexadecimal files for Verilog simulation.
|
|
|
|
|
# Note: The exe2hex utility that comes with Spike doesn’t work for our purposes because it doesn’t
|
|
|
|
|
# handle programs that start at 0x80000000. The SiFive version above is touchy to install.
|
|
|
|
|
# For example, if Python version 2.x is in your path, it won’t install correctly.
|
|
|
|
|
# Also, be sure riscv64-unknown-elf-objcopy shows up in your path in $RISCV/riscv-gnu-toolchain/bin
|
|
|
|
|
# at the time of compilation, or elf2hex won’t work properly.
|
2024-06-22 04:18:09 +00:00
|
|
|
|
echo -e "\n*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "Installing elf2hex"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************\n"
|
|
|
|
|
cd "$RISCV"
|
2023-03-20 16:52:10 +00:00
|
|
|
|
export PATH=$RISCV/bin:$PATH
|
2024-06-22 04:18:09 +00:00
|
|
|
|
if [[ ((! -e elf2hex) && ($(git clone https://github.com/sifive/elf2hex.git) || true)) || ($(cd elf2hex; git fetch; git rev-parse HEAD) != $(cd elf2hex; git rev-parse master)) || (! -e $RISCV/bin/riscv64-unknown-elf-elf2bin) ]]; then
|
|
|
|
|
cd elf2hex
|
|
|
|
|
git reset --hard && git clean -f && git checkout master && git pull
|
|
|
|
|
autoreconf -i
|
|
|
|
|
./configure --target=riscv64-unknown-elf --prefix="$RISCV"
|
|
|
|
|
make
|
|
|
|
|
make install
|
|
|
|
|
fi
|
2023-01-21 20:03:30 +00:00
|
|
|
|
|
|
|
|
|
|
2023-03-23 14:20:35 +00:00
|
|
|
|
# QEMU (https://www.qemu.org/docs/master/system/target-riscv.html)
|
2024-06-22 04:18:09 +00:00
|
|
|
|
echo -e "\n*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "Installing QEMU"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************\n"
|
|
|
|
|
cd "$RISCV"
|
|
|
|
|
if [[ ((! -e qemu) && ($(git clone --recurse-submodules https://github.com/qemu/qemu) || true)) || ($(cd qemu; git fetch --recurse-submodules=yes; git rev-parse HEAD) != $(cd qemu; git rev-parse master)) || (! -e $RISCV/include/qemu-plugin.h) ]]; then
|
|
|
|
|
cd qemu
|
|
|
|
|
git reset --hard && git clean -f && git checkout master && git pull --recurse-submodules
|
|
|
|
|
./configure --target-list=riscv64-softmmu --prefix="$RISCV"
|
|
|
|
|
make -j ${NUM_THREADS}
|
|
|
|
|
make install
|
|
|
|
|
fi
|
2023-01-21 20:03:30 +00:00
|
|
|
|
|
2023-03-23 14:20:35 +00:00
|
|
|
|
# Spike (https://github.com/riscv-software-src/riscv-isa-sim)
|
2024-06-22 04:18:09 +00:00
|
|
|
|
# Spike also takes a while to install and compile, but this can be done concurrently
|
|
|
|
|
# with the GCC installation.
|
|
|
|
|
echo -e "\n*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "Installing SPIKE"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************\n"
|
|
|
|
|
cd "$RISCV"
|
|
|
|
|
if [[ ((! -e riscv-isa-sim) && ($(git clone https://github.com/riscv-software-src/riscv-isa-sim) || true)) || ($(cd riscv-isa-sim; git fetch; git rev-parse HEAD) != $(cd riscv-isa-sim; git rev-parse master)) || (! -e $RISCV/lib/pkgconfig/riscv-riscv.pc) ]]; then
|
|
|
|
|
cd riscv-isa-sim
|
|
|
|
|
git reset --hard && git clean -f && git checkout master && git pull
|
|
|
|
|
mkdir -p build
|
|
|
|
|
cd build
|
|
|
|
|
../configure --prefix="$RISCV"
|
|
|
|
|
make -j ${NUM_THREADS}
|
|
|
|
|
make install
|
|
|
|
|
fi
|
2024-03-24 22:19:36 +00:00
|
|
|
|
|
2023-01-21 20:03:30 +00:00
|
|
|
|
|
2024-01-06 15:11:25 +00:00
|
|
|
|
# Wally needs Verilator 5.021 or later.
|
2023-06-09 16:37:09 +00:00
|
|
|
|
# Verilator needs to be built from scratch to get the latest version
|
|
|
|
|
# apt-get install verilator installs version 4.028 as of 6/8/23
|
2024-06-22 04:18:09 +00:00
|
|
|
|
echo -e "\n*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "Installing Verilator"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************\n"
|
|
|
|
|
cd "$RISCV"
|
|
|
|
|
if [[ ((! -e verilator) && ($(git clone https://github.com/verilator/verilator) || true)) || ($(cd verilator; git fetch; git rev-parse HEAD) != $(cd verilator; git rev-parse master)) || (! -e $RISCV/share/pkgconfig/verilator.pc) ]]; then
|
|
|
|
|
# unsetenv VERILATOR_ROOT # For csh; ignore error if on bash
|
|
|
|
|
unset VERILATOR_ROOT # For bash
|
|
|
|
|
cd verilator
|
|
|
|
|
git reset --hard && git clean -f && git checkout master && git pull
|
|
|
|
|
autoconf # Create ./configure script
|
|
|
|
|
./configure --prefix="$RISCV" # Configure and create Makefile
|
|
|
|
|
make -j ${NUM_THREADS} # Build Verilator itself (if error, try just 'make')
|
|
|
|
|
make install
|
|
|
|
|
fi
|
2023-06-09 16:37:09 +00:00
|
|
|
|
|
2024-06-22 19:18:38 +00:00
|
|
|
|
# RISC-V Sail Model (https://github.com/riscv/sail-riscv)
|
|
|
|
|
# The RISC-V Sail Model is the golden reference model for RISC-V. It is written in Sail,
|
|
|
|
|
# a language designed for expressing the semantics of an ISA. Sail itself is written in
|
|
|
|
|
# OCaml, which is an object-oriented extension of ML, which in turn is a functional programming
|
|
|
|
|
# language suited to formal verification. The Sail compiler is installed with the opam OCcaml
|
|
|
|
|
# package manager. The Sail compiler has so many dependencies that it can be difficult to install,
|
|
|
|
|
# but a binary release of it should be available soon, removing the need to use opam.
|
2024-06-22 04:18:09 +00:00
|
|
|
|
echo -e "\n*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "Installing Sail Compiler"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************\n"
|
|
|
|
|
cd "$RISCV"
|
2023-01-21 23:24:21 +00:00
|
|
|
|
opam init -y --disable-sandboxing
|
2024-06-22 04:18:09 +00:00
|
|
|
|
opam update -y
|
|
|
|
|
opam upgrade -y
|
|
|
|
|
opam switch create 5.1.0 || opam switch set 5.1.0
|
|
|
|
|
opam install sail -y
|
2023-01-21 20:03:30 +00:00
|
|
|
|
|
2024-06-22 19:18:38 +00:00
|
|
|
|
echo -e "\n*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "Installing RISC-V Sail Model"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************\n"
|
2024-06-22 04:18:09 +00:00
|
|
|
|
if [[ ((! -e sail-riscv) && ($(git clone https://github.com/riscv/sail-riscv.git) || true)) || ($(cd sail-riscv; git fetch; git rev-parse HEAD) != $(cd sail-riscv; git rev-parse master)) || (! -e $RISCV/bin/riscv_sim_RV32) ]]; then
|
2024-06-22 19:18:38 +00:00
|
|
|
|
eval $(opam config env)
|
2024-06-22 04:18:09 +00:00
|
|
|
|
cd sail-riscv
|
|
|
|
|
git reset --hard && git clean -f && git checkout master && git pull
|
|
|
|
|
export OPAMCLI=2.0 # Sail is not compatible with opam 2.1 as of 4/16/24
|
|
|
|
|
ARCH=RV64 make -j ${NUM_THREADS} c_emulator/riscv_sim_RV64
|
|
|
|
|
ARCH=RV32 make -j ${NUM_THREADS} c_emulator/riscv_sim_RV32
|
|
|
|
|
cd "$RISCV"
|
|
|
|
|
ln -sf ../sail-riscv/c_emulator/riscv_sim_RV64 bin/riscv_sim_RV64
|
|
|
|
|
ln -sf ../sail-riscv/c_emulator/riscv_sim_RV32 bin/riscv_sim_RV32
|
|
|
|
|
fi
|
2023-01-21 20:03:30 +00:00
|
|
|
|
|
2023-12-19 21:25:10 +00:00
|
|
|
|
# riscof
|
2024-06-22 04:18:09 +00:00
|
|
|
|
echo -e "\n*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "Installing riscof"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************\n"
|
|
|
|
|
pip3 install git+https://github.com/riscv/riscof.git
|
2023-01-21 20:03:30 +00:00
|
|
|
|
|
2023-10-19 17:44:03 +00:00
|
|
|
|
# Download OSU Skywater 130 cell library
|
2024-06-22 04:18:09 +00:00
|
|
|
|
echo -e "\n*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "Installing OSU Skywater 130 cell library"
|
|
|
|
|
echo -e "*************************************************************************"
|
|
|
|
|
echo -e "*************************************************************************\n"
|
|
|
|
|
mkdir -p "$RISCV"/cad/lib
|
|
|
|
|
cd "$RISCV"/cad/lib
|
|
|
|
|
if [[ ((! -e sky130_osu_sc_t12) && ($(git clone https://foss-eda-tools.googlesource.com/skywater-pdk/libs/sky130_osu_sc_t12) || true)) || ($(cd sky130_osu_sc_t12; git fetch; git rev-parse HEAD) != $(cd sky130_osu_sc_t12; git rev-parse master)) ]]; then
|
|
|
|
|
cd sky130_osu_sc_t12
|
2024-06-22 19:18:38 +00:00
|
|
|
|
git reset --hard && git clean -f && git checkout main && git pull
|
2024-06-22 04:18:09 +00:00
|
|
|
|
fi
|