mgmt: updatehub: Clean-up mcuboot & system dependencies

Currently MCUboot and system reset are invoked directly in the sample
applicatiion. This introduce 2 new methods to isolate system from
application.

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
This commit is contained in:
Gerson Fernando Budke 2023-01-05 17:10:00 +01:00 committed by Carles Cufí
commit eb39f1f12e
3 changed files with 36 additions and 7 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 O.S.Systems
* Copyright (c) 2018-2023 O.S.Systems
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -69,6 +69,23 @@ enum updatehub_response updatehub_probe(void);
*/
enum updatehub_response updatehub_update(void);
/**
* @brief Confirm that image is running as expected.
*
* @details Must be used before the UpdateHub probe. It should be one of first
* actions after reboot.
*
* @return Return 0 if success otherwise a negative @errorno value.
*/
int updatehub_confirm(void);
/**
* @brief Request system to reboot.
*
* @return Return 0 if success otherwise a negative @errorno value.
*/
int updatehub_reboot(void);
/**
* @}
*/

View file

@ -19,6 +19,7 @@ LOG_MODULE_REGISTER(updatehub, CONFIG_UPDATEHUB_LOG_LEVEL);
#include <zephyr/drivers/flash.h>
#include <zephyr/sys/reboot.h>
#include <zephyr/data/json.h>
#include <zephyr/dfu/mcuboot.h>
#include <zephyr/storage/flash_map.h>
#include "include/updatehub.h"
@ -762,6 +763,18 @@ static void probe_cb(char *metadata, size_t metadata_size)
LOG_INF("Probe metadata received");
}
int updatehub_confirm(void)
{
return boot_write_img_confirmed();
}
int updatehub_reboot(void)
{
sys_reboot(SYS_REBOOT_WARM);
return 0;
}
enum updatehub_response updatehub_probe(void)
{
struct probe request;
@ -985,14 +998,14 @@ static void autohandler(struct k_work *work)
"confirmed image.");
LOG_PANIC();
sys_reboot(SYS_REBOOT_WARM);
updatehub_reboot();
break;
case UPDATEHUB_HAS_UPDATE:
switch (updatehub_update()) {
case UPDATEHUB_OK:
LOG_PANIC();
sys_reboot(SYS_REBOOT_WARM);
updatehub_reboot();
break;
default: