MCUBoot: How to execute code only before fw upgrade starts

Hi,

i am using MCUBOOT + nrF5340 and i am using the nRF Connect Device Manager to upload firmware and perform the upgrade.

I would like to know if it is possible to execute code before the upgrade of the firmware starts. In the specific case, i would like have a led blinking ONLY when the firmware upgrade is on going (that is, a new image has been detected, validated and being then swapped with the actual one).

I know that there is the SYS_INIT(_init_fn, _level, _prio).

Are there other options `?

Thanks in advance !

Kind regards

Riccardo Gaiati

Parents
  • i would like have a led blinking ONLY when the firmware upgrade is on going (that is, a new image has been detected, validated and being then swapped with the actual one)

    Hello,

    I believe there exists some events that you can hook onto from the application. However,  during the actual swap, that would not be possible, as the applications are actually being moved, so your appliication will not be running to control your LEDs.

    So would these DFU events be something that you could use, even though you can't use them during the swap?

    I know that there is the SYS_INIT(_init_fn, _level, _prio).

    What is this used for, exactly?

    Best regards,

    Edvin

  • I found a private ticket discussing this. Here is the implementation of the callbacks that I was talking about:

    static void dfu_started_cb(void) {
        if (update_mode == false) {
            // we did not enter into dfu mode before update! do it now.
            NordicUpdate_enter_update_mode();
        }
    
        LOG_INF("DFU Started");
        k_work_cancel_delayable(&dfu_not_started_handler);
        dfuLedOnDFUStarted();
    }
    static void dfu_stopped_cb(void) {
        LOG_INF("DFU Stopped");
        sys_reboot(SYS_REBOOT_COLD);
    }
    
    static void dfu_pending_cb(void) {
        LOG_INF("DFU Pending");
    }
    
    static void dfu_paused_cb(struct k_timer *timer) {
        is_dfu_paused = true;
        dfuLedOnDFUMode();
    }
    K_TIMER_DEFINE(dfu_paused_timer, dfu_paused_cb, NULL);
    
    int dfu_upload_cb(uint32_t offset, uint32_t size, void* arg) {
        if (is_dfu_paused) {
            dfuLedOnDFUStarted();
            is_dfu_paused = false;
        }
        k_timer_start(&dfu_paused_timer, K_MSEC(DFU_PAUSED_TIMEOUT_MILLIS), K_MSEC(0));
        return 0;
    }
    
    static struct img_mgmt_dfu_callbacks_t dfu_callbacks = {
        .dfu_started_cb = dfu_started_cb,
        .dfu_stopped_cb = dfu_stopped_cb,
        .dfu_pending_cb = dfu_pending_cb,
        .dfu_confirmed_cb = NULL,
    };
    
    void NordicUpdate_init()
    {
        LOG_INF("Register callbacks");
        img_mgmt_register_callbacks(&dfu_callbacks);
        img_mgmt_set_upload_cb(dfu_upload_cb, NULL);
    }

    Best regards,

    Edvin

  • Thanks for the info. Unfortunately, as you pointed out, these callbacks do not satisfy my requirement.

Reply Children
No Data
Related