summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2025-03-27 22:04:42 +0100
committerxengineering <me@xengineering.eu>2025-03-30 18:51:33 +0200
commit3ffdafa73301aad063e3637141d9d3b898757f79 (patch)
tree95c748f7766911a0848dd1fec02e0df6fee3e313
parentb2afe2a52d421a6f9ce87d6b20c0230f93ecbdc4 (diff)
downloadiot-contact-3ffdafa73301aad063e3637141d9d3b898757f79.tar
iot-contact-3ffdafa73301aad063e3637141d9d3b898757f79.tar.zst
iot-contact-3ffdafa73301aad063e3637141d9d3b898757f79.zip
fw: app: update: Add data rx on HTTP PUT /update
This implements a HTTP handler capable of receiving the full data of the firmware image upload. The data is not handled at all and thus not written to flash. This is just an incremental step towards successful firmware image upload to the secondary MCUboot slot.
-rw-r--r--fw/app/src/update.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/fw/app/src/update.c b/fw/app/src/update.c
index 13471d2..9e91380 100644
--- a/fw/app/src/update.c
+++ b/fw/app/src/update.c
@@ -5,9 +5,13 @@
*/
+#include <stdbool.h>
+
+#include <zephyr/dfu/flash_img.h>
#include <zephyr/logging/log.h>
#include <zephyr/net/http/server.h>
#include <zephyr/net/http/service.h>
+#include <zephyr/net/http/status.h>
LOG_MODULE_REGISTER(update);
@@ -19,21 +23,28 @@ static int update_handler(
struct http_response_ctx *response_ctx,
void *user_data
) {
- LOG_DBG("Handling update request");
+ static size_t processed;
+
+ if (status == HTTP_SERVER_DATA_ABORTED) {
+ LOG_WRN("Transaction aborted after %zd bytes.", processed);
+ processed = 0;
+ return 0;
+ }
+
+ processed += request_ctx->data_len;
- response_ctx->body = NULL;
- response_ctx->body_len = 0;
- response_ctx->final_chunk = true;
- response_ctx->status = HTTP_204_NO_CONTENT;
+ if (status == HTTP_SERVER_DATA_FINAL) {
+ LOG_INF("Handled update request receiving %zd octets.", processed);
+ processed = 0;
+ }
- LOG_DBG("Update request handled");
return 0;
}
static struct http_resource_detail_dynamic update_resource_detail = {
.common = {
.type = HTTP_RESOURCE_TYPE_DYNAMIC,
- .bitmask_of_supported_http_methods = BIT(HTTP_GET),
+ .bitmask_of_supported_http_methods = BIT(HTTP_PUT),
},
.cb = update_handler,
.user_data = NULL,