IEEE.org     |     IEEE Xplore Digital Library     |     IEEE Standards     |     IEEE Spectrum     |     More Sites

riscv_vm_setup.sh 5.39 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
#------------------------------------------------------------------------------
# Copyright (c) 2019 BTA Design Services Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# 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.
#------------------------------------------------------------------------------
# Authors: Alfredo Herrera  (aherrera@btadesignservices.com) 
#          KichwaCoders     (info@kichwacoders.com)
#--- 
# This script can be used to install a subset of RISC-V tools to study, 
# configure as-referred, modify, implement or release hardware based on the 
# RISC-V Instruction Set Architecture. The VM is preconfigured for RISC-V HW
# development.
#    * RISC-V SW tool chain using the Eclipse-IDE
#    * RISC-V Imperas OVPSim model
#    * RISC-V Verilator model
#
#--- 
# Exit if not in a script, if not sudo/root or if runtime errors
#--- 
function die() {
  echo "$@: " 1>&2
  exit 1
}
# ref: https://askubuntu.com/a/30157/8698
if ! [ $(id -u) = 0 ]; then
   echo "The RISC-V VM installtion script needs to be run as root." >&2
   exit 1
fi
# Show commands being used and error out on unexpected situations
set -eux 

#--- 
# Update UBUNTU OS prior to installing tools
#--- 
echo "Updating Ubuntu"; echo""

apt-get install openssh-server xauth git-core lsb-core xorg vim-gtk3 dos2unix
# libudev package not available
apt-get install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libusb-1.0-0-dev libudev1 libudev-dev g++ openjdk-8-jdk

apt-get upgrade
apt-get clean
apt-get autoremove --purge

#--- 
# Install PULP-Platform GNU toolchain
#--- 
echo "Installing PULP GNU toolchain"; echo""
cd /home/user
sudo -u user git clone -recursive https://github.com/pulp-platform/pulp-riscv-gnu-toolchain
cd pulp-riscv-gnu-toolchain
sudo -u user ./configure --prefix=/opt/pulp --with-arch=rv32imc --with-cmodel=medlow --enable-multilib
sudo -u user make
cd ..
rm -rf pulp-riscv-gnu-toolchain

#--- 
echo "Installing Verilator tool"; echo""
cd /home/user
apt-get install libfl2 libfl-dev

git clone http://git.veripool.org/git/verilator
unset VERILATOR_ROOT
cd verilator
git pull
git checkout stable
autoconf
./configure
make
sudo make install
cd ..
rm -rf verilator

#--- 
echo "Installing rv32m1 tools"; echo""
curl -L https://github.com/open-isa-org/open-isa.org/releases/download/1.0.0/rv32m1_sdk_riscv_installer.sh > rv32m1_sdk_riscv_installer.sh
# Convert SDK shell script into the tar file -- this implictly accepts the license and extract to ./vega
ARCHIVE=$(awk '/^__ARCHIVE__/ {print NR + 1; exit 0; }' "rv32m1_sdk_riscv_installer.sh")
tail -n+${ARCHIVE} "rv32m1_sdk_riscv_installer.sh" | tar -xz > /dev/null 2>&1 || true
mkdir vega
(cd vega && tar xf ../rv32m1_sdk_riscv.tar.gz)

curl -L https://github.com/open-isa-org/open-isa.org/releases/download/1.0.0/Toolchain_Linux.tar.gz > Toolchain_Linux.tar.gz
# Extract toolchain, takes two steps as there are archives in Toolchain_Linux.tar.gz)
mkdir toolchain
pushd toolchain
tar xf ../Toolchain_Linux.tar.gz # this makes tar files for next lines
tar xf riscv32-unknown-elf-gcc.tar.gz
rm riscv32-unknown-elf-gcc.tar.gz
tar xf openocd.tar.gz
rm openocd.tar.gz
popd

#--- 
echo "Installing Eclipse-IDE and MCU plugins"; echo""
curl -L https://github.com/gnu-mcu-eclipse/org.eclipse.epp.packages/releases/download/v4.5.1-20190101-2018-12/20190101-2023-gnumcueclipse-4.5.1-2018-12-R-linux.gtk.x86_64.tar.gz > 20190101-2023-gnumcueclipse-4.5.1-2018-12-R-linux.gtk.x86_64.tar.gz
curl -L https://github.com/riscv/riscv-ovpsim/archive/master.zip > riscv-ovpsim-master.zip
# Extract eclipse that includes GNU MCU plugins, eclipse executable will be ./eclipse/eclipse
tar xf 20190101-2023-gnumcueclipse-4.5.1-2018-12-R-linux.gtk.x86_64.tar.gz

# Set the toolchain defaults for GNU MCU plug-ins to what we just "installed"
mkdir -p eclipse/configuration/.settings/
# openocd location
echo "eclipse.preferences.version=1" > eclipse/configuration/.settings/ilg.gnumcueclipse.debug.gdbjtag.openocd.prefs 
echo "install.folder=$PWD/toolchain" >> eclipse/configuration/.settings/ilg.gnumcueclipse.debug.gdbjtag.openocd.prefs 
# gcc & friends location
echo "eclipse.preferences.version=1" > eclipse/configuration/.settings/ilg.gnumcueclipse.managedbuild.cross.riscv.prefs 
# (magic number comes from https://github.com/gnu-mcu-eclipse/eclipse-plugins/blob/ce601cf2ec20cba90d9f2c2fbdb236b5fd7a6385/bundles/ilg.gnumcueclipse.managedbuild.cross.riscv/src/ilg/gnumcueclipse/managedbuild/cross/riscv/ToolchainDefinition.java#L30)
echo "toolchain.path.512258282=$PWD/toolchain/riscv32-unknown-elf-gcc/bin" >> eclipse/configuration/.settings/ilg.gnumcueclipse.managedbuild.cross.riscv.prefs

# Setup RISC-V OVP Simulator
unzip riscv-ovpsim-master.zip
mv riscv-ovpsim-master riscv-ovpsim

# Optional, comment to preserve downloads
cd ~
rm rv32m1_sdk_riscv.tar.gz 20190101-2023-gnumcueclipse-4.5.1-2018-12-R-linux.gtk.x86_64.tar.gz rv32m1_sdk_riscv_installer.sh Toolchain_Linux.tar.gz riscv-ovpsim-master.zip