-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Unable to burn bootloader with Atmel-ICE in Arduino IDE 1.8.13 #11107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What seems to be happening is that the second command tries to set the lock bits so that the bootloader or sketch cannot overwrite bootloader, but for some reason, that fails. There have been some issues with verification of fuses and lock bytes wrt the bits that are unused (some programmers read them back as 0, some as 1), but the avrdude version that you are using has been patched by Arduino to ignore these unused bytes entirely when verifiying. In this case, I think that the upper two bits are unused and the lower six (0x3F) are used. The second avrdude programs a value of 0x0F, so that's lock bit 4 and 5 set (0 is set, 1 is cleared), but the value read back is 0xFF, which has lock bit 4 and 5 cleared (0). Also, bit 6 and 7 are different, but those are unused bits, so that's ok. I'm not sure why setting the lock bits fails, though... |
Hi @matthijskooijman , I believe there is no Hardware issue. The same error message appears when I try to burn the bootloader into my other PS: By the way - the reason I'm diving into Arduino has everything to do with this new free IDE for microcontrollers: Embeetle IDE (see https://embeetle.com). I'm currently in the process of adding Arduino support there. |
If you have specific questions, just ask.
Well, it looks like the bootloader was flashed succesfully, it's just the lock bits that could not be set for some reason. So I'd expect that your board works, it's just not as well-protected as it should. You could also try running avrdude manually to read the lock byte back, to see if it the write really failed, or it's just the verify that fails somehow (maybe the lock bytes only take effect after a reset or so?). For that, I think you can use this command (haven't fully tested it though):
I'm not 100% sure that using
If you haven't already, check out arduino-cli, that's a convenient CLI tool that can handle the entire Arduino build process and might be useful to use as a backend for other IDEs (it's not yet used directly by the Java IDE yet, that still uses arduino-builder, but that again includes parts of arduino-cli). |
Hi @matthijskooijman , I just tried something. I entered the exact same commands that the Arduino IDE prints in its console into a Windows terminal. 1. Same commands - but in Windows TerminalI opened a Windows Terminal and entered the two 1.1 First avrdude commandThe first command I entered is this one: "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude" -C"C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf" -v -patmega328p -catmelice_isp -Pusb -e -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xDE:m -Ulfuse:w:0xFF:m Restyled and reformatted, it looks like this (see also my original post): avrdude -C C:/Program Files (x86)/.../avrdude.conf
-v
-patmega328p
-catmelice_isp
-Pusb
-e
-Ulock:w:0x3F:m
-Uefuse:w:0xFD:m
-Uhfuse:w:0xDE:m
-Ulfuse:w:0xFF:m The output is exactly the same as before (see my original post), with a few exceptions. After printing the table with memory info,
In the original output (from the Arduino IDE console), the following is printed right after that line: Reading | ################################################## | 100% 0.01s
avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: erasing chip
avrdude: reading input file "0x3F" In the Windows terminal output, I see this instead: Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as FD
avrdude: erasing chip
avrdude: reading input file "0x3F" Another difference is all the way at the end of the output. The original output (from the Arduino IDE console, see original post) ends like this: Reading | ################################################## | 100% 0.00s
avrdude: verifying ...
avrdude: 1 bytes of lfuse verified
avrdude done. Thank you. While the Windows terminal outputs this: Reading | ################################################## | 100% 0.02s
avrdude: verifying ...
avrdude: 1 bytes of lfuse verified
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as FD
avrdude: safemode: Fuses OK (E:FD, H:DE, L:FF)
avrdude done. Thank you. 1.2 Second avrdude commandThe second "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude" -C"C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf" -v -patmega328p -catmelice_isp -Pusb -Uflash:w:"C:\Program Files (x86)\Arduino\hardware\arduino\avr/bootloaders/optiboot/optiboot_atmega328.hex":i -Ulock:w:0x0F:m Restyled and reformatted, it looks like this (see also my original post): avrdude -C C:/Program Files (x86)/.../avrdude.conf
-v
-patmega328p
-catmelice_isp
-Pusb
-Uflash:w:"C:/Program Files (x86)/.../optiboot_atmega328.hex":i
-Ulock:w:0x0F:m The output is the same as before, with the exception that the output in the Arduino IDE ends like this: Reading | ################################################## | 100% 0.01s
avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
0xff != 0x0f
avrdude: verification error; content mismatch
avrdude done. Thank you. and the output in the Windows terminal ends like this: 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 0xcf instead of 0x0f (double check with your datasheet first).
avrdude: 1 bytes of lock verified
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as FD
avrdude: safemode: Fuses OK (E:FD, H:DE, L:FF)
avrdude done. Thank you. 2. Conclusions?I don't know what to conclude from this. How is it possible that the same One thing that comes to my mind is a timing issue. In the Arduino IDE, they run rapidly one after the other. When I enter them manually, there is considerably more time between them. However, that doesn't explain the difference in the output of the first command. To test the timing-issue-theory, I put both commands in a 3. Additional questionWell - it seems like it does work in the Windows console, and that's what ultimately matters to me (of course, it would be nice if it gets fixed in the Arduino IDE as well). However, the following output scares me a little (it's at the end of the output for the second command): 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 0xcf instead of 0x0f (double check with your datasheet first).
avrdude: 1 bytes of lock verified
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as FD
avrdude: safemode: Fuses OK (E:FD, H:DE, L:FF)
avrdude done. Thank you. Especially this phrase: I assume it has to do with the last flag in the second command: |
Hm, interesting. I had also noticed that the warning appears the first time but not the second time, but re-reading the avrdude patch (https://github.com/arduino/avrdude-build-script/blob/master/avrdude-6.3-patches/80-Avoid-failing-fuse-check-if-different-bits-are-reserved.patch) I see that the patch is only shown when verification succeeds (with only differences in the unused bits), not when verification fails. So the main difference is that your manual run succeeds, while the IDE run somehow does not. I'm not sure why your manual run shows more (debug) output wrt "safemode" (extra fuse comparisons after programming).
This relates to the unused lock bits I mentioned before. Originally, you'd need 0x0F for some programmers and 0xCF for others. With an Arduino-specific patch, the unused bits are ignored, but also this warning was added to encourage users of the avrdude binary to switch to 0xCF instead. In this case, that means changing the lock byte values in the So this is something we should fix in
Hm, so maybe not a timing problem between both commands, then. However, what you said reminded me of lock-byte timing issue I had observed with the JTAGICE3 years ago. I did a bit of digging and found my bug report: https://savannah.nongnu.org/bugs/?func=detailitem&item_id=42267 This was fixed in avrdude also years ago, but the "fix" was adding a bit of a delay, so maybe the delay isn't always enough somehow? In the report it was also suggested that adding more -v options could slow down things enough to fix them, so maybe you could try editing |
Hi @matthijskooijman , 1. Unused lock bitsThe unused lock bits issue is indicated by the warning: 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 0xcf instead of 0x0f (double check with your datasheet first).
avrdude: 1 bytes of lock verified As you say, this issue is most probably not causing the
The warning suggests to check the datasheet first before deciding. Unfortunately, I have not enough experience with AVR microcontrollers to make an informed decision here. I hope you can give me a suggestion. 2. avrdude crash in Arduino IDEYou're absolutely right about this:
Very intriguing, indeed.
Interesting observation! I just added a tools.avrdude.bootloader.pattern="{cmd.path}" "-C{config.path}" {bootloader.verbose} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{runtime.platform.path}/bootloaders/{bootloader.file}:i" -Ulock:w:{bootloader.lock_bits}:m -v The error persisted. Even with two https://embeetle.com/downloads/misc/extremely_verbose_output.txt Shouldn't this be fixed in a proper way in |
You should use Note that this does assume using the Arduino-patched version of avrdude, since upstream has not merged this patch yet. Without this patch,
Hm, you testing suggests that maybe the delay put into avrdude is not enough somehow. IIRC they put in 10ms while (later) Atmel suggested they use 20ms, so maybe the delay should be extended, then. I'll dig out my JTAGICE3 (which is very similar to the Atmel ICE) and see if I can reproduce this in the coming days. I'll also see if I can build a custom avrdude with a bit more delay, to see if that solves the problem reliably. If so, we can provide a patch to avrdude upstream, see if they want to merge that (and in the meanwhile, probably apply the patch in the Arduino version too). |
Hi @matthijskooijman ,
That's a great idea! Please let me know if you can't reproduce the issue with the |
Hi @matthijskooijman , Some more interesting news. I just tried to run the two In Embeetle IDE, I added an artificial wait time (up to several seconds) between both However, just like in Arduino IDE, the bootloader burning works when I add three(!) Thanks a lot for your help :-) |
If I can't, I'll probably try to send you a custom avrdude build to test, probably easier. Also, I have access to an Atmel ICE in the office of a customer, but due to Corona I'm not yet sure when I'll be there again. In any case, thanks for the offer!
Thinking on this a bit more, I suspect that the output handling might be difference here. Probably outputting to a console is slightly slower than to a pipe (as used by the IDE), leading to this difference in timing. You could try running in the console with output redirected to a file, I'd guess that would break it. |
Hi @matthijskooijman ,
The offer for a new Atmel-ICE still stands. It's the least I can do for your generous help! I could purchase it on Farnell and send it to your address directly - so you'd have it in one day.
That could very well be true!
Unfortunately, that's not possible in Embeetle IDE. I mean - it would be possible, but it would require too much code refactoring. PS: please drop me a mail so we can stay in contact: |
I meant in the windows terminal, where until now your manual avrdude call did not break.
I'd rather keep this on github as much as possible, for others to read, contribute and for public history. If you do need to contact me privately, my e-mail is in my github profile. |
Hi @matthijskooijman , "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude" -C"C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf" -v -patmega328p -catmelice_isp -Pusb -Uflash:w:"C:\Program Files (x86)\Arduino\hardware\arduino\avr/bootloaders/optiboot/optiboot_atmega328.hex":i -Ulock:w:0x0F:m > file.txt 2> errfile.txt All output is now redirected to files 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 0xcf instead of 0x0f (double check with your datasheet first).
avrdude: 1 bytes of lock verified
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as FD
avrdude: safemode: Fuses OK (E:FD, H:DE, L:FF)
avrdude done. Thank you. That looks fine - no errors. PS: I dropped you a mail, just to open a communication channel (and to see if I don't end up in your SPAM folder). |
Yeah, I think it does that. Annoying, because all output is marked red by the IDE, but that's how it is...
Ok, so maybe something slightly different that affects timing somehow. In any case:
So, the avrdude version you have does not have the 10ms delay workaround for https://savannah.nongnu.org/bugs/?func=detailitem&item_id=42267 at all, so the problem we're seeing is most likely just that. I'm not sure why this commit is reverted, I've created a new issue for that at facchinm/avrdude#13. From here, I think @facchinm must pick this up, there's not more I can do now. If you want to test this yourself, you could try building avrdude yourself using https://github.com/arduino/avrdude-build-script and/or https://github.com/facchinm/avrdude with facchinm/avrdude@6b08631 reverted, but I'm not sure how easy that is under Windows (probably needs cygwin or mingw or so). |
Hi @matthijskooijman , Mr. @facchinm (https://github.com/facchinm) is the one in charge of the |
Hi everyone, |
Yay for cleanup! Thanks! |
Hi @facchinm , Are you the |
@kristofmulier unfortunately yes (at the moment) 😄 |
@matthijskooijman I adopted your version of fuse check patch here facchinm/avrdude@41988d0 (see arduino/avrdude-build-script#2 (comment)) 😉 |
Thank you @facchinm and @matthijskooijman for your help! When will the patched
If the patched Kind regards, |
Hi @kristofmulier , @matthijskooijman I had to replace your "fuses" patch with the old one since it was segfaulting on atmega4809 + edgb (uno wifi rev2). I'm attaching it here alongside the old one as a reference (I'd love to restore it once it's fixed) |
Hm, bummer. Any chance you could run it through gdb to get a backtrace? I don't have that hardware, so I don't think I can try that myself... |
Sure, here we go
( |
Hi @facchinm and @matthijskooijman , 1. How I use avrdudeI'm part of a team creating a new (free) IDE for microcontrollers: Embeetle IDE (see https://embeetle.com). We're currently working on Arduino support in the IDE. To use As you can see in the figure above, it's the folder In Embeetle IDE, I then invoke C:/embeetle/gnu_avr_toolchain_7.3.0_32b/bin/avrdude -C "C:/embeetle/gnu_avr_toolchain_7.3.0_32b/etc/avrdude.conf"
-v -patmega328p
-catmelice_isp
-Pusb
-e
-Ulock:w:0x3F:m
-Uefuse:w:0xFD:m
-Uhfuse:w:0xDE:m
-Ulfuse:w:0xFF:m and like this for the second command: C:/embeetle/gnu_avr_toolchain_7.3.0_32b/bin/avrdude -C "C:/embeetle/gnu_avr_toolchain_7.3.0_32b/etc/avrdude.conf"
-v
-patmega328p
-catmelice_isp
-Pusb
-Uflash:w:../config/bootloaders/optiboot_atmega328.hex:i
-Ulock:w:0xCF:m This second command always ended in the following error, both on the Arduino IDE and in Embeetle IDE: avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
0xff != 0x0f
avrdude: verification error; content mismatch
avrdude done. Thank you. 2. Replace avrdude with new buildI just downloaded the latest build (8 Jan 2021) at https://github.com/arduino/avrdude-build-script/releases/tag/6.3.0-arduino19 I then launched Embeetle IDE and attempted to flash the bootloader - just like I did before. Now it works. The second command ends in: avrdude: verifying ...
avrdude: 1 bytes of lock verified
avrdude done. Thank you. I'm still a bit flabbergasted that it actually worked. After all, I ignored all files in the build from @facchinm except for Will this approach also work on Linux? I will try that tomorrow. Thanks a lot for this new build! Kind regards, |
Hi. I've tried the AVRDUDE.EXE binary from the recent nightly Arduino build and it still has an error when I try to burn bootloader with Atmel ICE. The facchinm's temporary version works just fine but I would like the fix to be included in the official Arduino build. |
Hi @dbychkov , Kind regards, |
Hi @dbychkov , My apologies. |
@kristofmulier @matthijskooijman I just published the
|
Hi,
I've copied AVRDUDE files from "avrdude-6.3.0-arduino19-i686-w64-mingw32.zip" to my Arduino install folder and tried to burn bootloader and upload sketch to the Arduino Nano via ISP with Atmel-ICE programmer. Both tests were completed successfully. Attached 2 files with console output from Arduino/AVRDUDE.
OS: Windows 7 Ultimate SP1, x64 on Intel i7
Arduino: 1.8.13
Programmer: Atmel-ICE
Thank you for fixing this issue.
[burn_bootloader.txt](https://github.com/arduino/Arduino/files/6337388/burn_bootloader.txt)
[upload_sketch.txt](https://github.com/arduino/Arduino/files/6337390/upload_sketch.txt)
|
I don't have a setup for testing ready quickly, but I'm interested in the source and patches applied to have a look at that side of things. However, it seems that's still a bit unclear, with @facchinm's avrdude repo being used without being tagged, so it's not quite clear which code is used to build each version exactly. Maybe that's something to clear up, i.e. using git submodules or git tags in the https://github.com/facchinm/avrdude repository? MIght be better to discuss in arduino/avrdude-build-script#15, though. |
I'm trying to burn an Arduino bootloader on an
Arduino UNO
board with theAtmel-ICE
probe. Unfortunately,avrdude
throws an error message when verifying the bytes.1. Hardware setup
My hardware setup looks like this:
By the way - I'm working on a 64-bit Windows 10 PC.
2. Atmel-ICE driver
At first I thought that the
Atmel-ICE
doesn't require installation, because Windows recognizes it as an HID-device. However, I quickly learned thatavrdude
- launched by the Arduino IDE - needs another driver to interact with theAtmel-ICE
. Therefore, I installed thelibusb-win32
driver with Zadig (just as suggested on the GitHub thread #4368):The driver installation succeeded, and I observe a change in the Windows Device Manager. The
Atmel-ICE
probe no longer appears as an HID-device but as alibusb-win32
device instead:I believe the
Atmel-ICE
is now ready to be used withavrdude
.3. Software setup
I'm running a fresh-installed Arduino IDE (version 1.8.13) on a Windows 10 PC. First I activate maximal verbosity for the console output (
File
>Preferences
>Show verbose output
). Next, I select the probe:Tools
>Programmer
>Atmel-ICE (AVR)
Next I select my board:
Tools
>Board
>Arduino AVR Boards
>Arduino UNO
Finally, I burn the bootloader:
Tools
>Burn Bootloader
In the console output, I can see two
avrdude
commands being launched.3.1 First avrdude command
The first
avrdude
command looks like this:the output for this command is:
That looks good.
3.2 Second avrdude command
The second
avrdude
command is:with the following output:
3.3 The error message
As you can see,
avrdude
throws this error message:What should I do to solve this?
The text was updated successfully, but these errors were encountered: