2018-11-27 03:15 PM
Hi,
I'm currently developing an application on a STM32F103 MCU that is capable of upgrading its own firmware over CAN. The flash memory is split into 2 partitions and the when the currently active application receives a FW update it copies it into the flash memory of the inactive partition. The application has a custom bootloader that verifies the CRC and chooses which partition to boot. This way if an error occurs or a invalid image is flashed, the bootloader can fall back on the old image.
This works fine. However this means that to run an application on the first partition it needs to be built and linked with the flash base set to the location of that partition. And the same applies to the other partition.
What I'm looking for is a method where I can generate a binary that can be flashed into either location and still work.
I've seen some suggestions to use the -fPIC and -fPIE compiler and linker options to produce position independent code. However I haven't been able to get that to work.
There is even a guide for that in the atollic truestudio manual: http://gotland.atollic.com/resources/manuals/9.0.0/Atollic_TrueSTUDIO_for_STM32_User_Guide.pdf Page 163
I'm wondering if anyone has done it or knows how to do it and can provide a complete description of how it can be done.
Any help is very much appreciated,
Thanks
2018-11-27 03:34 PM
The image needs to be fixed-up to run in an alternate location. The vector table contains absolute addresses. You'd likely want a small loader, which you don't erase, which checks the images, and builds a vector table in RAM that you contract between your loader/app not to use for other variables, etc.
2018-11-27 10:13 PM
Fully position-independant applications only work with OS support and virtual memory (MMU).