Patrick Venture | 22e3875 | 2018-11-21 08:52:49 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 Google Inc. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 17 | #include "firmware_handler.hpp" |
| 18 | |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 19 | #include "image_handler.hpp" |
Patrick Venture | 1d66fe6 | 2019-06-03 14:57:27 -0700 | [diff] [blame] | 20 | #include "status.hpp" |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 21 | #include "util.hpp" |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 22 | |
Patrick Venture | 137ad2c | 2018-11-06 11:30:43 -0800 | [diff] [blame] | 23 | #include <algorithm> |
Patrick Venture | 192d60f | 2018-11-06 11:11:59 -0800 | [diff] [blame] | 24 | #include <cstdint> |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 25 | #include <cstring> |
Patrick Venture | b3b4db7 | 2019-05-15 11:30:24 -0700 | [diff] [blame] | 26 | #include <fstream> |
Patrick Venture | 68cf64f | 2018-11-06 10:46:51 -0800 | [diff] [blame] | 27 | #include <memory> |
Patrick Venture | d333a87 | 2018-12-03 16:24:26 -0800 | [diff] [blame] | 28 | #include <phosphor-logging/log.hpp> |
Patrick Venture | fa6c4d9 | 2018-11-02 18:34:53 -0700 | [diff] [blame] | 29 | #include <string> |
| 30 | #include <vector> |
| 31 | |
Patrick Venture | d333a87 | 2018-12-03 16:24:26 -0800 | [diff] [blame] | 32 | using namespace phosphor::logging; |
| 33 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 34 | namespace ipmi_flash |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 35 | { |
Patrick Venture | b3b4db7 | 2019-05-15 11:30:24 -0700 | [diff] [blame] | 36 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 37 | std::unique_ptr<blobs::GenericBlobInterface> |
Patrick Venture | 148cd65 | 2018-11-06 10:59:47 -0800 | [diff] [blame] | 38 | FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | 3ecb350 | 2019-05-17 11:03:51 -0700 | [diff] [blame] | 39 | const std::vector<HandlerPack>& firmwares, |
Patrick Venture | 74059d6 | 2019-05-17 10:40:26 -0700 | [diff] [blame] | 40 | const std::vector<DataHandlerPack>& transports, |
Patrick Venture | 1d66fe6 | 2019-06-03 14:57:27 -0700 | [diff] [blame] | 41 | std::unique_ptr<TriggerableActionInterface> verification, |
| 42 | std::unique_ptr<TriggerableActionInterface> update) |
Patrick Venture | 68cf64f | 2018-11-06 10:46:51 -0800 | [diff] [blame] | 43 | { |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 44 | /* There must be at least one. */ |
| 45 | if (!firmwares.size()) |
| 46 | { |
Patrick Venture | d333a87 | 2018-12-03 16:24:26 -0800 | [diff] [blame] | 47 | log<level::ERR>("Must provide at least one firmware handler."); |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 48 | return nullptr; |
| 49 | } |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 50 | if (!transports.size()) |
| 51 | { |
| 52 | return nullptr; |
| 53 | } |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 54 | |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 55 | std::vector<std::string> blobs; |
| 56 | for (const auto& item : firmwares) |
| 57 | { |
| 58 | blobs.push_back(item.blobName); |
| 59 | } |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 60 | |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 61 | if (0 == std::count(blobs.begin(), blobs.end(), hashBlobId)) |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 62 | { |
| 63 | return nullptr; |
| 64 | } |
Patrick Venture | 4cceb8e | 2018-11-06 11:56:48 -0800 | [diff] [blame] | 65 | |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 66 | std::uint16_t bitmask = 0; |
| 67 | for (const auto& item : transports) |
| 68 | { |
| 69 | /* TODO: can use std::accumulate() unless I'm mistaken. :D */ |
| 70 | bitmask |= item.bitmask; |
| 71 | } |
| 72 | |
Patrick Venture | 3ecb350 | 2019-05-17 11:03:51 -0700 | [diff] [blame] | 73 | return std::make_unique<FirmwareBlobHandler>( |
Patrick Venture | 27ac582 | 2019-05-20 17:39:31 -0700 | [diff] [blame] | 74 | firmwares, blobs, transports, bitmask, std::move(verification), |
| 75 | std::move(update)); |
Patrick Venture | 68cf64f | 2018-11-06 10:46:51 -0800 | [diff] [blame] | 76 | } |
| 77 | |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 78 | /* Check if the path is in our supported list (or active list). */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 79 | bool FirmwareBlobHandler::canHandleBlob(const std::string& path) |
| 80 | { |
Patrick Venture | 6032dc0 | 2019-05-17 11:01:44 -0700 | [diff] [blame] | 81 | return (std::count(blobIDs.begin(), blobIDs.end(), path) > 0); |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 82 | } |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 83 | |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 84 | /* |
| 85 | * Grab the list of supported firmware. |
| 86 | * |
| 87 | * If there's an open firmware session, it'll already be present in the |
| 88 | * list as "/flash/active/image", and if the hash has started, |
| 89 | * "/flash/active/hash" regardless of mechanism. This is done in the open |
| 90 | * comamnd, no extra work is required here. |
| 91 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 92 | std::vector<std::string> FirmwareBlobHandler::getBlobIds() |
| 93 | { |
Patrick Venture | 4cceb8e | 2018-11-06 11:56:48 -0800 | [diff] [blame] | 94 | return blobIDs; |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 95 | } |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 96 | |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 97 | /* |
| 98 | * Per the design, this mean abort, and this will trigger whatever |
| 99 | * appropriate actions are required to abort the process. |
| 100 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 101 | bool FirmwareBlobHandler::deleteBlob(const std::string& path) |
| 102 | { |
Patrick Venture | bcc0c77 | 2019-06-17 10:42:06 -0700 | [diff] [blame] | 103 | /* This cannot be called if you have an open session to the path. |
| 104 | * You can have an open session to verify/update/hash/image, but not active* |
| 105 | * |
| 106 | * Therefore, if this is called, it's either on a blob that isn't presently |
| 107 | * open. However, there could be open blobs, so we need to close all open |
| 108 | * sessions. This closing on our is an invalid handler behavior. Therefore, |
| 109 | * we cannot close an active session. To enforce this, we only allow |
| 110 | * deleting if there isn't a file open. |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 111 | */ |
Patrick Venture | bcc0c77 | 2019-06-17 10:42:06 -0700 | [diff] [blame] | 112 | if (fileOpen) |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 113 | { |
| 114 | return false; |
| 115 | } |
| 116 | |
Patrick Venture | 7267676 | 2019-06-17 11:22:38 -0700 | [diff] [blame^] | 117 | /* only includes states where fileOpen == false */ |
| 118 | switch (state) |
| 119 | { |
| 120 | case UpdateState::notYetStarted: |
| 121 | /* Trying to delete anything at this point has no effect and returns |
| 122 | * false. |
| 123 | */ |
| 124 | return false; |
| 125 | case UpdateState::verificationPending: |
| 126 | break; |
| 127 | case UpdateState::updatePending: |
| 128 | break; |
| 129 | default: |
| 130 | break; |
| 131 | } |
| 132 | |
Patrick Venture | bcc0c77 | 2019-06-17 10:42:06 -0700 | [diff] [blame] | 133 | /* TODO: implement. */ |
| 134 | return false; |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 135 | } |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 136 | |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 137 | /* |
| 138 | * Stat on the files will return information such as what supported |
| 139 | * transport mechanisms are available. |
| 140 | * |
| 141 | * Stat on an active file or hash will return information such as the size |
| 142 | * of the data cached, and any additional pertinent information. The |
| 143 | * blob_state on the active files will return the state of the update. |
| 144 | */ |
Patrick Venture | e312f39 | 2019-06-04 07:44:37 -0700 | [diff] [blame] | 145 | bool FirmwareBlobHandler::stat(const std::string& path, blobs::BlobMeta* meta) |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 146 | { |
Patrick Venture | 46637c8 | 2018-11-06 15:20:24 -0800 | [diff] [blame] | 147 | /* We know we support this path because canHandle is called ahead */ |
Patrick Venture | d342a95 | 2019-05-29 09:09:10 -0700 | [diff] [blame] | 148 | if (path == verifyBlobId || path == activeImageBlobId || |
Patrick Venture | 5f56269 | 2019-05-30 16:49:46 -0700 | [diff] [blame] | 149 | path == activeHashBlobId || path == updateBlobId) |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 150 | { |
Patrick Venture | d342a95 | 2019-05-29 09:09:10 -0700 | [diff] [blame] | 151 | /* These blobs are placeholders that indicate things, or allow actions, |
| 152 | * but are not stat-able as-is. |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 153 | */ |
Patrick Venture | d342a95 | 2019-05-29 09:09:10 -0700 | [diff] [blame] | 154 | return false; |
Patrick Venture | 46637c8 | 2018-11-06 15:20:24 -0800 | [diff] [blame] | 155 | } |
| 156 | |
Patrick Venture | d342a95 | 2019-05-29 09:09:10 -0700 | [diff] [blame] | 157 | /* They are requesting information about the generic blob_id. */ |
| 158 | meta->blobState = bitmask; |
| 159 | meta->size = 0; |
| 160 | |
| 161 | /* The generic blob_ids state is only the bits related to the transport |
| 162 | * mechanisms. |
| 163 | */ |
| 164 | return true; |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 165 | } |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 166 | |
Patrick Venture | da66fd8 | 2019-06-03 11:11:24 -0700 | [diff] [blame] | 167 | ActionStatus FirmwareBlobHandler::getActionStatus() |
Patrick Venture | a2d8239 | 2019-06-03 10:55:17 -0700 | [diff] [blame] | 168 | { |
Patrick Venture | da66fd8 | 2019-06-03 11:11:24 -0700 | [diff] [blame] | 169 | ActionStatus value = ActionStatus::unknown; |
Patrick Venture | a2d8239 | 2019-06-03 10:55:17 -0700 | [diff] [blame] | 170 | |
| 171 | switch (state) |
| 172 | { |
| 173 | case UpdateState::verificationPending: |
Patrick Venture | da66fd8 | 2019-06-03 11:11:24 -0700 | [diff] [blame] | 174 | value = ActionStatus::unknown; |
Patrick Venture | a2d8239 | 2019-06-03 10:55:17 -0700 | [diff] [blame] | 175 | break; |
| 176 | case UpdateState::verificationStarted: |
| 177 | value = verification->status(); |
Patrick Venture | da66fd8 | 2019-06-03 11:11:24 -0700 | [diff] [blame] | 178 | lastVerificationStatus = value; |
Patrick Venture | a2d8239 | 2019-06-03 10:55:17 -0700 | [diff] [blame] | 179 | break; |
| 180 | case UpdateState::verificationCompleted: |
Patrick Venture | da66fd8 | 2019-06-03 11:11:24 -0700 | [diff] [blame] | 181 | value = lastVerificationStatus; |
Patrick Venture | a2d8239 | 2019-06-03 10:55:17 -0700 | [diff] [blame] | 182 | break; |
Patrick Venture | a2d8239 | 2019-06-03 10:55:17 -0700 | [diff] [blame] | 183 | case UpdateState::updatePending: |
Patrick Venture | da66fd8 | 2019-06-03 11:11:24 -0700 | [diff] [blame] | 184 | value = ActionStatus::unknown; |
Patrick Venture | a2d8239 | 2019-06-03 10:55:17 -0700 | [diff] [blame] | 185 | break; |
| 186 | case UpdateState::updateStarted: |
| 187 | value = update->status(); |
| 188 | lastUpdateStatus = value; |
| 189 | break; |
| 190 | case UpdateState::updateCompleted: |
| 191 | value = lastUpdateStatus; |
| 192 | break; |
| 193 | default: |
| 194 | break; |
| 195 | } |
| 196 | |
| 197 | return value; |
| 198 | } |
| 199 | |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 200 | /* |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 201 | * Return stat information on an open session. It therefore must be an active |
| 202 | * handle to either the active image or active hash. |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 203 | */ |
Patrick Venture | e312f39 | 2019-06-04 07:44:37 -0700 | [diff] [blame] | 204 | bool FirmwareBlobHandler::stat(uint16_t session, blobs::BlobMeta* meta) |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 205 | { |
Patrick Venture | cc7d160 | 2018-11-15 13:58:33 -0800 | [diff] [blame] | 206 | auto item = lookup.find(session); |
| 207 | if (item == lookup.end()) |
| 208 | { |
| 209 | return false; |
| 210 | } |
| 211 | |
Patrick Venture | b3b4db7 | 2019-05-15 11:30:24 -0700 | [diff] [blame] | 212 | /* The size here refers to the size of the file -- of something analagous. |
| 213 | */ |
| 214 | meta->size = (item->second->imageHandler) |
| 215 | ? item->second->imageHandler->getSize() |
| 216 | : 0; |
| 217 | |
| 218 | meta->metadata.clear(); |
| 219 | |
Patrick Venture | da66fd8 | 2019-06-03 11:11:24 -0700 | [diff] [blame] | 220 | if (item->second->activePath == verifyBlobId || |
| 221 | item->second->activePath == updateBlobId) |
Patrick Venture | b3b4db7 | 2019-05-15 11:30:24 -0700 | [diff] [blame] | 222 | { |
Patrick Venture | da66fd8 | 2019-06-03 11:11:24 -0700 | [diff] [blame] | 223 | ActionStatus value = getActionStatus(); |
Patrick Venture | 699750d | 2019-05-15 09:24:09 -0700 | [diff] [blame] | 224 | |
Patrick Venture | e955e07 | 2019-05-15 16:16:46 -0700 | [diff] [blame] | 225 | meta->metadata.push_back(static_cast<std::uint8_t>(value)); |
| 226 | |
| 227 | /* Change the firmware handler's state and the blob's stat value |
| 228 | * depending. |
| 229 | */ |
Patrick Venture | da66fd8 | 2019-06-03 11:11:24 -0700 | [diff] [blame] | 230 | if (value == ActionStatus::success || value == ActionStatus::failed) |
Patrick Venture | e955e07 | 2019-05-15 16:16:46 -0700 | [diff] [blame] | 231 | { |
Patrick Venture | da66fd8 | 2019-06-03 11:11:24 -0700 | [diff] [blame] | 232 | if (item->second->activePath == verifyBlobId) |
Patrick Venture | e955e07 | 2019-05-15 16:16:46 -0700 | [diff] [blame] | 233 | { |
Patrick Venture | da66fd8 | 2019-06-03 11:11:24 -0700 | [diff] [blame] | 234 | state = UpdateState::verificationCompleted; |
Patrick Venture | e955e07 | 2019-05-15 16:16:46 -0700 | [diff] [blame] | 235 | } |
| 236 | else |
| 237 | { |
Patrick Venture | da66fd8 | 2019-06-03 11:11:24 -0700 | [diff] [blame] | 238 | /* item->second->activePath == updateBlobId */ |
| 239 | state = UpdateState::updateCompleted; |
Patrick Venture | e955e07 | 2019-05-15 16:16:46 -0700 | [diff] [blame] | 240 | } |
Patrick Venture | 40d7ffc | 2019-05-30 17:12:06 -0700 | [diff] [blame] | 241 | |
Patrick Venture | f1f0f65 | 2019-06-03 09:10:19 -0700 | [diff] [blame] | 242 | item->second->flags &= ~blobs::StateFlags::committing; |
| 243 | |
Patrick Venture | da66fd8 | 2019-06-03 11:11:24 -0700 | [diff] [blame] | 244 | if (value == ActionStatus::success) |
Patrick Venture | f1f0f65 | 2019-06-03 09:10:19 -0700 | [diff] [blame] | 245 | { |
| 246 | item->second->flags |= blobs::StateFlags::committed; |
| 247 | } |
| 248 | else |
| 249 | { |
| 250 | item->second->flags |= blobs::StateFlags::commit_error; |
| 251 | } |
| 252 | } |
Patrick Venture | 40d7ffc | 2019-05-30 17:12:06 -0700 | [diff] [blame] | 253 | } |
Patrick Venture | cc7d160 | 2018-11-15 13:58:33 -0800 | [diff] [blame] | 254 | |
Patrick Venture | e955e07 | 2019-05-15 16:16:46 -0700 | [diff] [blame] | 255 | /* The blobState here relates to an active sesion, so we should return the |
| 256 | * flags used to open this session. |
| 257 | */ |
| 258 | meta->blobState = item->second->flags; |
| 259 | |
Patrick Venture | cc7d160 | 2018-11-15 13:58:33 -0800 | [diff] [blame] | 260 | /* The metadata blob returned comes from the data handler... it's used for |
| 261 | * instance, in P2A bridging to get required information about the mapping, |
| 262 | * and is the "opposite" of the lpc writemeta requirement. |
| 263 | */ |
Patrick Venture | cc7d160 | 2018-11-15 13:58:33 -0800 | [diff] [blame] | 264 | if (item->second->dataHandler) |
| 265 | { |
Patrick Venture | 7430464 | 2019-01-17 09:31:04 -0800 | [diff] [blame] | 266 | auto bytes = item->second->dataHandler->readMeta(); |
Patrick Venture | cc7d160 | 2018-11-15 13:58:33 -0800 | [diff] [blame] | 267 | meta->metadata.insert(meta->metadata.begin(), bytes.begin(), |
| 268 | bytes.end()); |
| 269 | } |
| 270 | |
Patrick Venture | cc7d160 | 2018-11-15 13:58:33 -0800 | [diff] [blame] | 271 | return true; |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | /* |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 275 | * If you open /flash/image or /flash/tarball, or /flash/hash it will |
| 276 | * interpret the open flags and perform whatever actions are required for |
| 277 | * that update process. The session returned can be used immediately for |
| 278 | * sending data down, without requiring one to open the new active file. |
| 279 | * |
| 280 | * If you open the active flash image or active hash it will let you |
| 281 | * overwrite pieces, depending on the state. |
| 282 | * |
| 283 | * Once the verification process has started the active files cannot be |
| 284 | * opened. |
| 285 | * |
| 286 | * You can only have one open session at a time. Which means, you can only |
| 287 | * have one file open at a time. Trying to open the hash blob_id while you |
| 288 | * still have the flash image blob_id open will fail. Opening the flash |
| 289 | * blob_id when it is already open will fail. |
| 290 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 291 | bool FirmwareBlobHandler::open(uint16_t session, uint16_t flags, |
| 292 | const std::string& path) |
| 293 | { |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 294 | /* 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] | 295 | * |
Patrick Venture | 7c8b97e | 2018-11-08 09:14:30 -0800 | [diff] [blame] | 296 | * Further on this, if there's an active session to the hash we don't allow |
| 297 | * re-opening the image, and if we have the image open, we don't allow |
| 298 | * opening the hash. This design decision may be re-evaluated, and changed |
| 299 | * to only allow one session per object type (of the two types). But, |
| 300 | * consider if the hash is open, do we want to allow writing to the image? |
| 301 | * And why would we? But, really, the point of no-return is once the |
| 302 | * verification process has begun -- which is done via commit() on the hash |
| 303 | * blob_id, we no longer want to allow updating the contents. |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 304 | */ |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 305 | if (fileOpen) |
| 306 | { |
| 307 | return false; |
| 308 | } |
| 309 | |
Patrick Venture | 723113f | 2019-06-05 09:38:35 -0700 | [diff] [blame] | 310 | /* The active blobs are only meant to indicate status that something has |
| 311 | * opened the image file or the hash file. |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 312 | */ |
Patrick Venture | 19f5d88 | 2019-05-30 14:34:55 -0700 | [diff] [blame] | 313 | if (path == activeImageBlobId || path == activeHashBlobId) |
| 314 | { |
| 315 | /* 2a) are they opening the active image? this can only happen if they |
| 316 | * already started one (due to canHandleBlob's behavior). |
| 317 | */ |
| 318 | /* 2b) are they opening the active hash? this can only happen if they |
| 319 | * already started one (due to canHandleBlob's behavior). |
| 320 | */ |
| 321 | return false; |
| 322 | } |
| 323 | |
Patrick Venture | 723113f | 2019-06-05 09:38:35 -0700 | [diff] [blame] | 324 | /* Check that they've opened for writing - read back not currently |
| 325 | * supported. |
| 326 | */ |
| 327 | if ((flags & blobs::OpenFlags::write) == 0) |
| 328 | { |
| 329 | return false; |
| 330 | } |
| 331 | |
| 332 | /* Because canHandleBlob is called before open, we know that if they try to |
| 333 | * open the verifyBlobId, they're in a state where it's present. |
| 334 | */ |
| 335 | |
| 336 | switch (state) |
| 337 | { |
| 338 | case UpdateState::uploadInProgress: |
| 339 | /* Unreachable code because if it's started a file is open. */ |
| 340 | break; |
| 341 | case UpdateState::verificationPending: |
| 342 | /* Handle opening the verifyBlobId --> we know the image and hash |
| 343 | * aren't open because of the fileOpen check. They can still open |
| 344 | * other files from this state to transition back into |
| 345 | * uploadInProgress. |
| 346 | * |
| 347 | * The file must be opened for writing, but no transport mechanism |
| 348 | * specified since it's irrelevant. |
| 349 | */ |
| 350 | if (path == verifyBlobId) |
| 351 | { |
| 352 | verifyImage.flags = flags; |
Patrick Venture | 723113f | 2019-06-05 09:38:35 -0700 | [diff] [blame] | 353 | |
| 354 | lookup[session] = &verifyImage; |
| 355 | |
| 356 | fileOpen = true; |
| 357 | return true; |
| 358 | } |
| 359 | break; |
| 360 | case UpdateState::verificationStarted: |
| 361 | case UpdateState::verificationCompleted: |
| 362 | /* Unreachable code because if it's started a file is open. */ |
| 363 | return false; |
| 364 | case UpdateState::updatePending: |
| 365 | { |
| 366 | /* When in this state, they can only open the updateBlobId */ |
| 367 | if (path == updateBlobId) |
| 368 | { |
| 369 | updateImage.flags = flags; |
Patrick Venture | 723113f | 2019-06-05 09:38:35 -0700 | [diff] [blame] | 370 | |
| 371 | lookup[session] = &updateImage; |
| 372 | |
| 373 | fileOpen = true; |
| 374 | return true; |
| 375 | } |
| 376 | else |
| 377 | { |
| 378 | return false; |
| 379 | } |
| 380 | } |
| 381 | case UpdateState::updateStarted: |
| 382 | case UpdateState::updateCompleted: |
| 383 | /* Unreachable code because if it's started a file is open. */ |
| 384 | break; |
| 385 | default: |
| 386 | break; |
| 387 | } |
| 388 | |
| 389 | /* There are two abstractions at play, how you get the data and how you |
| 390 | * handle that data. such that, whether the data comes from the PCI bridge |
| 391 | * or LPC bridge is not connected to whether the data goes into a static |
| 392 | * layout flash update or a UBI tarball. |
| 393 | */ |
| 394 | |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 395 | /* 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] | 396 | * support what they request. |
| 397 | */ |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 398 | if ((flags & bitmask) == 0) |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 399 | { |
| 400 | return false; |
| 401 | } |
| 402 | |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 403 | /* How are they expecting to copy this data? */ |
| 404 | auto d = std::find_if( |
| 405 | transports.begin(), transports.end(), |
| 406 | [&flags](const auto& iter) { return (iter.bitmask & flags); }); |
| 407 | if (d == transports.end()) |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 408 | { |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 409 | return false; |
| 410 | } |
| 411 | |
| 412 | /* We found the transport handler they requested, no surprise since |
| 413 | * above we verify they selected at least one we wanted. |
| 414 | */ |
Patrick Venture | c02849b | 2018-11-06 17:31:15 -0800 | [diff] [blame] | 415 | |
Patrick Venture | 6e307a7 | 2018-11-09 18:21:17 -0800 | [diff] [blame] | 416 | /* Elsewhere I do this check by checking "if ::ipmi" because that's the |
| 417 | * only non-external data pathway -- but this is just a more generic |
| 418 | * approach to that. |
| 419 | */ |
| 420 | if (d->handler) |
| 421 | { |
| 422 | /* If the data handler open call fails, open fails. */ |
| 423 | if (!d->handler->open()) |
| 424 | { |
| 425 | return false; |
| 426 | } |
| 427 | } |
| 428 | |
Patrick Venture | 70e30bf | 2019-01-17 10:29:28 -0800 | [diff] [blame] | 429 | /* Do we have a file handler for the type of file they're opening. |
| 430 | * Note: This should only fail if something is somehow crazy wrong. |
| 431 | * Since the canHandle() said yes, and that's tied into the list of explicit |
| 432 | * firmware handers (and file handlers, like this'll know where to write the |
| 433 | * tarball, etc). |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 434 | */ |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 435 | auto h = std::find_if( |
| 436 | handlers.begin(), handlers.end(), |
| 437 | [&path](const auto& iter) { return (iter.blobName == path); }); |
| 438 | if (h == handlers.end()) |
| 439 | { |
| 440 | return false; |
| 441 | } |
| 442 | |
| 443 | /* Ok, so we found a handler that matched, so call open() */ |
| 444 | if (!h->handler->open(path)) |
| 445 | { |
| 446 | return false; |
| 447 | } |
| 448 | |
Patrick Venture | 70e30bf | 2019-01-17 10:29:28 -0800 | [diff] [blame] | 449 | Session* curr; |
| 450 | const std::string* active; |
| 451 | |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 452 | if (path == hashBlobId) |
Patrick Venture | 70e30bf | 2019-01-17 10:29:28 -0800 | [diff] [blame] | 453 | { |
| 454 | /* 2c) are they opening the /flash/hash ? (to start the process) */ |
| 455 | curr = &activeHash; |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 456 | active = &activeHashBlobId; |
Patrick Venture | 70e30bf | 2019-01-17 10:29:28 -0800 | [diff] [blame] | 457 | } |
| 458 | else |
| 459 | { |
| 460 | curr = &activeImage; |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 461 | active = &activeImageBlobId; |
Patrick Venture | 70e30bf | 2019-01-17 10:29:28 -0800 | [diff] [blame] | 462 | } |
| 463 | |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 464 | curr->flags = flags; |
| 465 | curr->dataHandler = d->handler; |
| 466 | curr->imageHandler = h->handler; |
| 467 | |
| 468 | lookup[session] = curr; |
| 469 | |
Patrick Venture | efba42d | 2019-05-24 10:48:16 -0700 | [diff] [blame] | 470 | addBlobId(*active); |
Patrick Venture | 930c7b7 | 2019-05-24 11:11:08 -0700 | [diff] [blame] | 471 | removeBlobId(verifyBlobId); |
Patrick Venture | db253bf | 2018-11-09 19:36:03 -0800 | [diff] [blame] | 472 | |
Patrick Venture | 12233c5 | 2019-05-16 09:26:59 -0700 | [diff] [blame] | 473 | state = UpdateState::uploadInProgress; |
Patrick Venture | 991910a | 2018-11-09 19:43:48 -0800 | [diff] [blame] | 474 | fileOpen = true; |
| 475 | |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 476 | return true; |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 477 | } |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 478 | |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 479 | /** |
| 480 | * The write command really just grabs the data from wherever it is and sends it |
| 481 | * to the image handler. It's the image handler's responsibility to deal with |
| 482 | * the data provided. |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 483 | * |
| 484 | * This receives a session from the blob manager, therefore it is always called |
| 485 | * between open() and close(). |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 486 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 487 | bool FirmwareBlobHandler::write(uint16_t session, uint32_t offset, |
| 488 | const std::vector<uint8_t>& data) |
| 489 | { |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 490 | auto item = lookup.find(session); |
| 491 | if (item == lookup.end()) |
| 492 | { |
| 493 | return false; |
| 494 | } |
| 495 | |
Patrick Venture | b1b68fc | 2018-11-09 09:37:04 -0800 | [diff] [blame] | 496 | /* Prevent writing during verification. */ |
| 497 | if (state == UpdateState::verificationStarted) |
| 498 | { |
| 499 | return false; |
| 500 | } |
| 501 | |
Patrick Venture | 4e2fdcd | 2019-05-30 14:58:57 -0700 | [diff] [blame] | 502 | /* Prevent writing to the verification or update blobs. */ |
| 503 | if (item->second->activePath == verifyBlobId || |
| 504 | item->second->activePath == updateBlobId) |
Patrick Venture | 8af15eb | 2019-05-15 09:39:22 -0700 | [diff] [blame] | 505 | { |
| 506 | return false; |
| 507 | } |
Patrick Venture | 699750d | 2019-05-15 09:24:09 -0700 | [diff] [blame] | 508 | |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 509 | std::vector<std::uint8_t> bytes; |
| 510 | |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 511 | if (item->second->flags & UpdateFlags::ipmi) |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 512 | { |
| 513 | bytes = data; |
| 514 | } |
| 515 | else |
| 516 | { |
| 517 | /* little endian required per design, and so on, but TODO: do endianness |
| 518 | * with boost. |
| 519 | */ |
| 520 | struct ExtChunkHdr header; |
| 521 | |
| 522 | if (data.size() != sizeof(header)) |
| 523 | { |
| 524 | return false; |
| 525 | } |
| 526 | |
| 527 | std::memcpy(&header, data.data(), data.size()); |
| 528 | bytes = item->second->dataHandler->copyFrom(header.length); |
| 529 | } |
| 530 | |
| 531 | return item->second->imageHandler->write(offset, bytes); |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 532 | } |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 533 | |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 534 | /* |
| 535 | * If the active session (image or hash) is over LPC, this allows |
| 536 | * configuring it. This option is only available before you start |
| 537 | * writing data for the given item (image or hash). This will return |
| 538 | * false at any other part. -- the lpc handler portion will know to return |
| 539 | * false. |
| 540 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 541 | bool FirmwareBlobHandler::writeMeta(uint16_t session, uint32_t offset, |
| 542 | const std::vector<uint8_t>& data) |
| 543 | { |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 544 | auto item = lookup.find(session); |
| 545 | if (item == lookup.end()) |
| 546 | { |
| 547 | return false; |
| 548 | } |
| 549 | |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 550 | if (item->second->flags & UpdateFlags::ipmi) |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 551 | { |
| 552 | return false; |
| 553 | } |
| 554 | |
Patrick Venture | d56097a | 2019-05-15 09:47:55 -0700 | [diff] [blame] | 555 | /* Prevent writing meta to the verification blob (it has no data handler). |
| 556 | */ |
| 557 | if (item->second->dataHandler) |
| 558 | { |
| 559 | return item->second->dataHandler->writeMeta(data); |
| 560 | } |
Patrick Venture | 699750d | 2019-05-15 09:24:09 -0700 | [diff] [blame] | 561 | |
Patrick Venture | d56097a | 2019-05-15 09:47:55 -0700 | [diff] [blame] | 562 | return false; |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 563 | } |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 564 | |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 565 | /* |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 566 | * If this command is called on the session for the verifyBlobId, it'll |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 567 | * trigger a systemd service `verify_image.service` to attempt to verify |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 568 | * the image. |
| 569 | * |
| 570 | * For this file to have opened, the other two must be closed, which means any |
| 571 | * out-of-band transport mechanism involved is closed. |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 572 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 573 | bool FirmwareBlobHandler::commit(uint16_t session, |
| 574 | const std::vector<uint8_t>& data) |
| 575 | { |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 576 | auto item = lookup.find(session); |
| 577 | if (item == lookup.end()) |
| 578 | { |
| 579 | return false; |
| 580 | } |
| 581 | |
Patrick Venture | 1a406fe | 2019-05-31 07:29:56 -0700 | [diff] [blame] | 582 | /* You can only commit on the verifyBlodId or updateBlobId */ |
| 583 | if (item->second->activePath != verifyBlobId && |
| 584 | item->second->activePath != updateBlobId) |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 585 | { |
Patrick Venture | 1a406fe | 2019-05-31 07:29:56 -0700 | [diff] [blame] | 586 | std::fprintf(stderr, "path: '%s' not expected for commit\n", |
| 587 | item->second->activePath.c_str()); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 588 | return false; |
| 589 | } |
| 590 | |
Patrick Venture | 433cbc3 | 2019-05-30 09:53:10 -0700 | [diff] [blame] | 591 | switch (state) |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 592 | { |
Patrick Venture | 1a406fe | 2019-05-31 07:29:56 -0700 | [diff] [blame] | 593 | case UpdateState::verificationPending: |
| 594 | /* Set state to committing. */ |
| 595 | item->second->flags |= blobs::StateFlags::committing; |
| 596 | return triggerVerification(); |
Patrick Venture | 433cbc3 | 2019-05-30 09:53:10 -0700 | [diff] [blame] | 597 | case UpdateState::verificationStarted: |
| 598 | /* Calling repeatedly has no effect within an update process. */ |
| 599 | return true; |
| 600 | case UpdateState::verificationCompleted: |
| 601 | /* Calling after the verification process has completed returns |
| 602 | * failure. */ |
| 603 | return false; |
Patrick Venture | 1a406fe | 2019-05-31 07:29:56 -0700 | [diff] [blame] | 604 | case UpdateState::updatePending: |
Patrick Venture | 433cbc3 | 2019-05-30 09:53:10 -0700 | [diff] [blame] | 605 | item->second->flags |= blobs::StateFlags::committing; |
Patrick Venture | 1a406fe | 2019-05-31 07:29:56 -0700 | [diff] [blame] | 606 | return triggerUpdate(); |
Patrick Venture | 0079d89 | 2019-05-31 11:27:44 -0700 | [diff] [blame] | 607 | case UpdateState::updateStarted: |
| 608 | /* Calling repeatedly has no effect within an update process. */ |
| 609 | return true; |
Patrick Venture | 1a406fe | 2019-05-31 07:29:56 -0700 | [diff] [blame] | 610 | default: |
| 611 | return false; |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 612 | } |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 613 | } |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 614 | |
| 615 | /* |
| 616 | * Close must be called on the firmware image before triggering |
| 617 | * verification via commit. Once the verification is complete, you can |
| 618 | * then close the hash file. |
| 619 | * |
| 620 | * If the `verify_image.service` returned success, closing the hash file |
| 621 | * will have a specific behavior depending on the update. If it's UBI, |
| 622 | * it'll perform the install. If it's static layout, it'll do nothing. The |
| 623 | * verify_image service in the static layout case is responsible for placing |
| 624 | * the file in the correct staging position. |
| 625 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 626 | bool FirmwareBlobHandler::close(uint16_t session) |
| 627 | { |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 628 | auto item = lookup.find(session); |
| 629 | if (item == lookup.end()) |
| 630 | { |
| 631 | return false; |
| 632 | } |
| 633 | |
Patrick Venture | e95dbb6 | 2019-06-05 09:59:29 -0700 | [diff] [blame] | 634 | switch (state) |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 635 | { |
Patrick Venture | e95dbb6 | 2019-06-05 09:59:29 -0700 | [diff] [blame] | 636 | case UpdateState::uploadInProgress: |
| 637 | /* They are closing a data pathway (image, tarball, hash). */ |
| 638 | state = UpdateState::verificationPending; |
Patrick Venture | 85ae86b | 2019-06-05 09:18:40 -0700 | [diff] [blame] | 639 | |
Patrick Venture | e95dbb6 | 2019-06-05 09:59:29 -0700 | [diff] [blame] | 640 | /* Add verify blob ID now that we can expect it. */ |
| 641 | addBlobId(verifyBlobId); |
| 642 | break; |
| 643 | case UpdateState::verificationPending: |
| 644 | /* They haven't triggered, therefore closing is uninteresting. |
| 645 | */ |
| 646 | break; |
| 647 | case UpdateState::verificationStarted: |
Patrick Venture | d574102 | 2019-06-17 09:08:35 -0700 | [diff] [blame] | 648 | /* Abort without checking to see if it happened to finish. Require |
| 649 | * the caller to stat() deliberately. |
Patrick Venture | e95dbb6 | 2019-06-05 09:59:29 -0700 | [diff] [blame] | 650 | */ |
Patrick Venture | d574102 | 2019-06-17 09:08:35 -0700 | [diff] [blame] | 651 | abortVerification(); |
| 652 | abortProcess(); |
| 653 | break; |
Patrick Venture | e95dbb6 | 2019-06-05 09:59:29 -0700 | [diff] [blame] | 654 | case UpdateState::verificationCompleted: |
| 655 | if (lastVerificationStatus == ActionStatus::success) |
| 656 | { |
| 657 | state = UpdateState::updatePending; |
| 658 | addBlobId(updateBlobId); |
| 659 | removeBlobId(verifyBlobId); |
| 660 | } |
| 661 | else |
| 662 | { |
| 663 | /* TODO: Verification failed, what now? */ |
| 664 | } |
| 665 | break; |
| 666 | case UpdateState::updatePending: |
| 667 | /* They haven't triggered the update, therefore this is |
| 668 | * uninteresting. */ |
| 669 | break; |
| 670 | case UpdateState::updateStarted: |
Patrick Venture | 4973171 | 2019-06-17 10:04:02 -0700 | [diff] [blame] | 671 | /* Abort without checking to see if it happened to finish. Require |
| 672 | * the caller to stat() deliberately. |
| 673 | */ |
| 674 | abortUpdate(); |
| 675 | abortProcess(); |
Patrick Venture | e95dbb6 | 2019-06-05 09:59:29 -0700 | [diff] [blame] | 676 | break; |
| 677 | case UpdateState::updateCompleted: |
| 678 | if (lastUpdateStatus == ActionStatus::failed) |
| 679 | { |
| 680 | /* TODO: lOG something? */ |
| 681 | } |
Patrick Venture | 930c7b7 | 2019-05-24 11:11:08 -0700 | [diff] [blame] | 682 | |
Patrick Venture | e95dbb6 | 2019-06-05 09:59:29 -0700 | [diff] [blame] | 683 | state = UpdateState::notYetStarted; |
| 684 | removeBlobId(updateBlobId); |
| 685 | removeBlobId(activeImageBlobId); |
| 686 | removeBlobId(activeHashBlobId); |
| 687 | break; |
| 688 | default: |
| 689 | break; |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 690 | } |
| 691 | |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 692 | if (item->second->dataHandler) |
| 693 | { |
| 694 | item->second->dataHandler->close(); |
| 695 | } |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 696 | if (item->second->imageHandler) |
| 697 | { |
| 698 | item->second->imageHandler->close(); |
| 699 | } |
| 700 | |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 701 | lookup.erase(item); |
Patrick Venture | 991910a | 2018-11-09 19:43:48 -0800 | [diff] [blame] | 702 | fileOpen = false; |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 703 | return true; |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 704 | } |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 705 | |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 706 | bool FirmwareBlobHandler::expire(uint16_t session) |
| 707 | { |
| 708 | return false; |
| 709 | } |
Patrick Venture | d6461d6 | 2018-11-09 17:30:25 -0800 | [diff] [blame] | 710 | |
| 711 | /* |
| 712 | * Currently, the design does not provide this with a function, however, |
| 713 | * it will likely change to support reading data back. |
| 714 | */ |
| 715 | std::vector<uint8_t> FirmwareBlobHandler::read(uint16_t session, |
| 716 | uint32_t offset, |
| 717 | uint32_t requestedSize) |
| 718 | { |
| 719 | return {}; |
| 720 | } |
| 721 | |
Patrick Venture | d574102 | 2019-06-17 09:08:35 -0700 | [diff] [blame] | 722 | void FirmwareBlobHandler::abortProcess() |
| 723 | { |
| 724 | /* Closing of open files is handled from close() -- Reaching here from |
| 725 | * delete may never be supported. |
| 726 | */ |
| 727 | removeBlobId(verifyBlobId); |
| 728 | removeBlobId(updateBlobId); |
| 729 | removeBlobId(activeImageBlobId); |
| 730 | removeBlobId(activeHashBlobId); |
| 731 | |
| 732 | state = UpdateState::notYetStarted; |
| 733 | } |
| 734 | |
| 735 | void FirmwareBlobHandler::abortVerification() |
| 736 | { |
| 737 | verification->abort(); |
| 738 | } |
| 739 | |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 740 | bool FirmwareBlobHandler::triggerVerification() |
| 741 | { |
Patrick Venture | 1d66fe6 | 2019-06-03 14:57:27 -0700 | [diff] [blame] | 742 | bool result = verification->trigger(); |
Patrick Venture | 3ecb350 | 2019-05-17 11:03:51 -0700 | [diff] [blame] | 743 | if (result) |
Patrick Venture | cabc117 | 2018-11-16 16:14:26 -0800 | [diff] [blame] | 744 | { |
Patrick Venture | 453f06a | 2019-01-17 10:02:12 -0800 | [diff] [blame] | 745 | state = UpdateState::verificationStarted; |
Patrick Venture | cabc117 | 2018-11-16 16:14:26 -0800 | [diff] [blame] | 746 | } |
Patrick Venture | cabc117 | 2018-11-16 16:14:26 -0800 | [diff] [blame] | 747 | |
Patrick Venture | 3ecb350 | 2019-05-17 11:03:51 -0700 | [diff] [blame] | 748 | return result; |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 749 | } |
| 750 | |
Patrick Venture | 4973171 | 2019-06-17 10:04:02 -0700 | [diff] [blame] | 751 | void FirmwareBlobHandler::abortUpdate() |
| 752 | { |
| 753 | update->abort(); |
| 754 | } |
| 755 | |
Patrick Venture | 1a406fe | 2019-05-31 07:29:56 -0700 | [diff] [blame] | 756 | bool FirmwareBlobHandler::triggerUpdate() |
| 757 | { |
Patrick Venture | 1d66fe6 | 2019-06-03 14:57:27 -0700 | [diff] [blame] | 758 | bool result = update->trigger(); |
Patrick Venture | 1a406fe | 2019-05-31 07:29:56 -0700 | [diff] [blame] | 759 | if (result) |
| 760 | { |
| 761 | state = UpdateState::updateStarted; |
| 762 | } |
| 763 | |
| 764 | return result; |
| 765 | } |
| 766 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 767 | } // namespace ipmi_flash |