Use the IAR ELF Tool to convert executable targets to their binary formats - iarsystems/cmake-tutorial GitHub Wiki

Introduction

A CMake function can be used to convert executable target (*.elf or *.out) to binary formats such as Motorola S-Record (*.srec, *.mot), Intel Hexadecimal format (*.hex) and Raw Binary (*.bin).

Applies to

  • CMake projects using the IAR C/C++ Compilers with the IAR ILINK technology.

Helpful Resources

Tasks

  • Add the following function() to the CMake project:
# Convert the ELF output to its binary formats
function(iar_elftool tgt)
  add_custom_command(TARGET ${tgt}
    POST_BUILD 
    COMMAND ${CMAKE_IAR_ELFTOOL} --silent --ihex $<TARGET_FILE:${tgt}> <TARGET_PROPERTY:${tgt},NAME>.hex
    COMMAND ${CMAKE_IAR_ELFTOOL} --silent --srec $<TARGET_FILE:${tgt}> <TARGET_PROPERTY:${tgt},NAME>.srec
    COMMAND ${CMAKE_IAR_ELFTOOL} --silent --bin  $<TARGET_FILE:${tgt}> <TARGET_PROPERTY:${tgt},NAME>.bin
)
endfunction()
  • Call the iar_elftool(<target>) function replacing <target> by the actual executable target. Example:
iar_elftool(MyTarget)
  • Build the target.

  • Find MyTarget.hex, MyTarget.srec and MyTarget.bin inside the build sub-directory.

Related resources

⚠️ **GitHub.com Fallback** ⚠️