Patrick Venture | bf58cd6 | 2018-12-11 09:05:46 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | a658636 | 2018-12-11 18:47:13 -0800 | [diff] [blame] | 3 | #include "interface.hpp" |
Patrick Venture | 0088759 | 2018-12-11 10:57:06 -0800 | [diff] [blame] | 4 | |
Patrick Venture | 664c5bc | 2019-03-07 08:09:45 -0800 | [diff] [blame] | 5 | #include <ipmiblob/blob_interface.hpp> |
Patrick Venture | bf58cd6 | 2018-12-11 09:05:46 -0800 | [diff] [blame] | 6 | #include <string> |
| 7 | |
Patrick Venture | 9b534f0 | 2018-12-13 16:10:02 -0800 | [diff] [blame] | 8 | namespace host_tool |
| 9 | { |
| 10 | |
Patrick Venture | 55646de | 2019-05-16 10:06:26 -0700 | [diff] [blame] | 11 | /** Object that actually handles the update itself. */ |
| 12 | class UpdateHandler |
| 13 | { |
| 14 | public: |
| 15 | UpdateHandler(ipmiblob::BlobInterface* blob, DataInterface* handler) : |
| 16 | blob(blob), handler(handler) |
| 17 | { |
| 18 | } |
| 19 | |
| 20 | virtual ~UpdateHandler() = default; |
| 21 | |
| 22 | /** |
| 23 | * Check if the goal firmware is listed in the blob_list and that the |
| 24 | * handler's supported data type is available. |
| 25 | * |
| 26 | * @param[in] goalFirmware - the firmware to check /flash/image |
| 27 | * /flash/tarball, etc. |
| 28 | */ |
| 29 | virtual bool checkAvailable(const std::string& goalFirmware); |
| 30 | |
| 31 | /** |
| 32 | * Send the file contents at path to the blob id, target. |
| 33 | * |
| 34 | * @param[in] target - the blob id |
| 35 | * @param[in] path - the source file path |
| 36 | * @throw ToolException on failure. |
| 37 | */ |
| 38 | virtual void sendFile(const std::string& target, const std::string& path); |
| 39 | |
| 40 | /** |
| 41 | * Trigger verification. |
| 42 | * |
| 43 | * @param[in] target - the verification blob id (may support multiple in the |
| 44 | * future. |
| 45 | * @return true if verified, false if verification errors. |
| 46 | * @throw ToolException on failure (TODO: throw on timeout.) |
| 47 | */ |
| 48 | virtual bool verifyFile(const std::string& target); |
| 49 | |
| 50 | private: |
| 51 | ipmiblob::BlobInterface* blob; |
| 52 | DataInterface* handler; |
| 53 | }; |
| 54 | |
Patrick Venture | bf58cd6 | 2018-12-11 09:05:46 -0800 | [diff] [blame] | 55 | /** |
Patrick Venture | d61b0ff | 2019-05-15 15:58:06 -0700 | [diff] [blame] | 56 | * Poll an open verification session. |
| 57 | * |
| 58 | * @param[in] session - the open verification session |
| 59 | * @param[in] blob - pointer to blob interface implementation object. |
| 60 | * @return true if the verification was successul. |
| 61 | */ |
Patrick Venture | 14713be | 2019-06-05 13:42:28 -0700 | [diff] [blame] | 62 | bool pollStatus(std::uint16_t session, ipmiblob::BlobInterface* blob); |
Patrick Venture | d61b0ff | 2019-05-15 15:58:06 -0700 | [diff] [blame] | 63 | |
| 64 | /** |
Patrick Venture | bf58cd6 | 2018-12-11 09:05:46 -0800 | [diff] [blame] | 65 | * Attempt to update the BMC's firmware using the interface provided. |
| 66 | * |
Patrick Venture | 55646de | 2019-05-16 10:06:26 -0700 | [diff] [blame] | 67 | * @param[in] updater - update handler object. |
Patrick Venture | bf58cd6 | 2018-12-11 09:05:46 -0800 | [diff] [blame] | 68 | * @param[in] imagePath - the path to the image file. |
| 69 | * @param[in] signaturePath - the path to the signature file. |
Patrick Venture | 2bc23fe | 2018-12-13 10:16:36 -0800 | [diff] [blame] | 70 | * @throws ToolException on failures. |
Patrick Venture | bf58cd6 | 2018-12-11 09:05:46 -0800 | [diff] [blame] | 71 | */ |
Patrick Venture | 55646de | 2019-05-16 10:06:26 -0700 | [diff] [blame] | 72 | void updaterMain(UpdateHandler* updater, const std::string& imagePath, |
Patrick Venture | 2bc23fe | 2018-12-13 10:16:36 -0800 | [diff] [blame] | 73 | const std::string& signaturePath); |
Patrick Venture | 9b534f0 | 2018-12-13 16:10:02 -0800 | [diff] [blame] | 74 | |
| 75 | } // namespace host_tool |