X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=LoadFile%2Fload.dfu;h=5c7719c2c12c7f7c0fcd16c169229c578d3b7349;hb=0e6f107ea108bea0b179bcc2a2ac17d3ba49e1a7;hp=8eead300a2e42c7a626658598bc41952967daa27;hpb=3b06d8f6ae2ed8af492a26b8a356ce49c56cebd6;p=kiibohd-controller.git diff --git a/LoadFile/load.dfu b/LoadFile/load.dfu index 8eead30..5c7719c 100755 --- a/LoadFile/load.dfu +++ b/LoadFile/load.dfu @@ -1,8 +1,77 @@ -#!/bin/bash +#!/usr/bin/env bash +# Convenience script for loading firmware onto a dfu type device +# By default, initiates dfu-util + +SERIAL_PORT="" +AUTO_SCREEN_SESSION="" +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 + ;; + -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 + sleep 2 +fi # Load via dfu-util # Used for McHCK based uCs -dfu-util -D @TARGET_BIN@ +if type dfu-util &>/dev/null; then + dfu-util -D @TARGET_BIN@ + EXIT_STATUS=$? +else + echo "dfu-util is required to reprogram the device" + exit 3 +fi + +# Load Screen Session if specified +if (( "$EXIT_STATUS" == "0" )) && [[ "$AUTO_SCREEN_SESSION" != "" ]]; then + if type screen &>/dev/null; then + sleep 0.1 + screen $AUTO_SCREEN_SESSION + else + echo "screen is not installed" + exit 3 + fi +fi -exit $? +exit $EXIT_STATUS