Looking for some pointers on the scenario below. I'm fairly new to firmware and bare-metal programming.
In the system I'm working on, I am looking to get a bootloader and 2 application programs compiled. The 2 application programs will be placed in FLASH but they maybe overriden by a firmware update depending on which firmware is invalid. The location of the bootloader is fixed and with the firmware update scenario 2 application programs do not have a known physical location.
How would I get the 2 application programs compiled given that I am not able to determine what is the final locations during compile time. Is there a way to make it relocatable via some linking or compile switches?
I'm using the ARM GCC Toolchain on Linux and working on a Cortex M0 MCU.
Thanking everybody in advance.
I am not sure I understand why firmware update will make application physical location undecided. But if it is genuinely need to go with location known, the position independent code is what you need. The way it work in bare-metal is following two options:
1. -fPIC in compile and linker option to make applications compiled for position independent
2. -msingle-pic-base -mpic-register=r9 in compile option makes r9 pointing to your GOT table for relocation in your application
3. bootloader sets r9 to the GOT table location before invoking the application
Thanks for the input Joe
Just to elaborate a little more on the undetermined physical location of the AppCode. Just as an example for a 8K flash space, App1 occupies 1st 4k and App2 occupies the 2nd 4k. However, only one of them functions as the active firmware (latest update).
From a programmers standpoint, they would not know whether the compiled App will be in the first 4K or the 2nd 4K which is why I asked if there was a way to compile such that the code can be relocated anywhere and still function.
I took some ideas from the x86 arch where one initialises CS (Code Segment) register and then all code accesses are relative to that Register location. However, I was not able to find a similar feature in the M0 architecture.
I believe your suggestion could be what I need, but I will need to find out more information on setting up the GOT table and how it works.
Also thanks for putting the correct terms into the context ie. Position Independent Code and the Global Offset Table (GOT). Makes searching for the right solution alot easier.
View all questions in GNU Toolchain forum