This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build-spike.sh
executable file
·286 lines (223 loc) · 5.99 KB
/
build-spike.sh
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/bin/bash
# Check we have verilator
if ! test $(which verilator)
then
echo "ERROR: verilator required for building the GDB Server"
exit 1
fi
if ! test $(which dtc)
then
echo "ERROR: device-tree-compiler (dtc) required to build SPIKE"
exit 1
fi
TOOLCHAIN_DIR=$(cd "`dirname \"$0\"`"; pwd)
TOP=$(cd ${TOOLCHAIN_DIR}/..; pwd)
# ====================================================================
WITH_TARGET=riscv32-unknown-elf
WITH_ARCH=rv32i
CLEAN_BUILD=no
DEBUG_BUILD=no
BUILD_DIR=${TOP}/build
INSTALL_DIR=${TOP}/install
VERILATOR_DIR=`pkg-config --variable=prefix verilator`
SPIKE_SRC_DIR=${TOP}/riscv-isa-sim
JOBS=
LOAD=
# ====================================================================
function usage () {
MSG=$1
echo "${MSG}"
echo
echo "Usage: ./build-targets.sh [--build-dir <build_dir>]"
echo " [--install-dir <install_dir>]"
echo " [--jobs <count>] [--load <load>]"
echo " [--spike-source <source_dir>]"
echo " [--single-thread]"
echo " [--clean]"
echo " [--debug]"
echo " [--with-target <target>]"
echo " [--with-arch <arch>]"
echo
echo "Defaults:"
echo " --with-target riscv32-unknown-elf"
echo " --with-arch rv32ima"
exit 1
}
# Parse options
until
opt=$1
case ${opt} in
--build-dir)
shift
BUILD_DIR=$(realpath -m $1)
;;
--install-dir)
shift
INSTALL_DIR=$(realpath -m $1)
;;
--jobs)
shift
JOBS=$1
;;
--load)
shift
LOAD=$1
;;
--spike-source)
shift
spike_src_dir=$1
;;
--single-thread)
JOBS=1
LOAD=1000
;;
--clean)
CLEAN_BUILD=yes
;;
--debug)
DEBUG_BUILD=yes
;;
--with-target)
shift
WITH_TARGET=$1
;;
--with-arch)
shift
WITH_ARCH=$1
;;
?*)
usage "Unknown argument $1"
;;
*)
;;
esac
[ "x${opt}" = "x" ]
do
shift
done
set -u
# ====================================================================
FESVR_BUILD_DIR=${BUILD_DIR}/riscv-fesvr
PK_BUILD_DIR=${BUILD_DIR}/riscv-pk
SPIKE_BUILD_DIR=${BUILD_DIR}/riscv-isa-sim
echo " Top: ${TOP}"
echo " Toolchain: ${TOOLCHAIN_DIR}"
echo " Build Dir: ${BUILD_DIR}"
echo " Install Dir: ${INSTALL_DIR}"
echo " SPIKE Build Dir: ${SPIKE_BUILD_DIR}"
echo " SPIKE Source Dir: ${SPIKE_SRC_DIR}"
if [ "x${CLEAN_BUILD}" = "xyes" ]
then
for T in `seq 5 -1 1`
do
echo -ne "\rClean Build: yes (in ${T} seconds)"
sleep 1
done
echo -e "\rClean Build: yes "
rm -fr ${SPIKE_BUILD_DIR}
else
echo "Clean Build: no"
fi
if [ "x${DEBUG_BUILD}" = "xyes" ]
then
export CFLAGS="-g3 -O0"
export CXXFLAGS="-g3 -O0"
fi
# Default parallellism
processor_count="`(echo processor; cat /proc/cpuinfo 2>/dev/null echo processor) \
| grep -c processor`"
if [ "x${JOBS}" == "x" ]; then JOBS=${processor_count}; fi
if [ "x${LOAD}" == "x" ]; then LOAD=${processor_count}; fi
PARALLEL="-j ${JOBS} -l ${LOAD}"
JOB_START_TIME=
JOB_TITLE=
SCRIPT_START_TIME=`date +%s`
LOGDIR=${TOP}/logs
LOGFILE=${LOGDIR}/build-$(date +%F-%H%M).log
echo " Log file: ${LOGFILE}"
echo " Start at: "`date`
echo " Parallel: ${PARALLEL}"
echo ""
rm -f ${LOGFILE}
if ! mkdir -p ${LOGDIR}
then
echo "Failed to create log directory: ${LOGDIR}"
exit 1
fi
if ! touch ${LOGFILE}
then
echo "Failed to initialise logfile: ${LOGFILE}"
exit 1
fi
# ====================================================================
# Defines: msg, error, times_to_time_string, job_start, job_done,
# mkdir_and_enter, enter_dir, run_command
#
# Requires LOGFILE and SCRIPT_START_TIME environment variables to be
# set.
source common.sh
# ====================================================================
# Add Binutils and GCC to path to build newlib
export PATH=${INSTALL_DIR}/bin:$PATH
# ====================================================================
# Build and Install RISC-V Front-End Server (fesvr)
# ====================================================================
job_start "Building fesvr (RISC-V Front-End Server used by SPIKE)"
mkdir_and_enter ${FESVR_BUILD_DIR}
if ! run_command ${TOP}/riscv-fesvr/configure \
--prefix=${INSTALL_DIR}
then
error "Failed to configure fesvr"
fi
if ! run_command make install
then
error "Failed to build and install fesvr"
fi
job_done
# ====================================================================
# Build and Install RISC-V Proxy Kernel (pk)
# ====================================================================
job_start "Building pk (RISC-V Proxy Kernel used by SPIKE)"
mkdir_and_enter ${PK_BUILD_DIR}
if ! run_command ${TOP}/riscv-pk/configure \
--prefix=${INSTALL_DIR} \
--host=${WITH_TARGET}
then
error "Failed to configure pk"
fi
if ! run_command make
then
error "Failed to build pk"
fi
if ! run_command make install
then
error "Failed to install pk"
fi
job_done
# ====================================================================
# Build and Install RISC-V ISA Simulator (SPIKE)
# ====================================================================
job_start "Building SPIKE (RISC-V ISA Simulator)"
mkdir_and_enter ${SPIKE_BUILD_DIR}
if ! run_command ${SPIKE_SRC_DIR}/configure \
--prefix=${INSTALL_DIR} \
--with-fesvr=${INSTALL_DIR} \
--with-isa=${WITH_ARCH}
then
error "Failed to configure SPIKE"
fi
if ! run_command make
then
error "Failed to build SPIKE"
fi
if ! run_command make install
then
error "Failed to install SPIKE"
fi
job_done
# ====================================================================
# Finished
# ====================================================================
SCRIPT_END_TIME=`date +%s`
TIME_STR=`times_to_time_string ${SCRIPT_START_TIME} ${SCRIPT_END_TIME}`
echo "All finished ${TIME_STR}." | tee -a ${LOGFILE}