From 7e543fc99c12195e06555c19901521bf13f23492 Mon Sep 17 00:00:00 2001 From: Zou Hanya Date: Sat, 3 Jun 2017 07:58:41 +0900 Subject: [PATCH 1/2] Use dd command instead of test command to wait the Serial device --- tools/macosx/maple_upload | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/macosx/maple_upload b/tools/macosx/maple_upload index 3521aa1ef..984fa6dd6 100755 --- a/tools/macosx/maple_upload +++ b/tools/macosx/maple_upload @@ -55,7 +55,7 @@ ${DFU_UTIL} -d ${usbID} -a ${altID} -D ${binfile} -R ${dfuse_addr} -R echo -n Waiting for ${dummy_port_fullpath} serial... COUNTER=0 -while [ ! -c ${dummy_port_fullpath} ] && ((COUNTER++ < 40)); do +while ! dd if=${dummy_port_fullpath} of=/dev/null count=0 > /dev/null 2>&1 && ((COUNTER++ < 40)); do sleep 0.1 done From 19028676b46d2d6fd7089227e04b358e8a4b98b2 Mon Sep 17 00:00:00 2001 From: Zou Hanya Date: Sun, 22 Oct 2017 15:00:12 +0900 Subject: [PATCH 2/2] Add wait loop after upload-reset instead of fixed delay --- tools/macosx/maple_upload | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tools/macosx/maple_upload b/tools/macosx/maple_upload index 984fa6dd6..7d6a66234 100755 --- a/tools/macosx/maple_upload +++ b/tools/macosx/maple_upload @@ -1,5 +1,7 @@ #!/bin/bash +MAXWAITCOUNT=40 # about 4000ms + set -e if [ $# -lt 4 ]; then @@ -25,13 +27,7 @@ DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) #fi # ------------------ End of old code ----------------- -# ----------------- IMPORTANT ----------------- -# The 2nd parameter to upload-reset is the delay after resetting before it exits -# This value is in milliseonds -# You may need to tune this to your system -# 750ms to 1500ms seems to work on my Mac - -${DIR}/upload-reset ${dummy_port_fullpath} 750 +${DIR}/upload-reset ${dummy_port_fullpath} if [ $# -eq 5 ]; then dfuse_addr="--dfuse-address $5" @@ -50,12 +46,22 @@ if [ ! -x ${DFU_UTIL} ]; then exit 2 fi +# wait for the DFU device after upload-reset command reboot target +COUNTER=0 +while ! ${DFU_UTIL} -d ${usbID} -l | grep -e '^Found DFU: ' && ((COUNTER++ < ${MAXWAITCOUNT})); do + sleep 0.1 +done +if ((${MAXWAITCOUNT} <= $COUNTER)); then + echo "$0: error: cannot find ${usbID}" >&2 + exit 2 +fi + ${DFU_UTIL} -d ${usbID} -a ${altID} -D ${binfile} -R ${dfuse_addr} -R echo -n Waiting for ${dummy_port_fullpath} serial... COUNTER=0 -while ! dd if=${dummy_port_fullpath} of=/dev/null count=0 > /dev/null 2>&1 && ((COUNTER++ < 40)); do +while ! dd if=${dummy_port_fullpath} of=/dev/null count=0 > /dev/null 2>&1 && ((COUNTER++ < ${MAXWAITCOUNT})); do sleep 0.1 done