From 66dcf910bd4744d8ced56cb9586aa937a1a2d4c5 Mon Sep 17 00:00:00 2001 From: vg Date: Tue, 7 Jul 2020 16:24:01 +0200 Subject: first commit --- avr-test2/avr-fusedump.bash | 102 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100755 avr-test2/avr-fusedump.bash (limited to 'avr-test2/avr-fusedump.bash') diff --git a/avr-test2/avr-fusedump.bash b/avr-test2/avr-fusedump.bash new file mode 100755 index 0000000..d6c6e50 --- /dev/null +++ b/avr-test2/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 -p " + 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 -- cgit v1.2.3