S32DS ARM2.2 K144xx fPic Example description.
Provided example demonstrate possibility of creation Position Independent Code using standard S32DS ARM 2.2 tools. Example code blink RGB LED using svc interrupt handler. Output picExample.bin should be loaded via restore gdb command only into existing K144 RAM area(0x1fff8000 – 20007000 for EVB board), then pc set to startup value.(see picExample_Debug_RAM_PNE_fpic Debug configuration).
Note: restore gdb command needs absolute path to *.bin file.
Example is based on standard K144 application.
Changes:
- -fPIC option should be set(Project->Properties->C/C++ Build ->Settings->Standard S32DS Compiler->Miscalenous->Position Independent Code).
- Create flash image checkbox should bes set.( Project->Properties->Cross Settings -> Create flash image).
- Flash Image output file format should be set to Raw binary(Project->Properties->C/C++ Build ->Settings->Standard S32DS Create Flash Image )
- Add -nostdlib linker option(Project->Properties->C/C++ Build ->Settings->Standard S32DS Linker->General ->No startup or default libs).
- Existing S was modified(stack pointer was corrected, bl instead of blx for function calls was used.
- Standard linker script was modified(see example)
- Interrupts vector table was moved to data area. Due to this vector addresses are corrected on startup by FixGot routine(see SystemInit()c)
- Common RAM area was declared starting from 0.
- __got_start and __got_end were declared in Global Offset Table
For an in-depth analysis and step-by-step guide on the topic of implementing position-independent code, please see the following blog at mcuoneclipse.com:
Position-Independent Code With GCC for arm Cortex M