[U-Boot-Users] booting elf images where VMA != LMA

Robin Getz rgetz at blackfin.uclinux.org
Fri Mar 25 15:53:55 CET 2005

The elf standard (& the gnu linker) supports two types of memory addresses:
  - virtual memory address (VMA).
     This is the address the section will have when the output file is run.
  - load memory address (LMA)
     This is the address at which the section will be loaded.

In most cases the two addresses will be the same (LMA equal to the VMA). 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. In this case 
the ROM address would be the LMA, and the RAM address would be the VMA.

What seems to happen in the 'bootelf' command in U-boot, is it ignores the 
LMA, and loads things at the VMA. This means that any elf image that 
expects things to be at the LMA at run time does not function properly, as 
things have already been relocated. (Normally when LMA != VMA, relocation 
is done in the startup code).

Question is:
  - Do I patch the standard elf relocation code to always load things at 
the LMA?
  - Do I patch the standard elf relocation code to load at the LMA when 
CONFIG_ELF_LOAD_LMA is set? (or some such thing)

Comments welcome.


Details of the issue:

Looking at the elf file with objdump and readelf shows a section named 
.text_l1, with a VMA = ffa00000, and a LMA = 000f27c8.

'objdump -h' gives me:

Idx Name          Size      VMA       LMA       File off  Algn
   5 .text_l1      00000170  ffa00000  000f27c8  000e4000  2**4

'readelf -S' provides:

Section Headers:
   [Nr] Name              Type            Addr     Off    Size ES Flg Lk Inf Al
   [ 6] .text_l1          PROGBITS        ffa00000 0e4000 
00017000  AX  0   0 16

'readelf -l' provides

Elf file type is EXEC (Executable file)
Entry point 0x1000
There are 2 program headers, starting at offset 52

Program Headers:
   Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
   LOAD           0x001000 0x00001000 0x00001000 0xe2be0 0xf17c8 RWE 0x1000
   LOAD           0x0e4000 0xffa00000 0x000f27c8 0x00170 0x00170 R E 0x1000

  Section to Segment mapping:
   Segment Sections...
    00     .text .init .data .bss
    01     .text_l1

It looks like the elf relocation loads sections from the section list 
rather than use the segment (program) header (which is where the load 
address and virtual addresses are stored).

uboot with bootelf says :
Bytes transferred = 5328594 (514ed2 hex)
Loading .text_l1 @ 0xffa00000 (368 bytes)

Futher reading (and where I snipped some of the above from) is at:

More information about the U-Boot mailing list