Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 1 | #include "firmware_handler.hpp" |
| 2 | |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 3 | #include "image_handler.hpp" |
| 4 | |
Patrick Venture | 137ad2c | 2018-11-06 11:30:43 -0800 | [diff] [blame] | 5 | #include <algorithm> |
Patrick Venture | 192d60f | 2018-11-06 11:11:59 -0800 | [diff] [blame] | 6 | #include <cstdint> |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 7 | #include <cstring> |
Patrick Venture | 68cf64f | 2018-11-06 10:46:51 -0800 | [diff] [blame] | 8 | #include <memory> |
Patrick Venture | fa6c4d9 | 2018-11-02 18:34:53 -0700 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 12 | namespace blobs |
| 13 | { |
| 14 | |
Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 15 | const std::string FirmwareBlobHandler::hashBlobID = "/flash/hash"; |
Patrick Venture | 7b9256f | 2018-11-06 15:06:04 -0800 | [diff] [blame] | 16 | const std::string FirmwareBlobHandler::activeImageBlobID = |
| 17 | "/flash/active/image"; |
| 18 | const std::string FirmwareBlobHandler::activeHashBlobID = "/flash/active/hash"; |
Patrick Venture | 4cceb8e | 2018-11-06 11:56:48 -0800 | [diff] [blame] | 19 | |
Patrick Venture | 68cf64f | 2018-11-06 10:46:51 -0800 | [diff] [blame] | 20 | std::unique_ptr<GenericBlobInterface> |
Patrick Venture | 148cd65 | 2018-11-06 10:59:47 -0800 | [diff] [blame] | 21 | FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 22 | const std::vector<HandlerPack>& firmwares, |
| 23 | const std::vector<DataHandlerPack>& transports) |
Patrick Venture | 68cf64f | 2018-11-06 10:46:51 -0800 | [diff] [blame] | 24 | { |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 25 | /* There must be at least one. */ |
| 26 | if (!firmwares.size()) |
| 27 | { |
| 28 | return nullptr; |
| 29 | } |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 30 | if (!transports.size()) |
| 31 | { |
| 32 | return nullptr; |
| 33 | } |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 34 | |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 35 | std::vector<std::string> blobs; |
| 36 | for (const auto& item : firmwares) |
| 37 | { |
| 38 | blobs.push_back(item.blobName); |
| 39 | } |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 40 | |
| 41 | if (0 == std::count(blobs.begin(), blobs.end(), hashBlobID)) |
| 42 | { |
| 43 | return nullptr; |
| 44 | } |
Patrick Venture | 4cceb8e | 2018-11-06 11:56:48 -0800 | [diff] [blame] | 45 | |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 46 | std::uint16_t bitmask = 0; |
| 47 | for (const auto& item : transports) |
| 48 | { |
| 49 | /* TODO: can use std::accumulate() unless I'm mistaken. :D */ |
| 50 | bitmask |= item.bitmask; |
| 51 | } |
| 52 | |
| 53 | return std::make_unique<FirmwareBlobHandler>(firmwares, blobs, transports, |
| 54 | bitmask); |
Patrick Venture | 68cf64f | 2018-11-06 10:46:51 -0800 | [diff] [blame] | 55 | } |
| 56 | |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 57 | /* Check if the path is in our supported list (or active list). */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 58 | bool FirmwareBlobHandler::canHandleBlob(const std::string& path) |
| 59 | { |
Patrick Venture | 4cceb8e | 2018-11-06 11:56:48 -0800 | [diff] [blame] | 60 | if (std::count(blobIDs.begin(), blobIDs.end(), path)) |
Patrick Venture | 137ad2c | 2018-11-06 11:30:43 -0800 | [diff] [blame] | 61 | { |
| 62 | return true; |
| 63 | } |
| 64 | |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 65 | return false; |
| 66 | } |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 67 | |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 68 | /* |
| 69 | * Grab the list of supported firmware. |
| 70 | * |
| 71 | * If there's an open firmware session, it'll already be present in the |
| 72 | * list as "/flash/active/image", and if the hash has started, |
| 73 | * "/flash/active/hash" regardless of mechanism. This is done in the open |
| 74 | * comamnd, no extra work is required here. |
| 75 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 76 | std::vector<std::string> FirmwareBlobHandler::getBlobIds() |
| 77 | { |
Patrick Venture | 4cceb8e | 2018-11-06 11:56:48 -0800 | [diff] [blame] | 78 | return blobIDs; |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 79 | } |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 80 | |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 81 | /* |
| 82 | * Per the design, this mean abort, and this will trigger whatever |
| 83 | * appropriate actions are required to abort the process. |
| 84 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 85 | bool FirmwareBlobHandler::deleteBlob(const std::string& path) |
| 86 | { |
| 87 | return false; |
| 88 | } |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 89 | |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 90 | /* |
| 91 | * Stat on the files will return information such as what supported |
| 92 | * transport mechanisms are available. |
| 93 | * |
| 94 | * Stat on an active file or hash will return information such as the size |
| 95 | * of the data cached, and any additional pertinent information. The |
| 96 | * blob_state on the active files will return the state of the update. |
| 97 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 98 | bool FirmwareBlobHandler::stat(const std::string& path, struct BlobMeta* meta) |
| 99 | { |
Patrick Venture | 46637c8 | 2018-11-06 15:20:24 -0800 | [diff] [blame] | 100 | /* We know we support this path because canHandle is called ahead */ |
| 101 | if (path == FirmwareBlobHandler::activeImageBlobID) |
| 102 | { |
| 103 | /* We need to return information for the image that's staged. */ |
| 104 | } |
| 105 | else if (path == FirmwareBlobHandler::activeHashBlobID) |
| 106 | { |
| 107 | /* We need to return information for the hash that's staged. */ |
| 108 | } |
| 109 | else |
| 110 | { |
| 111 | /* They are requesting information about the generic blob_id. */ |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 112 | meta->blobState = bitmask; |
Patrick Venture | 46637c8 | 2018-11-06 15:20:24 -0800 | [diff] [blame] | 113 | meta->size = 0; |
| 114 | |
| 115 | /* The generic blob_ids state is only the bits related to the transport |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 116 | * mechanisms. |
| 117 | */ |
Patrick Venture | 46637c8 | 2018-11-06 15:20:24 -0800 | [diff] [blame] | 118 | return true; |
| 119 | } |
| 120 | |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 121 | return false; |
| 122 | } |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 123 | |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 124 | /* |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 125 | * Return stat information on an open session. It therefore must be an active |
| 126 | * handle to either the active image or active hash. |
| 127 | * |
| 128 | * The stat() and sessionstat() commands will return the same information in |
| 129 | * many cases, therefore the logic will be combined. |
| 130 | * |
| 131 | * TODO: combine the logic for stat and sessionstat(). |
| 132 | */ |
| 133 | bool FirmwareBlobHandler::stat(uint16_t session, struct BlobMeta* meta) |
| 134 | { |
| 135 | /* |
| 136 | * Return session specific information. |
| 137 | */ |
| 138 | return false; |
| 139 | } |
| 140 | |
| 141 | /* |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 142 | * If you open /flash/image or /flash/tarball, or /flash/hash it will |
| 143 | * interpret the open flags and perform whatever actions are required for |
| 144 | * that update process. The session returned can be used immediately for |
| 145 | * sending data down, without requiring one to open the new active file. |
| 146 | * |
| 147 | * If you open the active flash image or active hash it will let you |
| 148 | * overwrite pieces, depending on the state. |
| 149 | * |
| 150 | * Once the verification process has started the active files cannot be |
| 151 | * opened. |
| 152 | * |
| 153 | * You can only have one open session at a time. Which means, you can only |
| 154 | * have one file open at a time. Trying to open the hash blob_id while you |
| 155 | * still have the flash image blob_id open will fail. Opening the flash |
| 156 | * blob_id when it is already open will fail. |
| 157 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 158 | bool FirmwareBlobHandler::open(uint16_t session, uint16_t flags, |
| 159 | const std::string& path) |
| 160 | { |
Patrick Venture | 6e307a7 | 2018-11-09 18:21:17 -0800 | [diff] [blame^] | 161 | /* Check that they've opened for writing - read back not currently |
| 162 | * supported. |
| 163 | */ |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 164 | if ((flags & OpenFlags::write) == 0) |
| 165 | { |
| 166 | return false; |
| 167 | } |
| 168 | |
Patrick Venture | b1b68fc | 2018-11-09 09:37:04 -0800 | [diff] [blame] | 169 | /* Is the verification process underway? */ |
| 170 | if (state == UpdateState::verificationStarted) |
| 171 | { |
| 172 | return false; |
| 173 | } |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 174 | |
| 175 | /* Is there an open session already? We only allow one at a time. |
Patrick Venture | 6e307a7 | 2018-11-09 18:21:17 -0800 | [diff] [blame^] | 176 | * |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 177 | * TODO: Temporarily using a simple boolean flag until there's a full |
| 178 | * session object to check. |
Patrick Venture | 7c8b97e | 2018-11-08 09:14:30 -0800 | [diff] [blame] | 179 | * |
| 180 | * Further on this, if there's an active session to the hash we don't allow |
| 181 | * re-opening the image, and if we have the image open, we don't allow |
| 182 | * opening the hash. This design decision may be re-evaluated, and changed |
| 183 | * to only allow one session per object type (of the two types). But, |
| 184 | * consider if the hash is open, do we want to allow writing to the image? |
| 185 | * And why would we? But, really, the point of no-return is once the |
| 186 | * verification process has begun -- which is done via commit() on the hash |
| 187 | * blob_id, we no longer want to allow updating the contents. |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 188 | */ |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 189 | if (fileOpen) |
| 190 | { |
| 191 | return false; |
| 192 | } |
| 193 | |
| 194 | /* There are two abstractions at play, how you get the data and how you |
| 195 | * handle that data. such that, whether the data comes from the PCI bridge |
| 196 | * or LPC bridge is not connected to whether the data goes into a static |
| 197 | * layout flash update or a UBI tarball. |
| 198 | */ |
| 199 | |
| 200 | /* Check the flags for the transport mechanism: if none match we don't |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 201 | * support what they request. |
| 202 | */ |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 203 | if ((flags & bitmask) == 0) |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 204 | { |
| 205 | return false; |
| 206 | } |
| 207 | |
| 208 | /* 2) there isn't, so what are they opening? */ |
| 209 | if (path == activeImageBlobID) |
| 210 | { |
| 211 | /* 2a) are they opening the active image? this can only happen if they |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 212 | * already started one (due to canHandleBlob's behavior). |
| 213 | */ |
Patrick Venture | 21c62c1 | 2018-11-09 17:46:58 -0800 | [diff] [blame] | 214 | return false; |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 215 | } |
| 216 | else if (path == activeHashBlobID) |
| 217 | { |
| 218 | /* 2b) are they opening the active hash? this can only happen if they |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 219 | * already started one (due to canHandleBlob's behavior). |
| 220 | */ |
Patrick Venture | 21c62c1 | 2018-11-09 17:46:58 -0800 | [diff] [blame] | 221 | return false; |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 222 | } |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 223 | |
| 224 | /* How are they expecting to copy this data? */ |
| 225 | auto d = std::find_if( |
| 226 | transports.begin(), transports.end(), |
| 227 | [&flags](const auto& iter) { return (iter.bitmask & flags); }); |
| 228 | if (d == transports.end()) |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 229 | { |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 230 | return false; |
| 231 | } |
| 232 | |
| 233 | /* We found the transport handler they requested, no surprise since |
| 234 | * above we verify they selected at least one we wanted. |
| 235 | */ |
| 236 | Session* curr; |
Patrick Venture | db253bf | 2018-11-09 19:36:03 -0800 | [diff] [blame] | 237 | const std::string* active; |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 238 | |
| 239 | if (path == hashBlobID) |
| 240 | { |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 241 | /* 2c) are they opening the /flash/hash ? (to start the process) */ |
Patrick Venture | 7c8b97e | 2018-11-08 09:14:30 -0800 | [diff] [blame] | 242 | |
Patrick Venture | 21c62c1 | 2018-11-09 17:46:58 -0800 | [diff] [blame] | 243 | curr = &activeHash; |
Patrick Venture | db253bf | 2018-11-09 19:36:03 -0800 | [diff] [blame] | 244 | active = &activeHashBlobID; |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 245 | } |
| 246 | else |
| 247 | { |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 248 | curr = &activeImage; |
Patrick Venture | db253bf | 2018-11-09 19:36:03 -0800 | [diff] [blame] | 249 | active = &activeImageBlobID; |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 250 | } |
| 251 | |
Patrick Venture | 6e307a7 | 2018-11-09 18:21:17 -0800 | [diff] [blame^] | 252 | /* Elsewhere I do this check by checking "if ::ipmi" because that's the |
| 253 | * only non-external data pathway -- but this is just a more generic |
| 254 | * approach to that. |
| 255 | */ |
| 256 | if (d->handler) |
| 257 | { |
| 258 | /* If the data handler open call fails, open fails. */ |
| 259 | if (!d->handler->open()) |
| 260 | { |
| 261 | return false; |
| 262 | } |
| 263 | } |
| 264 | |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 265 | /* 2d) are they opening the /flash/tarball ? (to start the UBI process) |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 266 | * 2e) are they opening the /flash/image ? (to start the process) |
| 267 | * 2...) are they opening the /flash/... ? (to start the process) |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 268 | */ |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 269 | auto h = std::find_if( |
| 270 | handlers.begin(), handlers.end(), |
| 271 | [&path](const auto& iter) { return (iter.blobName == path); }); |
| 272 | if (h == handlers.end()) |
| 273 | { |
| 274 | return false; |
| 275 | } |
| 276 | |
| 277 | /* Ok, so we found a handler that matched, so call open() */ |
| 278 | if (!h->handler->open(path)) |
| 279 | { |
| 280 | return false; |
| 281 | } |
| 282 | |
| 283 | curr->flags = flags; |
| 284 | curr->dataHandler = d->handler; |
| 285 | curr->imageHandler = h->handler; |
Patrick Venture | cd31022 | 2018-11-09 18:47:13 -0800 | [diff] [blame] | 286 | curr->state = Session::State::open; |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 287 | |
| 288 | lookup[session] = curr; |
| 289 | |
Patrick Venture | db253bf | 2018-11-09 19:36:03 -0800 | [diff] [blame] | 290 | blobIDs.push_back(*active); |
| 291 | |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 292 | return true; |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 293 | } |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 294 | |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 295 | /** |
| 296 | * The write command really just grabs the data from wherever it is and sends it |
| 297 | * to the image handler. It's the image handler's responsibility to deal with |
| 298 | * the data provided. |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 299 | * |
| 300 | * This receives a session from the blob manager, therefore it is always called |
| 301 | * between open() and close(). |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 302 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 303 | bool FirmwareBlobHandler::write(uint16_t session, uint32_t offset, |
| 304 | const std::vector<uint8_t>& data) |
| 305 | { |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 306 | auto item = lookup.find(session); |
| 307 | if (item == lookup.end()) |
| 308 | { |
| 309 | return false; |
| 310 | } |
| 311 | |
Patrick Venture | b1b68fc | 2018-11-09 09:37:04 -0800 | [diff] [blame] | 312 | /* Prevent writing during verification. */ |
| 313 | if (state == UpdateState::verificationStarted) |
| 314 | { |
| 315 | return false; |
| 316 | } |
| 317 | |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 318 | std::vector<std::uint8_t> bytes; |
| 319 | |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 320 | if (item->second->flags & UpdateFlags::ipmi) |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 321 | { |
| 322 | bytes = data; |
| 323 | } |
| 324 | else |
| 325 | { |
| 326 | /* little endian required per design, and so on, but TODO: do endianness |
| 327 | * with boost. |
| 328 | */ |
| 329 | struct ExtChunkHdr header; |
| 330 | |
| 331 | if (data.size() != sizeof(header)) |
| 332 | { |
| 333 | return false; |
| 334 | } |
| 335 | |
| 336 | std::memcpy(&header, data.data(), data.size()); |
| 337 | bytes = item->second->dataHandler->copyFrom(header.length); |
| 338 | } |
| 339 | |
| 340 | return item->second->imageHandler->write(offset, bytes); |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 341 | } |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 342 | |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 343 | /* |
| 344 | * If the active session (image or hash) is over LPC, this allows |
| 345 | * configuring it. This option is only available before you start |
| 346 | * writing data for the given item (image or hash). This will return |
| 347 | * false at any other part. -- the lpc handler portion will know to return |
| 348 | * false. |
| 349 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 350 | bool FirmwareBlobHandler::writeMeta(uint16_t session, uint32_t offset, |
| 351 | const std::vector<uint8_t>& data) |
| 352 | { |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 353 | auto item = lookup.find(session); |
| 354 | if (item == lookup.end()) |
| 355 | { |
| 356 | return false; |
| 357 | } |
| 358 | |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 359 | if (item->second->flags & UpdateFlags::ipmi) |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 360 | { |
| 361 | return false; |
| 362 | } |
| 363 | |
| 364 | return item->second->dataHandler->write(data); |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 365 | } |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 366 | |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 367 | /* |
| 368 | * If this command is called on the session for the hash image, it'll |
| 369 | * trigger a systemd service `verify_image.service` to attempt to verify |
| 370 | * the image. Before doing this, if the transport mechanism is not IPMI |
| 371 | * BT, it'll shut down the mechanism used for transport preventing the |
| 372 | * host from updating anything. |
| 373 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 374 | bool FirmwareBlobHandler::commit(uint16_t session, |
| 375 | const std::vector<uint8_t>& data) |
| 376 | { |
| 377 | return false; |
| 378 | } |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 379 | |
| 380 | /* |
| 381 | * Close must be called on the firmware image before triggering |
| 382 | * verification via commit. Once the verification is complete, you can |
| 383 | * then close the hash file. |
| 384 | * |
| 385 | * If the `verify_image.service` returned success, closing the hash file |
| 386 | * will have a specific behavior depending on the update. If it's UBI, |
| 387 | * it'll perform the install. If it's static layout, it'll do nothing. The |
| 388 | * verify_image service in the static layout case is responsible for placing |
| 389 | * the file in the correct staging position. |
| 390 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 391 | bool FirmwareBlobHandler::close(uint16_t session) |
| 392 | { |
| 393 | return false; |
| 394 | } |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 395 | |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 396 | bool FirmwareBlobHandler::expire(uint16_t session) |
| 397 | { |
| 398 | return false; |
| 399 | } |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 400 | |
| 401 | /* |
| 402 | * Currently, the design does not provide this with a function, however, |
| 403 | * it will likely change to support reading data back. |
| 404 | */ |
| 405 | std::vector<uint8_t> FirmwareBlobHandler::read(uint16_t session, |
| 406 | uint32_t offset, |
| 407 | uint32_t requestedSize) |
| 408 | { |
| 409 | return {}; |
| 410 | } |
| 411 | |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 412 | } // namespace blobs |