Skip to content

Convert the ELF output to bin

Felipe Torrezan edited this page Apr 13, 2024 · 2 revisions

Introduction

A CMake function can be used to convert an executable (*.elf or *.out) to the binary format (*.bin).

Applies to

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

Tasks

  • Add the following function() to the CMake project:
# Convert the ELF output to .bin
function(iar_elf_tool_hex TARGET)
  add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} --silent --bin $<TARGET_FILE:${TARGET}> $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.bin)
endfunction()
  • Call the iar_elf_tool_bin(<target>) function replacing <target> by the actual executable target. Example:
iar_elf_tool_bin(MyTarget)
  • Build the target.

  • Find MyTarget.bin inside the build subdirectory.

Note

${CMAKE_IAR_ELFTOOL} is automatically detected by CMake

Clone this wiki locally