Skip to content

Commit aa4efdd

Browse files
authored
Merge pull request #62 from GrantM11235/maple-script
[maple_upload] Improve script on linux and macosx
2 parents 7664bfa + bec6008 commit aa4efdd

File tree

3 files changed

+88
-44
lines changed

3 files changed

+88
-44
lines changed

linux/maple_upload.sh

+32-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
#set -e
3+
set -e
44

55
if [ $# -lt 4 ]; then
66
echo "Usage: $0 $# <dummy_port> <altID> <usbID> <binfile>" >&2
@@ -24,16 +24,41 @@ DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
2424
# This value is in milliseonds
2525
# You may need to tune this to your system
2626
# 750ms to 1500ms seems to work on my Mac
27+
# This is less critical now that we automatically retry dfu-util
2728

28-
"${DIR}/upload-reset" "${dummy_port_fullpath}" 750
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.
35+
fi
2936

30-
"${DIR}/dfu-util.sh" -d "${usbID}" -a "${altID}" -D "${binfile}" ${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
3150

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

34-
COUNTER=0
35-
while [ ! -r "${dummy_port_fullpath}" ] && ((COUNTER++ < 40)); do
53+
COUNTER=40
54+
while [ ! -r "${dummy_port_fullpath}" ] && ((COUNTER--)); do
55+
echo -n "." >&2
3656
sleep 0.1
3757
done
3858

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

macosx/dfu-util.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
# Get the directory where the script is running.
4+
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
5+
6+
DFU_UTIL=${DIR}/dfu-util/dfu-util
7+
if [ ! -x "${DFU_UTIL}" ]; then
8+
DFU_UTIL=/opt/local/bin/dfu-util
9+
fi
10+
11+
# Not found!
12+
if [ ! -x "${DFU_UTIL}" ]; then
13+
echo "$0: error: cannot find ${DFU_UTIL}" >&2
14+
exit 2
15+
fi
16+
17+
# Pass all parameters through
18+
"${DFU_UTIL}" "$@"

macosx/maple_upload.sh

+38-37
Original file line numberDiff line numberDiff line change
@@ -6,58 +6,59 @@ 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=""
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.
5235
fi
5336

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
5550

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

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
6056
sleep 0.1
6157
done
6258

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

Comments
 (0)