Creating and Linking a Custom Bootloader or Library
Posted: Thu Jul 31, 2014 10:40 pm
I have a PIC16F1454 that needs to update its firmware via USB. The complete application + USB stack is a little more than 50% of the code space, so I can't just download the new code and switch to it.
What I think I can do is:
They will always be downloaded as a pair, and there should always be enough evidence for the PC side to resume correctly if it gets interrupted. I would think that that would make the linking a little easier than if the versions were not locked to each other.
So how can I do that? How to make 2 projects that can link to each other, or 1 project that can create 2 downloadable files?
What I think I can do is:
- 1. Tease out a section to be a bootloader that can download code via USB all on its own, but that's about all it can do. Put it as high as I can get it so that the application code can have the rest, starting at the interrupt vector. (instruction 0x0004)
- 2. Use the old bootloader to download a new bootloader over the top of the application code, including a sacrificial section that starts at the reset vector. (instruction 0x0000) The USB is polled, so once this starts, I don't need interrupts. Don't actually write the reset vector until the new code is verified, in case I lose power partway through.
- 3. Reboot and use the sacrificial section to copy the new bootloader into upper memory over the top of the old bootloader. Verify the copy, then change the reset vector to jump to it.
- 4. Reboot again and use the new bootloader to download the new application code. As far as the bootloader is concerned, this is the same as step #2 except that the reset vector jumps to the bootloader just like it already does.
They will always be downloaded as a pair, and there should always be enough evidence for the PC side to resume correctly if it gets interrupted. I would think that that would make the linking a little easier than if the versions were not locked to each other.
So how can I do that? How to make 2 projects that can link to each other, or 1 project that can create 2 downloadable files?