Jump to content

[TOOL] Easily flash firmware and encode scripts with Debian, Ubuntu and other Linux distros.


Recommended Posts

Here's a bash script that lets you easily compile scripts as well as flash firmware!

Unfortunately, when I paste the script directly on to this page, it isn't shown correctly so here is a dropbox link to it (my Github account has messed up a bit so I can't sync my repositories anymore):

Link (Click Here!)

Here's the script if you want to review it before downloading:

#!/bin/bash
# DFU-PROGRAMMER MUST BE INSTALLED TO USE THIS SCRIPT! RUN "sudo apt-get install dfu-programmer" TO INSTALL IT!
PROGRAM_VER="Mark 3"
PATH_DUCK_ENCODER="/var/DuckEncoder/encoder.jar"
PATH_DUCK_PATH_LAYOUTS="/var/DuckEncoder/resources"
DUCK_CHIPSET=at32uc3b1256
if ! [[ -f /usr/bin/dfu-programmer ]]
then
echo "WARNING! Package 'dfu-programmer' not installed!"
echo "Installing package..."
sudo apt-get -y install dfu-programmer
if ! [[ -f /usr/bin/dfu-programmer ]]
then
echo "Failed to install the required package! Cannot continue."
exit 0
fi
fi
if [[ $1 == "" ]]
then
echo "No command specified! Use --help for usage information."
exit 0
fi
if [[ $1 == "--help" ]]
then
echo ""
echo " HAK5 USB RUBBER DUCKY FLASH UTILITY"
echo " By Lavanoid Volcanic - $PROGRAM_VER"
echo ""
echo ""
echo " Duck commands:"
echo ""
echo " flash - Flash a .hex firmware file (must be in DFU mode)"
echo " dump - Dump the currently installed firmware (must be in DFU mode)"
echo " erase - Erase the currently installed firmware (must be in DFU mode)"
echo " info - Obtain various information about the device (must be in DFU mode)"
echo " reset - Reset/reboot the device (must be in DFU mode)"
echo " start - Start the device (must be in DFU mode)"
echo " encode - Encode/compile a script into a .bin file"
echo " schips - List chips supported by dfu-programmer"
echo ""
exit 0
fi
if [[ $1 == "start" ]]
then
echo "Starting device..."
sudo dfu-programmer $DUCK_CHIPSET start
echo "Done!"
exit 0
fi
if [[ $1 == "schips" ]]
then
sudo dfu-programmer --targets
exit 0
fi
if [[ $1 == "info" ]]
then
echo "Obtaining information..."
sudo dfu-programmer $DUCK_CHIPSET get bootloader-version
sudo dfu-programmer $DUCK_CHIPSET get manufacturer
sudo dfu-programmer $DUCK_CHIPSET get family
sudo dfu-programmer $DUCK_CHIPSET get product-name
sudo dfu-programmer $DUCK_CHIPSET get product-revision
sudo dfu-programmer $DUCK_CHIPSET get ID1
sudo dfu-programmer $DUCK_CHIPSET get ID2
sudo dfu-programmer $DUCK_CHIPSET getfuse LOCK
sudo dfu-programmer $DUCK_CHIPSET getfuse EPFL
sudo dfu-programmer $DUCK_CHIPSET getfuse BOOTPROT
sudo dfu-programmer $DUCK_CHIPSET getfuse BODLEVEL
sudo dfu-programmer $DUCK_CHIPSET getfuse BODHYST
sudo dfu-programmer $DUCK_CHIPSET getfuse BODEN
sudo dfu-programmer $DUCK_CHIPSET getfuse ISP_BOD_EN
sudo dfu-programmer $DUCK_CHIPSET getfuse ISP_IO_COND_EN
sudo dfu-programmer $DUCK_CHIPSET getfuse ISP_FORCE
echo "Done!"
exit 0
fi
if [[ $1 == "flash" ]]
then
if [[ $2 == "" ]]
then
echo "No firmware specified! Flash failed!"
exit 0
else
if [[ -f $2 ]]
then
echo "Flashing firmware file '$2'..."
echo "Erasing duck (not SD) before flash..."
sudo dfu-programmer $DUCK_CHIPSET erase
echo "Flashing new firmware..."
sudo dfu-programmer $DUCK_CHIPSET flash --suppress-bootloader-mem "$2"
echo "Done! Use "duck reset" to reset/reboot the device."
exit 0
else
echo "Cannot find firmware file. Flash failed!"
exit 0
fi
fi
fi
if [[ $1 == "dump" ]]
then
if [[ $2 == "" ]]
then
echo "No file was specified to dump the firmware to! Dump failed!"
exit 0
else
echo "Dumping firmware to '$2'..."
sudo dfu-programmer $DUCK_CHIPSET dump > "$2"
if [[ -f $2 ]]
then
echo "Dump file '$2' written successfully!"
echo "The file is written even if you have encountered an error."
exit 0
else
echo "Failed to write file '$2'. Firmware dump unsuccessful."
exit 0
fi
fi
fi
if [[ $1 == "erase" ]]
then
echo "Erasing currently installed firmware (not SD)..."
sudo dfu-programmer $DUCK_CHIPSET erase
echo "Done!"
exit 0
fi
if [[ $1 == "reset" ]]
then
echo "Resetting/rebooting device..."
sudo dfu-programmer $DUCK_CHIPSET reset
echo "Done!"
exit 0
fi
if [[ $1 == "encode" ]]
then
if [[ $2 == "" ]]
then
echo "No input file specified!"
exit 0
else
if [[ $3 == "" ]]
then
echo "No output file specified!"
exit 0
else
if [[ $4 == "" ]]
then
echo "No keyboard layout specified!"
exit 0
else
if [[ -f $2 ]]
then
if [[ -f $3 ]]
then
rm -f "$3"
fi
if [[ -f "$PATH_DUCK_PATH_LAYOUTS/$4.properties" ]]
then
echo "Encoding script..."
java -jar "$PATH_DUCK_ENCODER" -l "$PATH_DUCK_PATH_LAYOUTS/$4.properties" -i "$2" -o "$3"
if [[ -f $3 ]]
then
echo "Successfully compiled '$2' -> '$3'"
exit 0
else
echo "Failed to compile '$2' -> '$3'"
exit 0
fi
else
echo "Layout '$PATH_DUCK_PATH_LAYOUTS/$4.properties' cannot be found! Encode failed!"
exit 0
fi
else
echo "Cannot locate input file '$2'! Encode failed!"
exit 0
fi
fi
fi
fi
fi
if ! [[ $1 == "" ]]
then
echo "Invalid command specified! Use 'duck --help' for usage information."
exit 0
fi
Edited by Lavanoid
Link to post
Share on other sites

