Download ELF when VMA! = LMA


I have a problem with this. I am using ARM Cortex-A9 with DS-5 to create firmware for baremetal. I modified my linker file to intentionally place the LMA.data section next to the text and rodata sections, since its default VMA is 1 MB at runtime and the .bin image is about 1 MB but contains 90% zeros. And so I intentionally made LMA! = VMA to save space. I also added code to start.S, which moves the .data section from its lma to vma.

However, when loading the resulting elf file into DS-5, it already loads the entire section into its VMA. As a result, my start.S code, which should move the data, was copied from the LMA with the contents of the garbage to the already correct VMA, and soon after that the garbage led to an error.

I had experience with unequal VMA and LMA in the Cortex-M4 binary, and used gdb to debug the elf, and there was no problem there, but it was a microcontroller. In my current pen software, as it were then, I modeled in the el module the debugging of a script for correctly copying data from its LMA to VMA. Most likely, there will be no problems with offline loading using the binary format, but now we are still in debugging the elf, so I have to fix it.

0
source share
1 answer

The problem is resolved ... I would like to share a solution with you:

This helps to understand that "VMA" and "LMA" are GNU terminology, not an ELF specification. After you start interpreting it using the ELF executable, you will find that there is a program header field called "p_paddr" and another - "p_vaddr" - this makes searching easier! In DS-5, to use p_paddr you can:

Link to the ARM DS-5 debugger command: 1.3.138 set elf load-segment-at-p_paddr

By default, DS-5 uses p_vaddr, which is the standard. Using p_paddr is an implementation quality and is very poorly defined in the specification. The ARM compiler, linker, and C library do not generate this information because the move process is handled internally (scatter loading). In some environments, p_paddr is used not as a physical address, but as a download address (hence, "LMA"), and some use it as an address for resolving characters before and after enabling MMU.

+1
source

Source: https://habr.com/ru/post/889647/


All Articles