Skip to main content
CTapp.1
Senior III
Jun 9, 2025 8:31 PM UTC
Solved

Changing default memory sections

I'm working on some code that has a boot loader and an application. At the moment I am using one linker script for each, which means I have to make sure I keep them in sync. Is it possible to configure the build for (e.g.) the boot loader so that .boottext is used instead of .text for the code so that a single linker file can be used?

I've tried searching (here and internet) and it appears as if this can't be done with GCC - but I thought it was worth asking just in case I've missed something.

 

This topic has been closed for replies.
CTapp.1
CTapp.1Best answer
Senior III
Jun 10, 2025 9:27 AM UTC

Thanks, that's got me where I need to be (only needed the --defsym).

I've just used DEFINED when creating the memory regions:

flashStart = DEFINED(isBootLoader) ? 0x8000000 : 0x8010000;
flashLength = DEFINED(isBootLoader) ? 64K : 64K;

/* Memories definition */
MEMORY
{
 RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
 FLASH (rx) : ORIGIN = flashStart, LENGTH = flashLength
}

 And then just add a linker flag when building the boot loader:

-Xlinker --defsym isBootLoader=1

 

All posts are made in a personal capacity. MISRA C++ Chair, MISRA C WG Member, Director The MISRA Consortium Limited (TMCL)

2 replies

Pavel A.
Jun 9, 2025 11:22 PM UTC

Kind of. You can use  the --defsym option to define constants for linker script on the command line.

Use these constants as addresses and sizes of  memory regions.

Also you can use REGION_ALIAS statements  to define aliases for memory regions.

For example in the common part of the script use the region name "ROM" which is alias of either FLASH1 or FLASH2, etc.

 

 

CTapp.1
CTapp.1AuthorBest answer
Senior III
Jun 10, 2025 9:27 AM UTC

Thanks, that's got me where I need to be (only needed the --defsym).

I've just used DEFINED when creating the memory regions:

flashStart = DEFINED(isBootLoader) ? 0x8000000 : 0x8010000;
flashLength = DEFINED(isBootLoader) ? 64K : 64K;

/* Memories definition */
MEMORY
{
 RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
 FLASH (rx) : ORIGIN = flashStart, LENGTH = flashLength
}

 And then just add a linker flag when building the boot loader:

-Xlinker --defsym isBootLoader=1

 

All posts are made in a personal capacity. MISRA C++ Chair, MISRA C WG Member, Director The MISRA Consortium Limited (TMCL)