I have a project for a PIC16F1454 that needs some custom linking. Basically, I've separated my code into two parts that can be downloaded separately in the field and thus update (almost) all of the flash memory, including the bootloader. As part of the plan to avoid bricking itself, I have this structure:
- Lower, protected by hardware, not field-updateable:
- Startup and image-copy code, written in assembly
- Application space
- Also used to download new images
- Bootloader space
And there's some code in various places that enforces that structure.
The bootloader includes a USB stack, a main loop, and some helper functions that add up to slightly more than one page of flash, which causes some problems for the linker. For example, the help file says that this option is supposed to concatenate the entire list and put it against the specified upper limit (note the negative address):
But when I do that, all four psects overlap, with the usual, unintended consequences. I did this:
- -L-aBootloader=1400h-17FFh,1800h-1FFDh -L-dBootloader=2 -L-pUSBCode=Bootloader -L-pUSBConst=Bootloader -L-pBootloaderCode=Bootloader -L-pBootloaderConst=Bootloader
which defines a class with 2-byte elements that crosses a page boundary at 1800h and puts all four psects in that class. While they didn't overlap, I got a big hole next to the page boundary, big enough for several of the helper functions to fit in.
I could assign functions more granularly to more than four psects, and that would probably make things fit better, but I'd rather not make it any more complicated than I have to. Someone else (could be me after a few months) is probably going to modify it later, and I don't expect him to be intimately familiar with the details.
How can I pack the entire bootloader section as tightly as possible into upper memory, accounting for the springboard to main() at 1FFEh-1FFFh, without requiring a future developer to change anything outside of the C source files?