aboutsummaryrefslogtreecommitdiffstats
path: root/avr-test/avr-fusedump.bash
diff options
context:
space:
mode:
authorvg <vgm+dev@devys.org>2020-07-07 16:24:01 +0200
committervg <vgm+dev@devys.org>2020-07-07 16:24:01 +0200
commit66dcf910bd4744d8ced56cb9586aa937a1a2d4c5 (patch)
treedf4dca1ae4af1e5df0be0d1f4f2cd0d54751f8e8 /avr-test/avr-fusedump.bash
downloadhic-master.tar.gz
hic-master.tar.bz2
hic-master.zip
first commitHEADmaster
Diffstat (limited to 'avr-test/avr-fusedump.bash')
-rwxr-xr-xavr-test/avr-fusedump.bash102
1 files changed, 102 insertions, 0 deletions
diff --git a/avr-test/avr-fusedump.bash b/avr-test/avr-fusedump.bash
new file mode 100755
index 0000000..d6c6e50
--- /dev/null
+++ b/avr-test/avr-fusedump.bash
@@ -0,0 +1,102 @@
+#!/bin/bash
+#############################################################################
+#Bash script to dump the fuse bits for AVR microcontrollers and open
+#the Engbedded Atmel AVR Fuse Calculator with the current fuse settings.
+#
+#05-Nov-2009
+#Craig Heffner
+#http://www.hackingwithgum.com
+#############################################################################
+
+LFUSE=lfuse
+HFUSE=hfuse
+EFUSE=efuse
+URL="http://www.engbedded.com/cgi-bin/fcx.cgi?P=MMCU&V_LOW=$LFUSE&V_HIGH=$HFUSE&V_EXTENDED=$EFUSE&O_HEX=Apply+values"
+ADSUCCESS=OK
+ADOK=0
+FUSE=""
+DATA=""
+ADARGS=""
+
+#Loop through all the arguments to the script and concatenate them into $ADARGS.
+#These arguments get passed directly to avrdude.
+while [ $# -ne 0 ]
+do
+ #If this argument is -p, then the next one is the chip name
+ if [ "$1" == "-p" ] && [ "$2" != "" ]
+ then
+ URL=$(echo $URL | sed -e "s/MMCU/$2/")
+ fi
+
+ ADARGS="$ADARGS $1"
+ shift
+done
+
+#Does the user need usage help?
+if [ "$ADARGS" == "" ] || [ "$ADARGS" == "-h" ] || [ "$ADARGS" == "--help" ]
+then
+ echo ""
+ echo "Usage: $0 -c <programmer> -p <partno>"
+ echo ""
+ echo -e "\tExample: $0 -c usbtiny -p ATmega8"
+ echo ""
+ echo -e "Note that the argument supplied to -p is case-sensitive.\nIt should look exactly as it does in the Engbedded Web site's select box.\n"
+ exit
+fi
+
+#Dump fuse info with avrdude and loop through the output word by word
+for WORD in $(avrdude $ADARGS -q -U lfuse:r:-:i -U hfuse:r:-:i -U efuse:r:-:i 2>&1)
+do
+ #Check for the success indicator
+ if [ "$WORD" == "$ADSUCCESS" ]
+ then
+ ADOK=1
+ fi
+
+ #Look for keywords "lfuse", "hfuse", or "efuse". They appear
+ #just before the corresponding fuse values are displayed.
+ if [ $(echo $WORD | grep $LFUSE) ]
+ then
+ FUSE=$LFUSE
+ elif [ $(echo $WORD | grep $HFUSE) ]
+ then
+ FUSE=$HFUSE
+ elif [ $(echo $WORD | grep $EFUSE) ]
+ then
+ FUSE=$EFUSE
+ fi
+
+ #Have we seen one of the fuse keywords?
+ if [ "$FUSE" != "" ]
+ then
+ #Displayed fuse values start with a colon
+ DATA=$(echo $WORD | grep -e "^:")
+
+ if [ "$DATA" != "" ]
+ then
+ #Pull out the fuse byte; 9th and 10th characters in the displayed value
+ DATA=${DATA:9:2}
+
+ #Display the fuse value and update the Engbedded URL with the value
+ echo -e "$FUSE\t0x$DATA"
+ URL=$(echo $URL | sed -e "s/$FUSE/$DATA/")
+
+ #Clear these in order to look for the next fuse
+ FUSE=""
+ DATA=""
+ fi
+ fi
+done
+
+#If there was an error, let the user know.
+#Else, open the Engbedded URL.
+if [ $ADOK -ne 1 ]
+then
+ echo "Avrdude failed! Check your programmer and chip arguments."
+else
+ #Show the URL
+ #echo $URL
+
+ #Open the URL automatically
+ firefox $URL &
+fi