From 4d73cd39809b7d013c6488510a7fedb4fae61f00 Mon Sep 17 00:00:00 2001 From: Adrien Maillard Date: Tue, 29 Apr 2025 15:08:27 +0200 Subject: [PATCH] updatehub: report error before rollback on unconfirmed image Report the error state to the UpdateHub server before triggering a rollback in autohandler mode. This prevents the server from redeploying the same (failed) update after rollback, avoiding update loops. Also exposes a new public syscall: updatehub_report_error(), allowing manual mode users to report an error explicitly. Signed-off-by: Adrien Maillard --- doc/releases/release-notes-4.2.rst | 4 ++++ include/zephyr/mgmt/updatehub.h | 9 +++++++++ subsys/mgmt/updatehub/updatehub.c | 9 ++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/doc/releases/release-notes-4.2.rst b/doc/releases/release-notes-4.2.rst index 6c4f6831a2b..e4c037a9ef3 100644 --- a/doc/releases/release-notes-4.2.rst +++ b/doc/releases/release-notes-4.2.rst @@ -284,6 +284,10 @@ New APIs and options * :kconfig:option:`CONFIG_DEBUG_COREDUMP_BACKEND_IN_MEMORY` * :kconfig:option:`CONFIG_DEBUG_COREDUMP_BACKEND_IN_MEMORY_SIZE` +* UpdateHub + + * :c:func:`updatehub_report_error` + * Other * :kconfig:option:`CONFIG_LV_Z_COLOR_MONO_HW_INVERSION` diff --git a/include/zephyr/mgmt/updatehub.h b/include/zephyr/mgmt/updatehub.h index c37ba423900..c2a3e3b4b0d 100644 --- a/include/zephyr/mgmt/updatehub.h +++ b/include/zephyr/mgmt/updatehub.h @@ -90,6 +90,15 @@ __syscall int updatehub_confirm(void); */ __syscall int updatehub_reboot(void); +/** + * @brief Report an update failure to the UpdateHub server. + * + * @details This sends an ERROR state (UPDATEHUB_STATE_ERROR) for the last package. + * + * @return 0 on success, negative errno on failure. + */ +__syscall int updatehub_report_error(void); + #ifdef __cplusplus } #endif diff --git a/subsys/mgmt/updatehub/updatehub.c b/subsys/mgmt/updatehub/updatehub.c index 95f3b67e1ca..4494ce94c1a 100644 --- a/subsys/mgmt/updatehub/updatehub.c +++ b/subsys/mgmt/updatehub/updatehub.c @@ -1001,7 +1001,9 @@ static void autohandler(struct k_work *work) case UPDATEHUB_UNCONFIRMED_IMAGE: LOG_ERR("Image is unconfirmed. Rebooting to revert back to previous" "confirmed image."); - + if (report(UPDATEHUB_STATE_ERROR) < 0) { + LOG_ERR("Failed to report rollback error to server"); + } LOG_PANIC(); updatehub_reboot(); break; @@ -1044,3 +1046,8 @@ void z_impl_updatehub_autohandler(void) k_work_init_delayable(&updatehub_work_handle, autohandler); k_work_reschedule(&updatehub_work_handle, K_NO_WAIT); } + +int z_impl_updatehub_report_error(void) +{ + return report(UPDATEHUB_STATE_ERROR); +}