@@ -6,58 +6,59 @@ if [ $# -lt 4 ]; then
6
6
echo " Usage: $0 $# <dummy_port> <altID> <usbID> <binfile>" >&2
7
7
exit 1
8
8
fi
9
- altID=$2
10
- usbID=$3
11
- binfile=$4
9
+ altID=" $2 "
10
+ usbID=" $3 "
11
+ binfile=" $4 "
12
12
dummy_port_fullpath=" /dev/$1 "
13
+ if [ $# -eq 5 ]; then
14
+ dfuse_addr=" --dfuse-address $5 "
15
+ else
16
+ dfuse_addr=" "
17
+ fi
13
18
14
19
# Get the directory where the script is running.
15
20
DIR=$( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd)
16
21
17
- # ----------------- Old code to reset the USB - which doesn't seem to work --------
18
- #
19
- # if we can find the Serial device try resetting it and then sleeping for 1 sec while the board reboots
20
- # if [ -e $dummy_port_fullpath ]; then
21
- # echo "resetting " $dummy_port_fullpath
22
- # stty -f $dummy_port_fullpath 1200
23
- # sleep 1
24
- # # stty -f $dummy_port_fullpath 1200
25
- # # sleep 1
26
- # fi
27
- # ------------------ End of old code -----------------
28
-
29
22
# ----------------- IMPORTANT -----------------
30
23
# The 2nd parameter to upload-reset is the delay after resetting before it exits
31
24
# This value is in milliseonds
32
25
# You may need to tune this to your system
33
26
# 750ms to 1500ms seems to work on my Mac
27
+ # This is less critical now that we automatically retry dfu-util
34
28
35
- " ${DIR} " /upload-reset " ${dummy_port_fullpath} " 750
36
-
37
- if [ $# -eq 5 ]; then
38
- dfuse_addr=" --dfuse-address $5 "
39
- else
40
- dfuse_addr=" "
41
- fi
42
-
43
- # DFU_UTIL=/usr/local/bin/dfu-util
44
- DFU_UTIL=${DIR} /dfu-util/dfu-util
45
- if [ ! -x " ${DFU_UTIL} " ]; then
46
- DFU_UTIL=/opt/local/bin/dfu-util
47
- fi
48
-
49
- if [ ! -x ${DFU_UTIL} ]; then
50
- echo " $0 : error: cannot find ${DFU_UTIL} " >&2
51
- exit 2
29
+ if ! " ${DIR} /upload-reset" " ${dummy_port_fullpath} " 750; then
30
+ echo " ****************************************" >&2
31
+ echo " * Could not automatically reset device *" >&2
32
+ echo " * Please manually reset device! *" >&2
33
+ echo " ****************************************" >&2
34
+ sleep 2 # Wait for user to see message.
52
35
fi
53
36
54
- ${DFU_UTIL} -d " ${usbID} " -a " ${altID} " -D " ${binfile} " -R ${dfuse_addr} -R
37
+ COUNTER=5
38
+ while
39
+ " ${DIR} /dfu-util.sh" -d " ${usbID} " -a " ${altID} " -D " ${binfile} " ${dfuse_addr} -R
40
+ (( ret = $? ))
41
+ do
42
+ if [ $ret -eq 74 ] && [ $(( -- COUNTER)) -gt 0 ]; then
43
+ # I/O error, probably because no DFU device was found
44
+ echo " Trying ${COUNTER} more time(s)" >&2
45
+ sleep 1
46
+ else
47
+ exit $ret
48
+ fi
49
+ done
55
50
56
- echo -n Waiting for " ${dummy_port_fullpath} " serial...
51
+ echo -n " Waiting for ${dummy_port_fullpath} serial..." >&2
57
52
58
- COUNTER=0
59
- while [ ! -c " ${dummy_port_fullpath} " ] && (( COUNTER++ < 40 )) ; do
53
+ COUNTER=40
54
+ while [ ! -r " ${dummy_port_fullpath} " ] && (( COUNTER-- )) ; do
55
+ echo -n " ." >&2
60
56
sleep 0.1
61
57
done
62
58
63
- echo Done
59
+ if [ $COUNTER -eq -1 ]; then
60
+ echo " Timed out." >&2
61
+ exit 1
62
+ else
63
+ echo " Done." >&2
64
+ fi
0 commit comments