Kiibohd Controller
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

load.dfu 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. # Convenience script for loading firmware onto a dfu type device
  3. # By default, initiates dfu-util
  4. SERIAL_PORT=""
  5. AUTO_SCREEN_SESSION=""
  6. PROG_NAME=$(basename $0)
  7. # Parse all the command line arguments
  8. while (( "$#" >= "1" )); do
  9. # Scan each argument
  10. key="$1"
  11. case $key in
  12. -a|--autoscreen)
  13. AUTO_SCREEN_SESSION="$2"
  14. shift
  15. ;;
  16. -f|--fastload)
  17. SERIAL_PORT="$2"
  18. shift
  19. ;;
  20. -h|--help)
  21. echo "Usage: $PROG_NAME [options...]"
  22. echo ""
  23. echo "Loads the most recent built firmware (@TARGET_BIN@) to the device."
  24. echo " (load.dfu)"
  25. echo ""
  26. echo "Arguments:"
  27. echo " -a, --autoscreen SERIAL_PORT Use screen on the specified serial port after loading."
  28. echo " e.g. /dev/ttyACM0"
  29. echo " -f, --fastload SERIAL_PORT Send the reload command to the debug terminal."
  30. echo " e.g. /dev/ttyACM0"
  31. echo " NOTE: May not work due to non-functional terminal, or disable remote flashing"
  32. echo " -h, --help This message."
  33. exit 1
  34. ;;
  35. *)
  36. echo "INVALID ARG: '$1'"
  37. exit 2
  38. ;;
  39. esac
  40. # Shift to the next argument
  41. shift
  42. done
  43. # If a SERIAL_PORT was specified set the uC into reflash mode
  44. # XXX May not be successful if uC is not in a good state (or does not allow remote flashing)
  45. if [[ "$SERIAL_PORT" != "" ]] && [[ -e "$SERIAL_PORT" ]]; then
  46. echo "NOTE: This may fail if the uC is in a bad state or does not support remote flashing"
  47. printf "reload\r" > $SERIAL_PORT
  48. sleep 2
  49. fi
  50. # Load via dfu-util
  51. # Used for McHCK based uCs
  52. if type dfu-util &>/dev/null; then
  53. dfu-util -D @TARGET_BIN@
  54. EXIT_STATUS=$?
  55. else
  56. echo "dfu-util is required to reprogram the device"
  57. exit 3
  58. fi
  59. # Load Screen Session if specified
  60. if (( "$EXIT_STATUS" == "0" )) && [[ "$AUTO_SCREEN_SESSION" != "" ]]; then
  61. if type screen &>/dev/null; then
  62. sleep 0.1
  63. screen $AUTO_SCREEN_SESSION
  64. else
  65. echo "screen is not installed"
  66. exit 3
  67. fi
  68. fi
  69. exit $EXIT_STATUS