redken
June 20, 2020, 1:46am
1
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:
opened 01:53AM - 01 Aug 16 UTC
Using Arduino IDE 1.6.10/Arduino AVR Boards 1.6.12 with Windows 7 64 and 32 bit
… 1. Tools > Board > Uno
2. Tools > Programmer > AVRISP mkII
3. Tools > Burn Bootloader fails with:
```
Arduino: 1.6.10 (Windows 7), Board: "Arduino/Genuino Uno"
C:\Program Files (x86)\arduino-1.6.10\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\arduino-1.6.10\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -cstk500v2 -Pusb -e -Ulock:w:0x3F:m -Uefuse:w:0x05:m -Uhfuse:w:0xDE:m -Ulfuse:w:0xFF:m
avrdude: Version 6.3, compiled on Jun 22 2016 at 16:05:21
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "C:\Program Files (x86)\arduino-1.6.10\hardware\tools\avr/etc/avrdude.conf"
Using Port : usb
Using Programmer : stk500v2
avrdude: usbdev_open(): Found AVRISP mkII, serno: 000200217496
AVR Part : ATmega328P
Chip Erase delay : 9000 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 65 20 4 0 no 1024 4 0 3600 3600 0xff 0xff
flash 65 6 128 0 yes 32768 128 256 4500 4500 0xff 0xff
lfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
efuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
lock 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
Programmer Type : STK500V2
Description : Atmel STK500 Version 2.x firmware
Programmer Model: AVRISP mkII
Hardware Version: 1
Firmware Version Master : 1.23
Vtarget : 5.4 V
SCK period : 8.00 us
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% -0.00s
avrdude: Device signature = 0x1e950f (probably m328p)
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.
```
The same issue occurs with all the Arduino AVR Boards I tested(every ATmega328P, ATmega168, ATmega32U4, and ATmega2560 based board in boards.txt) except for Gemma(which is unaffected by this issue or the patch).
Using the same programmer with avrdude 6.0.1-arduino5 works correctly.
The issue is caused by:
http://savannah.nongnu.org/bugs/?46759
It is fixed by modifying avrdude.conf according to this patch:
https://savannah.nongnu.org/patch/index.php?8996
I applied the patch to Arduino AVR Boards 1.6.12's avrdude.conf(attached: [avrdude.conf.txt](https://github.com/arduino/avrdude-build-script/files/392783/avrdude.conf.txt)) and modified the `unlock_bits` and `lock_bits` in boards.txt(attached:[boards.txt](https://github.com/arduino/avrdude-build-script/files/395092/boards.txt))(EDIT: boards.txt updated with a couple edits I missed), which has `extended_fuses` values also modified according to https://github.com/arduino/Arduino/pull/5182. I did **Tools > Burn Bootloader** on every ATmega328P, ATmega168, ATmega32U4, ATmega2560 based board in boards.txt using Atmel AVRISP mkII, USBasp, Arduino as ISP and USBtinyISP. I was unable to completely test the `lock_bits` with my USBtinyISP because it's been failing verification of larger hex files lately for some reason but that issue is happening universally and so is not specific to this test or avrdude 6.3.0-arduino2. I was able to successfully burn ATmega328P and ATmega168 based boards with the USBtinyISP.
The disadvantage I see to applying the patch to avrdude.conf is this will break any 3rd party boards packages that use the affected MCUs and Arduino's avrdude.conf. In order to fix this and maintain backwards compatibility with previous Arduino AVR Boards versions they will need to specify their own avrdude tool(EDIT: I had assumed this patch required a recent AVRDUDE version but this may not be the case?) in the JSON file(EDIT: as well as include it with manual installation files) and include their own avrdude.conf file. Some of these packages will already need to do this due to https://github.com/arduino/Arduino/issues/5175.
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)
redken
June 21, 2020, 3:45am
2
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
redken
June 22, 2020, 4:37am
4
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.
redken
June 22, 2020, 10:58pm
6
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
mega.bootloader.unlock_bits=0xFF
mega.bootloader.lock_bits=0xFF
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.