This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How do I implement multiple relocate segments?

We recently added external SRAM to an existing product.
Now that I have internal and external SRAM, how do I setup the system to initialize variables in external SRAM correctly as well as in internal SRAM?
Background:
I've created a memory range for the external ram in the linker script file: (see "xsram" below)
MEMORY
{
rom (rx) : ORIGIN = 0x00400000, LENGTH = 0x001F0000
ram (rwx) : ORIGIN = 0x20400000, LENGTH = 0x0005F738
ble_tst (RW) : ORIGIN = 0x2045F738, LENGTH = 0x00000004
led_cnt (RW) : ORIGIN = 0x2045F73C, LENGTH = 0x00000004
mpm_ram (RW) : ORIGIN = 0x2045F740, LENGTH = 0x00000040
fpa_ram (RW) : ORIGIN = 0x2045F780, LENGTH = 0x00000800
rst_buf (RW) : ORIGIN = 0x2045FF80, LENGTH = 0x00000080
xsram (RWXI) : ORIGIN = 0x61000000, LENGTH = 0x00200000
}
I've created two output sections for external SRAM
.relocate : AT (_etext)
{
. = ALIGN(4);
_srelocate = .;
*(.ramfunc .ramfunc.*);
*(.data .data.*);
. = ALIGN(4);
_erelocate = .;
} > ram

/* external SRAM section */
.xsram_no_init (NOLOAD):
{
*(.x_sram_no_init*);
} > xsram

.xsram :
{
*(.x_sram*);
} > xsram

/* .bss section which is used for uninitialized data */
.bss (NOLOAD) :
{
. = ALIGN(4);
_sbss = . ;
_szero = .;
*(.bss .bss.*)
*(COMMON)
. = ALIGN(4);
_ebss = . ;
_ezero = .;
} > ram
I've defined macros for putting variables into the output sections I've created
#define __XSRAM__ __attribute__((section(".x_sram"))) 
#define __XSRAM_NO_INIT__ __attribute__((section(".x_sram_no_init"))) 
Now, for the code below:
  • xsram_test_buf[] should not be initialized
  • xsram_var should be initialized to 3 before main is called
  • xsram_init_buf[] should be initialized to 1,2,3,4 before main is called
  • xsram_init_to_zero should be initialized to zero by default before main is called.

__XSRAM_NO_INIT__ uint8_t xsram_test_buf[XSRAM_TEST_BUF_SIZE]; 
__XSRAM__ uint8_t xsram_var = 3; 
__XSRAM__ uint8_t xsram_init_buf[4] ={1, 2, 3, 4}; 
__XSRAM__ uint32_t xsram_init_to_zero;

uint8_t isram_init_buf[4] ={1, 2, 3, 4};
uint32_t isram_init_to_zero;

I've found that isram_init_buf[] (which is in internal SRAM) gets initialized to 1,2,3,4 and isram_init_to_zero gets initialized to 0, but  xsram_var, xsram_init_buf[], and  xsram_init_to_zero (all in external SRAM) do not.
I believe this is the code that does the initialization.  It looks like all the data that is in flash that gets copied into RAM during startup is all in one group, and all the variables in RAM that have data copied into them are in one group.  All variables that get initialized to zero are in one RAM group.
pSrc = &_etext;
pDest = &_srelocate;

if (pSrc != pDest) {
   for (; pDest < &_erelocate;) {
      *pDest++ = *pSrc++;
   }
}


/* Clear the zero segment */
for (pDest = &_szero; pDest < &_ezero;) {
   *pDest++ = 0;
}
Is there a way to implement 2 relocate segments - one for internal SRAM and one for external SRAM?
I have a similar question for the zero segment (to initialize to 0)