2 # Convenience script for loading firmware onto a dfu type device
3 # By default, initiates dfu-util
7 PROG_NAME=$(basename $0)
9 # Parse all the command line arguments
10 while (( "$#" >= "1" )); do
15 AUTO_SCREEN_SESSION="$2"
23 echo "Usage: $PROG_NAME [options...]"
25 echo "Loads the most recent built firmware (@TARGET_BIN@) to the device."
29 echo " -a, --autoscreen SERIAL_PORT Use screen on the specified serial port after loading."
30 echo " e.g. /dev/ttyACM0"
31 echo " -f, --fastload SERIAL_PORT Send the reload command to the debug terminal."
32 echo " e.g. /dev/ttyACM0"
33 echo " NOTE: May not work due to non-functional terminal, or disable remote flashing"
34 echo " -h, --help This message."
38 echo "INVALID ARG: '$1'"
43 # Shift to the next argument
47 # If a SERIAL_PORT was specified set the uC into reflash mode
48 # XXX May not be successful if uC is not in a good state (or does not allow remote flashing)
49 if [[ "$SERIAL_PORT" != "" ]] && [[ -e "$SERIAL_PORT" ]]; then
50 echo "NOTE: This may fail if the uC is in a bad state or does not support remote flashing"
51 printf "reload\r" > $SERIAL_PORT
56 # Used for McHCK based uCs
57 if type dfu-util &>/dev/null; then
58 dfu-util -D @TARGET_BIN@
61 echo "dfu-util is required to reprogram the device"
65 # Load Screen Session if specified
66 if (( "$EXIT_STATUS" == "0" )) && [[ "$AUTO_SCREEN_SESSION" != "" ]]; then
67 if type screen &>/dev/null; then
69 screen $AUTO_SCREEN_SESSION
71 echo "screen is not installed"