Automating merged.hex Patching After Build

Hello Nordic team,

I would like to automatically patch the merged.hex file each time I build my project. I’ve attempted to use extra_post_build in CMakeLists.txt, but my patching script still runs before the merged.hex file is generated.

From what I’ve read here https://devzone.nordicsemi.com/f/nordic-q-a/102010/adding-extra_post_build-step-from-out-of-tree-application, this behavior might be due to the CONFIG_BOOTLOADER_MCUBOOT macro.
Is there an alternative solution or recommended approach to ensure that my patching logic runs after merged.hex is fully created? i am using nrf 5340 and sdk 2.9.0

Thank you in advance!

Best regards,
kelk

Parents
  • Add a condition in your CMakeLists.txt using POST_BUILD for your execution something like below

    if (DEFINED CONFIG_BOOTLOADER_MCUBOOT)
      add_custom_command(
        TARGET mergehex
        POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}
                python ${CMAKE_CURRENT_SOURCE_DIR}/scripts/patch_hex.py
                ${CMAKE_BINARY_DIR}/merged.hex
      )
    endif()
    

  • Hi,

    I tested the provided code, but encountered the following error:

    CMake Error at CMakeLists.txt:119 (add_custom_command):
      No TARGET 'mergehex' has been created in this directory.
    

    To work around this, I manually added the target using:

    add_custom_target(mergehex
    --input ${CMAKE_BINARY_DIR}/../merged.hex
    )

    However, after doing so, the Python script does not get executed.

Reply
  • Hi,

    I tested the provided code, but encountered the following error:

    CMake Error at CMakeLists.txt:119 (add_custom_command):
      No TARGET 'mergehex' has been created in this directory.
    

    To work around this, I manually added the target using:

    add_custom_target(mergehex
    --input ${CMAKE_BINARY_DIR}/../merged.hex
    )

    However, after doing so, the Python script does not get executed.

Children
No Data
Related