forked from timvideos/HDMI2USB-litex-firmware
-
Notifications
You must be signed in to change notification settings - Fork 8
/
enter-env.sh
executable file
·535 lines (383 loc) · 11.9 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
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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
#!/bin/bash
if [ ! -n "$BASH_VERSION" ] ; then
echo "This script has to be sourced in bash"
return 1 2> /dev/null || exit 1
fi
if [ "`whoami`" = "root" ]
then
echo "Running the script as root is not permitted"
return 1 2> /dev/null || 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."
return 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."
return 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
# Figure out the cpu architecture
if [ -z "$CPU" ]; then
export CPU=vexriscv
fi
if [ "$CPU" = "lm32" ]; then
export CPU_ARCH=lm32
elif [ "$CPU" = "mor1kx" ]; then
export CPU_ARCH=or1k
elif [ "$CPU" = "vexriscv" -o "$CPU" = "picorv32" -o "$CPU" = "minerva" ]; then
export CPU_ARCH=riscv32
elif [ "$CPU" = "none" ]; then
export CPU_ARCH=$(gcc -dumpmachine)
else
echo
echo "Unknown CPU value '$CPU'. Valid values are;"
echo " * CPU='lm32' - LatticeMico"
echo " * CPU='mor1kx' - OpenRISC"
echo " * CPU='vexriscv' - RISC-V"
echo " * CPU='picorv32' - RISC-V"
echo " * CPU='minerva' - RISC-V"
echo " * CPU='none' - None or host CPU in use"
return 1
fi
if [ -z "${CPU_ARCH}" ]; then
echo "Internal error, no CPU_ARCH value found."
return 1
fi
# Figure out the PLATFORM value
PLATFORMS=$(ls ${TOP_DIR}/targets/ | grep -v ".py" | grep -v "common" | sed -e"s+targets/++")
if [ -z "$PLATFORM" -o ! -e ${TOP_DIR}/targets/$PLATFORM ]; then
echo
echo "Unknown platform '$PLATFORM'"
echo
echo "Valid platforms are:"
for PLATFORM in $PLATFORMS; do
echo " * $PLATFORM"
done
return 1
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 || exit 1) || return 1
(
cd $TOP_DIR
export HDMI2USB_ENV=1
make info || exit 1
echo
) || return 1
# Check the Python version
check_version python ${PYTHON_VERSION} || return 1
# FPGA toolchain
################################################
echo ""
echo "Checking FPGA toolchain"
echo "---------------------------------------"
PLATFORM_TOOLCHAIN=$(grep 'class Platform' $TOP_DIR/platforms/$PLATFORM.py | sed -e's/class Platform(//' -e's/Platform)://')
echo ""
echo "Platform Toolchain: $PLATFORM_TOOLCHAIN"
case $PLATFORM_TOOLCHAIN in
Xilinx)
if [ -z "$LIKELY_XILINX_LICENSE_DIR" ]; then
LIKELY_XILINX_LICENSE_DIR="$HOME/.Xilinx"
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
echo " - *No* Xilinx ISE toolchain found"
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
echo " - *No* Xilinx Vivado toolchain found!"
export HAVE_XILINX_VIVADO=0
fi
if [ $HAVE_XILINX_ISE -eq 1 -o $HAVE_XILINX_VIVADO -eq 1 ]; then
export HAVE_XILINX_TOOLCHAIN=1
export HAVE_FPGA_TOOLCHAIN=1
else
echo " - *No* Xilinx toolchain found!"
export HAVE_XILINX_TOOLCHAIN=0
export HAVE_FPGA_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
;;
Lattice)
export HAVE_FPGA_TOOLCHAIN=1
# yosys
check_exists yosys || return 1
# nextpnr
check_exists nextpnr-ice40 || return 1
;;
*)
;;
esac
# FPGA Programming tools
################################################
echo ""
echo "Checking programming tools in environment"
echo "-----------------------------------------"
# tinyfpga boards
if [ "$PLATFORM" = "tinyfpga_b2" ]; then
check_exists tinyfpgab || return 1
fi
if [ "$PLATFORM" = "tinyfpga_bx" ]; then
check_exists tinyprog || return 1
fi
# 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
# openocd for programming via Cypress FX2
check_version openocd $OPENOCD_VERSION || return 1
# C compiler toolchain
################################################
echo ""
echo "Checking C compiler toolchain"
echo "---------------------------------------"
# binutils for the target
check_version ${CPU_ARCH}-elf-ld $BINUTILS_VERSION || return 1
# gcc for the target
check_version ${CPU_ARCH}-elf-gcc $GCC_VERSION || return 1
# gdb for the target
#
#
#
#check_version ${CPU_ARCH}-elf-gdb $GDB_VERSION
# Zephyr SDK
################################################
if [ "$FIRMWARE" = "zephyr" ]; then
SCRIPT_NAME="zephyr-sdk-$ZEPHYR_SDK_VERSION-setup.run"
LOCAL_LOCATION="$BUILD_DIR/zephyr_sdk"
DETECTED_SDK_LOCATION=""
for DIR in "$LOCAL_LOCATION" "$ZEPHYR_SDK_INSTALL_DIR"; do
if [ -d "$DIR" ]; then
cat "$DIR/sdk_version" | grep -q $ZEPHYR_SDK_VERSION && DETECTED_SDK_LOCATION="$DIR"
fi
done
echo
if [ -d "$DETECTED_SDK_LOCATION" ]; then
true
else
echo "Zephyr SDK not found. Please run download-env.sh"
return 1
fi
fi
# Python modules
################################################
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
if [ "$FIRMWARE" = "zephyr" ]; then
# yaml for parsing configuration in Zephyr SDK
check_import yaml || return 1
# gperf for Zephyr SDK
check_exists gperf || return 1
# ninja for Zephyr SDK
check_exists ninja || return 1
# elftools for Zephyr SDK
check_import elftools || return 1
# west tool for building Zephyr
check_import west || return 1
# pykwalify for building Zephyr
check_import pykwalify.core || return 1
# cmake for building Zephyr
check_version cmake $CMAKE_VERSION || return 1
fi
# 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}"