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