diff --git a/tools/macosx/maple_upload b/tools/macosx/maple_upload index 3521aa1ef..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 [ ! -c ${dummy_port_fullpath} ] && ((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