Skip to main content
Associate II
May 23, 2025
Question

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

  • May 23, 2025
  • 2 replies
  • 419 views

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?

2 replies

Technical Moderator
May 23, 2025

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"
Tesla DeLorean
Guru
May 23, 2025

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

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
EvOAuthor
Associate II
May 23, 2025

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?