AnsweredAssumed Answered

Position independent code on STM32F2xx

Question asked by richn on Jul 17, 2013
I'm trying to create a position-independent application that will run in one of two possible locations in flash as part of a firmware update process. A 'live' application will download a new application, check it for errors and save it to the 'non live' flash location. A reset is then forced. A boot manager will determine the most recent of the applications at run time, and jump to that. But at link time, it is not possible to tell where the application will end up.
When we're downloading a new App, we modify the reset vectors accordingly, and this works fine. But the compiled code contains some absolute addresses, which mess things up.
So I've tried using -fPIC (GCC compiler in Rowley Crossworks). This generates a GOT as expected, but there are still absolute addresses in the compiled code which appear to originate from the start-up code and ST libraries. Because the absolute addresses are not in defined positions in the code (unlike the vector table for example), it's a lot more difficult to modify them whilst writing the new code to flash.
Any suggestions for generating truly position independent code?