Skip to content
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

[Question] is 'setBootProt' dangerous? #73

Closed
GMagician opened this issue Jun 29, 2019 · 6 comments
Closed

[Question] is 'setBootProt' dangerous? #73

GMagician opened this issue Jun 29, 2019 · 6 comments

Comments

@GMagician
Copy link

GMagician commented Jun 29, 2019

Hello,

I'm creating code to program SEE size and I'm getting some hints from function above.

When fuses to set boot code protection are to be written, code does:
exec_cmd(NVMCTRL_CTRLB_CMD_EP);
this will format a page so 512 bytes set to 0xFF (but why format? if we only clear bits no format is required)
program then write fuses[0] and fuses[1] (first 64 bits)
and finally:
exec_cmd(NVMCTRL_CTRLB_CMD_WQW);

but SAMD51 datasheets writes:

159:128 Reserved Factory settings - do not change.

so do we destroy something?

@ladyada
Copy link
Member

ladyada commented Jun 29, 2019

not sure, it could be wrong - if you have other code that works please submit it as a PR

@GMagician
Copy link
Author

Yes, I'm not sure as well, that's why I asked

@GMagician
Copy link
Author

GMagician commented Jun 29, 2019

@ladyada may you check in a brand new board, loading a boot code without fuse programming, what are the content in user page (512 bytes), I think my board has lost them, since fuse are programmed as soon as board starts the first time (since no 16k are protected by default)

@dhalbert
Copy link

The SAMD51 data sheet says:

Note:  Before erasing the NVM User Page, ensure that the first 32 Bytes are read to a buffer and later
written back to the same area unless a configuration change is intended.

So I think you're right, fuses should be eight words (32 bytes) instead of just two, for the SAMD51.

The SAMD21 makes the calibration data unwritable, and it's in a different row.

The fuse fixing code was added because we were seeing broken boards where the entire user page was set to all 1's (by some unknown cause), which was enabling the watchdog timer. We only reset the first two words if they appear to have been completely smashed (all 1's).

You're right that a factory-fresh chip would only need BOOTPROT bits to be cleared, with no page erase necessary. But someone could also want to use an update-bootloader UF2 after using Atmel Studio, etc., and so BOOTPROT might not be pristine.

@ladyada I'm not sure what the factory programmers are doing in terms of preserving bytes past the first two words.

@GMagician
Copy link
Author

GMagician commented Jun 29, 2019

@dhalbert not only first 8 words (32 bits) but more, user page is 512 and when you format it you lose also some "personal" data stored by users.

The remaining 480 Bytes can be used for storing custom parameters.

The problem is that if for some reason a board has executed the "restore" fuses code then we lost all "factory defaults" and I don't know what is the use of that.

Edit: And for sure every board Adafruit sold has lost them (since first time you execute boot code you write bootprotect fuses)

@GMagician
Copy link
Author

Proposed a PR..I close this

piquan pushed a commit to piquan/uf2-samdx1 that referenced this issue Oct 28, 2019
pybadge and pygamer fixes; new boards; improved splashscreen display; merge from upstream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants