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

  • The "work around" by creating a dummy.out and depending merged_hex on this dummy.out doesn't seem to be necessary.

    The key solution (at least for me) seems that the custom commands, that need to run after merged.hex are created, are now located in sysbuild/CmakeLists.txt instead of in the projects CmakeLists.txt.

    My sysbuild/CmakeList has some more project specific names, but this should do the trick:


    find_package(Sysbuild REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(sysbuild LANGUAGES)
    
    set(DIR ${CMAKE_CURRENT_SOURCE_DIR}/../)
    set(BUILD_DIR ${DIR}/build)
    
    add_custom_command(OUTPUT ${BUILD_DIR}/changed_merged.hex
        WORKING_DIRECTORY ${DIR}
        DEPENDS merged_hex
        COMMAND python ${DIR}/foo/bar.py ${BUILD_DIR}/merged.hex)

  • Right, it was just a trivial example that shows how to create a target that depends on merged_hex.

Related