2015-08-10 20:49:46 +00:00
|
|
|
#!/usr/bin/env bash
|
2015-02-09 23:58:07 +00:00
|
|
|
# Convenience script for loading firmware onto a dfu type device
|
|
|
|
# By default, initiates dfu-util
|
|
|
|
|
2016-05-31 07:19:45 +00:00
|
|
|
SERIAL_PORT="/dev/kiibohd"
|
|
|
|
AUTO_SCREEN_SESSION="/dev/kiibohd"
|
|
|
|
NOSCREEN=0
|
2015-02-09 23:58:07 +00:00
|
|
|
PROG_NAME=$(basename $0)
|
|
|
|
|
|
|
|
# Parse all the command line arguments
|
|
|
|
while (( "$#" >= "1" )); do
|
|
|
|
# Scan each argument
|
|
|
|
key="$1"
|
|
|
|
case $key in
|
|
|
|
-a|--autoscreen)
|
|
|
|
AUTO_SCREEN_SESSION="$2"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-f|--fastload)
|
|
|
|
SERIAL_PORT="$2"
|
|
|
|
shift
|
|
|
|
;;
|
2016-05-31 07:19:45 +00:00
|
|
|
-n|--noscreen)
|
|
|
|
NOSCREEN=1
|
|
|
|
shift
|
|
|
|
;;
|
2015-02-09 23:58:07 +00:00
|
|
|
-h|--help)
|
|
|
|
echo "Usage: $PROG_NAME [options...]"
|
|
|
|
echo ""
|
|
|
|
echo "Loads the most recent built firmware (@TARGET_BIN@) to the device."
|
|
|
|
echo " (load.dfu)"
|
|
|
|
echo ""
|
|
|
|
echo "Arguments:"
|
|
|
|
echo " -a, --autoscreen SERIAL_PORT Use screen on the specified serial port after loading."
|
|
|
|
echo " e.g. /dev/ttyACM0"
|
|
|
|
echo " -f, --fastload SERIAL_PORT Send the reload command to the debug terminal."
|
|
|
|
echo " e.g. /dev/ttyACM0"
|
|
|
|
echo " NOTE: May not work due to non-functional terminal, or disable remote flashing"
|
|
|
|
echo " -h, --help This message."
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "INVALID ARG: '$1'"
|
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Shift to the next argument
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
# If a SERIAL_PORT was specified set the uC into reflash mode
|
|
|
|
# XXX May not be successful if uC is not in a good state (or does not allow remote flashing)
|
|
|
|
if [[ "$SERIAL_PORT" != "" ]] && [[ -e "$SERIAL_PORT" ]]; then
|
|
|
|
echo "NOTE: This may fail if the uC is in a bad state or does not support remote flashing"
|
|
|
|
printf "reload\r" > $SERIAL_PORT
|
|
|
|
fi
|
2014-09-14 23:22:27 +00:00
|
|
|
|
|
|
|
# Load via dfu-util
|
|
|
|
# Used for McHCK based uCs
|
2015-02-13 03:42:01 +00:00
|
|
|
if type dfu-util &>/dev/null; then
|
2016-05-31 07:19:45 +00:00
|
|
|
# Wait for device to appear
|
|
|
|
while true; do
|
|
|
|
dfu-util -l | grep -q "Kiibohd DFU"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
sleep 0.1
|
|
|
|
done
|
2015-02-13 03:42:01 +00:00
|
|
|
dfu-util -D @TARGET_BIN@
|
|
|
|
EXIT_STATUS=$?
|
|
|
|
else
|
|
|
|
echo "dfu-util is required to reprogram the device"
|
|
|
|
exit 3
|
|
|
|
fi
|
2015-02-09 23:58:07 +00:00
|
|
|
|
|
|
|
# Load Screen Session if specified
|
2016-05-31 07:19:45 +00:00
|
|
|
if (( "$EXIT_STATUS" == "0" )) && [[ "$AUTO_SCREEN_SESSION" != "" ]] && [[ $NOSCREEN -ne 1 ]]; then
|
2015-02-13 03:42:01 +00:00
|
|
|
if type screen &>/dev/null; then
|
2016-05-31 07:19:45 +00:00
|
|
|
# Wait for interface
|
|
|
|
while [ ! -e $AUTO_SCREEN_SESSION ]; do
|
|
|
|
sleep 0.1
|
|
|
|
done
|
2015-02-13 03:42:01 +00:00
|
|
|
screen $AUTO_SCREEN_SESSION
|
|
|
|
else
|
|
|
|
echo "screen is not installed"
|
|
|
|
exit 3
|
|
|
|
fi
|
2015-02-09 23:58:07 +00:00
|
|
|
fi
|
2014-09-14 23:22:27 +00:00
|
|
|
|
2015-02-09 23:58:07 +00:00
|
|
|
exit $EXIT_STATUS
|
2014-09-14 23:22:27 +00:00
|
|
|
|