Skip to content

Commit bc96a44

Browse files
committed
Convert output to Intel HEX format unconditionally in post-build
This converts output to Intel HEX format unconditionally but to BIN format just on demand for the following reasons: 1. Most flash programming tools support Intel HEX format, e.g. GDB load command. 2. Output can have large holes in addresses which BIN format cannot handle and can generate very large file.
1 parent e3c163b commit bc96a44

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

tools/cmake/mbed_target_functions.cmake

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,24 @@ function(mbed_generate_bin_hex target)
1313

1414
set(artifact_name $<TARGET_FILE_BASE_NAME:${target}>)
1515

16+
# Convert to BIN format just on demand because the resultant output
17+
# can have large holes in addresses which BIN format cannot handle and
18+
# can generate very large file.
19+
#
1620
# The first condition is quoted in case MBED_OUTPUT_EXT is unset
1721
if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "bin")
1822
list(APPEND CMAKE_POST_BUILD_COMMAND
1923
COMMAND ${elf_to_bin} -O binary $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.bin
2024
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.bin"
2125
)
2226
endif()
23-
if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "hex")
24-
list(APPEND CMAKE_POST_BUILD_COMMAND
25-
COMMAND ${elf_to_bin} -O ihex $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex
26-
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex"
27-
)
28-
endif()
27+
# Convert to Intel HEX format unconditionally which most flash programming
28+
# tools can support. For example, GDB load command supports Intel HEX format
29+
# but no BIN format.
30+
list(APPEND CMAKE_POST_BUILD_COMMAND
31+
COMMAND ${elf_to_bin} -O ihex $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex
32+
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex"
33+
)
2934

3035
add_custom_command(
3136
TARGET

0 commit comments

Comments
 (0)