2018/03/28

GNU's LMA and VMA



What is LMA and VMA
Every loadable or allocatable output section has two addresses. The first is the VMA, or virtual memory address. This is the address the section will have when the output file is run. The second is the LMA, or load memory address. This is the address at which the section will be loaded. In most cases the two addresses will be the same. An example of when they might be different is when a data section is loaded into ROM, and then copied into RAM when the program starts up (this technique is often used to initialize global variables in a ROM based system). In this case the ROM address would be the LMA, and the RAM address would be the VMA.

You can see the sections in an object file by using the objdump program with the -h option.

Configure LMA/VMA in Linker Script
The full description of an output section looks like this:
   
section [address] [(type)] : [AT(lma)]
  {
    output-section-command
    output-section-command
    ...
  } [>region] [AT>lma_region] [:phdr :phdr ...] [=fillexp]



Generating Binary Image (to burn to Flash)
objcopy can be used to generate a raw binary file by using an output target of `binary' (e.g., use `-O binary'). When objcopy generates a raw binary file, it will essentially produce a memory dump of the contents of the input object file. All symbols and relocation information will be discarded. The memory dump will start at the load address of the lowest section copied into the output file.


Move LMA to VMA
GNU toolchain does not have scattering mechanism like that in ARM toolchain. so BSS (zero init) part needs to be init by startup code.  no library to do that.

How to find out the .bss part?  via __bss_start__ and __bss_end__
_cstartup:

    /* Relocate .fastcode section (copy from ROM to RAM) */

    LDR     r0,=__fastcode_load

    LDR     r1,=__fastcode_start

    LDR     r2,=__fastcode_end


    .fastcode : {

        __fastcode_load = LOADADDR (.fastcode);

        __fastcode_start = .;


        *(.glue_7t) *(.glue_7)

        *isr.o (.text.*)

        *(.text.fastcode)

        *(.text.Blinky_dispatch)

        /* add other modules here ... */


        . = ALIGN (4);

        __fastcode_end = .;

    } >RAM AT>ROM


Reference
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/scripts.html#BASIC-SCRIPT-CONCEPTS

https://www.embedded.com/design/mcus-processors-and-socs/4007119/Building-Bare-Metal-ARM-Systems-with-GNU-Part-1--Getting-Started
http://www.delorie.com/gnu/docs/binutils/ld_19.html
http://www.delorie.com/gnu/docs/binutils/ld_33.html
https://ftp.gnu.org/old-gnu/Manuals/binutils-2.12/html_chapter/binutils_3.html



No comments:

Post a Comment

Post Code on Blogger

Simplest way to post code to blogger for me: <pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black;overflow-x:...