Last active
April 22, 2020 13:47
-
-
Save ssokolow/2c121880e65e665ee34da6210f2e2e22 to your computer and use it in GitHub Desktop.
Simple script to streamline the process of updating a Retrode's firmware on Linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# update_retrode.sh | |
# By: Stephan Sokolow | |
# | |
# A simple script to streamline the process of updating a Retrode's firmware | |
# Linux and reduce the chance of errors. | |
# | |
# License: MIT | |
# | |
# Usage: ./update_retrode.sh <firmware_file.hex> | |
show_usage() { | |
echo "Usage: $0 <firmware_file.hex>" | |
exit 1 | |
} | |
error() { | |
echo "$(tput setaf 1)ERROR:$(tput sgr0) $@" | |
} | |
if [ "$#" != 1 ]; then | |
show_usage | |
fi | |
case "$1" in | |
-h|--help|-?) | |
show_usage | |
;; | |
*.hex) | |
;; # pass through to the body of the script | |
*) | |
error "Please provide a file with a .hex extension." | |
exit 2 | |
esac | |
if [ ! -f "$1" ]; then | |
error "Missing or not a file: $1" | |
exit 4 | |
fi | |
if ! type dfu-programmer 1>/dev/null 2>&1; then | |
error "Could not find 'dfu-programmer'. Please install it and try again." | |
exit 5 | |
fi | |
echo "$(tput setaf 3)REMINDER:$(tput sgr0) Make sure you don't try to flash a Retrode 2 with Retrode 1 firmware or vice-versa." | |
echo | |
echo "To put the Retrode into programming mode:" | |
echo | |
echo "0. Unplug any other flashable AVR devices (eg. Arduino, BlissBox 4-Play)" | |
echo "1. Hold down RESET (the front button)" | |
echo "2. Hold down HWB (the back button)" | |
echo "3. Release RESET" | |
echo "4. Release HWB" | |
echo | |
echo "After doing this, press Enter and your device will be reprogrammed..." | |
read _ | |
if ! dfu-programmer at90usb646 get product-revision > /dev/null 2>&1; then | |
error "Could not find your Retrode" | |
echo "This is typically caused by one of two things:" | |
echo | |
echo "1. You didn't successfully put it into programming mode" | |
echo "2. Your system may require you to run this via 'sudo' to grant " | |
echo " dfu-programmer permission to reprogram devices." | |
exit 3 | |
fi | |
echo "Erasing existing firmware..." | |
dfu-programmer at90usb646 erase && | |
echo "Writing new firmware..." && | |
dfu-programmer at90usb646 flash "$1" && | |
echo "$(tput setaf 2)PROGRAMMING COMPLETE.$(tput sgr0) Please press RESET (the front button) on your Retrode" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment