-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqp_jtag_verify
executable file
·187 lines (166 loc) · 4.91 KB
/
qp_jtag_verify
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
#!/usr/bin/env bash
#
# Verifying with Quartus Prime Programmer via JTAG
#
# This script launches Intel Quartus Prime Programmer to program 'jic' file via JTAG.
# Verification files are searched 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:46:54>
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] [prg-file-name] "
echo ""
echo "ARGS:"
echo " <prg-file-name>"
echo " File name for verification."
echo "OPTIONS:"
echo " -1..9|-c=1..9"
echo " Cable index from 'jtagconfig'."
echo ""
echo "Examples:"
echo " $SCRIPT_NAME"
echo " $SCRIPT_NAME path/project.jic"
echo " $SCRIPT_NAME -2 path/project.jic"
echo " $SCRIPT_NAME path/project.jic -1"
echo " export QP_CABLE_NAME=USB-Blaster[USB-0] # set environment variable for Bash."
}
if [ "$#" -gt 2 ] || [ "$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")
if [ -n "$ARG1" ]; then
get_cable_name "$ARG1"
elif [ -n "$ARG2" ]; then
CINDEX="$ARG2"
get_cable_name "$ARG2"
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"
if [ -s "$1" ]; then
FNAME="$FNAME_ARG1"
elif [ -s "$2" ]; then
FNAME="$FNAME_ARG2"
fi
fi
get_file_name () {
IFS=$'\n' f_arr=($(find . -type f \( -name "*.jic" \)))
file_num=0
if [ ${#f_arr[@]} -gt 0 ]; then
echo " file(s) to check:"
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 *.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
}
# if the path to the file is specified as script argument, programming is started without request
if [ -z "$FNAME" ]; then
get_file_name
if ! read_yesno "Would you like verification with file: $FNAME" ; then
echo "Exit without load!";
exit 0;
fi
fi
FTIME=$(date +%c -r "$FNAME")
echo "Verification file: $FNAME $FTIME"
quartus_pgm -c "$CNAME" -m jtag -o v\;"$FNAME"
RC=$?
RED="\e[31m\e[1m"
GREEN="\e[32m\e[1m"
NORMAL="\e[0m"
if [ "$RC" != 0 ]; then
printf "${RED}Verification failed!${NORMAL}\n"
else
printf "${GREEN}Verification 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: