Julian Hall | c1353f7 | 2022-11-18 12:00:09 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2022, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef FW_DIRECTORY_H |
| 9 | #define FW_DIRECTORY_H |
| 10 | |
| 11 | #include <stdbool.h> |
| 12 | #include <stddef.h> |
| 13 | #include <stdint.h> |
| 14 | #include <common/uuid/uuid.h> |
| 15 | #include "install_type.h" |
| 16 | |
| 17 | #ifdef __cplusplus |
| 18 | extern "C" { |
| 19 | #endif |
| 20 | |
| 21 | /** |
| 22 | * The default maximum number of images that can be held by the fw_directory. |
| 23 | * Can be overridden by an external definition. |
| 24 | */ |
| 25 | #ifndef FWU_MAX_FW_DIRECTORY_ENTRIES |
| 26 | #define FWU_MAX_FW_DIRECTORY_ENTRIES (20) |
| 27 | #endif |
| 28 | |
| 29 | /** |
| 30 | * \brief Boot information structure definition |
| 31 | * |
| 32 | * The boot_info structure holds information obtained from the boot loader |
| 33 | * about the most recent boot. |
| 34 | */ |
| 35 | struct boot_info { |
| 36 | /* Identifies the bank that was used during boot */ |
| 37 | uint32_t boot_index; |
| 38 | |
| 39 | /* The state of the active_index metadata variable during boot */ |
| 40 | uint32_t active_index; |
| 41 | |
| 42 | /* The state of the previous_active_index metadata variable during boot */ |
| 43 | uint32_t previous_active_index; |
| 44 | }; |
| 45 | |
| 46 | /** |
| 47 | * \brief Image information structure definition |
| 48 | * |
| 49 | * Information about an updatable image. Firmware may consist of an arbitrary |
| 50 | * number of images that may be updated as a single unit. Images may correspond |
| 51 | * to individual components, such as the Crypto SP image, or a collection of |
| 52 | * components contained within a package understood by firmware such as a FIP. |
| 53 | */ |
| 54 | struct image_info { |
| 55 | /* Unique identifier for the image type. This corresponds to the UUID/GUID |
| 56 | * assigned by the originator of the update package to identify the image. |
| 57 | */ |
| 58 | struct uuid_octets img_type_uuid; |
| 59 | |
| 60 | /* The maximum size that can be accommodated for an image of this type. |
| 61 | * A platform integrator will have sized back-end storage to provide |
| 62 | * sufficient headroom to accommodate updates. |
| 63 | */ |
| 64 | size_t max_size; |
| 65 | |
| 66 | /* The lowest accepted version number for this image. This will correspond |
| 67 | * to the NV anti-rollback counter value associated with the image. |
| 68 | */ |
| 69 | uint32_t lowest_accepted_version; |
| 70 | |
| 71 | /* The version of the currently active version of this image. */ |
| 72 | uint32_t active_version; |
| 73 | |
| 74 | /* Bitmap of access permissions for this iamge. */ |
| 75 | uint32_t permissions; |
| 76 | |
| 77 | /* The index [0..n] of the image in the fw directory. */ |
| 78 | uint32_t image_index; |
| 79 | |
| 80 | /* The location_id assigned by the platform integrator. A fw_store may |
| 81 | * be distributed over multiple locations (e.g. different storage partitions). |
| 82 | * The location_id is used to associate installers to storage volumes. |
| 83 | */ |
| 84 | uint32_t location_id; |
| 85 | |
| 86 | /* Identifies the type of installation needed for the image. */ |
| 87 | enum install_type install_type; |
| 88 | }; |
| 89 | |
| 90 | /** |
| 91 | * \brief Firmware directory structure definition |
| 92 | * |
| 93 | * The fw_directory holds information about currently active firmware. Information |
| 94 | * will have been collected via a trusted pathway. A subset of the information held |
| 95 | * is presented to external clients. |
| 96 | */ |
| 97 | struct fw_directory { |
| 98 | struct boot_info boot_info; |
| 99 | size_t num_images; |
| 100 | struct image_info entries[FWU_MAX_FW_DIRECTORY_ENTRIES]; |
| 101 | }; |
| 102 | |
| 103 | /** |
| 104 | * \brief Initialise a fw_directory |
| 105 | * |
| 106 | * Initialises the subject fw_directory. After initialisation, the empty fw_directory |
| 107 | * will need to be populated by a trusted agent (the fw_inspector). |
| 108 | * |
| 109 | * \param[in] fw_directory The subject fw_directory |
| 110 | */ |
| 111 | void fw_directory_init( |
| 112 | struct fw_directory *fw_directory); |
| 113 | |
| 114 | /** |
| 115 | * \brief De-initialise a fw_directory |
| 116 | * |
| 117 | * \param[in] fw_directory The subject fw_directory |
| 118 | */ |
| 119 | void fw_directory_deinit( |
| 120 | struct fw_directory *fw_directory); |
| 121 | |
| 122 | /** |
| 123 | * \brief Sets the boot_info held by the fw_directory |
| 124 | * |
| 125 | * Used by a fw_inspector to set the boot_info for the most recent system boot. |
| 126 | * |
| 127 | * \param[in] fw_directory The subject fw_directory |
| 128 | * \param[in] boot_info boot_info for most recent system boot |
| 129 | */ |
| 130 | void fw_directory_set_boot_info( |
| 131 | struct fw_directory *fw_directory, |
| 132 | const struct boot_info *boot_info); |
| 133 | |
| 134 | /** |
| 135 | * \brief Adds an image_info to the directory |
| 136 | * |
| 137 | * Used by a fw_inspector to add an image_info entry to the directory. |
| 138 | * |
| 139 | * \param[in] fw_directory The subject fw_directory |
| 140 | * \param[in] image_info The entry to add |
| 141 | * |
| 142 | * \return FWU status |
| 143 | */ |
| 144 | int fw_directory_add_image_info( |
| 145 | struct fw_directory *fw_directory, |
| 146 | const struct image_info *image_info); |
| 147 | |
| 148 | /** |
| 149 | * \brief Find an image_info entry |
| 150 | * |
| 151 | * Query to find an image_info entry using the image type UUID as the key. |
| 152 | * |
| 153 | * \param[in] fw_directory The subject fw_directory |
| 154 | * \param[in] image_type_uuid Image type UUID |
| 155 | * |
| 156 | * \return Pointer to image_info or NULL |
| 157 | */ |
| 158 | const struct image_info *fw_directory_find_image_info( |
| 159 | const struct fw_directory *fw_directory, |
| 160 | const struct uuid_octets *img_type_uuid); |
| 161 | |
| 162 | /** |
| 163 | * \brief Get the boot_info |
| 164 | * |
| 165 | * \param[in] fw_directory The subject fw_directory |
| 166 | * |
| 167 | * \return Pointer to the boot_info |
| 168 | */ |
| 169 | const struct boot_info *fw_directory_get_boot_info( |
| 170 | const struct fw_directory *fw_directory); |
| 171 | |
| 172 | /** |
| 173 | * \brief Get an image_info by index |
| 174 | * |
| 175 | * Can be used for iterating over all image_info objects held. |
| 176 | * |
| 177 | * \param[in] fw_directory The subject fw_directory |
| 178 | * \param[in] index Index in range [0..num_images-1] |
| 179 | * |
| 180 | * \return Pointer to the image_info or NULL if index invalid |
| 181 | */ |
| 182 | const struct image_info *fw_directory_get_image_info( |
| 183 | const struct fw_directory *fw_directory, |
| 184 | size_t index); |
| 185 | |
| 186 | /** |
| 187 | * \brief Get the number of image_info entries held |
| 188 | * |
| 189 | * \param[in] fw_directory The subject fw_directory |
| 190 | * |
| 191 | * \return Number of entries |
| 192 | */ |
| 193 | size_t fw_directory_num_images( |
| 194 | const struct fw_directory *fw_directory); |
| 195 | |
| 196 | #ifdef __cplusplus |
| 197 | } |
| 198 | #endif |
| 199 | |
| 200 | #endif /* FW_DIRECTORY_H */ |