Skip to content

Commit

Permalink
Merge pull request #20237 from benpicco/suit_worker_done_cb
Browse files Browse the repository at this point in the history
sys/suit: introduce suit_worker_done_cb()
  • Loading branch information
benpicco authored Jan 9, 2024
2 parents ec4d1b0 + 7c9345f commit 45bc3bb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
9 changes: 9 additions & 0 deletions sys/include/suit/transport/worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ void suit_worker_trigger_prepared(const uint8_t *manifest, size_t size);
*/
int suit_worker_try_prepare(uint8_t **buffer, size_t *size);

/**
* @brief Callback that is executed after the SUIT process has finished
*
* @param[in] res Result of the SUIT update, 0 on success
*
* By default this will reboot the board, can be overwritten by the application.
*/
void suit_worker_done_cb(int res);

/**
* @brief Trigger a SUIT update
*
Expand Down
26 changes: 16 additions & 10 deletions sys/suit/transport/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,21 @@ int suit_handle_manifest_buf(const uint8_t *buffer, size_t size)
return res;
}

__attribute__((weak))
void suit_worker_done_cb(int res)
{
if (res == 0) {
LOG_INFO("suit_worker: update successful\n");
if (IS_USED(MODULE_SUIT_STORAGE_FLASHWRITE)) {
LOG_INFO("suit_worker: rebooting...\n");
pm_reboot();
}
}
else {
LOG_INFO("suit_worker: update failed, hdr invalid\n ");
}
}

static void *_suit_worker_thread(void *arg)
{
(void)arg;
Expand All @@ -159,16 +174,7 @@ static void *_suit_worker_thread(void *arg)
res = suit_handle_url(_url);
}

if (res == 0) {
LOG_INFO("suit_worker: update successful\n");
if (IS_USED(MODULE_SUIT_STORAGE_FLASHWRITE)) {
LOG_INFO("suit_worker: rebooting...\n");
pm_reboot();
}
}
else {
LOG_INFO("suit_worker: update failed, hdr invalid\n ");
}
suit_worker_done_cb(res);

mutex_unlock(&_worker_lock);
thread_zombify();
Expand Down

0 comments on commit 45bc3bb

Please sign in to comment.