From e3f182549a60ac9e1d84a4f4ce27bced6de0972b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fin=20Maa=C3=9F?= Date: Thu, 28 Mar 2024 11:53:49 +0100 Subject: [PATCH] mgmt: hawkbit: Add support for reboot after update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for automatic reboot after successful update completion Signed-off-by: Fin Maaß --- include/zephyr/mgmt/hawkbit.h | 5 +++++ subsys/mgmt/hawkbit/hawkbit.c | 12 +++++++++--- subsys/mgmt/hawkbit/shell.c | 4 ++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/zephyr/mgmt/hawkbit.h b/include/zephyr/mgmt/hawkbit.h index d22330fc683..46a0ff34328 100644 --- a/include/zephyr/mgmt/hawkbit.h +++ b/include/zephyr/mgmt/hawkbit.h @@ -63,6 +63,11 @@ void hawkbit_autohandler(void); */ enum hawkbit_response hawkbit_probe(void); +/** + * @brief Request system to reboot. + */ +void hawkbit_reboot(void); + /** * @} */ diff --git a/subsys/mgmt/hawkbit/hawkbit.c b/subsys/mgmt/hawkbit/hawkbit.c index 69ee267023f..37a98717a7a 100644 --- a/subsys/mgmt/hawkbit/hawkbit.c +++ b/subsys/mgmt/hawkbit/hawkbit.c @@ -952,6 +952,12 @@ static bool send_request(enum http_method method, enum hawkbit_http_request type return true; } +void hawkbit_reboot(void) +{ + LOG_PANIC(); + sys_reboot(SYS_REBOOT_WARM); +} + enum hawkbit_response hawkbit_probe(void) { int ret; @@ -1186,8 +1192,7 @@ static void autohandler(struct k_work *work) LOG_ERR("Rebooting to previous confirmed image"); LOG_ERR("If this image is flashed using a hardware tool"); LOG_ERR("Make sure that it is a confirmed image"); - k_sleep(K_SECONDS(1)); - sys_reboot(SYS_REBOOT_WARM); + hawkbit_reboot(); break; case HAWKBIT_NO_UPDATE: @@ -1203,7 +1208,8 @@ static void autohandler(struct k_work *work) break; case HAWKBIT_UPDATE_INSTALLED: - LOG_INF("Update installed, please reboot"); + LOG_INF("Update installed"); + hawkbit_reboot(); break; case HAWKBIT_DOWNLOAD_ERROR: diff --git a/subsys/mgmt/hawkbit/shell.c b/subsys/mgmt/hawkbit/shell.c index efe2eccbf16..8b79eb7b223 100644 --- a/subsys/mgmt/hawkbit/shell.c +++ b/subsys/mgmt/hawkbit/shell.c @@ -8,7 +8,6 @@ #include #include #include -#include #include #include "hawkbit_firmware.h" #include "hawkbit_device.h" @@ -25,7 +24,7 @@ static void cmd_run(const struct shell *sh, size_t argc, char **argv) sh, SHELL_ERROR, "Image is unconfirmed." "Rebooting to revert back to previous confirmed image\n"); - sys_reboot(SYS_REBOOT_WARM); + hawkbit_reboot(); break; case HAWKBIT_CANCEL_UPDATE: @@ -43,6 +42,7 @@ static void cmd_run(const struct shell *sh, size_t argc, char **argv) case HAWKBIT_UPDATE_INSTALLED: shell_fprintf(sh, SHELL_INFO, "Update Installed\n"); + hawkbit_reboot(); break; case HAWKBIT_DOWNLOAD_ERROR: