From 647c48c574b8fcfac0d319d80ccc80229c309333 Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Fri, 20 Jan 2023 17:45:38 +0100 Subject: [PATCH] mgmt: updatehub: Add userspace syscalls The current updatehub version forces user application to run in kernel mode. This add necessary api syscalls to isolate userspace from kernel. Signed-off-by: Gerson Fernando Budke --- include/zephyr/mgmt/updatehub.h | 19 ++++++++--- samples/subsys/mgmt/updatehub/sample.yaml | 11 ++++-- subsys/mgmt/updatehub/CMakeLists.txt | 2 ++ subsys/mgmt/updatehub/updatehub.c | 10 +++--- subsys/mgmt/updatehub/updatehub_handlers.c | 39 ++++++++++++++++++++++ 5 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 subsys/mgmt/updatehub/updatehub_handlers.c diff --git a/include/zephyr/mgmt/updatehub.h b/include/zephyr/mgmt/updatehub.h index 073da6efb19..80a865bdf8e 100644 --- a/include/zephyr/mgmt/updatehub.h +++ b/include/zephyr/mgmt/updatehub.h @@ -14,6 +14,10 @@ #ifndef ZEPHYR_INCLUDE_MGMT_UPDATEHUB_H_ #define ZEPHYR_INCLUDE_MGMT_UPDATEHUB_H_ +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief Responses messages from UpdateHub. * @@ -41,7 +45,7 @@ enum updatehub_response { * @details The updatehub_autohandler handles the whole process * in pre-determined time intervals. */ -void updatehub_autohandler(void); +__syscall void updatehub_autohandler(void); /** * @brief The UpdateHub probe verify if there is some update to be performed. @@ -52,7 +56,7 @@ void updatehub_autohandler(void); * @return UPDATEHUB_INCOMPATIBLE_HARDWARE if Incompatible hardware. * @return UPDATEHUB_METADATA_ERROR fail to parse or to encode the metadata. */ -enum updatehub_response updatehub_probe(void); +__syscall enum updatehub_response updatehub_probe(void); /** * @brief Apply the update package. @@ -67,7 +71,7 @@ enum updatehub_response updatehub_probe(void); * @return UPDATEHUB_INSTALL_ERROR fail while installing the update package. * @return UPDATEHUB_FLASH_INIT_ERROR fail to initialize the flash. */ -enum updatehub_response updatehub_update(void); +__syscall enum updatehub_response updatehub_update(void); /** * @brief Confirm that image is running as expected. @@ -77,17 +81,22 @@ enum updatehub_response updatehub_update(void); * * @return Return 0 if success otherwise a negative 'errno' value. */ -int updatehub_confirm(void); +__syscall int updatehub_confirm(void); /** * @brief Request system to reboot. * * @return Return 0 if success otherwise a negative 'errno' value. */ -int updatehub_reboot(void); +__syscall int updatehub_reboot(void); + +#ifdef __cplusplus +} +#endif /** * @} */ +#include #endif /* ZEPHYR_INCLUDE_MGMT_UPDATEHUB_H_ */ diff --git a/samples/subsys/mgmt/updatehub/sample.yaml b/samples/subsys/mgmt/updatehub/sample.yaml index 712ff7d20cf..ccd6d51cb91 100644 --- a/samples/subsys/mgmt/updatehub/sample.yaml +++ b/samples/subsys/mgmt/updatehub/sample.yaml @@ -15,11 +15,18 @@ tests: - CONFIG_UPDATEHUB_PRODUCT_UID="e4d37cfe6ec48a2d069cc0bbb8b078677e9a0d8df3a027c4d8ea131130c4265f" - CONFIG_UPDATEHUB_POLL_INTERVAL=1 - CONFIG_UPDATEHUB_CE=y - - CONFIG_UPDATEHUB_SERVER="10.5.3.67" + - CONFIG_UPDATEHUB_SERVER="updatehub.io" + sample.net.updatehub.userspace: + extra_configs: + - CONFIG_UPDATEHUB_PRODUCT_UID="e4d37cfe6ec48a2d069cc0bbb8b078677e9a0d8df3a027c4d8ea131130c4265f" + - CONFIG_UPDATEHUB_POLL_INTERVAL=1 + - CONFIG_UPDATEHUB_CE=y + - CONFIG_UPDATEHUB_SERVER="updatehub.io" + - CONFIG_USERSPACE=y sample.net.updatehub.dtls: extra_args: OVERLAY_CONFIG="overlay-dtls.conf" extra_configs: - CONFIG_UPDATEHUB_PRODUCT_UID="e4d37cfe6ec48a2d069cc0bbb8b078677e9a0d8df3a027c4d8ea131130c4265f" - CONFIG_UPDATEHUB_POLL_INTERVAL=1 - CONFIG_UPDATEHUB_CE=y - - CONFIG_UPDATEHUB_SERVER="10.5.3.67" + - CONFIG_UPDATEHUB_SERVER="updatehub.io" diff --git a/subsys/mgmt/updatehub/CMakeLists.txt b/subsys/mgmt/updatehub/CMakeLists.txt index bb9886a4038..285616b57c9 100644 --- a/subsys/mgmt/updatehub/CMakeLists.txt +++ b/subsys/mgmt/updatehub/CMakeLists.txt @@ -14,6 +14,8 @@ zephyr_library_sources_ifdef(CONFIG_UPDATEHUB updatehub_integrity.c) zephyr_library_sources_ifdef(CONFIG_UPDATEHUB updatehub_storage.c) zephyr_library_sources_ifdef(CONFIG_UPDATEHUB_SHELL shell.c) +zephyr_library_sources_ifdef(CONFIG_USERSPACE updatehub_handlers.c) + zephyr_include_directories( ${ZEPHYR_BASE}/subsys/mgmt/updatehub/include ) diff --git a/subsys/mgmt/updatehub/updatehub.c b/subsys/mgmt/updatehub/updatehub.c index a2f4e6a4470..0bc14f3b886 100644 --- a/subsys/mgmt/updatehub/updatehub.c +++ b/subsys/mgmt/updatehub/updatehub.c @@ -743,19 +743,19 @@ static void probe_cb(char *metadata, size_t metadata_size) LOG_INF("Probe metadata received"); } -int updatehub_confirm(void) +int z_impl_updatehub_confirm(void) { return updatehub_storage_mark_partition_as_confirmed(UPDATEHUB_SLOT_PARTITION_0); } -int updatehub_reboot(void) +int z_impl_updatehub_reboot(void) { sys_reboot(SYS_REBOOT_WARM); return 0; } -enum updatehub_response updatehub_probe(void) +enum updatehub_response z_impl_updatehub_probe(void) { struct probe request; struct resp_probe_some_boards metadata_some_boards = { 0 }; @@ -919,7 +919,7 @@ error: return ctx.code_status; } -enum updatehub_response updatehub_update(void) +enum updatehub_response z_impl_updatehub_update(void) { if (report(UPDATEHUB_STATE_DOWNLOADING) < 0) { LOG_ERR("Could not reporting downloading state"); @@ -1005,7 +1005,7 @@ static void autohandler(struct k_work *work) k_work_reschedule(&updatehub_work_handle, UPDATEHUB_POLL_INTERVAL); } -void updatehub_autohandler(void) +void z_impl_updatehub_autohandler(void) { #if defined(CONFIG_UPDATEHUB_DOWNLOAD_SHA256_VERIFICATION) LOG_INF("SHA-256 verification on download only"); diff --git a/subsys/mgmt/updatehub/updatehub_handlers.c b/subsys/mgmt/updatehub/updatehub_handlers.c new file mode 100644 index 00000000000..33a0d4acac6 --- /dev/null +++ b/subsys/mgmt/updatehub/updatehub_handlers.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 O.S.Systems + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + + +static inline void z_vrfy_updatehub_autohandler(void) +{ + z_impl_updatehub_autohandler(); +} +#include + +static inline enum updatehub_response z_vrfy_updatehub_probe(void) +{ + return z_impl_updatehub_probe(); +} +#include + +static inline enum updatehub_response z_vrfy_updatehub_update(void) +{ + return z_impl_updatehub_update(); +} +#include + +static inline int z_vrfy_updatehub_confirm(void) +{ + return z_impl_updatehub_confirm(); +} +#include + +static inline int z_vrfy_updatehub_reboot(void) +{ + return z_impl_updatehub_reboot(); +} +#include