cancel
Showing results for 
Search instead for 
Did you mean: 

how to convert .hex file to .elf file

karan
Associate III

i have two project one is bootloader and other is application.for downloading purpose i have pls usb/jtag adapter and ude visual platform 4.4 which only programme .elf file. i have knowledge how to combine two hex file .but dont know how to convert hex file to elf file.

i can convert elf to hex using command

objcopy.exe -O ihex out.elf out.hex

but don't know how to convert reverse??

and is there any other way of doing this?

This discussion has been locked for participation. If you have a question, please start a new topic in order to ask your question
3 REPLIES 3

This is on Linux for 32-bit ARM, but should work on all architectures and platforms:

$ file foo.elf
foo.elf: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped
 
$ arm-none-eabi-objcopy -O ihex foo.elf foo.hex
 
$ file foo*
foo.elf: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped
foo.hex: ASCII text, with CRLF line terminators
 
$ head -4 foo.hex
:020000042002D8
:1000000000C00720B9030220C5020220C702022057
:10001000C9020220CB020220CD020220CF02022020
:10002000D1020220D3020220D5020220D7020220F0
 
$ arm-none-eabi-objcopy -I ihex -O elf32-littlearm foo.hex foo2.elf
 
$ file foo* 
foo.elf:  ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped
foo.hex:  ASCII text, with CRLF line terminators
foo2.elf: ELF 32-bit LSB relocatable, no machine, version 1, stripped
 
$ wc -c foo*
3246308 foo.elf
   2870 foo.hex
   1192 foo2.elf
3250370 total
 

Note that the foo2.elf copy is much smaller than foo.elf because foo.elf was compiled with -g and has lots of debug data that was lost in the conversion to hex.

Again, this is for ARM32. Do "objcopy --help" to see a list of supported ELF formats and choose the one that matches your original out.elf file.

karan
Associate III

i have spc5668g powerpc core.and here is snapshot of objcopy -h but i dont know which one is used by spc studio to generate .elf

0690X000008B9cYQAS.png

Try doing "objdump.exe -a" or "objdump.exe --archive-headers" (might be ""objdump.exe /a", ""objdump.exe /archive-headers" on Windows) and see if the file format it reports matches any of the ones reported by "objcopy --help".