Schr0nk
Schr0nk

Reputation: 41

GCC Linker . CC3200 - why data is copied from Application Image in SRAM to another location in SRAM?

I have noticed that in the TI for the CC3200 (ARMv8 / ARM Cortex M4) examples of the startup_gcc.c the actual data section within the application image is copied to a different location. The application image itself is copied from flash to SRAM by the cc3200s internal bootloader. The application image itself is loaded into SRAM and run this way.

So in my opinion this is a total waste of memory, as the copies the data section to another place in SRAM. Am I missing something? Would the removing the code section out of the ResetISR and altering the Linker file would work fine and just use the memory within the application image in SRAM itself?

ResetISR:

uint32_t *pui32Src, *pui32Dest;
pui32Src = &__init_data;
for(pui32Dest = &_data; pui32Dest < &_edata; )
{
    *pui32Dest++ = *pui32Src++;
}

Linker:

.text :
{
    _text = .;
    KEEP(*(.intvecs))
    *(.bss.gpCtlTbl)
    *(.text*)
*(.ARM.extab* .gnu.linkonce.armextab.*)
. = ALIGN(8);
    _etext = .;
} > SRAM

.rodata :
{
*(.rodata*)
} > SRAM

.ARM : {
__exidx_start = .;
  *(.ARM.exidx*)
  __exidx_end = .;
} > SRAM

__init_data = .;

.data : AT(__init_data)
{
    _data = .;
    *(.data*)
. = ALIGN (8);
    _edata = .;
} > SRAM

Edited Linker without copy (and changing the linker):

.data
{
    _data = .;
    *(.data*)
. = ALIGN (8);
    _edata = .;
} > SRAM

Upvotes: 0

Views: 281

Answers (2)

Tom V
Tom V

Reputation: 5510

This kind of thing is normal when you are loading to ROM. I would expect __init_data to point to an address in ROM, in which case the copy loads it from there to RAM.

In your case it appears that everything is already in SRAM, so there is no need to do a copy of the initialized data.

The only question is, how does the internal bootloader know how big the image is and how much to copy? As long as it includes the data section in its image size then you should be fine to remove the copy loop, and the : AT(__init_data).

It should be easy to test, just define a static int x = 42; and then if (x == 42) { led(on); } or similar.

Upvotes: 2

SoronelHaetir
SoronelHaetir

Reputation: 15172

I am not aware of the capabilities of the particular processor you are using but on X86 for example doing this allows the image to be loaded read-only. The data is then copied to pages that can be written to (actually for X86 in particular, copy-on-write is generally used for these pages so that multiple processes can initialize .data from the same memory and not copy pages that aren't actually changed).

In order to not need this step the image would need to be written with the various sections padded to page-alignment but people generally prefer that the image be as small as possible while containing all needed information.

Upvotes: 0

Related Questions