blob: 8e7f74c37d883894b04a035e21c44c3e8ca61b90 [file] [log] [blame]
Julian Hall65bb4102023-01-19 12:09:02 +00001/*
2 * Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef FWU_APP_H
8#define FWU_APP_H
9
10#include <stdint.h>
11#include <vector>
12#include <common/uuid/uuid.h>
13#include <service/fwu/agent/update_agent.h>
14#include <service/fwu/fw_store/banked/banked_fw_store.h>
15
16/*
17 * The fwu_app class is intended to provide the core for an application
18 * that uses the update_agent for updating the contents of a disk image
19 * file. The app uses standard fwu components, such as the update_agent,
20 * to manage updates. To support additional update methods (e.g.
21 * update_capsule), inherit from this class and add additional methods
22 * to the derived class. This allows the core app to be reused for
23 * different application areas without overloading the base app.
24 */
25class fwu_app {
26
27public:
28 fwu_app();
29 virtual ~fwu_app();
30
31 /**
32 * \brief Configure storage and installers
33 *
34 * Configures a set of storage volumes and installers to manage the
35 * contents of the specified disk image file.
36 *
37 * \param[in] disk_img_filename UEFI formatted disk image
38 *
39 * \return Status (0 on success)
40 */
41 int configure(
42 const char *disk_img_filename);
43
44 /**
45 * \brief Get boot info from the FWU metadata
46 *
47 * \param[out] active_index The active index seen by the bootloader
48 * \param[out] metadata_version Current metadata version
49 *
50 * \return Status (0 on success)
51 */
52 int get_boot_info(
53 unsigned int &active_index,
54 unsigned int &metadata_version);
55
56 /**
57 * \brief Initialise the update agent
58 *
59 * \param[in] boot_index The boot_index chosen by the bootloader
60 * \param[in] metadata_version Current metadata version
61 *
62 * \return Status (0 on success)
63 */
64 int init_update_agent(
65 unsigned int boot_index,
66 unsigned int metadata_version);
67
68 /**
69 * \brief Update a single image
70 *
71 * Begins staging, writes the raw contents of the image file and ends
72 * staging.
73 *
74 * \param[in] img_type_uuid UUID of image to update
75 * \param[in] img_data Buffer containing image data
76 * \param[in] img_size Size in bytes of image
77 *
78 * \return Status (0 on success)
79 */
80 int update_image(
81 const struct uuid_octets &img_type_uuid,
82 const uint8_t *img_data,
83 size_t img_size);
84
85 /**
86 * \brief Read an object from the update agent
87 *
88 * \param[in] object_uuid UUID of object
89 * \param[out] data Read object data
90 *
91 * \return Status (0 on success)
92 */
93 int read_object(
94 const struct uuid_octets &object_uuid,
95 std::vector<uint8_t> &data);
96
97protected:
98
99 /**
100 * \brief Return pointer to update_agent struct
101 *
102 * \return Pointer to the core update_agent.
103 */
104 struct update_agent *update_agent();
105
106private:
107
108 static const size_t MAX_STORAGE_DEVICES = 4;
109
110 static const struct metadata_serializer *select_metadata_serializer(
111 unsigned int version);
112
113 struct update_agent m_update_agent;
114 struct fw_store m_fw_store;
115};
116
117#endif /* FWU_APP_H */