-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqp_jtag
executable file
·236 lines (211 loc) · 6.52 KB
/
qp_jtag
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
#!/usr/bin/env bash
#
# Programming with Quartus Prime Programmer via JTAG
#
# This script launches Intel Quartus Prime Programmer to program 'sof' or 'jic' file via JTAG.
# Program files are searched for in the current directory or given as an argument.
#
# NOTE: jtagconfig.exe -n -- for describe current status information
#
# TODO: add handler for error: Error (213019): Can't scan JTAG chain. Error code 87.
# for example latch command: 'jtagconfig.exe'
#
# NOTE: if there is a need to choose the cable name then for greater speed you should use
# setting the environment variable QP_CABLE_NAME instead of set cable index because to get
# index is used command 'jtagconfig' which will took for a awhile
# Time-stamp: <2024-01-29 10:47:14>
echo "+------------------------------------------------------------------------+"
echo "| Quartus Prime Programmer ( JTAG ) |"
echo "+------------------------------------------------------------------------+"
read_yesno () {
while :
do
echo "$* (y/n)?"
read -r yn
case $yn in
y|Y|yes|Yes|YES)
return 0
;;
n|N|no|No|NO)
return 1
;;
*)
echo Please answer Yes or No.
;;
esac
done
}
usage() {
SCRIPT_NAME="${BASH_SOURCE##*/}"
echo "Usage:"
echo " $SCRIPT_NAME [-1..9|-c=1..9] [-a|--auto] [prg-file-name] "
echo ""
echo "ARGS:"
echo " <prg-file-name>"
echo " File name for programming."
echo "OPTIONS:"
echo " -1..9|-c=1..9"
echo " Cable index from 'jtagconfig' (or qp_jtag_info script)."
echo " -a|--auto"
echo " Automatic programming start if only one file is find."
echo " -v|--verbosity"
echo " Enable verbosity output message."
echo "Examples:"
echo " $SCRIPT_NAME"
echo " $SCRIPT_NAME path/project.sof"
echo " $SCRIPT_NAME -2 path/project.sof"
echo " $SCRIPT_NAME path/project.sof -1"
echo " export QP_CABLE_NAME=USB-Blaster[USB-0] # set environment variable for Bash."
}
if [ "$#" -gt 3 ] || [ "$1" == '-h' ] || [ "$1" == '--help' ] || [ "$1" == '-help' ]; then
usage
exit 0
fi
# Cable name
CNAME=""
get_cable_name () {
index="$1"
if ! hash jtagconfig 2>/dev/null; then
echo "ERROR! 'jtagconfig' was not found in PATH!"
exit 4
fi
IFS=$'\n' cable_arr=($(jtagconfig | sed -n 's/^[0-9]\+)\s\+// p'))
RC=$?
if [ "$RC" != 0 ]; then
echo "ERROR! Error during launch 'jtagconfig'!"
exit 5
fi
ARR_SIZE=${#cable_arr[@]}
if [ "$ARR_SIZE" -eq 0 ]; then
echo "ERROR! Can not find JTAG cable!"
exit 6
fi
# FIXME: remove index decrement
((index--)) # 'jtagconfig' return list from '1'; cable_arr begin from '0'
if [ "$index" -gt "$ARR_SIZE" ] || [ "$index" -lt 0 ]; then
echo "ERROR! Wrong cable index specified! See 'jtagconfig'."
echo ""
usage
exit 7
fi
CNAME="${cable_arr[$index]}"
}
ARG1=$(echo "$1" | sed -n "s/^-\(c=\)\?\([0-9]\{1,2\}\)$/\2/ p")
ARG2=$(echo "$2" | sed -n "s/^-\(c=\)\?\([0-9]\{1,2\}\)$/\2/ p")
ARG3=$(echo "$3" | sed -n "s/^-\(c=\)\?\([0-9]\{1,2\}\)$/\2/ p")
ARG4=$(echo "$4" | sed -n "s/^-\(c=\)\?\([0-9]\{1,2\}\)$/\2/ p")
if [ -n "$ARG1" ]; then
get_cable_name "$ARG1"
elif [ -n "$ARG2" ]; then
get_cable_name "$ARG2"
elif [ -n "$ARG3" ]; then
get_cable_name "$ARG3"
elif [ -n "$ARG4" ]; then
get_cable_name "$ARG4"
elif [ -n "$QP_CABLE_NAME" ]; then
CNAME="$QP_CABLE_NAME"
fi
# File name
FNAME=""
if [ "$#" -eq 1 ] || [ "$#" -eq 2 ]; then
FNAME_ARG1="$1"
FNAME_ARG2="$2"
FNAME_ARG3="$3"
if [ -s "$1" ]; then
FNAME="$FNAME_ARG1"
elif [ -s "$2" ]; then
FNAME="$FNAME_ARG2"
elif [ -s "$3" ]; then
FNAME="$FNAME_ARG3"
elif [ -s "$4" ]; then
FNAME="$FNAME_ARG4"
fi
fi
get_file_name () {
IFS=$'\n' f_arr=($(find . -type f \( -name "*.sof" -o -name "*.jic" \)))
file_num=0
if [ ${#f_arr[@]} -gt 0 ]; then
echo " file(s) for programming:"
if [ ${#f_arr[@]} -eq 1 ]; then
file_num=0
echo "${f_arr[$file_num]}"
else
cnt=1
for i in "${f_arr[@]}"; do
echo "$cnt: $i"
((cnt++))
done
echo "Select file :"
read -r file_num
((file_num--))
fi
else
echo "ERROR! There must be at least one *.sof or *.jic file in dir: $(pwd)"
exit 2
fi
f_name="${f_arr[$file_num]}"
if [ ! -s "$f_name" ]; then
echo "ERROR! Can not open selected file!"
else
FNAME=$f_name
fi
}
# Automatic programming
AUTOPGM=0
if [ "$1" = "-a" ] || [ "$1" = "--auto" ] \
|| [ "$2" = "-a" ] || [ "$2" = "--auto" ] \
|| [ "$3" = "-a" ] || [ "$3" = "--auto" ] \
|| [ "$4" = "-a" ] || [ "$4" = "--auto" ]; then
AUTOPGM=1
fi
# if the path to the file is specified as script argument, programming is started without request
if [ -z "$FNAME" ]; then
get_file_name
if [ "$AUTOPGM" -eq 0 ]; then
if ! read_yesno "Would you like load file: $FNAME" ; then
echo "Exit without load!";
exit 0;
fi
fi
fi
# Verbosity
VERBOSITY=0
if [ "$1" = "-v" ] || [ "$1" = "--verbosity" ] \
|| [ "$2" = "-v" ] || [ "$2" = "--verbosity" ] \
|| [ "$3" = "-v" ] || [ "$3" = "--verbosity" ] \
|| [ "$4" = "-v" ] || [ "$4" = "--verbosity" ]; then
VERBOSITY=1
fi
FTIME=$(date +%c -r "$FNAME")
echo "File: $FNAME ($FTIME)"
echo "Started Programmer operation ..."
if [ "$VERBOSITY" -eq 1 ]; then
if [[ "$f_name" == *.jic ]]; then
# Blank-checking device(s), Performing CRC verification on device(s)
echo quartus_pgm -c "$CNAME" -m jtag -o pvbi\;"$FNAME"
else
echo quartus_pgm -c "$CNAME" -m jtag -o p\;"$FNAME"
fi
fi
if [[ "$f_name" == *.jic ]]; then
# Blank-checking device(s), Performing CRC verification on device(s)
quartus_pgm -c "$CNAME" -m jtag -o pvbi\;"$FNAME"
else
quartus_pgm -c "$CNAME" -m jtag -o p\;"$FNAME"
fi
RC=$?
RED="\e[31m\e[1m"
GREEN="\e[32m\e[1m"
NORMAL="\e[0m"
if [ "$RC" != 0 ]; then
printf "${RED}Programming Error!${NORMAL}\n"
else
printf "${GREEN}Programming successful!${NORMAL}\n"
fi
exit "$RC"
# This is for the sake of Emacs.
# Local Variables:
# time-stamp-end: "$"
# time-stamp-format: "<%:y-%02m-%02d %02H:%02M:%02S>"
# time-stamp-start: "Time-stamp: "
# End: