Restoring MEGA2560 bootloader, lock bits problem?

Mac OS-X High Sierra 10.13.6, ArduinoIDE 1.8.12, avrdude 6.3-20190619, AVR JTAGICE3.

I’ve just finished experimenting with USBasploader on a couple of MEGAs (one genuine, one cheapie) for a standalone project and wanted to restore the standard bootloader using ArduinoIDE “Tools->Burn Bootlader”.

The bootloader gets written (can upload sketches using USB cable) but I get a verification error.

See attached file (can’t use code tags because of 9000 char post limit).

If I write the bootloader from a terminal I don’t get the error because

a) no -D, does full chip erase including lock bits
b) doesn’t do the ArduinoIDE pre and post lock bit manipulation.

This looks to me related to this old bug:

I’ve had a quick play with the lock bits masks in avrdude.conf with no success.

Any ideas what’s wrong?

Thanks in advance.

avrdude-arduino_lock_bits_problem.txt (396 Bytes)

Attached the wrong file.

This new attachment is avrdude output from Tools → Burn Bootloader

Sorry about that…

avrdude-arduino_lock_bits_problem2.txt (10.1 KB)

I think its the same issue found here which is a issue with avrdude as explained by per. I am not sure if this is the exact case. Check it out hope it helps

Yes, I think that's the problem.

Is the solution offered supposed to be in the current ArduinoIDE?

The avrdude.conf that's used by the IDE is not modified with the suggested lock bit masks.

As I said I played with lock bit masks in avrdude.conf without success but overlooked the need to make changes to boards.txt.

My install has several boards.txt and not sure which is the one used but none have the modified unlock/lock masks.

Just discovered ArduinoIDE uses a modified avrdude which apparently "fiddles" with lock bits.

UNOs have this problem as well. Bug has been around a few years.

Helpful post

Only way I can get rid of the burn bootloader error is to edit avrdude.conf ATmega2560 memory "lock" section to

read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0",
"x x x x x x x x 0 0 o o o o o o"

(this is from the suggested patch)

and edit boards.txt to


I can now upload sketches via the USB cable MOST OF THE TIME, now getting the odd can't talk to the stk500 error which I've not seen before.

Can't see leaving the lock bits unprogrammed would cause this.