Julian Hall | 56387ba | 2022-11-18 11:47:44 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2022-2023, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef FWU_INSTALLATION_INSTALLER_H |
| 9 | #define FWU_INSTALLATION_INSTALLER_H |
| 10 | |
| 11 | #include <stdbool.h> |
| 12 | #include <stddef.h> |
| 13 | #include <stdint.h> |
| 14 | #include <common/uuid/uuid.h> |
| 15 | #include <service/fwu/agent/install_type.h> |
| 16 | |
| 17 | #ifdef __cplusplus |
| 18 | extern "C" { |
| 19 | #endif |
| 20 | |
| 21 | /** |
| 22 | * Interface dependencies |
| 23 | */ |
| 24 | struct image_info; |
| 25 | struct fw_directory; |
| 26 | |
| 27 | /** |
| 28 | * \brief Image installer interface |
| 29 | * |
| 30 | * The installer_interface structure provides a common interface for |
| 31 | * any image installer. Concrete installers will implement installation |
| 32 | * strategies that match the class of image being installed (e.g. component, |
| 33 | * whole firmware). |
| 34 | */ |
| 35 | struct installer_interface { |
| 36 | /** |
| 37 | * \brief Begin a transaction of one or more image install operations |
| 38 | * |
| 39 | * \param[in] context The concrete installer context |
| 40 | * \param[in] current_volume_id Where the active fw was loaded from |
| 41 | * \param[out] update_volume_id Where the update should be installed |
| 42 | * |
| 43 | * \return FWU status |
| 44 | */ |
| 45 | int (*begin)(void *context, |
| 46 | uint32_t current_volume_id, |
| 47 | uint32_t update_volume_id); |
| 48 | |
| 49 | /** |
| 50 | * \brief Finalize a transaction of one or more image install operations |
| 51 | * |
| 52 | * \param[in] context The concrete installer context |
| 53 | * |
| 54 | * \return FWU status |
| 55 | */ |
| 56 | int (*finalize)(void *context); |
| 57 | |
| 58 | /** |
| 59 | * \brief Abort a transaction |
| 60 | * |
| 61 | * \param[in] context The concrete installer context |
| 62 | */ |
| 63 | void (*abort)(void *context); |
| 64 | |
| 65 | /** |
| 66 | * \brief Open a stream for writing installation data |
| 67 | * |
| 68 | * \param[in] context The concrete installer context |
| 69 | * \param[in] image_info Describes the image to install |
| 70 | * |
| 71 | * \return FWU status |
| 72 | */ |
| 73 | int (*open)(void *context, |
| 74 | const struct image_info *image_info); |
| 75 | |
| 76 | /** |
| 77 | * \brief Commit installed data (called once per open) |
| 78 | * |
| 79 | * \param[in] context The concrete installer context |
| 80 | * |
| 81 | * \return FWU status |
| 82 | */ |
| 83 | int (*commit)(void *context); |
| 84 | |
| 85 | /** |
| 86 | * \brief Write installation data to an opened installer |
| 87 | * |
| 88 | * \param[in] context The concrete installer context |
| 89 | * \param[in] data Data to write |
| 90 | * \param[in] data_len Length of data |
| 91 | * |
| 92 | * \return FWU status |
| 93 | */ |
| 94 | int (*write)(void *context, |
| 95 | const uint8_t *data, |
| 96 | size_t data_len); |
| 97 | |
| 98 | /** |
| 99 | * \brief Enumerate the collection of images that can be handled by the installer |
| 100 | * |
| 101 | * A concrete installer will use its specialized knowledge of the associated |
| 102 | * storage volume to enumerate the set of images that can be handled by the |
| 103 | * installer. |
| 104 | * |
| 105 | * \param[in] context The concrete installer context |
| 106 | * \param[in] volume_id Identifies the target volume |
| 107 | * \param[in] fw_directory Add results to this fw_directory |
| 108 | * |
| 109 | * \return FWU status |
| 110 | */ |
| 111 | int (*enumerate)(void *context, |
| 112 | uint32_t volume_id, |
| 113 | struct fw_directory *fw_directory); |
| 114 | }; |
| 115 | |
| 116 | /** |
| 117 | * \brief Base installer structure |
| 118 | * |
| 119 | */ |
| 120 | struct installer { |
| 121 | |
| 122 | /* The installation type handled by the installer */ |
| 123 | enum install_type install_type; |
| 124 | |
| 125 | /* The location id is a short ID that identifies an updatable logical |
| 126 | * portion of the firmware store. The location id only needs to be |
| 127 | * unique within the device and will have been assigned dynamically |
| 128 | * during FWU configuration. The location id is used to bind a set of |
| 129 | * installers to the intended set of target volumes. |
| 130 | */ |
| 131 | uint32_t location_id; |
| 132 | |
| 133 | /* The location UUID is a globally unique ID that reflects the same |
| 134 | * logical scope as a location id. It is used to associate incoming |
| 135 | * update images, either directly or indirectly, to the corresponding |
| 136 | * location within the firmware store. For images contained within a |
| 137 | * disk partition, this will correspond to the partition type UUID. |
| 138 | */ |
| 139 | struct uuid_octets location_uuid; |
| 140 | |
| 141 | /* The opaque context for the concrete installer */ |
| 142 | void *context; |
| 143 | |
| 144 | /* Pointer to a concrete installer_interface */ |
| 145 | const struct installer_interface *interface; |
| 146 | |
| 147 | /* Error status encountered during an update transaction. During an update, |
| 148 | * an installer will be called multiple times. If one or more errors are encountered |
| 149 | * during the update transaction, the first error status is saved to allow for |
| 150 | * appropriate handling. |
| 151 | */ |
| 152 | uint32_t install_status; |
| 153 | |
| 154 | /** |
| 155 | * During a multi-image update, images may be delegated to different concrete |
| 156 | * installers to allow for alternative installation strategies and install destinations. |
| 157 | * Each active installer must be sequenced through a begin->finalize transaction to |
| 158 | * ensure that installation operations are completed for all images handled by an |
| 159 | * installer and by all installers used during the update. |
| 160 | */ |
| 161 | bool is_active; |
| 162 | struct installer *next; |
| 163 | }; |
| 164 | |
| 165 | static inline bool installer_is_active(const struct installer *installer) |
| 166 | { |
| 167 | return installer->is_active; |
| 168 | } |
| 169 | |
| 170 | static inline uint32_t installer_status(const struct installer *installer) |
| 171 | { |
| 172 | return installer->install_status; |
| 173 | } |
| 174 | |
| 175 | void installer_init( |
| 176 | struct installer *installer, |
| 177 | enum install_type install_type, |
| 178 | uint32_t location_id, |
| 179 | const struct uuid_octets *location_uuid, |
| 180 | void *context, |
| 181 | const struct installer_interface *interface); |
| 182 | |
| 183 | int installer_begin( |
| 184 | struct installer *installer, |
| 185 | uint32_t current_volume_id, |
| 186 | uint32_t update_volume_id); |
| 187 | |
| 188 | int installer_finalize( |
| 189 | struct installer *installer); |
| 190 | |
| 191 | void installer_abort( |
| 192 | struct installer *installer); |
| 193 | |
| 194 | int installer_open( |
| 195 | struct installer *installer, |
| 196 | const struct image_info *image_info); |
| 197 | |
| 198 | int installer_commit( |
| 199 | struct installer *installer); |
| 200 | |
| 201 | int installer_write( |
| 202 | struct installer *installer, |
| 203 | const uint8_t *data, |
| 204 | size_t data_len); |
| 205 | |
| 206 | int installer_enumerate( |
| 207 | struct installer *installer, |
| 208 | uint32_t volume_id, |
| 209 | struct fw_directory *fw_directory); |
| 210 | |
| 211 | #ifdef __cplusplus |
| 212 | } |
| 213 | #endif |
| 214 | |
| 215 | #endif /* FWU_INSTALLATION_INSTALLER_H */ |