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