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

Caterina bootKey position is in the middle of RAM on Leonardo #10377

Open
DataGhost opened this issue Jun 17, 2020 · 0 comments
Open

Caterina bootKey position is in the middle of RAM on Leonardo #10377

DataGhost opened this issue Jun 17, 2020 · 0 comments
Labels
Architecture: AVR Applies only to the AVR microcontrollers (Uno, etc.) Component: Bootloader The bootloader is the program used to load the uploaded program into the microcontroller's memory Type: Bug

Comments

@DataGhost
Copy link

DataGhost commented Jun 17, 2020

This has been discussed at length in #2474 and the core was fixed to allow bootKey to live at RAMEND-1 rather than the hardcoded 0x800, which is in the middle of RAM on Leonardo/32u4 boards and boards with more than 2kB of RAM that use this code. The changes made in that bug report are rather pointless without an updated bootloader and board definitions, as mentioned there as well but nothing has happened since 2016 (unless I'm mistaken, but the current Caterina.c hasn't been touched in 8 years according to Git)

Case in point: I have a pretty large sketch that has a 1kB display buffer that's updated at about 20fps, well within the 120ms watchdog timeout for the reset. Adding more features has pushed the display buffer to 0x437-0x837, so when the reset is triggered, the bootKey is overwritten before the watchdog fires, and the chip resets but starts the sketch rather than going into the bootloader. I went to some lengths to keep my code "small" (27868/28672 at the moment) while I could have done away with the USB bit altogether (saving me some kBs), but I liked the practical side of it so I kept it and then got a bit disappointed to run into this issue.

I could hack up several different fixes but I think I don't know nearly enough about which other boards use this code and the reasons behind this magic position to write something good for everyone. One possible fix without having to re-flash the bootloader would be to write the bootKey at RAMEND-1 and have the sketch check for it in main() (so before setup()), write it to 0x800 and restart. That's a pretty ugly hack though and costs a few bytes of sketch flash. The bootloader overwrites it so that doesn't work.

The "best" fix is flashing the bootloader. I think this should be possible "in place", I don't see any reason why not because it's "just somewhere in flash". Maybe this can be done through a (modified) Caterina as a sketch (so it's not writing where it's executing) with the very slight risk of bricking the device (power outage etc). Is that reasoning a bit sound? That would save the hassle of having to hook up all your boards to a programmer, and it would be nice if this were exposed as an option in the IDE or arduino-cli. That would make it easier for beginners and people without separate programmers. I could try hacking this up if I have some spare time.

@per1234 per1234 added Architecture: AVR Applies only to the AVR microcontrollers (Uno, etc.) Component: Bootloader The bootloader is the program used to load the uploaded program into the microcontroller's memory Type: Bug labels Aug 1, 2020
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: Bootloader The bootloader is the program used to load the uploaded program into the microcontroller's memory Type: Bug
Projects
None yet
Development

No branches or pull requests

2 participants