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