diff --git a/samples/subsys/mgmt/updatehub/src/main.c b/samples/subsys/mgmt/updatehub/src/main.c index 28db2dc864f..e4d22f99834 100644 --- a/samples/subsys/mgmt/updatehub/src/main.c +++ b/samples/subsys/mgmt/updatehub/src/main.c @@ -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 #include #include -#include #if defined(CONFIG_UPDATEHUB_DTLS) #include @@ -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"); } diff --git a/subsys/mgmt/updatehub/include/updatehub.h b/subsys/mgmt/updatehub/include/updatehub.h index 1cbf3889177..19206becdc9 100644 --- a/subsys/mgmt/updatehub/include/updatehub.h +++ b/subsys/mgmt/updatehub/include/updatehub.h @@ -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); + /** * @} */ diff --git a/subsys/mgmt/updatehub/updatehub.c b/subsys/mgmt/updatehub/updatehub.c index aecba382d49..685a4c9d1b9 100644 --- a/subsys/mgmt/updatehub/updatehub.c +++ b/subsys/mgmt/updatehub/updatehub.c @@ -19,6 +19,7 @@ LOG_MODULE_REGISTER(updatehub, CONFIG_UPDATEHUB_LOG_LEVEL); #include #include #include +#include #include #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: