From 74cd37f5ddc76671644ee25b91fcabdf55a4dd9e Mon Sep 17 00:00:00 2001 From: James Stine Date: Thu, 23 Mar 2023 09:13:40 -0500 Subject: [PATCH 1/2] Update README by removing install instructions since script is now available --- README.md | 224 ++---------------------------------------------------- 1 file changed, 6 insertions(+), 218 deletions(-) diff --git a/README.md b/README.md index 69570090..5339eca0 100644 --- a/README.md +++ b/README.md @@ -58,224 +58,12 @@ Run a regression simulation with Questa to prove everything is installed. # Toolchain Installation (Sys Admin) -This section describes the open source toolchain installation. These steps should only be done once by the system admin. - -## TL;DR Open Source Tool-chain Installation - -The full installation details are involved can be be skipped using the following script, wally-tool-chain-install.sh. -The script installs the open source tools to /opt/riscv by default. This can be changed by supply the path as the first argument. This script does not install buildroot (see the Detailed Tool-chain Install Guide in the following section) and does not install commercial EDA tools; Siemens Questa, Synopsys Design Compiler, or Cadence Innovus (see section Installing IDA Tools). It must be run as root or with sudo. This script is tested for Ubuntu, 20.04 and 22.04. Fedora and Red Hat can be installed in the Detailed Tool-chain Install Guide. - - $ sudo bin/wally-tool-chain-install.sh - -## Detailed Toolchain Install Guide - -This section describes how to install the tools needed for CORE-V-Wally. Superuser privileges are necessary for many of the tools. Setting up all of the tools can be time-consuming and fussy, so Appendix D also describes an option with a Docker container. - -### Open Source Software Installation - -Compiling, assembling, and simulating RISC-V programs requires downloading and installing the following free tools: - -1. The GCC cross-compiler -2. A RISC-V simulator such as Spike, Sail, and/or QEMU -3. Spike is easy to use but doesn’t support peripherals to boot Linux -4. QEMU is faster and can boot Linux -5. Sail is presently the official golden reference for RISC-V and is used by the riscof verification suite, but runs slowly and is painful to instal - -This setup needs to be done once by the administrator - -Note: The following directions assume you have an account called cad to install shared software and files. You can substitute a different user for cad if you prefer. - -Note: Installing software in Linux is unreasonably touchy and varies with the flavor and version of your Linux distribution. Don’t be surprised if the installation directions have changed since the book was written or don’t work on your machine; you may need some ingenuity to adjust them. Browse the openhwgroup/core-v-wally repo and look at the README.md for the latest build instructions. - -### Create the $RISCV Directory - -First, set up a directory for riscv software in some place such as /opt/riscv. We will call this shared directory $RISCV. - - $ export RISCV=/opt/riscv - $ sudo mkdir $RISCV - $ sudo chown cad $RISCV - $ sudo su cad (or root, if you don’t have a cad account) - $ export RISCV=/opt/riscv - $ chmod 755 $RISCV - $ umask 0002 - $ cd $RISCV - -### Update Tools - -Ubuntu users may need to install and update various tools. Beware when cutting and pasting that some lines are long! - - $ sudo apt update - $ sudo apt upgrade - $ sudo apt install git gawk make texinfo bison flex build-essential python3 zlib1g-dev libexpat-dev autoconf device-tree-compiler ninja-build libglib2.0-dev libpixman-1-dev build-essential ncurses-base ncurses-bin libncurses5-dev dialog - -### Install RISC-V GCC Cross-Compiler - -To install GCC from source can take hours to compile. This configuration enables multilib to target many flavors of RISC-V. This book is tested with GCC 12.2 (tagged 2023.01.31), but will likely work with newer versions as well. - - $ git clone https://github.com/riscv/riscv-gnu-toolchain - $ cd riscv-gnu-toolchain - $ git checkout 2023.01.31 - $ ./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 --jobs - -Note: make --jobs will reduce compile time by compiling in parallel. However, adding this option could dramatically increase the memory utilization of your local machine. - -### Install elf2hex - -We also need the elf2hex utility to convert executable files into hexadecimal files for Verilog simulation. Install with: - - $ cd $RISCV - $ export PATH=$RISCV/bin:$PATH - $ git clone https://github.com/sifive/elf2hex.git - $ cd elf2hex - $ autoreconf -i - $ ./configure --target=riscv64-unknown-elf --prefix=$RISCV - $ make - $ make install - -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. - -### Install RISC-V Spike Simulator - -Spike also takes a while to install and compile, but this can be done concurrently with the GCC installation. After the build, we need to change two Makefiles to support atomic instructions . - - $ cd $RISCV - $ git clone https://github.com/riscv-software-src/riscv-isa-sim - $ mkdir riscv-isa-sim/build - $ cd riscv-isa-sim/build - $ ../configure --prefix=$RISCV - $ make --jobs - $ make install - $ cd ../arch_test_target/spike/device - $ sed -i 's/--isa=rv32ic/--isa=rv32iac/' rv32i_m/privilege/Makefile.include - $ sed -i 's/--isa=rv64ic/--isa=rv64iac/' rv64i_m/privilege/Makefile.include - -### Install Sail Simulator - -Sail is the new golden reference model for RISC-V. Sail is written in OCaml, which is an object-oriented extension of ML, which in turn is a functional programming 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. - -On Ubuntu, apt-get makes opam installation fairly simple. - -$ sudo apt-get install opam build-essential libgmp-dev z3 pkg-config zlib1g-dev - -If you are on RedHat/Rocky Linux 8, installation is much more difficult because packages are not available in the default package manager and some need to be built from source. - - $ sudo bash -c "sh <(curl -fsSL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh)" - When prompted, put it in /usr/bin - $ sudo yum groupinstall 'Development Tools' - $ sudo yum -y install gmp-devel - $ sudo yum -y install zlib-devel - $ git clone https://github.com/Z3Prover/z3.git - $ cd z3 - $ python scripts/mk_make.py - $ cd build - $ make - $ sudo make install - $ cd ../.. - $ sudo pip3 install chardet==3.0.4 - $ sudo pip3 install urllib3==1.22 - -Once you have installed the packages on either Ubuntu or RedHat, use opam to install the OCaml compiler and Sail. Run as the cad user because you will be installing Sail in $RISCV. - - $ sudo su cad - $ opam init -y --disable-sandboxing - $ opam switch create ocaml-base-compiler.4.06.1 - $ opam install sail -y - -Now you can clone and compile Sail-RISCV. This will take a while. - - $ eval $(opam config env) - $ cd $RISCV - $ git clone https://github.com/riscv/sail-riscv.git - $ cd sail-riscv - $ make - $ ARCH=RV32 make - $ ARCH=RV64 make - $ exit - $ sudo su - $ export RISCV=/opt/riscv - $ ln -sf $RISCV/sail-riscv/c_emulator/riscv_sim_RV64 /usr/bin/riscv_sim_RV64 - $ ln -sf $RISCV/sail-riscv/c_emulator/riscv_sim_RV32 /usr/bin/riscv_sim_RV32 - $ exit - -### Install riscof - -riscof is a Python library used as the RISC-V compatibility framework test an implementation such as Wally or Spike against the Sail golden reference. It will be used to compile the riscv-arch-test suite. - -It is most convenient if the sysadmin installs riscof into the server’s Python libraries: - - $ sudo pip3 install testresources - $ sudo pip3 install riscof --ignore-installed PyYAML - -However, riscof can also be installed and run locally by individual users. - -### Other Python libraries - -While a sysadmin is installing Python libraries, it's worth doing some more that will be needed by visualization scripts. - - $ sudo pip3 install matplotlib scipy sklearn adjustText lief - -### Install Verilator - -Verilator is a free Verilog simulator with a good Lint tool used to catch errors in the SystemVerilog code. It is needed to run regression. -$ sudo apt install verilator - -### Install QEMU Simulator - -QEMU is another simulator used when booting Linux in Chapter 17. You can optionally install it using the following commands. - - -The QEMU patch changes the VirtIO driver to match the Wally peripherals, and also adds print statements to log the state of the CSRs (see Section 2.5XREF). - - - $ cd $RISCV - $ git clone --recurse-submodules https://github.com/qemu/qemu - $ cd qemu - $ git checkout v6.2.0 # last version tested; newer versions might be ok - $ ./configure --target-list=riscv64-softmmu --prefix=$RISCV - $ make --jobs - $ make install - -### Cross-Compile Buildroot Linux - -Building Linux is only necessary for exploring the boot process in Chapter 17. Building and generating a trace is a time-consuming operation that could be skipped for now; you can return to this section later if you are interested in the Linux details. - -Buildroot depends on configuration files in riscv-wally, so the cad user must install Wally first according to the instructions in Section 2.2.2. However, don’t source ~/wally-riscv/setup.sh because it will set LD_LIBRARY_PATH in a way to cause make to fail on buildroot. - -To configure and build Buildroot: - - $ cd $RISCV - $ export WALLY=~/riscv-wally # make sure you haven’t sourced ~/riscv-wally/setup.sh by now - $ git clone https://github.com/buildroot/buildroot.git - $ cd buildroot - $ git checkout 2021.05 # last tested working version - $ cp -r $WALLY/linux/buildroot-config-src/wally ./board - $ cp ./board/wally/main.config .config - $ make --jobs - -To generate disassembly files and the device tree, run another make script. Note that you can expect some warnings about phandle references while running dtc on wally-virt.dtb. - -$ source ~/riscv-wally/setup.sh -$ cd $WALLY/linux/buildroot-scripts -$ make all - -Note: When the make tasks complete, you’ll find source code in $RISCV/buildroot/output/build and the executables in $RISCV/buildroot/output/images. - -### Generate load images for linux boot - -The Questa linux boot uses preloaded bootram and ram memory. We use QEMU to generate these preloaded memory files. Files output in $RISCV/linux-testvectors - - cd cvw/linux/testvector-generation - ./genInitMem.sh - -This may require changing file permissions to the linux-testvectors directory. - -### Generate QEMU linux trace - -The linux testbench can instruction by instruction compare Wally's committed instructions against QEMU. To do this QEMU outputs a log file consisting of all instructions executed. Interrupts are handled by forcing the testbench to generate an interrupt at the same cycle as in QEMU. Generating this trace will take more than 24 hours. - - cd cvw/linux/testvector-generation - ./genTrace.sh +This section describes the open source toolchain installation. The +current version of the toolchain has been tested on Ubuntu and Red +Hat/Rocky 8. The latter is more difficult to install and Ubuntu may +be more recommended for new users. The
wally-tool-chain-install.sh
script inside +the bin directory can be utilized to install the toolchain on Ubuntu +using sudo. ### Download Synthesis Libraries From eb0b6860bb81fb6d3996c15ba8f4369dad05dbb2 Mon Sep 17 00:00:00 2001 From: James Stine Date: Thu, 23 Mar 2023 09:20:35 -0500 Subject: [PATCH 2/2] Update more information inside Wally install script --- bin/wally-tool-chain-install.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/bin/wally-tool-chain-install.sh b/bin/wally-tool-chain-install.sh index 181d097a..9faff81d 100755 --- a/bin/wally-tool-chain-install.sh +++ b/bin/wally-tool-chain-install.sh @@ -5,6 +5,7 @@ ## Written: Ross Thompson ross1728@gmail.com ## Created: 18 January 2023 ## Modified: 22 January 2023 +## Modified: 23 March 2023 ## ## Purpose: Open source tool chain installation script ## @@ -26,18 +27,20 @@ ## 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 set -e # break on error +# Modify accordingly for your machine NUM_THREADS=1 # for low memory machines > 16GiB #NUM_THREADS=8 # for >= 32GiB #NUM_THREADS=16 # for >= 64GiB sudo mkdir -p $RISCV -# UPDATE / UPGRADE +# Update and Upgrade (see https://itsfoss.com/apt-update-vs-upgrade/) apt update apt upgrade @@ -51,7 +54,7 @@ then ln -sf /usr/bin/python3 /usr/bin/python fi -# gcc cross-compiler +# gcc cross-compiler (https://github.com/riscv-collab/riscv-gnu-toolchain) cd $RISCV git clone https://github.com/riscv/riscv-gnu-toolchain cd riscv-gnu-toolchain @@ -60,9 +63,8 @@ git checkout 2023.01.31 make -j ${NUM_THREADS} make install -# elf2hex +# elf2hex (https://github.com/sifive/elf2hex) cd $RISCV -#export PATH=$RISCV/riscv-gnu-toolchain/bin:$PATH export PATH=$RISCV/bin:$PATH git clone https://github.com/sifive/elf2hex.git cd elf2hex @@ -77,7 +79,7 @@ apt-get -y install python3-pip apt-get -y install pkg-config apt-get -y install libglib2.0-dev -# QEMU +# QEMU (https://www.qemu.org/docs/master/system/target-riscv.html) cd $RISCV git clone --recurse-submodules https://github.com/qemu/qemu cd qemu @@ -85,7 +87,7 @@ cd qemu make -j ${NUM_THREADS} make install -# Spike +# Spike (https://github.com/riscv-software-src/riscv-isa-sim) cd $RISCV git clone https://github.com/riscv-software-src/riscv-isa-sim mkdir -p riscv-isa-sim/build @@ -97,7 +99,7 @@ cd ../arch_test_target/spike/device sed -i 's/--isa=rv32ic/--isa=rv32iac/' rv32i_m/privilege/Makefile.include sed -i 's/--isa=rv64ic/--isa=rv64iac/' rv64i_m/privilege/Makefile.include -# SAIL +# Sail (https://github.com/riscv/sail-riscv) cd $RISCV apt-get install -y opam build-essential libgmp-dev z3 pkg-config zlib1g-dev git clone https://github.com/Z3Prover/z3.git