This repository was archived by the owner on Aug 27, 2018. It is now read-only.
forked from timvideos/HDMI2USB-litex-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenter-env.sh
executable file
·360 lines (260 loc) · 8.08 KB
/
enter-env.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
#!/bin/bash
if [ "`whoami`" = "root" ]
then
echo "Running the script as root is not permitted"
exit 1
fi
CALLED=$_
[[ "${BASH_SOURCE[0]}" != "${0}" ]] && SOURCED=1 || SOURCED=0
SETUP_SRC="$(realpath ${BASH_SOURCE[0]})"
SETUP_DIR="$(dirname "${SETUP_SRC}")"
TOP_DIR="$(realpath "${SETUP_DIR}/..")"
if [ $SOURCED = 0 ]; then
echo "You must source this script, rather than try and run it."
echo ". $SETUP_SRC"
exit 1
fi
if [ ! -z "$HDMI2USB_ENV" ]; then
echo "Already sourced this file."
return 1
fi
if [ ! -z "$SETTINGS_FILE" -o ! -z "$XILINX" ]; then
echo "You appear to have sourced the Xilinx ISE settings, these are incompatible with building."
echo "Please exit this terminal and run again from a clean shell."
return 1
fi
# Conda does not support ' ' in the path (it bails early).
if echo "${SETUP_DIR}" | grep -q ' '; then
echo "You appear to have whitespace characters in the path to this script."
echo "Please move this repository to another path that does not contain whitespace."
exit 1
fi
# Conda does not support ':' in the path (it fails to install python).
if echo "${SETUP_DIR}" | grep -q ':'; then
echo "You appear to have ':' characters in the path to this script."
echo "Please move this repository to another path that does not contain this character."
exit 1
fi
# Check ixo-usb-jtag *isn't* installed
if [ -e /lib/udev/rules.d/85-ixo-usb-jtag.rules ]; then
echo "Please uninstall ixo-usb-jtag package from the timvideos PPA, the"
echo "required firmware is included in the HDMI2USB modeswitch tool."
echo
echo "On Debian/Ubuntu run:"
echo " sudo apt-get remove ixo-usb-jtag"
echo
return 1
fi
if [ -f /etc/udev/rules.d/99-hdmi2usb-permissions.rules -o -f /lib/udev/rules.d/99-hdmi2usb-permissions.rules -o -f /lib/udev/rules.d/60-hdmi2usb-udev.rules -o ! -z "$HDMI2USB_UDEV_IGNORE" ]; then
true
else
echo "Please install the HDMI2USB udev rules."
echo "These are installed by scripts/download-env-root.sh"
echo
return 1
fi
. $SETUP_DIR/settings.sh
echo " This script is: $SETUP_SRC"
echo " Firmware directory: $TOP_DIR"
echo " Build directory is: $BUILD_DIR"
echo " 3rd party directory is: $THIRD_DIR"
# Check the build dir
if [ ! -d $BUILD_DIR ]; then
echo "Build directory not found!"
return 1
fi
XILINX_SETTINGS_ISE='/opt/Xilinx/*/ISE_DS/settings64.sh'
XILINX_SETTINGS_VIVADO='/opt/Xilinx/Vivado/*/settings64.sh'
if [ -z "$XILINX_DIR" ]; then
LOCAL_XILINX_DIR=$BUILD_DIR/Xilinx
if [ -d "$LOCAL_XILINX_DIR/opt/Xilinx/" ]; then
# Reserved MAC address from documentation block, see
# http://www.iana.org/assignments/ethernet-numbers/ethernet-numbers.xhtml
export LIKELY_XILINX_LICENSE_DIR=$LOCAL_XILINX_DIR
export MACADDR=90:10:00:00:00:01
#export LD_PRELOAD=$XILINX_DIR/impersonate_macaddress/impersonate_macaddress.so
#ls -l $LD_PRELOAD
export XILINX_DIR=$LOCAL_XILINX_DIR
export XILINX_LOCAL_USER_DATA=no
fi
fi
if [ -z "$LIKELY_XILINX_LICENSE_DIR" ]; then
LIKELY_XILINX_LICENSE_DIR="$HOME/.Xilinx"
fi
# Find Xilinx toolchain versions...
shopt -s nullglob
XILINX_SETTINGS_ISE=($XILINX_DIR/$XILINX_SETTINGS_ISE)
XILINX_SETTINGS_VIVADO=($XILINX_DIR/$XILINX_SETTINGS_VIVADO)
shopt -u nullglob
# Tell user what we found...
echo " Xilinx directory is: $XILINX_DIR/opt/Xilinx/"
if [ ${#XILINX_SETTINGS_ISE[@]} -gt 0 ]; then
echo -n " - Xilinx ISE toolchain found!"
if [ ${#XILINX_SETTINGS_ISE[@]} -gt 1 ]; then
echo -n " (${#XILINX_SETTINGS_ISE[@]} versions)"
fi
echo ""
export HAVE_XILINX_ISE=1
else
export HAVE_XILINX_ISE=0
fi
if [ ${#XILINX_SETTINGS_VIVADO[@]} -gt 0 ]; then
echo -n " - Xilinx Vivado toolchain found!"
if [ ${#XILINX_SETTINGS_VIVADO[@]} -gt 1 ]; then
echo -n " (${#XILINX_SETTINGS_VIVADO[@]} versions)"
fi
echo ""
export HAVE_XILINX_VIVADO=1
else
export HAVE_XILINX_VIVADO=0
fi
if [ $HAVE_XILINX_ISE -eq 1 -o $HAVE_XILINX_VIVADO -eq 1 ]; then
export HAVE_XILINX_TOOLCHAIN=1
else
export HAVE_XILINX_TOOLCHAIN=0
fi
if [ $HAVE_XILINX_TOOLCHAIN -eq 1 ]; then
export MISOC_EXTRA_CMDLINE="-Ob toolchain_path $XILINX_DIR/opt/Xilinx/"
fi
# Detect a likely lack of license early, but just warn if it's missing
# just in case they've set it up elsewhere.
if [ ! -e $LIKELY_XILINX_LICENSE_DIR/Xilinx.lic ]; then
echo "(WARNING) Please ensure you have installed Xilinx and have a license."
echo "(WARNING) Copy your Xilinx license to Xilinx.lic in $LIKELY_XILINX_LICENSE_DIR to suppress this warning."
else
echo " Xilinx license in: $LIKELY_XILINX_LICENSE_DIR"
export XILINXD_LICENSE_FILE=$LIKELY_XILINX_LICENSE_DIR
fi
function check_exists {
TOOL=$1
if which $TOOL >/dev/null; then
echo "$TOOL found at $(which $TOOL)"
return 0
else
echo "$TOOL *NOT* found"
echo "Please try running the $SETUP_DIR/download-env.sh script again."
return 1
fi
}
function check_version {
TOOL=$1
VERSION=$2
if $TOOL --version 2>&1 | grep -q $VERSION > /dev/null; then
echo "$TOOL found at $VERSION"
return 0
else
$TOOL --version
echo "$TOOL (version $VERSION) *NOT* found"
echo "Please try running the $SETUP_DIR/download-env.sh script again."
return 1
fi
}
function check_import {
MODULE=$1
if python3 -c "import $MODULE"; then
echo "$MODULE found"
return 0
else
echo "$MODULE *NOT* found!"
echo "Please try running the $SETUP_DIR/download-env.sh script again."
return 1
fi
}
function check_import_version {
MODULE=$1
EXPECT_VERSION=$2
ACTUAL_VERSION=$(python3 -c "import $MODULE; print($MODULE.__version__)")
if echo "$ACTUAL_VERSION" | grep -q $EXPECT_VERSION > /dev/null; then
echo "$MODULE found at $ACTUAL_VERSION"
return 0
else
echo "$MODULE (version $EXPECT_VERSION) *NOT* found!"
echo "Please try running the $SETUP_DIR/download-env.sh script again."
return 1
fi
}
echo ""
echo "Checking environment"
echo "---------------------------------"
# Install and setup conda for downloading packages
export PATH=$CONDA_DIR/bin:$PATH:/sbin
eval $(cd $TOP_DIR; export HDMI2USB_ENV=1; make env || return 1) || return 1
(
cd $TOP_DIR
export HDMI2USB_ENV=1
make info || return 1
echo
) || return 1
# Check the Python version
check_version python 3.6 || return 1
echo ""
echo "Checking binaries in environment"
echo "---------------------------------"
# fxload
if [ "$PLATFORM" == "opsis" -o "$PLATFORM" == "atlys" ]; then
check_exists fxload || return 1
fi
# FIXME: Remove this once @jimmo has finished his new firmware
# MimasV2Config.py
if [ "$PLATFORM" == "mimasv2" ]; then
MIMASV2CONFIG=$BUILD_DIR/conda/bin/MimasV2Config.py
check_exists MimasV2Config.py || return 1
fi
# flterm
check_exists flterm || return 1
# binutils for the target
check_version ${CPU}-elf-ld $BINUTILS_VERSION || return 1
# gcc for the target
check_version ${CPU}-elf-gcc $GCC_VERSION || return 1
# gdb for the target
#
#
#
#check_version ${CPU}-elf-gdb $GDB_VERSION
# openocd for programming via Cypress FX2
check_version openocd $OPENOCD_VERSION || return 1
echo ""
echo "Checking Python modules in environment"
echo "---------------------------------------"
# pyserial for communicating via uarts
check_import serial || return 1
# ipython for interactive debugging
check_import IPython || return 1
# progressbar2 for progress bars
check_import progressbar || return 1
# colorama for progress bars
check_import colorama || return 1
# hexfile for embedding the Cypress FX2 firmware.
check_import_version hexfile $HEXFILE_VERSION || return 1
# Tool for changing the mode (JTAG/Serial/etc) of HDMI2USB boards
check_import_version hdmi2usb.modeswitch $HDMI2USB_MODESWITCH_VERSION || return 1
# git commands
echo ""
echo "Checking git submodules"
echo "-----------------------"
(
cd $TOP_DIR
git submodule status --recursive
)
# lite
for LITE in $LITE_REPOS; do
check_import $LITE || return 1
done
echo "-----------------------"
echo ""
alias python=python3
export HDMI2USB_ENV=1
# Set prompt
ORIG_PS1="$PS1"
litex_buildenv_prompt() {
P="$(cd $TOP_DIR; make prompt)"
PS1="(LX $P) $ORIG_PS1"
case "$TERM" in
xterm*|rxvt*)
PS1="$PS1\[\033]0;($P) \w\007\]"
;;
*)
;;
esac
}
PROMPT_COMMAND="litex_buildenv_prompt; ${PROMPT_COMMAND}"