Add fwu update agent deployment for linux-pc/posix
The fwu update agent can be deployed in different
execution environments to suite platform requirements.
This commit adds a deployment where the fwu update
agent runs within a command-line app for Posix
environments where the firmware image file is accessible
via standard file io. Can be built to run in a native PC
environment to enable a disk image file to be inspected.
Signed-off-by: Julian Hall <julian.hall@arm.com>
Change-Id: I3a652c7ab201c5b7059f8dd1bb6b590e6d8c4c37
diff --git a/deployments/fwu/env/posix/cmd_update_image.cpp b/deployments/fwu/env/posix/cmd_update_image.cpp
new file mode 100644
index 0000000..8e1014f
--- /dev/null
+++ b/deployments/fwu/env/posix/cmd_update_image.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <common/uuid/uuid.h>
+#include "cmd_update_image.h"
+
+
+int cmd_update_image(
+ fwu_app &app,
+ const std::string &img_type_uuid,
+ const std::string &img_filename)
+{
+ FILE *fp = fopen(img_filename.c_str(), "rb");
+
+ if (!fp) {
+
+ printf("Error: failed to open image file: %s\n", img_filename.c_str());
+ return -1;
+ }
+
+ /* Get file size */
+ fseek(fp, 0, SEEK_END);
+ size_t img_size = ftell(fp);
+ rewind(fp);
+
+ /* Allocate buffer for image data */
+ uint8_t *img_buf = (uint8_t *)malloc(img_size);
+
+ if (!img_buf) {
+
+ fclose(fp);
+ printf("Error: failed to allocate image buffer\n");
+ return -1;
+ }
+
+ /* Read file contents into buffer */
+ if (fread(img_buf, 1, img_size, fp)) {
+
+ fclose(fp);
+ printf("Error: failed to read image file\n");
+ return -1;
+ }
+
+ fclose(fp);
+
+ /* Apply update */
+ struct uuid_octets uuid;
+
+ uuid_guid_octets_from_canonical(&uuid, img_type_uuid.c_str());
+
+ int status = app.update_image(uuid, img_buf, img_size);
+
+ if (status)
+ printf("Error: update image failed\n");
+
+ free(img_buf);
+
+ return status;
+}