cvw/bin/wally-tool-chain-install.sh

193 lines
7.8 KiB
Bash
Raw Normal View History

#!/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
## Modified: 23 March 2023
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.
## 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.
################################################################################################
# Use /opt/riscv for installation - may require running script with sudo
export RISCV="${1:-/opt/riscv}"
export PATH=$PATH:$RISCV/bin:/usr/bin
2023-01-22 00:00:14 +00:00
set -e # break on error
# 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
#NUM_THREADS=16 # for >= 64GiB
2023-01-21 23:32:44 +00:00
sudo mkdir -p $RISCV
# *** need to update permissions to local user
2023-01-21 23:32:44 +00:00
2023-03-23 16:05:37 +00:00
# Update and Upgrade tools (see https://itsfoss.com/apt-update-vs-upgrade/)
sudo apt update -y
sudo apt upgrade -y
sudo apt install -y git gawk make texinfo bison flex build-essential python3 libz-dev libexpat-dev autoconf device-tree-compiler ninja-build libpixman-1-dev ncurses-base ncurses-bin libncurses5-dev dialog curl wget ftp libgmp-dev libglib2.0-dev python3-pip pkg-config opam z3 zlib1g-dev automake autotools-dev libmpc-dev libmpfr-dev gperf libtool patchutils bc mutt ssmtp
2023-03-23 16:31:17 +00:00
# Other python libraries used through the book.
sudo pip3 install sphinx sphinx_rtd_theme matplotlib scipy scikit-learn adjustText lief markdown
2023-01-22 00:00:14 +00:00
# needed for Ubuntu 22.04, gcc cross compiler expects python not python2 or python3.
if ! command -v python &> /dev/null
then
echo "WARNING: python3 was installed as python3 rather than python. Creating symlink."
sudo ln -sf /usr/bin/python3 /usr/bin/python
fi
# 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.
# This book is tested with GCC 13.2.0
# Versions newer than 2023-12-20 fail to compile the RISC-V arch test with an error:
# cvw/addins/riscv-arch-test/riscv-test-suite/rv32i_m/I/src/jalr-01.S:72: Error: illegal operands `la x0,5b'
# PR *** submitted to fix riscv-arch-test to be compatible with latest GCC by modifying test_macros.h for TEST_JALR_OP
2023-01-21 23:32:44 +00:00
cd $RISCV
2023-01-21 23:24:21 +00:00
git clone https://github.com/riscv/riscv-gnu-toolchain
cd riscv-gnu-toolchain
./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 8
# 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 doesnt work for our purposes because it doesnt
# 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 wont 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 wont work properly.
2023-01-21 23:32:44 +00:00
cd $RISCV
export PATH=$RISCV/bin:$PATH
2023-01-21 23:24:21 +00:00
git clone https://github.com/sifive/elf2hex.git
cd elf2hex
autoreconf -i
./configure --target=riscv64-unknown-elf --prefix=$RISCV
make
make install
# QEMU (https://www.qemu.org/docs/master/system/target-riscv.html)
2023-01-21 23:32:44 +00:00
cd $RISCV
2023-01-21 23:24:21 +00:00
git clone --recurse-submodules https://github.com/qemu/qemu
cd qemu
./configure --target-list=riscv64-softmmu --prefix=$RISCV
make -j 8
2023-01-21 23:24:21 +00:00
make install
# Spike (https://github.com/riscv-software-src/riscv-isa-sim)
2023-03-23 16:33:56 +00:00
# Spike also takes a while to install and compile, but this can be done concurrently
# with the GCC installation.
2023-01-21 23:32:44 +00:00
cd $RISCV
2023-01-21 23:24:21 +00:00
git clone https://github.com/riscv-software-src/riscv-isa-sim
mkdir -p riscv-isa-sim/build
2023-01-21 23:24:21 +00:00
cd riscv-isa-sim/build
2023-02-08 00:49:50 +00:00
../configure --prefix=$RISCV
make -j 8
2023-01-21 23:24:21 +00:00
make install
# 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
sudo apt-get install -y perl g++ ccache help2man libgoogle-perftools-dev numactl perl-doc zlib1g
sudo apt-get install -y perl g++ ccache help2man libgoogle-perftools-dev numactl perl-doc zlib1g
2023-06-09 16:37:09 +00:00
cd $RISCV
git clone https://github.com/verilator/verilator # Only first time
# unsetenv VERILATOR_ROOT # For csh; ignore error if on bash
unset VERILATOR_ROOT # For bash
2023-06-09 16:37:09 +00:00
cd verilator
git pull # Make sure git repository is up-to-date
git checkout master
2023-06-09 16:37:09 +00:00
autoconf # Create ./configure script
./configure # Configure and create Makefile
make -j 8 # Build Verilator itself (if error, try just 'make')
2023-06-09 16:37:09 +00:00
sudo make install
# Sail (https://github.com/riscv/sail-riscv)
2023-03-23 16:33:56 +00:00
# Sail is the new golden reference model for RISC-V. Sail is written in OCaml, which
2023-03-23 16:31:17 +00:00
# is an object-oriented extension of ML, which in turn is a functional programming
2023-03-23 16:33:56 +00:00
# language suited to formal verification. OCaml is installed with the opam OCcaml
# package manager. Sail has so many dependencies that it can be difficult to install.
# This script works for Ubuntu.
2023-03-23 16:31:17 +00:00
# Alex Solomatnikov found these commands worked to build Sail for Centos 8 on 1/12/24
#sudo su -
#dnf install ocaml.x86_64
#pip3 install z3-solver
#wget https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh
#sh install.sh
#opam init
#exit
#ocaml -version
#opam switch create 5.1.0
#eval $(opam config env)
#git clone --recurse-submodules git@github.com:riscv/sail-riscv.git
#cd sail-riscv
#make
#ARCH=RV32 make
#ARCH=RV64 make
#git log -1
#cp -p c_emulator/riscv_sim_RV* /tools/sail-riscv/d7a3d8012fd579f40e53a29569141d72dd5e0c32/bin/.
# This was an earlier attemp to prepare to install Sail on RedHat 8
2023-03-23 16:33:56 +00:00
# Do these commands only for RedHat / Rocky 8 to build from source.
2023-03-23 16:31:17 +00:00
#cd $RISCV
#git clone https://github.com/Z3Prover/z3.git
#cd z3
#python scripts/mk_make.py
#cd build
#make -j 8
2023-03-23 16:31:17 +00:00
#make install
#cd ../..
#pip3 install chardet==3.0.4
#pip3 install urllib3==1.22
cd $RISCV
2023-01-21 23:24:21 +00:00
opam init -y --disable-sandboxing
opam update
opam upgrade
opam switch create 5.1.0
2023-01-21 23:24:21 +00:00
opam install sail -y
2023-01-21 23:24:21 +00:00
eval $(opam config env)
git clone https://github.com/riscv/sail-riscv.git
cd sail-riscv
# For now, use checkout that is stable for Wally
#git checkout 72b2516d10d472ac77482fd959a9401ce3487f60 # not new enough for Zicboz?
2024-04-16 17:32:43 +00:00
export OPAMCLI=2.0 # Sail is not compatible with opam 2.1 as of 4/16/24
ARCH=RV64 make -j 8 c_emulator/riscv_sim_RV64
ARCH=RV32 make -j 8 c_emulator/riscv_sim_RV32
sudo ln -sf $RISCV/sail-riscv/c_emulator/riscv_sim_RV64 /usr/bin/riscv_sim_RV64
sudo ln -sf $RISCV/sail-riscv/c_emulator/riscv_sim_RV32 /usr/bin/riscv_sim_RV32
# riscof
sudo pip3 install -U testresources riscv_config
sudo pip3 install git+https://github.com/riscv/riscof.git
# Download OSU Skywater 130 cell library
sudo mkdir -p $RISCV/cad/lib
cd $RISCV/cad/lib
sudo git clone https://foss-eda-tools.googlesource.com/skywater-pdk/libs/sky130_osu_sc_t12