cancel
Showing results for 
Search instead for 
Did you mean: 

using ORIGIN in the MEMORY section of the linker file in .C source

EvO
Associate II

I have seen linker scripts like this:

MEMORY
{
  RAM (xrw)       : ORIGIN = 0x200000C0, LENGTH = 32K - 192  /* 192 for vector table  */
  BOOTLOADER (rx) : ORIGIN = 0x08000000, LENGTH = 4K
  FIRMWARE (rx)   : ORIGIN = 0x08001000, LENGTH = 256K - 4K
}
/* Main app start address symbol */
_main_app_start_address = 0x08001000;

with multiple DRY issues.

After trawling through linker script documentation, I came up with the following alternative:

/* Entry Point */
ENTRY(Reset_Handler)

BL_ORIGIN = 0x08000000;
BL_SIZE = 32K;
FW_ORIGIN = (BL_ORIGIN + BL_SIZE);

...

/* Memories definition */
MEMORY
{
  ...
  BOOTLOADER (rx)       : ORIGIN = BL_ORIGIN,  LENGTH = BL_SIZE
  FIRMWARE (rx)		: ORIGIN = FW_ORIGIN,  LENGTH = 256K - BL_SIZE
}
...

where the symbol FW_ORIGIN can be used straight from c, e.g. using:

extern uint32_t FW_ORIGIN[];
const uint32_t FIRMWARE_START_ADDR = (uint32_t)FW_ORIGIN;

I did not see this suggestion anywhere when looking for ways to do this (using search terms like the title of this post), and it works, so I assume it is valid, or are there issues with this approach that I should be aware of?

Best regards,
Edwin
3 REPLIES 3
Saket_Om
ST Employee

Hello @EvO 

There is no issue with your approach!

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om

Have SystemInit use a Linker symbol to set SCB->VTOR automatically rather than use #define macros.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Updated the labels: I am developing for STM32F0, so no VTOR....

But maybe there is a standard symbol for 0x08000000 that I could use to replace the define?

Best regards,
Edwin