Skip to main content
helmi haddad
Associate
March 28, 2019
Question

Position-Independent Code for STM32L4 relocatable application

  • March 28, 2019
  • 3 replies
  • 1766 views

how i can configure my project to make a relocatable application , i use the IAR workbench.

  1. i activated the --ROPI option in IAR Options
  2. i modified the .s file as follow :
MODULE ?cstartup
 
 ;; Forward declaration of sections.
 SECTION CSTACK:DATA:NOROOT(3)
 
 SECTION .intvec:CODE:NOROOT(2)
 
 EXTERN PI_Reset_Handler
 PUBLIC __vector_table
.
.
.
 PUBWEAK Reset_Handler
 SECTION .text:CODE:NOROOT:REORDER(2)
Reset_Handler
 LDR R0, =PI_Reset_Handler
 BX R0
.
.
.
  1. i modified in main.c
...
/* Private functions ---------------------------------------------------------*/
 
extern void __iar_data_init3(void);
 
extern void __iar_program_start(void);
 
void PI_Reset_Handler(void)
{
 SystemInit();
 __iar_data_init3();
 __iar_program_start();
}
 
/**
 * @brief Main program
 * @param None
 * @retval None
 */
int main(void)
{ ....

But when i put the binary file of app in flash at address (0x8010000) , my boot when jump to app , the app can't run . i remarked that the NVIC must be relocated . but the problem when i relocated the NVIC ( add an offset x10000) , i see the same problem .

So how i can configure my app to be relocatable please ?

This topic has been closed for replies.

3 replies

Tesla DeLorean
Guru
March 28, 2019

Will still have to deal with the fact the vector table has absolute addresses.

In IAR I'd expect a check box item for compiler/linker to generate position independent code. Check the documentation and support materials, surely covered.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
helmi haddad
Associate
March 28, 2019

where i can found the documentation please ?

David SIORPAES
ST Employee
March 28, 2019

Options / C/C++ Compiler / Code / Position-independence

0690X00000898rNQAQ.png

helmi haddad
Associate
March 28, 2019

I already activated this option , i still have the problem how the IVECT table be relocatable ?

Alex R
Associate II
March 28, 2019

Check the system_stm32l4xx.c and system_stm32l4xx.h files for the SystemInit() function.

At the end of it, you'll find the instructions to relocate the Vector Table.

In particular, you nee to write the SCB->VTOR register to set the address location (SRAM or FLASH) and the offset within that location.