EmbDev.net

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


von Lauren (Guest)


Rate this post
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:
1
SECTIONS 
2
{ 
3
   
4
    .text 0x08000000: 
5
    {    
6
     bootstart = ABSOLUTE(.) ;
7
     KEEP(*(.isr_vector .isr_vector.*)) 
8
     bootend = ABSOLUTE(.)  ; 
9
     *(.text .text.* .gnu.linkonce.t.*)    
10
     *(.glue_7t) *(.glue_7)                    
11
     *(.rodata .rodata* .gnu.linkonce.r.*)
12
    }        
13
...

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.
1
SECTIONS 
2
{ 
3
 . = 0x08000000;
4
 bootstart = . ;  
5
    .text : 
6
    {  ...
7
8
...
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?

Lauren

von Martin Thomas (Guest)


Rate this post
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 
TrueStudio:
1
ENTRY(Reset_Handler)
2
3
MEMORY
4
{
5
  FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 1024K
6
  RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 112K
7
}
8
9
SECTIONS
10
{
11
  .text :
12
  {
13
    ___SVECTOR = .;
14
    KEEP(*(.isr_vector)) /* Startup code */
15
    ASSERT (. != ___SVECTOR, "No isr_vector input-section!");
16
    . = ALIGN(4);
17
    *(.text)
18
    *(.text.*)
19
    *(.gnu.linkonce.t.*)
20
    [... removed ...]     
21
  } >FLASH
22
23
  [... arm.extab, arm.exidx, data and bss defintions here ...]

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.