ESP like OTA + rollback able bootloader #252
Replies: 8 comments 4 replies
-
A scheme which limited the sketch to the lower half of memory is possible, copying the current code to the high half to back it up. And you could restore than to the primary half of memory. However what you can;t do is have both f them in a usable form at the same time. The absolute location of the application section start must be known at compiletime, which must be where the chip places the inteerrupt vectors vectors to be. This is at an address of 0x200 * BOOTSIZE, and the bootloader cannot modify it's own fuses. You could use the CRC scan peripheral to implement the integrity checking if you marked the high half of the flash as "application data" (through th CODESIZE fuse) so it wouldn't get combined with the low half of the flash in the "app code" checksum so you don't even need an external IC to autorevert. However, swapping the active with backup is more work (since you'd need to do it piecewise with a giant buffer in ram) The copy operations are actually quite easy though they will take about as it does to upload a 64k sketch via SerialUPDI at 345600 baud, (at that speed you are right at the limit of how fast the flash can be written). Backup current sketch would just be setting the FLMPER32 mode, erase 4 0x10000, 0x14000, 0x18000, 0x1C000, then switch the mode to FLWR and loop from start of application section (probably 0x400 or 0x600) to 0xFFFE inclusive, incrementing by 2 (writing by words works, writing by byte is buggy). And reverting is basicall the inverse of that except thatyou can't use the 32-page erase on the first page because that has the bootloader section in it and the erase will jsut fail |
Beta Was this translation helpful? Give feedback.
-
One thing in favor of my 3 sections vs your 4 sections (3 = boot + active application + backup application, 4 = (boot + active, and two inactive applications sections) is that the hardware has explicit support for defining exactly three flash sections - "bootloader, "app code" and "app data" with only the bootloader able to write to app data, and code executing from either of the other two sections able to write to app data (Though both sections can be write protected by code in the bootloader, and that write protection is cleared only on reset. Are you proposing to have the application code be writing the new sketch image to the "old" sections as opposed to the bootloader or what? |
Beta Was this translation helpful? Give feedback.
-
Hi, |
Beta Was this translation helpful? Give feedback.
-
I ordered some Microchip Curiosity Nano Evaluation kits and hope I will be able to test a few things out. |
Beta Was this translation helpful? Give feedback.
-
I was able to build the bootloader using Microchip Studio. This already comes with all the needed libraries. I needed to add the AVR128DB48 to pin_defs_x.h. |
Beta Was this translation helpful? Give feedback.
-
Nope, you didn't need to modify anything. I have had nothing but woe and misery using microchip studio, I never touch it anymore. DA-series bootloader works every bit as well on the DB - there are no differences relevant to the bootloader. It's possible that bugs have been introduced since it was last rebuilt - I vaguely recall adding a bunch of stuff so I could build for the DD-series, which would require different bootloader binaries, but not actually building them yet, so that could hae been the origin of that), but I know I didn't rebuild the bootloaders a that time, because the parts were expevted to care still haven't been released. Sorry if I was unclear above. What I was really trying to get across was that you don't have to - and probably don't want to, be doing the whole process in the bootloader. Get the file written to he app data section which you've declared to be inactive( while the app is running and has access to all it's communication tools without duplicating them in the bootloader. Any copying to the active app sectio has to be done by code in the bootloader section - whether you get there with a callback, or a software reset, or whathaveyou is more of a detal An I mean if the thing only does OTA updates, or requires an otherwise unused pin pin shorted to gtound for non-OTA, since you wouldn't have to do hardly anything under normal conclusions, it could be set to stop using the WDT to exit the bootloader( (checking a pin takes setting one pinnctrl reg, waiting a few clocks, and testing if the pin is low in spite of that - if it wasn't high you could turn off the pullup, and jump to app and you'd essentially be in power up state again, so ou couold despense witth the WDT reset, and use that to help determine if the sketch if broke and needs to be restored from the backup - because that's something that I predict would be troublesome. |
Beta Was this translation helpful? Give feedback.
-
Maybe I was not as clear as I could have been there - you 100% must have a bootloader of some sort to actually copy the code, as only the bootloader section can write to the app data section. But the storing of the new code into a non-app-code location can totally be done by the application, and may well be better handled with the communication machinery of the full sketch, depending on how the firmware is getting to the device. |
Beta Was this translation helpful? Give feedback.
-
First, thank you for taking the time to discuss this with me. My Microchip studio project was compiled for a fixed CPU. I guess this comes with the idea of the studios project idea. Having this set to the AVR128DB64 this of course did not work with the makefile which only contained the AVR128DA series. From what I understood though is the DA and DB series identical for what the bootloader needs. I probably could choose the AVR128DA for compilation and would work in the AVR128DB and then need no change in the makefile? |
Beta Was this translation helpful? Give feedback.
-
Hi everyone,
might it be possible to implement options to the bootloader that allow to "partition" the space of the program memory into either three or two parts so that the bootloader could implement an ESP like behaviour for multiple versions of one program to reside on the chip and switch between them?
With an external watchdog IC this could even implement auto revert in case of failures.
Thanks
Marcel
Beta Was this translation helpful? Give feedback.
All reactions