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

Linker script for scatter file

Hello

I am a beginner at this field, and provided booting code with scatter file, compiled with ARM compiler. I need to recompile it using gnu compiler, so downloaded the binary from the below site: 

https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a

While converting assembly code one by one, I have been stuck at converting scatter file into linker file.So uploading question at this site,,,

For example, this is description of the HEAP address in the scatter file 

    HEAP00 0x10000 EMPTY 0x10000 {}      ; 64kb Heap

and it is refereed at steakheap.s as below.

CLUS0CPU0:
      LDR X0, =Image$$HEAP00$$ZI$$Base

How should I convert the code in the scatter file into linker file? And how the address could be referred in the assembly code..?

  • Hi Mongolee! This can be a bit of a convoluted topic, will try to simplify it here.

    The Arm scatter file is creating a section called 'HEAP00' that is 64kb in size. The compiler then automatically creates the symbol 'Image$$HEAP00$$ZI$$Base' upon compilation noting where the base of the HEAP00 section is. From your scatterfile code it looks like that is hardcoded at location '0x10000'. That is what your stackheap.s code is referring to.

    Now the question is now to create an equivalent structure for the GCC toolchain in a linker file, not scatter file. The GCC compiler will not automatically create the necessary symbol to call from the stackheap.s, so you need to name one at the correct location in your linker file. Here is a sample gcc.ld file to work from, attached.

    The symbols like "__code_base = .;" indicate that that symbol should take the value of where in memory the linker file is pointing at that time. The period "." keeps track of where the linker file's position in memory is. At the start of SECTIONS, the period starts at 0x0, where the FLASH section begins. Then all the code and data gets put in the section ".code". The area you are interested in is ".heap".

    The symbol "__HeapBase" is pointing to the base of the heap, just like we want. Now in the stackheap.s, you can create a new stackheap_gcc.s that points to the linker symbol as __HeapBase

    I hope that helps, let us know if that works or if you need further assistance! 

    MEMORY
    {
      FLASH (rwx) : ORIGIN = 0x00000000, LENGTH = 0x00040000
    }                      
    
    SECTIONS
    {
    
     . = 0x0;
    
     .code : 
           {
                  __code_base = .;
                  *.o (vectors)
                  *(.text)
                  *(.data)
                  __code_end = .;
           } > FLASH
    
     .heap (COPY):
           {
                  __end__     = .;     
                  __HeapBase  = .;     /* Image$$HEAP00$$ZI$$Base equal */
                  PROVIDE(end = .);    
                  *(.heap*)
                  __HeapLimit = .;     
           } > RAM
    
     . = ALIGN(8);
    
    __StackLimit = .;                  
     . = . + 0x4000; 
     __StackTop = .;                   
     PROVIDE(__stack = .);             
    
    }