Over a million developers have joined DZone.

Converting a Raw Binary File Into an ELF/Dwarf File

DZone's Guide to

Converting a Raw Binary File Into an ELF/Dwarf File

Need to convert your binary file into an ELF or Dwarf file to help with debugging and loading? Here are the simple steps to make it happen.

· IoT Zone ·
Free Resource

Digi-Key Electronics’ Internet of Things (IoT) Resource Center Inspires the Future: Read More

Binary files are just a binary blob without debug information. Most debug tools and flashers are able to deal (raw) binary (see S-Record, Intel Hex, and Binary Files). But GDB and/or the P&E GDB server really needs an ELF/Dwarf file, which usually has all the debug information in it. This is a problem if all that I have is a binary file.

This post is about transforming a raw binary (.bin) file into an ELF/Dwarf file and adding a header to it:

Added Elf Header to Raw Binary File

Added ELF header to the raw binary file

I can make an ELF file out of a bin (raw binary) file with the GNU ‘objcopy‘ command like this:

arm-none-eabi-objcopy.exe --input-target=binary --output-target=elf32-little myApp.bin myApp.bin.elf

myApp.bin’ is the application binary file, and it adds an ELF/Dwarf header file to the output file myApp.bin.elf. I can inspect/verify that with the ‘readelf’ GNU program:

arm-none-eabi-readelf.exe -a myApp.bin.elf

Which gives, for example:

ELF Header:
 Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
 Class: ELF32
 Data: 2's complement, little endian
 Version: 1 (current)
 OS/ABI: UNIX - System V
 ABI Version: 0
 Type: REL (Relocatable file)
 Machine: None
 Version: 0x1
 Entry point address: 0x0
 Start of program headers: 0 (bytes into file)
 Start of section headers: 26956 (bytes into file)
 Flags: 0x0
 Size of this header: 52 (bytes)
 Size of program headers: 0 (bytes)
 Number of program headers: 0
 Size of section headers: 40 (bytes)
 Number of section headers: 5
 Section header string table index: 2

Section Headers:
 [Nr] Name Type Addr Off Size ES Flg Lk Inf Al
 [ 0] NULL 00000000 000000 000000 00 0 0 0
 [ 1] .data PROGBITS 00000000 000034 0068f4 00 WA 0 0 1
 [ 2] .shstrtab STRTAB 00000000 006928 000021 00 0 0 1
 [ 3] .symtab SYMTAB 00000000 006a14 000050 10 4 2 4
 [ 4] .strtab STRTAB 00000000 006a64 000058 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)

Now I can use that file like any normal ELF/Dwarf file (of course, it does not have debug information in it), e.g. see Using Eclipse to Program Binary Files to an Embedded Target.

That’s all!

Happy Binaring!


Digi-Key’s IoT Component Selector is your one-stop-shop for the IoT

iot ,debugging ,embedded development ,bin file ,elf file ,dwarf file ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}