I have a bare metal stand alone elf image compiled with linaro gcc. I need to find out the last address in that image. I tried doing this with objcopy -O ihex
, and writing a small script to parse the ihex output, but this fails if the addresses exceed the 2G address space. So - how can I find out what is the last address in the image?
This is for an arm V8 64 bit architecture chip.
can objcopy be used for this, or should I use something else from the linaro toolchain? objdump maybe?
any help would be appriciated!
objdump
and readelf
can both display section summaries. objdump -h
and readelf -S
seem to be the proper options.
For example,
$ objdump -h boot_flag
boot_flag: file format elf32-littlearm
Sections:
Idx Name Size VMA LMA File off Algn
0 .note.gnu.build-id 00000024 000080b4 000080b4 000000b4 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
1 .text 00000310 000080d8 000080d8 000000d8 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
2 .rodata 00000030 000083e8 000083e8 000003e8 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .data 00000004 00010418 00010418 00000418 2**2
CONTENTS, ALLOC, LOAD, DATA
4 .comment 0000003a 00000000 00000000 0000041c 2**0
CONTENTS, READONLY
5 .ARM.attributes 0000002d 00000000 00000000 00000456 2**0
CONTENTS, READONLY
And...
$ readelf -S boot_flag
There are 8 section headers, starting at offset 0x4d0:
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .note.gnu.build-i NOTE 000080b4 0000b4 000024 00 A 0 0 4
[ 2] .text PROGBITS 000080d8 0000d8 000310 00 AX 0 0 4
[ 3] .rodata PROGBITS 000083e8 0003e8 000030 01 AMS 0 0 4
[ 4] .data PROGBITS 00010418 000418 000004 00 WA 0 0 4
[ 5] .comment PROGBITS 00000000 00041c 00003a 01 MS 0 0 1
[ 6] .ARM.attributes ARM_ATTRIBUTES 00000000 000456 00002d 00 0 0 1
[ 7] .shstrtab STRTAB 00000000 000483 00004b 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings)
I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
Show some section information for an ARM926 static binary. Of interest are the VMA
, LMA
, Size
and Addr
fields. Extract them and sort and then add the Size
to the final value.