| 
									
										
										
										
											2017-11-27 21:19:49 +00:00
										 |  |  | #!/bin/bash | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #set -e | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if [ $# -lt 4 ]; then | 
					
						
							|  |  |  |     echo "Usage: $0 $# <dummy_port> <altID> <usbID> <binfile>" >&2 | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2017-12-11 20:55:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 21:19:49 +00:00
										 |  |  | dummy_port="$1"; altID="$2"; usbID="$3"; binfile="$4"; dummy_port_fullpath="/dev/$1" | 
					
						
							| 
									
										
										
										
											2017-12-11 20:55:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 21:19:49 +00:00
										 |  |  | if [ $# -eq 5 ]; then | 
					
						
							|  |  |  |     dfuse_addr="--dfuse-address $5" | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  |     dfuse_addr="" | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Get the directory where the script is running. | 
					
						
							|  |  |  | DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-11 20:55:24 +00:00
										 |  |  | # Get the right upload-reset tool | 
					
						
							|  |  |  | uname -m | grep "x86_64" 2>&1 1>/dev/null | 
					
						
							|  |  |  | if [ $? -eq 0 ]; then | 
					
						
							|  |  |  |   # Do 64-bit stuff | 
					
						
							|  |  |  |   RESET_UTIL=${DIR}/../linux64/upload-reset | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  |   # Do 32-bit stuff | 
					
						
							|  |  |  |   RESET_UTIL=${DIR}/upload-reset | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 21:19:49 +00:00
										 |  |  | #  ----------------- 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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-11 20:55:24 +00:00
										 |  |  | "${RESET_UTIL}" ${dummy_port_fullpath} 750 | 
					
						
							| 
									
										
										
										
											2017-11-27 21:19:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 09:29:47 +01:00
										 |  |  | # Give the board a chance to reset to DFU mode | 
					
						
							|  |  |  | sleep 0.5 | 
					
						
							| 
									
										
										
										
											2017-11-27 21:19:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #DFU_UTIL=$(dirname $0)/dfu-util/dfu-util | 
					
						
							|  |  |  | DFU_UTIL=/usr/bin/dfu-util | 
					
						
							|  |  |  | DFU_UTIL=${DIR}/dfu-util/dfu-util | 
					
						
							|  |  |  | if [ ! -x "${DFU_UTIL}" ]; then | 
					
						
							|  |  |  |     echo "$0: error: cannot find ${DFU_UTIL}" >&2 | 
					
						
							|  |  |  |     exit 2 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "${DFU_UTIL}" -d ${usbID} -a ${altID} -D ${binfile} ${dfuse_addr} -R | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | echo -n Waiting for ${dummy_port_fullpath} serial... | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | COUNTER=0 | 
					
						
							|  |  |  | while [ ! -r ${dummy_port_fullpath} ] && ((COUNTER++ < 40)); do | 
					
						
							|  |  |  |     sleep 0.1 | 
					
						
							|  |  |  | done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | echo Done |