EXAMPLE S32K144 Position Independent Code

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

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 

ラベル(1)
添付
コメント

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

評価なし
バージョン履歴
最終更新日:
‎06-14-2021 12:13 PM
更新者: