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