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 | 1f09d41 | 2019-06-19 16:01:06 -0700 | [diff] [blame] | 11 | class UpdateHandlerInterface |
Patrick Venture | 55646de | 2019-05-16 10:06:26 -0700 | [diff] [blame] | 12 | { |
| 13 | public: |
Patrick Venture | 1f09d41 | 2019-06-19 16:01:06 -0700 | [diff] [blame] | 14 | virtual ~UpdateHandlerInterface() = default; |
Patrick Venture | 55646de | 2019-05-16 10:06:26 -0700 | [diff] [blame] | 15 | |
| 16 | /** |
| 17 | * Check if the goal firmware is listed in the blob_list and that the |
| 18 | * handler's supported data type is available. |
| 19 | * |
| 20 | * @param[in] goalFirmware - the firmware to check /flash/image |
| 21 | * /flash/tarball, etc. |
| 22 | */ |
Patrick Venture | 1f09d41 | 2019-06-19 16:01:06 -0700 | [diff] [blame] | 23 | virtual bool checkAvailable(const std::string& goalFirmware) = 0; |
Patrick Venture | 55646de | 2019-05-16 10:06:26 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Send the file contents at path to the blob id, target. |
| 27 | * |
| 28 | * @param[in] target - the blob id |
| 29 | * @param[in] path - the source file path |
Patrick Venture | 55646de | 2019-05-16 10:06:26 -0700 | [diff] [blame] | 30 | */ |
Patrick Venture | 1f09d41 | 2019-06-19 16:01:06 -0700 | [diff] [blame] | 31 | virtual void sendFile(const std::string& target, |
| 32 | const std::string& path) = 0; |
Patrick Venture | 55646de | 2019-05-16 10:06:26 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * Trigger verification. |
| 36 | * |
| 37 | * @param[in] target - the verification blob id (may support multiple in the |
| 38 | * future. |
| 39 | * @return true if verified, false if verification errors. |
Patrick Venture | 1f09d41 | 2019-06-19 16:01:06 -0700 | [diff] [blame] | 40 | */ |
| 41 | virtual bool verifyFile(const std::string& target) = 0; |
Patrick Venture | 5f2fcc4 | 2019-06-20 07:21:05 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * Cleanup the artifacts by triggering this action. |
| 45 | */ |
| 46 | virtual void cleanArtifacts() = 0; |
Patrick Venture | 1f09d41 | 2019-06-19 16:01:06 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | /** Object that actually handles the update itself. */ |
| 50 | class UpdateHandler : public UpdateHandlerInterface |
| 51 | { |
| 52 | public: |
| 53 | UpdateHandler(ipmiblob::BlobInterface* blob, DataInterface* handler) : |
| 54 | blob(blob), handler(handler) |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | ~UpdateHandler() = default; |
| 59 | |
| 60 | bool checkAvailable(const std::string& goalFirmware) override; |
| 61 | |
| 62 | /** |
| 63 | * @throw ToolException on failure. |
| 64 | */ |
| 65 | void sendFile(const std::string& target, const std::string& path) override; |
| 66 | |
| 67 | /** |
Patrick Venture | 55646de | 2019-05-16 10:06:26 -0700 | [diff] [blame] | 68 | * @throw ToolException on failure (TODO: throw on timeout.) |
| 69 | */ |
Patrick Venture | 1f09d41 | 2019-06-19 16:01:06 -0700 | [diff] [blame] | 70 | bool verifyFile(const std::string& target) override; |
Patrick Venture | 55646de | 2019-05-16 10:06:26 -0700 | [diff] [blame] | 71 | |
Patrick Venture | 5f2fcc4 | 2019-06-20 07:21:05 -0700 | [diff] [blame] | 72 | void cleanArtifacts() override; |
| 73 | |
Patrick Venture | 55646de | 2019-05-16 10:06:26 -0700 | [diff] [blame] | 74 | private: |
| 75 | ipmiblob::BlobInterface* blob; |
| 76 | DataInterface* handler; |
| 77 | }; |
| 78 | |
Patrick Venture | bf58cd6 | 2018-12-11 09:05:46 -0800 | [diff] [blame] | 79 | /** |
Patrick Venture | d61b0ff | 2019-05-15 15:58:06 -0700 | [diff] [blame] | 80 | * Poll an open verification session. |
| 81 | * |
| 82 | * @param[in] session - the open verification session |
| 83 | * @param[in] blob - pointer to blob interface implementation object. |
| 84 | * @return true if the verification was successul. |
| 85 | */ |
Patrick Venture | 14713be | 2019-06-05 13:42:28 -0700 | [diff] [blame] | 86 | bool pollStatus(std::uint16_t session, ipmiblob::BlobInterface* blob); |
Patrick Venture | d61b0ff | 2019-05-15 15:58:06 -0700 | [diff] [blame] | 87 | |
| 88 | /** |
Patrick Venture | bf58cd6 | 2018-12-11 09:05:46 -0800 | [diff] [blame] | 89 | * Attempt to update the BMC's firmware using the interface provided. |
| 90 | * |
Patrick Venture | 55646de | 2019-05-16 10:06:26 -0700 | [diff] [blame] | 91 | * @param[in] updater - update handler object. |
Patrick Venture | bf58cd6 | 2018-12-11 09:05:46 -0800 | [diff] [blame] | 92 | * @param[in] imagePath - the path to the image file. |
| 93 | * @param[in] signaturePath - the path to the signature file. |
Patrick Venture | 2bc23fe | 2018-12-13 10:16:36 -0800 | [diff] [blame] | 94 | * @throws ToolException on failures. |
Patrick Venture | bf58cd6 | 2018-12-11 09:05:46 -0800 | [diff] [blame] | 95 | */ |
Patrick Venture | 1f09d41 | 2019-06-19 16:01:06 -0700 | [diff] [blame] | 96 | void updaterMain(UpdateHandlerInterface* updater, const std::string& imagePath, |
Patrick Venture | 2bc23fe | 2018-12-13 10:16:36 -0800 | [diff] [blame] | 97 | const std::string& signaturePath); |
Patrick Venture | 9b534f0 | 2018-12-13 16:10:02 -0800 | [diff] [blame] | 98 | |
| 99 | } // namespace host_tool |