Looks very cool and useful. Can't wait to try it.

Be honest though, have you tested this? 80% of the scripts I see posted here have major halting bugs in them, which makes no sense because surely the developer attempted to run it ONCe on their machine, right? (and someone else's machine!)

Link to post
Share on other sites

Looks very cool and useful. Can't wait to try it. Be honest though, have you tested this? 80% of the scripts I see posted here have major halting bugs in them, which makes no sense because surely the developer attempted to run it ONCe on their machine, right? (and someone else's machine!)

Hi, I've tried all of the functions and it seems to work for me.

Edited by Lavanoid
Link to post
Share on other sites

Looks very cool and useful. Can't wait to try it. Be honest though, have you tested this? 80% of the scripts I see posted here have major halting bugs in them, which makes no sense because surely the developer attempted to run it ONCe on their machine, right? (and someone else's machine!)

Just tried it on some other systems, it certainly works with Ubuntu. I've also tested it on the Raspberry Pi running Debian Wheezy. Have you tried it?

Have you changed the variables at the top of the script to work with your configuration? If it doesn't work, please let me know :wink: .

P.S. You do know that the script that I pasted on this page isn't displayed correctly right? That's why I uploaded it to my dropbox account.

Don't forget to chmod the script too. I use "chmod 0777 duck" because 0777 means everything. I also recommend placing the "duck" file in your home directory/bin. E.g. /home/Username/bin

If a file is placed in your bin directory, then you can type "duck" from any directory and run the script. If you run the script like this: "sudo duck erase" etc, then it most likely won't execute because sudo doesn't use your home directory in its path variable. If you do want it to work with sudo, then you should place the script in /bin (not ~/bin or /home/USER/bin).

SUDO !! (BANG BANG!) :lol:

Edited by Lavanoid
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...