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 2.2KB

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