diff options
author | xengineering <me@xengineering.eu> | 2025-03-30 18:41:02 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2025-03-30 18:51:33 +0200 |
commit | f0668801d961157a61f20c9698164fb451a5d680 (patch) | |
tree | d8f541db60466a1f37ac884ead94216a570d44bb | |
parent | eb52105fd05ffc2ff98e59e76b48ae0968dfdced (diff) | |
download | iot-contact-f0668801d961157a61f20c9698164fb451a5d680.tar iot-contact-f0668801d961157a61f20c9698164fb451a5d680.tar.zst iot-contact-f0668801d961157a61f20c9698164fb451a5d680.zip |
fw: app: update: Finish first HTTP PUT /update
This adds marking the application firmware image in the secondary slot
for a permanent update and rebooting the device.
It is a known bug that the corresponding HTTP request is never properly
closed since the device reboots while handling the request.
Nevertheless the current state works and enables remote updates.
-rw-r--r-- | fw/app/src/update.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/fw/app/src/update.c b/fw/app/src/update.c index ff4ce6a..5e119eb 100644 --- a/fw/app/src/update.c +++ b/fw/app/src/update.c @@ -8,11 +8,14 @@ #include <stdint.h> #include <zephyr/dfu/flash_img.h> +#include <zephyr/dfu/mcuboot.h> #include <zephyr/logging/log.h> +#include <zephyr/logging/log_ctrl.h> #include <zephyr/net/http/server.h> #include <zephyr/net/http/service.h> #include <zephyr/net/http/status.h> #include <zephyr/storage/flash_map.h> +#include <zephyr/sys/reboot.h> LOG_MODULE_REGISTER(update); @@ -74,8 +77,21 @@ static int update_handler( LOG_ERR("Processed %zd octets but wrote %zd", processed, written); return ret; } - LOG_INF("Handled update request receiving %zd octets.", processed); + LOG_DBG("Received %zd octets.", processed); processed = 0; + + const bool permanent = true; + ret = boot_request_upgrade((int)permanent); + if (ret < 0) { + LOG_ERR("Failed to mark uploaded image for update (%d)", ret); + return ret; + } + + LOG_INF("New application firmware uploaded and marked for update"); + + LOG_INF("Rebooting to complete remote update"); + log_flush(); + sys_reboot(SYS_REBOOT_COLD); } return 0; |