- Thu Jan 29, 2015 4:27 pm
#8479
I've also been thinking how to implement OTA without duplicating the libraries. At first it seemed to be an easy thing to do.
My idea was to create the following flash layout:
0x00000 - 0x1C000 : .text, .data, .rodata (these sections contain data and some code from the libraries, plus my OTA procedure)
0x20000 - 0x40000 : .app.text, .app.data, .app.rodata (I would put my app into these sections)
0x40000 and up : .irom0.text (mostly code from the libraries)
The additional data sections (.app.data, .app.rodata, .app.bss) would be added to the linker script at some fixed offset in RAM, after the .data, .rodata, and .bss. When my firmware would start, it would copy the .app.data, .app.rodata, and .app.text sections from flash to RAM, zero-init .app.bss, and jump to the app entry point somewhere in .app.text.
The problem with this approach is that the heap start address is determined at link time, and library code (in libmain.a) uses that address. So when the actual size of .app.data + .app.rodata + .app.bss sections changes, __heap_start address has to be adjusted. But it is already baked into libmain.a which is stored in flash somewhere above 0x40000!
So the only way left is to have heap size fixed in the linker script. This will also fix the maximum amount of RAM available for the app, and this is something I would rather avoid.
I'm really stuck now. It seems that it's not possible to avoid library code duplication AND have variable heap size at the same time. Any ideas?