Skip to content

Commit 07a2620

Browse files
committed
[maple_upload] Copy script from linux to macosx
1 parent c0c0f9b commit 07a2620

File tree

1 file changed

+39
-26
lines changed

1 file changed

+39
-26
lines changed

macosx/maple_upload.sh

+39-26
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,60 @@ if [ $# -lt 4 ]; then
66
echo "Usage: $0 $# <dummy_port> <altID> <usbID> <binfile>" >&2
77
exit 1
88
fi
9-
altID=$2
10-
usbID=$3
11-
binfile=$4
9+
altID="$2"
10+
usbID="$3"
11+
binfile="$4"
1212
dummy_port_fullpath="/dev/$1"
13+
if [ $# -eq 5 ]; then
14+
dfuse_addr="--dfuse-address $5"
15+
else
16+
dfuse_addr=""
17+
fi
1318

1419
# Get the directory where the script is running.
1520
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
1621

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-
2922
# ----------------- IMPORTANT -----------------
3023
# The 2nd parameter to upload-reset is the delay after resetting before it exits
3124
# This value is in milliseonds
3225
# You may need to tune this to your system
3326
# 750ms to 1500ms seems to work on my Mac
27+
# This is less critical now that we automatically retry dfu-util
3428

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=""
29+
if ! "${DIR}/upload-reset" "${dummy_port_fullpath}" 750
30+
then
31+
echo "****************************************" >&2
32+
echo "* Could not automatically reset device *" >&2
33+
echo "* Please manually reset device! *" >&2
34+
echo "****************************************" >&2
35+
sleep 2 # Wait for user to see message.
4136
fi
4237

43-
"${DIR}/dfu-util.sh" -d "${usbID}" -a "${altID}" -D "${binfile}" -R ${dfuse_addr} -R
38+
COUNTER=10
39+
while "${DIR}/dfu-util.sh" -d "${usbID}" -a "${altID}" -D "${binfile}" ${dfuse_addr} -R ; ((ret=$?))
40+
do
41+
if [ $ret -eq 74 ] && [ $((--COUNTER)) -gt 0 ]
42+
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
4450

45-
echo -n Waiting for "${dummy_port_fullpath}" serial...
51+
echo -n "Waiting for ${dummy_port_fullpath} serial..." >&2
4652

47-
COUNTER=0
48-
while [ ! -c "${dummy_port_fullpath}" ] && ((COUNTER++ < 40)); do
53+
COUNTER=40
54+
while [ ! -r "${dummy_port_fullpath}" ] && ((COUNTER--)); do
55+
echo -n "." >&2
4956
sleep 0.1
5057
done
5158

52-
echo Done
59+
if [ $COUNTER -eq -1 ]
60+
then
61+
echo " Timed out." >&2
62+
exit 1
63+
else
64+
echo " Done." >&2
65+
fi

0 commit comments

Comments
 (0)