blob: 8bbaa9d4871552b4c00c1cd554661fa7a5ccbb10 [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>
Gyorgy Szing3c446242023-03-31 01:53:15 +020012
13#include "common/uuid/uuid.h"
14#include "service/fwu/agent/update_agent.h"
15#include "service/fwu/fw_store/banked/banked_fw_store.h"
Julian Hall65bb4102023-01-19 12:09:02 +000016
17/*
18 * The fwu_app class is intended to provide the core for an application
19 * that uses the update_agent for updating the contents of a disk image
20 * file. The app uses standard fwu components, such as the update_agent,
21 * to manage updates. To support additional update methods (e.g.
22 * update_capsule), inherit from this class and add additional methods
23 * to the derived class. This allows the core app to be reused for
24 * different application areas without overloading the base app.
25 */
26class fwu_app {
Julian Hall65bb4102023-01-19 12:09:02 +000027public:
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 */
Gyorgy Szing3c446242023-03-31 01:53:15 +020041 int configure(const char *disk_img_filename);
Julian Hall65bb4102023-01-19 12:09:02 +000042
43 /**
44 * \brief Get boot info from the FWU metadata
45 *
46 * \param[out] active_index The active index seen by the bootloader
47 * \param[out] metadata_version Current metadata version
48 *
49 * \return Status (0 on success)
50 */
Gyorgy Szing3c446242023-03-31 01:53:15 +020051 int get_boot_info(unsigned int &active_index, unsigned int &metadata_version);
Julian Hall65bb4102023-01-19 12:09:02 +000052
53 /**
54 * \brief Initialise the update agent
55 *
56 * \param[in] boot_index The boot_index chosen by the bootloader
57 * \param[in] metadata_version Current metadata version
58 *
59 * \return Status (0 on success)
60 */
Gyorgy Szing3c446242023-03-31 01:53:15 +020061 int init_update_agent(unsigned int boot_index, unsigned int metadata_version);
Julian Hall65bb4102023-01-19 12:09:02 +000062
63 /**
64 * \brief Update a single image
65 *
66 * Begins staging, writes the raw contents of the image file and ends
67 * staging.
68 *
69 * \param[in] img_type_uuid UUID of image to update
70 * \param[in] img_data Buffer containing image data
71 * \param[in] img_size Size in bytes of image
72 *
73 * \return Status (0 on success)
74 */
Gyorgy Szing3c446242023-03-31 01:53:15 +020075 int update_image(const struct uuid_octets &img_type_uuid, const uint8_t *img_data,
76 size_t img_size);
Julian Hall65bb4102023-01-19 12:09:02 +000077
78 /**
79 * \brief Read an object from the update agent
80 *
81 * \param[in] object_uuid UUID of object
82 * \param[out] data Read object data
83 *
84 * \return Status (0 on success)
85 */
Gyorgy Szing3c446242023-03-31 01:53:15 +020086 int read_object(const struct uuid_octets &object_uuid, std::vector<uint8_t> &data);
Julian Hall65bb4102023-01-19 12:09:02 +000087
88protected:
Julian Hall65bb4102023-01-19 12:09:02 +000089 /**
90 * \brief Return pointer to update_agent struct
91 *
92 * \return Pointer to the core update_agent.
93 */
94 struct update_agent *update_agent();
95
96private:
Julian Hall65bb4102023-01-19 12:09:02 +000097 static const size_t MAX_STORAGE_DEVICES = 4;
98
Gyorgy Szing3c446242023-03-31 01:53:15 +020099 static const struct metadata_serializer *select_metadata_serializer(unsigned int version);
Julian Hall65bb4102023-01-19 12:09:02 +0000100
101 struct update_agent m_update_agent;
102 struct fw_store m_fw_store;
103};
104
105#endif /* FWU_APP_H */