using ORIGIN in the MEMORY section of the linker file in .C source
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?
