Has Arduino selected wrong lock bits for 328Ps ?

This is what I get trying to burn bootloader with AVR ISP MKII (similar to this one made from Arduinos 16U2 serial adapter, BTW what a waste of 16U2!) or STK500 ATmega8 and FT232 based clone:
avrdude: Device signature = 0x1e950f (probably m328pa)
avrdude: erasing chip
avrdude: reading input file "0x3F"
avrdude: writing lock (1 bytes):

Error while burning bootloader.
Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x3F:
avrdude: load data lock data from input file 0x3F:
avrdude: input file 0x3F contains 1 bytes
avrdude: reading on-chip lock data:

Reading | ################################################## | 100% 0.00s
avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0xff != 0x3f
avrdude: verification error; content mismatch

avrdude done.  Thank you.

That means: I programmed 0x3F to lock bits, but I read 0xFF.
0x3F=0b00111111 and 0xFF=0b11111111
There's table from datasheet:


So who selected 0x3F when bits 7 and 6 are unused, should be equal to 1? 
So for bootloader entry in boards.txt in Arduino\hardware\arduino\avr
you should change lockbits and unlock bits from wrong values:
uno.bootloader.unlock_bits=0x3F
uno.bootloader.lock_bits=0x0F
to correct ones:
uno.bootloader.unlock_bits=0xFF
uno.bootloader.lock_bits=0xCF

Restart IDE, burn again and voila !

BTW for using 16U2 as AVR ISP MKII with avrdude (and Arduino by that) you have to install firmware and drivers provided by Olimex, they made great manual. For access to all ISP pins of 16U2 you have to solder JP2 header (PB4 is slave's RST) and avrdude and conf with compiled patch which have to replace original ones in Arduino\hardware\tools\avr\bin and Arduino\hardware\tools\avr\etc. for programming uC onboard You have to connect both ICSP headers (16U2's PB4 to RST) and cut RESET-EN solder bridge.

Comments