Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 1 | #include "firmware_handler.hpp" |
| 2 | |
Patrick Venture | 68cf64f | 2018-11-06 10:46:51 -0800 | [diff] [blame] | 3 | #include <memory> |
Patrick Venture | fa6c4d9 | 2018-11-02 18:34:53 -0700 | [diff] [blame] | 4 | #include <string> |
| 5 | #include <vector> |
| 6 | |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 7 | namespace blobs |
| 8 | { |
| 9 | |
Patrick Venture | 68cf64f | 2018-11-06 10:46:51 -0800 | [diff] [blame] | 10 | std::unique_ptr<GenericBlobInterface> |
Patrick Venture | 148cd65 | 2018-11-06 10:59:47 -0800 | [diff] [blame] | 11 | FirmwareBlobHandler::CreateFirmwareBlobHandler( |
| 12 | const std::vector<std::string>& firmwares) |
Patrick Venture | 68cf64f | 2018-11-06 10:46:51 -0800 | [diff] [blame] | 13 | { |
Patrick Venture | 148cd65 | 2018-11-06 10:59:47 -0800 | [diff] [blame] | 14 | return std::make_unique<FirmwareBlobHandler>(firmwares); |
Patrick Venture | 68cf64f | 2018-11-06 10:46:51 -0800 | [diff] [blame] | 15 | } |
| 16 | |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 17 | bool FirmwareBlobHandler::canHandleBlob(const std::string& path) |
| 18 | { |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 19 | /* Check if the path is in our supported list (or active list). */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 20 | return false; |
| 21 | } |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 22 | |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 23 | std::vector<std::string> FirmwareBlobHandler::getBlobIds() |
| 24 | { |
Patrick Venture | fa6c4d9 | 2018-11-02 18:34:53 -0700 | [diff] [blame] | 25 | /* |
| 26 | * Grab the list of supported firmware. |
| 27 | * If there's an open session, add that to this list. |
| 28 | */ |
Patrick Venture | 148cd65 | 2018-11-06 10:59:47 -0800 | [diff] [blame] | 29 | std::vector<std::string> blobs = baseFirmwares; |
Patrick Venture | fa6c4d9 | 2018-11-02 18:34:53 -0700 | [diff] [blame] | 30 | |
| 31 | /* |
| 32 | * If there's an open firmware session, it'll add "/flash/active/image", |
| 33 | * and if the hash has started, "/flash/active/hash" regardless of |
| 34 | * mechanism. |
| 35 | */ |
| 36 | |
| 37 | return blobs; |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 38 | } |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 39 | |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 40 | bool FirmwareBlobHandler::deleteBlob(const std::string& path) |
| 41 | { |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 42 | /* |
| 43 | * Per the design, this mean abort, and this will trigger whatever |
| 44 | * appropriate actions are required to abort the process. |
| 45 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 46 | return false; |
| 47 | } |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 48 | |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 49 | bool FirmwareBlobHandler::stat(const std::string& path, struct BlobMeta* meta) |
| 50 | { |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 51 | /* |
| 52 | * Stat on the files will return information such as what supported |
| 53 | * transport mechanisms are available. |
| 54 | * |
| 55 | * Stat on an active file or hash will return information such as the size |
| 56 | * of the data cached, and any additional pertinent information. The |
| 57 | * blob_state on the active files will return the state of the update. |
| 58 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 59 | return false; |
| 60 | } |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 61 | |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 62 | bool FirmwareBlobHandler::open(uint16_t session, uint16_t flags, |
| 63 | const std::string& path) |
| 64 | { |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 65 | /* |
| 66 | * If you open /flash/image or /flash/tarball, or /flash/hash it will |
| 67 | * interpret the open flags and perform whatever actions are required for |
| 68 | * that update process. The session returned can be used immediately for |
| 69 | * sending data down, without requiring one to open the new active file. |
| 70 | * |
| 71 | * If you open the active flash image or active hash it will let you |
| 72 | * overwrite pieces, depending on the state. |
| 73 | * Once the verification process has started the active files cannot be |
| 74 | * opened. |
| 75 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 76 | return false; |
| 77 | } |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 78 | |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 79 | std::vector<uint8_t> FirmwareBlobHandler::read(uint16_t session, |
| 80 | uint32_t offset, |
| 81 | uint32_t requestedSize) |
| 82 | { |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 83 | /* |
| 84 | * Currently, the design does not provide this with a function, however, |
| 85 | * it will likely change to support reading data back. |
| 86 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 87 | return {}; |
| 88 | } |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 89 | |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 90 | bool FirmwareBlobHandler::write(uint16_t session, uint32_t offset, |
| 91 | const std::vector<uint8_t>& data) |
| 92 | { |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 93 | /* |
| 94 | * This will do whatever behavior is expected by mechanism - likely will |
| 95 | * just call the specific write handler. |
| 96 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 97 | return false; |
| 98 | } |
| 99 | bool FirmwareBlobHandler::writeMeta(uint16_t session, uint32_t offset, |
| 100 | const std::vector<uint8_t>& data) |
| 101 | { |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 102 | /* |
| 103 | * If the active session (image or hash) is over LPC, this allows |
| 104 | * configuring it. This option is only available before you start |
| 105 | * writing data for the given item (image or hash). This will return |
| 106 | * false at any other part. |
| 107 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 108 | return false; |
| 109 | } |
| 110 | bool FirmwareBlobHandler::commit(uint16_t session, |
| 111 | const std::vector<uint8_t>& data) |
| 112 | { |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 113 | /* |
| 114 | * If this command is called on the session for the hash image, it'll |
| 115 | * trigger a systemd service `verify_image.service` to attempt to verify |
| 116 | * the image. Before doing this, if the transport mechanism is not IPMI |
| 117 | * BT, it'll shut down the mechanism used for transport preventing the |
| 118 | * host from updating anything. |
| 119 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 120 | return false; |
| 121 | } |
| 122 | bool FirmwareBlobHandler::close(uint16_t session) |
| 123 | { |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 124 | /* |
| 125 | * Close must be called on the firmware image before triggering |
| 126 | * verification via commit. Once the verification is complete, you can |
| 127 | * then close the hash file. |
| 128 | * |
| 129 | * If the `verify_image.service` returned success, closing the hash file |
| 130 | * will have a specific behavior depending on the update. If it's UBI, |
| 131 | * it'll perform the install. If it's static layout, it'll do nothing. The |
| 132 | * verify_image service in the static layout case is responsible for placing |
| 133 | * the file in the correct staging position. |
| 134 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 135 | return false; |
| 136 | } |
| 137 | bool FirmwareBlobHandler::stat(uint16_t session, struct BlobMeta* meta) |
| 138 | { |
Patrick Venture | 5397796 | 2018-11-02 18:59:35 -0700 | [diff] [blame] | 139 | /* |
| 140 | * Return the supported mechanisms if it's the handler blob_id, versus |
| 141 | * the active one. |
| 142 | */ |
Patrick Venture | c7ca291 | 2018-11-02 11:38:33 -0700 | [diff] [blame] | 143 | return false; |
| 144 | } |
| 145 | bool FirmwareBlobHandler::expire(uint16_t session) |
| 146 | { |
| 147 | return false; |
| 148 | } |
| 149 | } // namespace blobs |