3 # bit $1 is set in $2 (8 bits)
5 if [ $(($2 & $((1 << $1)))) -eq 0 ]; then
17 while [ $bit -ge 0 ]; do
18 NAME=`cut -d ' ' -f 2- ${MCU_DESC_FILE} | grep "^$bit $1" | cut -d ' ' -f 3`
19 if [ -z "$NAME" ]; then
24 echo -n "$NAME=$bitval"
34 echo "0x`cat $1 | head -1 | cut -b10-11`" > $1.tmp
40 printf ":01000000%.2X" `cat $1` > $1.tmp
41 printf "%.2X\n" $((0xFF - `cat $1`)) >> $1.tmp
42 echo ":00000001FF" >> $1.tmp
47 # 1/ read fuse state if possible
53 echo "----------------------------------------------------------"
54 echo " Programming fuses"
55 echo "----------------------------------------------------------"
57 echo "Warning : It can bue dangerous to program your fuses: some"
58 echo "configurations will prevent you to program your uC. Be sure"
59 echo "that you have carrefully read the documentation, and that"
60 echo "you know what you're doing"
62 echo "Warning : 0 means programmed and 1 means unprogrammed (see"
63 echo "AVR documentation for details"
65 echo "BIT FAT WARNING ! PLEASE CHECK THE DOCUMENTATION BEFORE"
66 echo "PROGRAMMING BECAUSE SOME PARTS HAVE NOT BEEN TESTED"
70 echo -n "Are you sure ? [y/n] "
82 echo " Please type 'y' or 'n'"
86 if [ ! -f ${MCU_DESC_FILE} ]; then
88 echo "Can't find the file ${MCU_DESC_FILE}"
89 echo "If `basename ${MCU_DESC_FILE}` is a valid uC, you should add it in"
90 echo "AVERSIVE/config/fuses_defs directory"
94 if [ -z "${PROGRAMMER}" ]; then
96 echo " PROGRAMMER variable is not defined, check that the script"
97 echo " is launched from a 'make fuse' in project directory"
101 if [ "${PROGRAMMER}" = "avrdude" -a -z "${AVRDUDE}" ]; then
103 echo " AVRDUDE variable is not defined, check that the script"
104 echo " is launched from a 'make fuse' in project directory"
108 if [ "${AVARICE}" = "avarice" -a -z "${AVARICE}" ]; then
110 echo " AVARICE variable is not defined, check that the script"
111 echo " is launched from a 'make fuse' in project directory"
115 if [ "${PROGRAMMER}" = "avarice" ]; then
117 echo " Sorry, AVARICE fuse programming is not implemented now"
121 if [ `wc -c ${MCU_DESC_FILE} | cut -d ' ' -f 1` -eq 0 ]; then
122 echo "Aborting : this uC does not have any fuse to program."
127 FUSE_LIST=`cut -d ' ' -f 3 ${MCU_DESC_FILE} | sort -u`
129 echo "Reading current fuse state"
131 if [ ! -z "${AVRDUDE_DELAY}" ]; then
132 DELAY="-i ${AVRDUDE_DELAY}"
139 for f in ${FUSE_LIST}
141 rm -f $f 2> /dev/null
142 echo 0xff > ${f}_new # default for each bit is 1 (unprogrammed)
143 ${AVRDUDE} ${DELAY} -p ${MCU} -P `echo ${AVRDUDE_PORT} | \
144 sed 's,",,g'` -c ${AVRDUDE_PROGRAMMER} -U ${f}:r:${f}:i
153 if [ $CANNOT_READ -eq 1 ]; then
154 echo -n "Problem during reading fuse. Continue anyway with writing ? [y/N] "
168 for f in ${FUSE_LIST}; do
170 disp_fuse $f `cat $f`
176 echo "Now please enter the new value for each fuse. The default one"
177 echo "is the value that has been read, or factory default if read failed"
181 NB_LINE=`wc -l ${MCU_DESC_FILE} | cut -d ' ' -f 1`
182 SEQ_END=$((${NB_LINE} - 1))
184 for i in `seq 0 ${SEQ_END}`
186 LINE=`grep "^${i} " ${MCU_DESC_FILE}`
187 BIT=`echo ${LINE} | cut -d ' ' -f 2`
188 FUSE=`echo ${LINE} | cut -d ' ' -f 3`
189 NAME=`echo ${LINE} | cut -d ' ' -f 4`
190 FACTORY=`echo ${LINE} | cut -d ' ' -f 5`
193 HELP=`echo ${LINE} | cut -d ' ' -f 6-`
194 if [ -f ${FUSE} ]; then
196 bit_is_set $BIT `printf "%d" $BIN_FUSE`
201 echo -n "[$FUSE:${BIT}] ${NAME} <${HELP}> (factory=${DEFAULT}) "
202 echo -n "(current=${CURRENT}) [${DEFAULT}] ? "
205 if [ -z "$ans" ] ; then
211 NEW_VAL=$((1 << $BIT | `cat ${FUSE}_new`))
212 printf "0x%x\n" ${NEW_VAL} > ${FUSE}_new
213 echo " get 1 (unprogrammed)"
216 NEW_VAL=$((~(1 << $BIT) & `cat ${FUSE}_new`))
217 printf "0x%x\n" ${NEW_VAL} > ${FUSE}_new
218 echo " get 0 (programmed)"
221 echo "Bad answer, aborting..."
228 echo "Summary of new values :"
231 for f in ${FUSE_LIST}; do
232 if [ ! -f ${f}_new ]; then
233 echo "ERROR: cannot find ${f}_new, aborting"
236 disp_fuse $f `cat ${f}_new`
244 echo -n "Are you sure ? [y/n] "
249 for f in ${FUSE_LIST}; do
250 echo "$f = $(cat ${f}_new)"
252 PORT=`echo ${AVRDUDE_PORT} | sed 's,",,g'`
253 echo -n "${AVRDUDE} -p ${MCU} -P ${PORT} "
254 echo -n "-c ${AVRDUDE_PROGRAMMER} "
255 echo "-U ${f}:w:${f}_new:i ${DELAY}"
256 ${AVRDUDE} -p ${MCU} -P ${PORT} \
257 -c ${AVRDUDE_PROGRAMMER} \
258 -U ${f}:w:${f}_new:i ${DELAY}
267 echo " Please type 'y' or 'n'"