Skip to content

Program unused lock bits to 1 #6601

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Program unused lock bits to 1 #6601

wants to merge 1 commit into from

Conversation

Osambezy
Copy link

When burning the bootloader, write access to the Boot Loader section is first unlocked and then locked again by setting the respective Lock bits in the Lock Bit Byte. Bits 7 and 6 are unused according to the datasheets of ATmega168, ATmega328P, ATmega32U4 and ATmega2560. They should therefore always be programmed to 1.

Currently they are programmed to 0. It still works, but could lead to undesired behavior. Avrdude issues a warning, that will turn into an error in the future.

This patch fixes all Lock bytes such that the unused bits will be programmed to 1.

When burning the bootloader, write access to the Boot Loader section is
first unlocked and then locked again by setting the respective Lock
bits in the Lock Bit Byte. Bits 7 and 6 are unused according to the
datasheets of ATmega168, ATmega328P, ATmega32U4 and ATmega2560. They
should therefore always be programmed to 1.

Currently they are programmed to 0. It still works, but could lead to
undesired behavior. Avrdude issues a warning, that will turn into an
error in the future.

This patch fixes all Lock bytes such that the unused bits will be
programmed to 1.
@facchinm facchinm added Architecture: AVR Applies only to the AVR microcontrollers (Uno, etc.) Component: Avrdude 6.3 Specific to AVRDUDE version 6.3 labels Aug 10, 2017
@matthijskooijman
Copy link
Collaborator

IIRC there is a related issue. One reason for not setting them to 1 originally is that, on some commonly used programmers, avrdude reads these bits back as 0, so setting them to 1 makes verification fail. This was fixed in the Arduino version of avrdude by excluding the unused bits from the verification comparison. From a quick look at the patch, it seems this only applies to fuse bits, lock bits might have been left out.

In any case, the patch was discussed here: arduino/avrdude-build-script#2 and originally here: #5202
Setting the unused fuse bits to 1 happened here: #5182

@matthijskooijman
Copy link
Collaborator

Note that on some programmers (such as FTDI bitbang), avrdude will actually start showing the warning with this change. This is something to be fixed upstream in avrdude, see https://savannah.nongnu.org/patch/?8996

@Osambezy
Copy link
Author

Yes, fixing this in avrdude seems to be the way to go, thanks for the info! If the datasheet says that unused bits are 1, then it should be kept like that all the way through the toolchain.

@matthijskooijman
Copy link
Collaborator

I came across this PR again, and I think the changes in it should maybe be applied? Looking at the current avrude 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) it does seem to apply to the lock bits as well, so I'm not sure why @descampsa only made this change for fuse bits and not lock bits in #5182

As for introducing new avrdude warnings, those should be fixed upstream, but in the meanwhile updating the avrdude patch to the one I submitted upstream (see arduino/avrdude-build-script#2 (comment)) would at least make the warning shown for programmers returning 0 more appropriate.

If this is done, this PR should be resubmitted to https://github.com/arduino/ArduinoCore-avr, since that's where this boards.txt file lives now. Probably needs to be retested on a bunch of different programmers too...

@facchinm, what would you think?

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Architecture: AVR Applies only to the AVR microcontrollers (Uno, etc.) Component: Avrdude 6.3 Specific to AVRDUDE version 6.3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants