Why convert HEX to ELF?
Some embedded toolchains and debuggers accept only ELF input, not raw HEX. Wrapping a .hex into .elf lets you load firmware into GDB or flashing utilities that require ELF format, even without a symbol table. The complete ELF with symbols and debug info is produced by the compiler; converting from HEX yields only a stripped shell.
How to convert HEX to ELF
avr-objcopy OPEN-SOURCE
Run avr-objcopy -I ihex -O elf32-avr firmware.hex firmware.elf; replace elf32-avr with the correct target (e.g., elf32-littlearm for ARM Cortex-M). avr-objcopy ships with avr-gcc and is bundled inside the Arduino IDE.
arm-none-eabi-objcopy OPEN-SOURCE
For ARM Cortex-M targets, run arm-none-eabi-objcopy -I ihex -O elf32-littlearm firmware.hex firmware.elf from the GNU Arm Embedded Toolchain.
About these formats
A .hex file is an Intel HEX file: compiled firmware for a microcontroller such as an Arduino, AVR, or PIC chip, stored as plain-text records. You don't run it on a PC - you flash it to the…
Open .HEX details →An ELF file is the binary executable format used by Linux, Android, the BSDs and most Unix-like systems - the equivalent of Windows EXE. On Linux you run it directly; a PS2 homebrew .elf…
Open .ELF details →Quality & what to watch
- The output ELF contains only raw bytes at their target addresses; section names will be generic (e.g.,
.sec1) rather than the original.text,.data,.bssnames assigned by the compiler. - If you compiled the firmware yourself, the build directory likely already contains a
.elfalongside the.hex- check there before converting. - The
-O elf32-avrarchitecture flag must match the actual CPU; using the wrong flag produces an ELF that debuggers or flashers will reject.
Frequently asked questions
Can I recover function names and debug symbols from a HEX file?
Where is avr-objcopy on my machine?
hardware/tools/avr/bin/; use arm-none-eabi-objcopy for ARM targets.