Add fwu_app for test and demonstration
Adds the fwu_app class to facilitate deployment of the update agent
as part of an application e.g. a user-space or UEFI app. It uses
the standard FWU service components but operates on a disk image
file rather than on a flash device. The disk image file needs to
be a UEFI formated image with MBR+GPT with partitions for metadata
and firmware banks. Will be initially used to test operation with
boot images generated from build tools.
Signed-off-by: Julian Hall <julian.hall@arm.com>
Change-Id: Ia4151841115010333a922c217352614062f8f86a
diff --git a/components/service/fwu/app/metadata_reader.h b/components/service/fwu/app/metadata_reader.h
new file mode 100644
index 0000000..d84017c
--- /dev/null
+++ b/components/service/fwu/app/metadata_reader.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef FWU_METADATA_READER_H
+#define FWU_METADATA_READER_H
+
+#include <cstdint>
+#include <vector>
+
+/*
+ * A version specific metadata reader. Before using get methods to extract
+ * metadata attributes, is_supported() should be called to verify that the
+ * input metadata version is supported.
+ */
+class metadata_version_specific_reader {
+
+public:
+
+ virtual ~metadata_version_specific_reader() {}
+
+ virtual bool is_supported(
+ const uint8_t *buf,
+ size_t data_len) const = 0;
+
+ virtual void get_version(
+ const uint8_t *buf,
+ size_t data_len,
+ unsigned int &version) const = 0;
+
+ virtual void get_active_index(
+ const uint8_t *buf,
+ size_t data_len,
+ unsigned int &active_index) const = 0;
+};
+
+/*
+ * A singleton that provides a common interface for reading fwu metadata.
+ * The caller doesn't need to worry about the version of metadata being used.
+ */
+class metadata_reader {
+
+public:
+
+ static metadata_reader *instance();
+ ~metadata_reader();
+
+ void register_reader(metadata_version_specific_reader *reader);
+
+ int get_boot_info(
+ unsigned int &active_index,
+ unsigned int &metadata_version) const;
+
+private:
+ metadata_reader();
+
+ std::vector<metadata_version_specific_reader *> registered_readers;
+};
+
+#endif /* FWU_METADATA_READER_H */