HEX generation

The installed hex_generation command converts a binary to Intel HEX at an address obtained from a layout macro. It uses the include directories and definitions from a selected entry in compile_commands.json to evaluate that macro.

Supported build-system inputs

This tool and the c_include helpers support compile_commands.json generated by the TF-M/RSE CMake build with its in-tree toolchains. The GNU, Arm and IAR compiler rules emit one separate -o <object> pair per compilation, including preprocessed layout objects. Output lookup uses that pair.

Custom toolchains and compiler flags must preserve this format. A standalone -o must only identify the compilation output; using it as another option’s operand or as a forwarded argument is outside the supported input contract.

Both command strings and arguments arrays are supported, with POSIX or Windows path quoting. Additional compiler-specific output options, joined -o<path> and long output options, and response-file expansion are outside this interface’s scope. Any manual invocation must use the database and object path from the same build.

Selecting the compilation output

--file_to_mirror now accepts a compilation output path, such as the object produced by preprocessing a linker script. Direct and out-of-tree callers that previously passed a source filename must pass the corresponding output instead. This selects the correct target when several targets compile the same source, and supports hashed filenames from CMAKE_INTERMEDIATE_DIR_STRATEGY=SHORT.

To find that path, locate the source in the compilation database’s file fields and select the entry for the intended target. Inspect its arguments array or command string for -o <path>. Resolve relative output paths against the entry’s directory. Do not reconstruct an output filename from the source name.

The optional output field also records the compilation output. CMake’s Makefile generator can make it relative to the build root, even when directory names a subdirectory. Prefer the compiler’s output option when present; check the path base before copying an output field into a direct invocation.

Missing output filenames and multiple standalone -o tokens are errors. Other tokens are not interpreted as output options, so an include directory such as -overlay cannot override the CMake output path.

When no output option is available, the lookup accepts metadata relative to either the command’s working directory or the compilation database directory. If metadata alone makes multiple entries match, use an absolute output field or include the compiler’s output option to disambiguate them.

For example, given /work/build/compile_commands.json containing:

[
  {
    "directory": "/work/build/secure_fw",
    "file": "/work/src/layout.c",
    "arguments": ["cc", "-I/work/src/include", "-E",
                  "-o", ".o/12345678/abcdef01.o", "-c", "/work/src/layout.c"],
    "output": "secure_fw/.o/12345678/abcdef01.o"
  }
]

the output is /work/build/secure_fw/.o/12345678/abcdef01.o. Use that absolute path or its path relative to the directory containing compile_commands.json:

hex_generation \
    --compile_commands_file /work/build/compile_commands.json \
    --file_to_mirror secure_fw/.o/12345678/abcdef01.o \
    --image_layout_h_file /work/src/include/region_defs.h \
    --macro_name IMAGE_ADDRESS \
    --input_binary_file /work/build/image.bin \
    --output_hex_file /work/build/image.hex

IMAGE_ADDRESS stands for the layout macro containing the desired load address. Relative --file_to_mirror paths are resolved from the compilation database directory, independently of the shell’s working directory. The path must match exactly one compilation entry; missing or ambiguous matches are errors. If a semicolon-separated list is supplied, only its first path is used.

CMake integrations should pass the generated object path through MIRROR_FILE to add_convert_to_offset_hex_target(). The in-tree callers already do this.


Copyright (c) 2026, Arm Limited. All rights reserved.