-
Notifications
You must be signed in to change notification settings - Fork 48
/
summon-fpga-tools.sh
executable file
·458 lines (404 loc) · 13 KB
/
summon-fpga-tools.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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
#!/bin/bash
#
# Summon FPGA Tools build script
# Written by Piotr Esden-Tempski <[email protected]>, released as public domain.
#
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication along
# with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
#
# TODO: this should be automatically detected and the deps should be installed when needed.
#
# Requirements (example is for Debian, replace package names as needed):
#
# apt-get install flex bison libgmp3-dev libmpfr-dev libncurses5-dev \
# libmpc-dev autoconf texinfo build-essential libftdi-dev zlib1g-dev git \
# gperf
#
# Or on Ubuntu Maverick give `apt-get build-dep gcc-4.5` a try.
#
# brew install cmake python boost boost-python3 qt5 gperf
#
# Stop if any command fails
set -e
##############################################################################
# Default settings section
# You probably want to customize those
# You can also pass them as parameters to the script
##############################################################################
PREFIX=${HOME}/sft # Install location of your final fpga tools
# We do not support MacPorts only homebrew for the time being...
#DARWIN_OPT_PATH=/usr/local # Path in which MacPorts or Fink is installed
# Set to 'sudo' if you need superuser privileges while installing
SUDO=
# Set to 1 to be quieter while running
QUIET=0
# Set to 'master' or a git revision number to use instead of stable version
ICESTORM_EN=1
ICESTORM_GIT=master
ARACHNEPNR_EN=1
ARACHNEPNR_GIT=master
NEXTPNR_EN=1
NEXTPNR_GIT=master
YOSYS_EN=1
YOSYS_GIT=master
IVERILOG_EN=1
IVERILOG_GIT=v10-branch
# Override automatic detection of cpus to compile on
CPUS=
# FTP options ... some environments do not support non-passive FTP
# FETCH_NO_PASSIVE="--no-passive-ftp "
FETCH_NO_CERTCHECK="--no-check-certificate "
##############################################################################
# Parsing command line parameters
##############################################################################
while [ $# -gt 0 ]; do
case $1 in
PREFIX=*)
PREFIX=$(echo $1 | sed 's,^PREFIX=,,')
;;
SUDO=*)
SUDO=$(echo $1 | sed 's,^SUDO=,,')
;;
QUIET=*)
QUIET=$(echo $1 | sed 's,^QUIET=,,')
;;
ICESTORM_GIT=*)
ICESTORM_GIT=$(echo $1 | sed 's,^ICESTORM_GIT=,,')
;;
ARACHNEPNR_GIT=*)
ARACHNEPNR_GIT=$(echo $1 | sed 's,^ARACHNEPNR_GIT=,,')
;;
NEXTPNR_GIT=*)
NEXTPNR_GIT=$(echo $1 | sed 's,^NEXTPNR_GIT=,,')
;;
YOSYS_GIT=*)
YOSYS_GIT=$(echo $1 | sed 's,^YOSYS_GIT=,,')
;;
IVERILOG_GIT=*)
IVERILOG_GIT=$(echo $1 | sed 's,^IVERILOG_GIT=,,')
;;
CPUS=*)
CPUS=$(echo $1 | sed 's,^CPUS=,,')
;;
*)
echo "Unknown parameter: $1"
exit 1
;;
esac
shift # shifting parameter list to access the next one
done
##############################################################################
# Version and download url settings section
##############################################################################
DEFAULT_ICESTORM=
DEFAULT_ARACHNEPNR=
DEFAULT_NEXTPNR=
DEFAULT_YOSYS=yosys-0.8
DEFAULT_IVERILOG_VERSION=v10_2
DEFAULT_IVERILOG=iverilog-${DEFAULT_IVERILOG_VERSION}
ICESTORM=${ICESTORM:-${DEFAULT_ICESTORM}}
ARACHNEPNR=${ARACHNEPNR:-${DEFAULT_ARACHNEPNR}}
NEXTPNR=${NEXTPNR:-${DEFAULT_NEXTPNR}}
YOSYS=${YOSYS:-${DEFAULT_YOSYS}}${IVERILOG}
IVERILOG_VERSION=${IVERILOG_VERSION:-${DEFAULT_IVERILOG_VERSION}}
IVERILOG=${IVERILOG:-${DEFAULT_IVERILOG}}
##############################################################################
# Print settings
##############################################################################
echo "Settings used for this build are:"
echo "PREFIX=$PREFIX"
echo "SUDO=$SUDO"
echo "QUIET=$QUIET"
echo "ICESTORM=$ICESTORM"
echo "ICESTORM_GIT=$ICESTORM_GIT"
echo "ARACHNEPNR=$ARACHNEPNR"
echo "ARACHNEPNR_GIT=$ARACHNEPNR_GIT"
echo "NEXTPNR=$NEXTPNR"
echo "NEXTPNR_GIT=$NEXTPNR_GIT"
echo "YOSYS=$YOSYS"
echo "YOSYS_GIT=$YOSYS_GIT"
echo "IVERILOG_VERSION=$IVERILOG_VERSION"
echo "IVERILOG=$IVERILOG"
echo "IVERILOG_GIT=$IVERILOG_GIT"
echo "CPUS=$CPUS"
##############################################################################
# Flags section
##############################################################################
if [ "x${CPUS}" == "x" ]; then
if which getconf > /dev/null; then
CPUS=$(getconf _NPROCESSORS_ONLN)
else
CPUS=1
fi
PARALLEL=-j$((CPUS + 1))
else
PARALLEL=-j${CPUS}
fi
echo "${CPUS} cpu's detected running make with '${PARALLEL}' flag"
ICESTORMFLAGS=
ARACHNEPNRFLAGS=
NEXTPNRFLAGS=
YOSYSFLAGS=
# Pull in the local configuration, if any
if [ -f local.sh ]; then
. ./local.sh
fi
MAKEFLAGS=${PARALLEL}
TARFLAGS=v
if [ ${QUIET} != 0 ]; then
TARFLAGS=
MAKEFLAGS="${MAKEFLAGS} -s"
fi
export PATH="${PREFIX}/bin:${PATH}"
SUMMON_DIR=$(pwd)
SOURCES=${SUMMON_DIR}/sources
STAMPS=${SUMMON_DIR}/stamps
##############################################################################
# Tool section
##############################################################################
TAR=tar
##############################################################################
# OS and Tooldetection section
# Detects which tools and flags to use
##############################################################################
case "$(uname)" in
Linux)
echo "Found Linux OS."
;;
Darwin)
echo "Found Darwin OS."
QT5_PREFIX="/usr/local/opt/qt5"
PATH="/usr/local/opt/bison/bin:$PATH"
LDFLAGS="-L/usr/local/opt/bison/lib"
;;
CYGWIN*)
echo "Found CygWin that means Windows most likely."
;;
*)
echo "Found unknown OS. Aborting!"
exit 1
;;
esac
##############################################################################
# Building section
# You probably don't have to touch anything after this
##############################################################################
##############################################################################
# Helper function definitions
##############################################################################
# Fetch a versioned file from a URL
function fetch {
if [ ! -e ${STAMPS}/$1.fetch ]; then
if [ ! -e ${SOURCES}/$1 ]; then
log "Downloading $1 sources..."
if [ "x$3" != "x" ]; then
wget -c ${FETCH_NO_PASSIVE} ${FETCH_NO_CERTCHECK} -O $3 $2 && touch ${STAMPS}/$1.fetch
else
wget -c ${FETCH_NO_PASSIVE} ${FETCH_NO_CERTCHECK} $2 && touch ${STAMPS}/$1.fetch
fi
fi
fi
}
function clone {
local NAME=$1
local GIT_REF=$2
local GIT_URL=$3
local POST_CLONE=$4
local GIT_SHA=$(git ls-remote ${GIT_URL} ${GIT_REF} | cut -f 1)
# It seems that the ref is actually a SHA as it could not be found through ls-remote
if [ "x${GIT_SHA}" == "x" ]; then
local GIT_SHA=${GIT_REF}
fi
# Setting uppercase NAME variable for future use to the source file name
eval $(echo ${NAME} | tr "[:lower:]" "[:upper:]")=${NAME}-${GIT_SHA}
# Clone the repository and do all necessary operations until we get an archive
if [ ! -e ${STAMPS}/${NAME}-${GIT_SHA}.fetch ]; then
# Making sure there is nothing in our way
if [ -e ${NAME}-${GIT_SHA} ]; then
log "The clone directory ${NAME}-${GIT_SHA} already exists, removing..."
rm -rf ${NAME}-${GIT_SHA}
fi
log "Cloning ${NAME}-${GIT_SHA} ..."
git clone ${GIT_URL} ${NAME}-${GIT_SHA}
cd ${NAME}-${GIT_SHA}
log "Checking out the revision ${GIT_REF} with the SHA ${GIT_SHA} ..."
git checkout -b sft-branch ${GIT_SHA}
if [ "x${POST_CLONE}" != "x" ]; then
log "Running post clone code for ${NAME}-${GIT_SHA} ..."
${POST_CLONE}
fi
log "Removing .git directory from ${NAME}-${GIT_SHA} ..."
rm -rf .git
cd ..
log "Generating source archive for ${NAME}-${GIT_SHA} ..."
tar cfj ${SOURCES}/${NAME}-${GIT_SHA}.tar.bz2 ${NAME}-${GIT_SHA}
rm -rf ${NAME}-${GIT_SHA}
touch ${STAMPS}/${NAME}-${GIT_SHA}.fetch
fi
}
# Log a message out to the console
function log {
echo "******************************************************************"
echo "* $*"
echo "******************************************************************"
}
# Unpack an archive
function unpack {
log Unpacking $*
# Use 'auto' mode decompression. Replace with a switch if tar doesn't support -a
ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
case ${ARCHIVE} in
*.bz2)
echo "archive type bz2"
TYPE=j
;;
*.gz)
echo "archive type gz"
TYPE=z
;;
*)
echo "Unknown archive type of $1"
echo ${ARCHIVE}
exit 1
;;
esac
${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
}
# Install a build
function install {
log $1
${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
}
##############################################################################
# Create directories
##############################################################################
mkdir -p ${STAMPS} ${SOURCES}
cd ${SOURCES}
##############################################################################
# Fetch sources
##############################################################################
if [ ${ICESTORM_EN} != 0 ]; then
if [ "x${ICESTORM_GIT}" == "x" ]; then
log "There is no icestorm stable release download server yet!"
exit 1
#fetch ${ICESTORM} https://github.com/cliffordwolf/icestorm/archive/${ICESTORM}.tar.bz2
else
clone icestorm ${ICESTORM_GIT} git://github.com/cliffordwolf/icestorm.git
fi
fi
if [ ${ARACHNEPNR_EN} != 0 ]; then
if [ "x${ARACHNEPNR_GIT}" == "x" ]; then
log "There is no arachne-pnr stable release download server yet!"
exit 1
#fetch ${ARACHNEPNR} https://github.com/YosysHQ/arachne-pnr/archive/${ARACHNEPNR}.tar.bz2
else
clone arachnepnr ${ARACHNEPNR_GIT} git://github.com/YosysHQ/arachne-pnr.git
fi
fi
if [ ${NEXTPNR_EN} != 0 ]; then
if [ "x${NEXTPNR_GIT}" == "x" ]; then
log "There is no arachne-pnr stable release download server yet!"
exit 1
#fetch ${NEXTPNR} https://github.com/YosysHQ/nextpnr/archive/${NEXTPNR}.tar.bz2
else
clone nextpnr ${NEXTPNR_GIT} git://github.com/YosysHQ/nextpnr.git
fi
fi
if [ ${YOSYS_EN} != 0 ]; then
if [ "x${YOSYS_GIT}" == "x" ]; then
fetch ${YOSYS} https://github.com/YosysHQ/yosys/archive/${YOSYS}.tar.gz
else
clone yosys ${YOSYS_GIT} git://github.com/YosysHQ/yosys.git
fi
fi
# if [ ${IVERILOG_EN} != 0 ]; then
# if [ "x${IVERILOG_GIT}" == "x" ]; then
# fetch ${IVERILOG} https://github.com/steveicarus/iverilog/archive/${IVERILOG_VERSION}.tar.gz ${IVERILOG}.tar.gz
# else
# clone iverilog ${IVERILOG_GIT} git://github.com/steveicarus/iverilog.git
# fi
# fi
##############################################################################
# Build tools
##############################################################################
cd ${SUMMON_DIR}
if [ ! -e build ]; then
mkdir build
fi
if [ ! -e ${STAMPS}/${ICESTORM}.build ]; then
unpack ${ICESTORM}
cd ${ICESTORM}
log "Building ${ICESTORM}"
make ${MAKEFLAGS} PREFIX=${PREFIX}
install ${ICESTORM} PREFIX=${PREFIX} install
cd ..
log "Cleaning up ${ICESTORM}"
touch ${STAMPS}/${ICESTORM}.build
rm -rf ${ICESTORM}
fi
if [ ! -e ${STAMPS}/${ARACHNEPNR}.build ]; then
unpack ${ARACHNEPNR}
cd ${ARACHNEPNR}
log "Building ${ARACHNEPNR}"
make ${MAKEFLAGS} PREFIX=${PREFIX}
install ${ARACHNEPNR} PREFIX=${PREFIX} install
cd ..
log "Cleaning up ${ARACHNEPNR}"
touch ${STAMPS}/${ARACHNEPNR}.build
rm -rf ${ARACHNEPNR}
fi
if [ ! -e ${STAMPS}/${NEXTPNR}.build ]; then
unpack ${NEXTPNR}
cd build
log "Configuring ${NEXTPNR}-ice40"
CMAKE_PREFIX_PATH=${QT5_PREFIX:-${QT5_PREFIX}/lib/cmake/Qt5}
cmake -DARCH=ice40 -DCMAKE_INSTALL_PREFIX=${PREFIX} \
-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} \
-DICEBOX_ROOT=${PREFIX}/share/icebox ../${NEXTPNR}
log "Building ${NEXTPNR}-ice40"
make ${MAKEFLAGS}
install ${NEXTPNR} install
cd ..
log "Cleaning up ${NEXTPNR}-ice40"
touch ${STAMPS}/${NEXTPNR}.build
rm -rf build/* ${NEXTPNR}
fi
if [ ! -e ${STAMPS}/${YOSYS}.build ]; then
unpack ${YOSYS}
if [ "x${YOSYS_GIT}" == "x" ]; then
cd yosys-${YOSYS}
else
cd ${YOSYS}
fi
log "Building ${YOSYS}"
make ${MAKEFLAGS} PREFIX=${PREFIX}
install ${YOSYS} PREFIX=${PREFIX} install
cd ..
log "Cleaning up ${YOSYS}"
touch ${STAMPS}/${YOSYS}.build
if [ "x${YOSYS_GIT}" == "x" ]; then
rm -rf yosys-${YOSYS}
else
rm -rf ${YOSYS}
fi
fi
# if [ ! -e ${STAMPS}/${IVERILOG}.build ]; then
# unpack ${IVERILOG}
# cd ${IVERILOG}
# log "Running autogen for ${IVERILOG}"
# sh ./autoconf.sh
# cd ../build
# log "Configuring ${IVERILOG}"
# ../${IVERILOG}/configure --prefix=${PREFIX}
# log "Building ${IVERILOG}"
# make ${MAKEFLAGS}
# install ${IVERILOG} install
# cd ..
# log "Cleaning up ${IVERILOG}"
# touch ${STAMPS}/${IVERILOG}.build
# rm -rf build/* ${IVERILOG}
# fi