Forum: ARM programming with GCC/GNU tools launchpad gcc for ARM: Understanding linker scripts

von Lauren (Guest)

Rate this post
0 useful
not useful
Greetings to all,

I want to run code from a ram-location on a STM32F407 (Cortex-M4) 
microcontroller, but before I can do this, I want to understand the 
linker-commands, and this seems to be a real challenge.
At first, I want to find out where some code-fragments to run from ram 
later are located.
I'm using Coocox in combined with launchpad-gcc-toolchain and modified 
the default-linker-script:
    .text 0x08000000: 
     bootstart = ABSOLUTE(.) ;
     KEEP(*(.isr_vector .isr_vector.*)) 
     bootend = ABSOLUTE(.)  ; 
     *(.text .text.* .gnu.linkonce.t.*)    
     *(.glue_7t) *(.glue_7)                    
     *(.rodata .rodata* .gnu.linkonce.r.*)

I inserted the assigment of the vars "bootstart" and "bootend" and hoped 
to see where the isr_vector-section begins and where it ends.
Regarding to the documentation of the linker I should get
"bootstart = 0x08000000" and "bootend = 0x080001ff".
But even these simple assigments don't work, I got "bootstart = 
0x20000804" and "bootend = 0xaf00b580", superfluouses to mention, that 
the STM doesn't have so much memory.
 . = 0x08000000;
 bootstart = . ;  
    .text : 
    {  ...

It's amazing, that the code generated with these linker-scripts is still 
executeable on my discovery-board...

Can someone please tell me, what's going (wr)on(g) here?


von Martin Thomas (Guest)

Rate this post
0 useful
not useful
You may start with a linker-script template for the GNU linker that 
comes with the ST StdPerLib or the template given in the readme-file of 
the "launchpad" package. The default linker-script shown by 
arm-none-eabi-ld --verbose does not fit well for systems with 
non-continues memory-regions for read-only (Flash) and read/write (RAM).

Just a remark: The entry KEEP(*(.isr_vector .isr_vector.*)) is not the 
best idea. There should be exactly one input-section with the vector 
table since this must be located a the correct location, so the 
controller finds initial stack-pointer and start-address.

Just to get an idea a few lines from the linker-script I'm currently 
using which is based on the one from the StdPerLib-Template for 

  FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 1024K
  RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 112K

  .text :
    ___SVECTOR = .;
    KEEP(*(.isr_vector)) /* Startup code */
    ASSERT (. != ___SVECTOR, "No isr_vector input-section!");
    . = ALIGN(4);
    [... removed ...]     
  } >FLASH

  [... arm.extab, arm.exidx, data and bss defintions here ...]


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.