EXAMPLE S32K144 Position Independent Code

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

EXAMPLE S32K144 Position Independent Code

EXAMPLE S32K144 Position Independent Code

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 

Labels (1)
Attachments
Comments

Hello , 

Thanks for the example . I am trying to make our current code position independant so that we can load apllication anywhere in memory . 

What i need to know is that , is there a way to make it work without setting No startup or default libs ? 

Your example is generating a hard fault exception could you give compiler version used or a compiled binary file ?  

Hi Ibrahima,

I have asked jiri.kral@nxp.com‌ to support you on this question.

Best Regards,

Mike

Thanks Mike 

ibrahima.thiaw,

In order to make this work from Flash memory GOT and PLT tables must be placed in the RAM to be patched further by the app itself (not bootloader).

 

Once flashed to Flash memory bootloader should set PC to entry point of the application. At the very beginning it patches GOT and PLT that re in RAM. And then it switches to regular application that exploits these tables for function calls and global variables.

Here is an article which might be helpful to you:

https://www.embeddedrelated.com/showthread/comp.arch.embedded/200209-1.php

Hope it helps,

Mike

No ratings
Version history
Last update:
‎06-14-2021 12:13 PM
Updated by: