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 or the P&E GDB server really needs a ELF/Dwarf file which usually has all the debug information in it. This is a problem if all what I have is a binary file.
This post is about transforming a raw binary (.bin) file into an ELF/Dwarf file with adding a header to it:
I can make a 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 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 🙂
- S-Record, Intel Hex and Binary Files
- Using Eclipse to Program Binary Files to an Embedded Target
- MCUXpresso IDE: S-Record, Intel Hex and Binary Files
- Converting S19 Files into Binary Files with GNU objcopy
- Binary (and S19) Files for the mbed Bootloader with Eclipse and GNU ARM Eclipse Plugins