Julian Hall | 65bb410 | 2023-01-19 12:09:02 +0000 | [diff] [blame] | 1 | /* |
| 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 Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame^] | 12 | |
| 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 Hall | 65bb410 | 2023-01-19 12:09:02 +0000 | [diff] [blame] | 16 | |
| 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 | */ |
| 26 | class fwu_app { |
Julian Hall | 65bb410 | 2023-01-19 12:09:02 +0000 | [diff] [blame] | 27 | public: |
| 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 Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame^] | 41 | int configure(const char *disk_img_filename); |
Julian Hall | 65bb410 | 2023-01-19 12:09:02 +0000 | [diff] [blame] | 42 | |
| 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 Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame^] | 51 | int get_boot_info(unsigned int &active_index, unsigned int &metadata_version); |
Julian Hall | 65bb410 | 2023-01-19 12:09:02 +0000 | [diff] [blame] | 52 | |
| 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 Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame^] | 61 | int init_update_agent(unsigned int boot_index, unsigned int metadata_version); |
Julian Hall | 65bb410 | 2023-01-19 12:09:02 +0000 | [diff] [blame] | 62 | |
| 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 Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame^] | 75 | int update_image(const struct uuid_octets &img_type_uuid, const uint8_t *img_data, |
| 76 | size_t img_size); |
Julian Hall | 65bb410 | 2023-01-19 12:09:02 +0000 | [diff] [blame] | 77 | |
| 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 Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame^] | 86 | int read_object(const struct uuid_octets &object_uuid, std::vector<uint8_t> &data); |
Julian Hall | 65bb410 | 2023-01-19 12:09:02 +0000 | [diff] [blame] | 87 | |
| 88 | protected: |
Julian Hall | 65bb410 | 2023-01-19 12:09:02 +0000 | [diff] [blame] | 89 | /** |
| 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 | |
| 96 | private: |
Julian Hall | 65bb410 | 2023-01-19 12:09:02 +0000 | [diff] [blame] | 97 | static const size_t MAX_STORAGE_DEVICES = 4; |
| 98 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame^] | 99 | static const struct metadata_serializer *select_metadata_serializer(unsigned int version); |
Julian Hall | 65bb410 | 2023-01-19 12:09:02 +0000 | [diff] [blame] | 100 | |
| 101 | struct update_agent m_update_agent; |
| 102 | struct fw_store m_fw_store; |
| 103 | }; |
| 104 | |
| 105 | #endif /* FWU_APP_H */ |