Adding extra_post_build step from out of tree application

I'm using NCS v2.3.0.

I am trying to add an additional step for post build processing.  My application is out of tree, and if possible I'm trying to keep my changes limited to the application folder.

I found other tickets recommending extra_post_build_commands, however I do not find any examples of using this extra_post_build_command from the application directory.

As a test I inserted my commands into zephyr/modules/trusted-firmware-m/CmakeLists.txt  and found that it was running but not at the conclusion of building the application.  It was being run during mcuboot generation.

Is there a way to add post build steps from an out of tree application?

Is it necessary to modify the NCS repo/source to use the extra_post_build_commands?  

If so, which CMakeLists.txt should I change to run a step after all child images are built?

  • Hi Anthony,

    I was told that the post build step are somewhat problematic, and that in this case you would essentially have to fork/modify mcuboot and change the cmake files there.

    and if possible I'm trying to keep my changes limited to the application folder.

    So as it currently stands, it looks like you won't be able to keep your changes separated like that. As the next best thing to keep the complexity low, I suggest you do the following:  How to capture changes to zephyr/mcuboot in source control? 

    In short, you fork mcuboot to add your changes, and then replace the reference to the repo in West.

    I hope that's useful.

    Best regards,

    Raoul

  • I have been trying to do something similar to you. I have a custom DFU system set up and need to prepend image headers onto the binary file app_update.bin generated by nrf connect sdk.
    I am used to working in eclipse or other editors where adding post build steps is relatively trivial in the project build settings. This would be a nice feature to add.

    I was able to find a workaround using vsCode tasks. If you are generating your code with the nrf connect extension in vscode you can create a custom compound task that first runs the normal build task and afterwards runs a given executable or whatever else you need to do.
    See https://code.visualstudio.com/docs/editor/tasks#_compound-tasks, particularly the "dependsOrder": "sequence" option. You can then link your custom task to the nrf build action button in the GUI (see https://nrfconnect.github.io/vscode-nrf-connect/guides/build_bind_tasks.html#binding-tasks-to-actions-from-gui

    This option is better for me than forking and modifying the MCUboot repo.

    My tasks.json file looks like this (the name of the default task can be found with the Configure Tasks dropdown in vsCode, this is one of the default tasks that nrf connect creates)

    {
        "tasks": [
            {
                "label": "build then execute task",
                "dependsOrder": "sequence",
                "dependsOn": "nRF Connect: Build: dfu_mcu_boot_uart_example/build (active)",
                "command": "hello_world_print.exe"
            },
        ]
    }
    and outputs in terminal (with minor edits). You can see my task outputs "Hello world from go script" after the app_update.bin file has been created. 

    Executing task: nRF Connect: Build: $$$$$$$/build (active)

    Building $$$$$$$$
    C:\WINDOWS\system32\cmd.exe /d /s /c "west build --build-dir $$$$$$$$ <edited

    [3/183] Generating include/generated/version.h
    -- Zephyr version: 3.5.99 (C:/ncs/v2.6.0/zephyr), build: v3.5.99-ncs1
    [1/1] Linking C executable zephyr\zephyr.elf
    Memory region Used Size Region Size %age Used
    FLASH: 32450 B 48 KB 66.02%
    RAM: 17728 B 256 KB 6.76%
    IDT_LIST: 0 GB 32 KB 0.00%
    [175/183] Linking C executable zephyr\zephyr.elf
    Memory region Used Size Region Size %age Used
    FLASH: 35068 B 499200 B 7.02%
    RAM: 9024 B 256 KB 3.44%
    IDT_LIST: 0 GB 32 KB 0.00%
    [178/183] Generating ../../zephyr/app_update.bin
    image.py: sign the payload
    [179/183] Generating ../../zephyr/app_signed.hex
    image.py: sign the payload
    [181/183] Generating ../../zephyr/app_test_update.hex
    image.py: sign the payload
    [183/183] Generating zephyr/merged.hex
    * Terminal will be reused by tasks, press any key to close it.

    * Executing task: hello_world_print.exe $$$$$$$$ <edited

    Hello world from go script
    * Terminal will be reused by tasks, press any key to close it.

     

Related