Skip to main content
Graduate II
June 9, 2025
Solved

Changing default memory sections

  • June 9, 2025
  • 2 replies
  • 291 views

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.
    Best answer by CTapp.1

    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

     

    2 replies

    Super User
    June 9, 2025

    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.1AuthorAnswer
    Graduate II
    June 10, 2025

    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