This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

linker script symbols to c source variables


Hi all,

I am now confused how I can get values from linker script to csource.

What I want is very simple (I think).

I have a function in a section which should be copied from flash to ram.
So I defined a section which locate the code into flash and should be executed in ram. Before that I have to copy the code from flash to ram.

But how can I get the values from the linker to the csource???

I have the following linker script:

/* We have 96K internal RAM for data only */
MEMORY
{
    IntCodeFlash (rx) : ORIGIN = 0x00000000, LENGTH = 512K   /* this is flash */
    IntDataRAM   (rw) : ORIGIN = 0x40000000, LENGTH = 96k
}



/* Section Definitions */

SECTIONS
{
    /* first section is .text which is used for code in flash memory*/
  .text :
  {
        ./startup.o (.text)         /* Startup code, importatnt to be the first file, need the vectors in front of flash */
        *(.text)                /* all the other text segments follow... */
        *(.glue_7t)
        *(.glue_7)
  } >IntCodeFlash =0

  . = ALIGN(4);                     /* . means actual address. Align this address by 4 */

  startCodeInFlashForRam = . ;

  .linkToRam : AT (startCodeInFlashForRam )
  {
      startCodeInRam = . ;
      *(.linkToRam)
  } > IntDataRAM

  endCodeInFlashForRam = . ;


  . = ALIGN(4);

  /* .rodata section which is used for read-only data (constants) */
  .rodata startCodeInFlashForRam + SIZEOF (.linkToRam) : AT(startCodeInFlashForRam + SIZEOF (.linkToRam) )
  {
      *(.rodata)
  } >IntCodeFlash

  . = ALIGN(4);

  _etext = . ; 
  PROVIDE (etext = .); 

  /* .data section which is used for initialized data */

  /* .data : AT (_etext) */
  .data : AT (startCodeInFlashForRam + SIZEOF (.linkToRam) + SIZEOF( .rodata) )
  {
      _data = . ; 
      *(.data)
      SORT(CONSTRUCTORS)
  } >IntDataRAM
  . = ALIGN(4);

  _edata = . ; 
  PROVIDE (edata = .); 


....

some more sections will follow...

No I have 2 c files:

main.c:
olatile int a,b;

int c=99;
const int d=104;

void f1(void) __attribute__ ((long_call));


extern unsigned int* startCodeInFlashForRam;
extern unsigned int* endCodeInFlashForRam;
extern unsigned int* startCodeInRam;


int main() {
    unsigned int *src=startCodeInFlashForRam;
    unsigned int *dst=startCodeInRam;
    a=(unsigned int)startCodeInFlashForRam;

    while ( src != endCodeInFlashForRam) { *dst++=*src++; } 
    f1();
    b=a;
    b=c;
    b=d;
}



and f1.c
extern volatile int a,b;
void f1(void) __attribute__ ((section (".linkToRam")));
void f1(void) {
    a=9;
} 

-----

This will compile fine and the objdump shows correct (I think) output:


Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000284  00000000  00000000  00008000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .linkToRam    00000014  40000000  00000284  00010000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .rodata       00000004  00000298  00000298  00010298  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  3 .data         00000004  40000014  0000029c  00018014  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  4 .bss          00000008  40000018  40000018  00018018  2**2
                  ALLOC


But the code will not be copied in the main loop :-(
I am wondering, because no error message occurs!


Anyway: I have not really understand how the "." value in linker script works. Is that the address of the execution or of the load view? (LMA/VMA)
What is it pointing to and how to get the source and target address (LMA/VMA) of a section?

Is there any good introduction to that point? As you can see my linker script is totally ugly and not really well to understand. 

Thanks
 Klaus

 


-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kanns mit allen: http://www.gmx.net/de/go/multimessenger


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]