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:
parent
689d7cb085
commit
eb39f1f12e
3 changed files with 36 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 O.S.Systems
|
||||
* Copyright (c) 2018-2023 O.S.Systems
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
@ -10,7 +10,6 @@
|
|||
#include <zephyr/net/net_event.h>
|
||||
#include <zephyr/net/net_conn_mgr.h>
|
||||
#include <zephyr/net/wifi_mgmt.h>
|
||||
#include <zephyr/dfu/mcuboot.h>
|
||||
|
||||
#if defined(CONFIG_UPDATEHUB_DTLS)
|
||||
#include <zephyr/net/tls_credentials.h>
|
||||
|
@ -45,7 +44,7 @@ void start_updatehub(void)
|
|||
switch (updatehub_update()) {
|
||||
case UPDATEHUB_OK:
|
||||
ret = 0;
|
||||
sys_reboot(SYS_REBOOT_WARM);
|
||||
updatehub_reboot();
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -110,7 +109,7 @@ void main(void)
|
|||
|
||||
/* The image of application needed be confirmed */
|
||||
LOG_INF("Confirming the boot image");
|
||||
ret = boot_write_img_confirmed();
|
||||
ret = updatehub_confirm();
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Error to confirm the image");
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue