-
Notifications
You must be signed in to change notification settings - Fork 11
/
init.sh
228 lines (199 loc) · 5.89 KB
/
init.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
#!/usr/bin/env bash
# Given the Xilinx FPGA part number, this finds the appropriate FPGA family,
# which is appended to the provided configFile
find_family () {
configFile=$1
part=$2
FPGA_family="${part:2:1}"
if [[ $FPGA_family == 'k' ]]; then
FPGA_family='Kintex'
elif [[ $FPGA_family == 'v' ]]; then
FPGA_family='Virtex'
elif [[ $FPGA_family == '7' ]]; then
FPGA_family='7series'
else
FPGA_family="${part:2:2}"
if [[ $FPGA_family != 'zu' ]]; then
return 1
fi
fi
if [[ $FPGA_family == '7series' ]]; then
FPGA_type="${part:3:1}"
if [[ $FPGA_type == 'k' ]]; then
FPGA_type='Kintex'
elif [[ $FPGA_type == 'v' ]]; then
FPGA_type='Virtex'
elif [[ $FPGA_type == 'z' ]]; then
FPGA_type='Zynq'
else
return 2
fi
else
FPGA_type="${part%%-*}"
FPGA_type="${FPGA_type: -1}"
if [[ $FPGA_type == 'p' ]]; then
FPGA_type='Ultrascale_Plus'
else
FPGA_type='Ultrascale'
fi
fi
if [[ $FPGA_family == 'zu' ]]; then
Solution='Zynq_Ultrascale_Plus'
else
Solution=${FPGA_family}_${FPGA_type}
fi
echo "export GALAPAGOS_PART_FAMILY=$Solution" >> $configFile
return 0
}
if [[ "$#" != 1 && "$#" != 5 && "$#" != 7 && "$#" != 8 ]]; then
echo "5,7 or 8 arguments expected, got $#"
echo "Usage: init.sh /abs/path/to/galapagos/repository /abs/path/to/vivado /abs/path/to/vivado_hls vivado_version vivado_hls_version [part name] [board] [board name]"
echo "Usage: source init.sh OPERATION"
return 1
fi
if [[ "$#" != 1 ]]; then
repoPath=$(readlink -f "$1")
vivadoPath=$(readlink -f "$2")
hlsPath=$(readlink -f "$3")
vivadoVersion=$4
hlsVersion=$5
if [[ "$#" > 5 ]]; then
part=$6
board_name=$7
fi
if [[ "$#" > 7 ]]; then
board=$8
fi
else
operation=$1
fi
# TODO prefix all "shells" with galapagos_
configFile=~/.galapagos
if [[ "$#" == 1 ]]; then
if [[ $operation == "switch" ]]; then
unset "${!GALAPAGOS@}"
sed -i '/# added by galapagos/s/^/#/' ~/.bashrc
sed -i '/# added by shells/s/^#//' ~/.bashrc
source $configFile
return 0
else
echo "Unknown operation: $operation"
return 1
fi
fi
if [[ -f $configFile ]]; then
echo "Updating galapagos initialization..."
unset GALAPAGOS_BOARD
rm $configFile
fi
# TODO make versions into a list and print supported versions on 'else' path
if [[ $hlsVersion == "2017.2" ]]; then
hlsPath_append=$hlsPath/$hlsVersion
elif [[ $hlsVersion == "2017.4" ]]; then
hlsPath_append=$hlsPath/$hlsVersion
elif [[ $hlsVersion == "2018.1" ]]; then
hlsPath_append=$hlsPath/$hlsVersion
elif [[ $hlsVersion == "2018.2" ]]; then
hlsPath_append=$hlsPath/$hlsVersion
elif [[ $hlsVersion == "2018.3" ]]; then
hlsPath_append=$hlsPath/$hlsVersion
elif [[ $hlsVersion == "2019.1" ]]; then
hlsPath_append=$hlsPath/$hlsVersion
else
echo "Error: unsupported Vivado HLS Version $hlsVersion"
return 1
fi
if [[ "$#" > 5 ]]; then
# https://stackoverflow.com/a/2264537
part=$(echo "$part" | tr '[:upper:]' '[:lower:]') # convert to lower-case
find_family $configFile $part
if [[ $? != 0 ]]; then
echo "Error $?: Unable to identify FPGA family from part $part"
return 1
fi
fi
vivadoPath_append=$vivadoPath/$vivadoVersion
{
echo "export GALAPAGOS_PATH=$repoPath"
echo "export GALAPAGOS_VIVADO_PATH=$vivadoPath_append"
echo "export GALAPAGOS_HLS_PATH=$hlsPath_append"
echo "export GALAPAGOS_VIVADO_VERSION=$vivadoVersion"
echo "export GALAPAGOS_HLS_VERSION=$hlsVersion"
} >> $configFile
if [[ "$#" > 5 ]]; then
echo "export GALAPAGOS_PART=$part" >> $configFile
echo "export GALAPAGOS_BOARD_NAME=$board_name" >> $configFile
fi
if [[ "$#" == 8 ]]; then
echo "export GALAPAGOS_BOARD=$board" >> $configFile
fi
# TODO print supported boards as help
cat >> $configFile <<EOF
galapagos-update-board() {
if [[ "\$#" != 1 || \$1 == '--h' || \$1 == '-help' ]]; then
echo "Usage: galapagos-update-board board"
return 1
fi
if [[ \$1 == "pynq-z2" ]]; then
partName=xc7z020clg400-1
board=tul.com.tw:pynq-z2:part0:1.0
elif [[ \$1 == "zedboard" ]]; then
partName=xc7z020clg484-1
board=em.avnet.com:zed:part0:1.3
elif [[ \$1 == "sidewinder" ]]; then
partName=xczu19eg-ffvc1760-2-i
board=fidus.com:sidewinder100:part0:1.0
elif [[ \$1 == "adm-8k5" ]]; then
partName=xcku115-flva1517-2-e
board="NULL"
elif [[ \$1 == "adm-8k5-debug" ]]; then
partName=xcku115-flva1517-2-e
board="NULL"
else
echo "Unknown board \$1 specified. No changes made to galapagos"
return 1
fi
boardName=\$1
if [[ \$board != "NULL" ]]; then
source \$GALAPAGOS_PATH/init.sh \\
\$GALAPAGOS_PATH \\
$vivadoPath \\
$hlsPath \\
\$GALAPAGOS_VIVADO_VERSION \\
\$GALAPAGOS_HLS_VERSION \\
\$partName \\
\$boardName \\
\$board
else
source \$GALAPAGOS_PATH/init.sh \\
\$GALAPAGOS_PATH \\
$vivadoPath \\
$hlsPath \\
\$GALAPAGOS_VIVADO_VERSION \\
\$GALAPAGOS_HLS_VERSION \\
\$partName \\
\$boardName
fi
}
galapagos-update-versions() {
if [[ "\$#" != 2 || \$1 == '--h' || \$1 == '-help' ]]; then
echo "Usage: galapagos-update-versions vivado_version vivado_hls_version"
return 1
fi
configFile=$configFile
vivadoPath=$vivadoPath
# replace only lines starting with GALAPAGOS_*
sed -i "/^export GALAPAGOS_VIVADO_VERSION=/ s/export GALAPAGOS_VIVADO_VERSION=.*/export GALAPAGOS_VIVADO_VERSION=\$1/" \$configFile
sed -i "/^export GALAPAGOS_HLS_VERSION=/ s/export GALAPAGOS_HLS_VERSION=.*/export GALAPAGOS_HLS_VERSION=\$2/" \$configFile
source \$configFile
export PATH=$vivadoPath_append/bin:$PATH
}
EOF
source $configFile
export PATH=$vivadoPath_append/bin:$PATH
# if it doesn't exist in the .bashrc, add it. Otherwise, uncomment it in case
if ! grep -Fq "# added by galapagos" ~/.bashrc; then
echo "source $configFile # added by galapagos" >> ~/.bashrc
else
sed -i '/# added by galapagos/s/^#//' ~/.bashrc
fi