I want to lock my ATmega8A chip so that the program on it cannot be read back.
According to the data sheet and my online research I should set the LB1 and LB2 bits of the lock byte in order to achieve this.
But when I do that avrdude gives me a confusing warning.
This is the command I use:
avrdude -v -patmega8 -cstk500v1 -PCOM3 -b19200 -Ulock:w:0xFC:m
It works but I get this weird warning:
avrdude: WARNING: invalid value for unused bits in fuse "lock", should be set to 1 according to datasheet
This behaviour is deprecated and will result in an error in future version
You probably want to use 0x3c instead of 0xfc (double check with your datasheet first).
avrdude: 1 bytes of lock verified
It says unused bits should be set to 1 according to the datasheet.
Well they are! 0xFC means everything is 1 except for LB2 and LB1.
And it suggests I should use 0x3C which is the exact opposite of what it is warning me about. 0x3C means the first two unused bits will be set to 0.
I don't understand what's going on here.
Complete avrdude output:
# avrdude -v -patmega8 -cstk500v1 -PCOM3 -b19200 -Ulock:w:0xFC:m
avrdude: Version 6.3-20201216
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "D:\Program Files\avrdude 6.3 (From Arduino 1.8.9)\avrdude.conf"
Using Port : COM3
Using Programmer : stk500v1
Overriding Baud Rate : 19200
AVR Part : ATmega8
Chip Erase delay : 10000 us
PAGEL : PD7
BS2 : PC2
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
eeprom 4 20 128 0 no 512 4 0 9000 9000 0xff 0xff
flash 33 10 64 0 yes 8192 64 128 4500 4500 0xff 0x00
lfuse 0 0 0 0 no 1 0 0 2000 2000 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 2000 2000 0x00 0x00
efuse 0 0 0 0 no 0 0 0 0 0 0x00 0x00
lock 0 0 0 0 no 1 0 0 2000 2000 0x00 0x00
calibration 0 0 0 0 no 4 0 0 0 0 0x00 0x00
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
Programmer Type : STK500
Description : Atmel STK500 Version 1.x firmware
Hardware Version: 2
Firmware Version: 1.18
Topcard : Unknown
Vtarget : 0.0 V
Varef : 0.0 V
Oscillator : Off
SCK period : 0.1 us
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.06s
avrdude: Device signature = 0x1e9307 (probably m8)
avrdude: safemode: lfuse reads as 24
avrdude: safemode: hfuse reads as D5
avrdude: safemode: Fuse reading not support by programmer.
Safemode disabled.
avrdude: reading input file "0xFC"
avrdude: writing lock (1 bytes):
Writing | | 0% 0.00s ***failed;
Writing | ################################################## | 100% 0.13s
avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0xFC:
avrdude: load data lock data from input file 0xFC:
avrdude: input file 0xFC contains 1 bytes
avrdude: reading on-chip lock data:
Reading | ################################################## | 100% 0.02s
avrdude: verifying ...
avrdude: WARNING: invalid value for unused bits in fuse "lock", should be set to 1 according to datasheet
This behaviour is deprecated and will result in an error in future version
You probably want to use 0x3c instead of 0xfc (double check with your datasheet first).
avrdude: 1 bytes of lock verified
avrdude: safemode: lfuse reads as 24
avrdude: safemode: hfuse reads as D5
avrdude: safemode: lfuse reads as 24
avrdude: safemode: hfuse reads as D5
avrdude: safemode: Sorry, reading back fuses was unreliable. I have given up and exited programming mode
avrdude done. Thank you.