ELF loading when VMA != LMA
Asked Answered
C

1

5

I have a problem on this one. I am using ARM Cortex-A9 with DS-5 to create baremetal firmware. I modified my linker file to intentionally put the .data section LMA adjacent to the text and rodata sections, because its default run-time VMA is located 1MB away and the .bin image is around 1MB but containing 90% zeroes. And so I intentionally made LMA != VMA to save space. I also added a code in start.S that relocates the .data section from its lma to vma.

However on loading the resulting elf file in DS-5, it already loads all section to their VMA. As a result, my start.S code that is supposed to relocate data, copied from the LMA with garbage content to the already correct VMA, and soon afterwards those garbage resulted to fault.

I've had experience with unequal VMA and LMA in binary in Cortex-M4 and used gdb for its elf debugging, and there were no problems there, but it was microcontroller. In my current arm processor application, how would I then simulate in elf debugging the scenario of correctly copying data from its LMA to VMA. Most likely when booting standalone using the binary format there will be no problems, but right now we're still in elf debugging so I have to fix this.

Coleoptile answered 6/10, 2016 at 5:47 Comment(3)
I do not know DS-5, but check if you can relocate the sections on a script when loading your ELF file. At least that is possible with T32.Vshaped
ARM DS-5 is the IDE we use to develop the firmware running on ARM. It's built over Eclipse. It's the one that loads the elf file to run straight from SDRAM and allows us to debug.Coleoptile
I took a look to the debugger commands in DS5 (static.docs.arm.com/dui0452/y/…) and seems like if you can apply an offset on the load command, take a look to page 1.3.85. DS5 also supports T32 like command syntax (CMM), but seems to be only partial, nevertheless you can check "data.load.elf FileName.AXF reloc .text at 0xaddress" (www2.lauterbach.com/pdf/general_ref_d.pdf) Hope it helps.Vshaped
C
6

Problem solved... I'd like to share the solution given to me:

It helps to realize that "VMA" and "LMA" are GNU utility terminology and not in the ELF specification. Once you get down to looking at it from interpreting an ELF executable file, you will find that there is a program header field called "p_paddr" and another called "p_vaddr" - that makes it easier to search for! The option you need in DS-5 to use p_paddr is:

ARM DS-5 Debugger Command Reference : 1.3.138 set elf load-segments-at-p_paddr

By default, DS-5 uses p_vaddr, which is the standard. Usage of p_paddr is a quality of implementation, and is left very loosely defined in the specification. The ARM Compiler, Linker and C Library doesn't generate this information since the relocation process is handled internally (scatter loading). Some environments use p_paddr not as a physical address, but the load address (hence "LMA"), and some use it as an address to resolve symbols before and after MMU is enabled..

Coleoptile answered 10/10, 2016 at 1:39 Comment(1)
Thanks. This has really helped me.Famagusta

© 2022 - 2024 — McMap. All rights reserved.