blob: 4352c824e26b6e02c5fd0094441a6ad08814efe2 [file] [log] [blame]
Patrick Venturebf58cd62018-12-11 09:05:46 -08001#pragma once
2
Patrick Venturea6586362018-12-11 18:47:13 -08003#include "interface.hpp"
Patrick Venture00887592018-12-11 10:57:06 -08004
Patrick Venture664c5bc2019-03-07 08:09:45 -08005#include <ipmiblob/blob_interface.hpp>
Patrick Venturebf58cd62018-12-11 09:05:46 -08006#include <string>
7
Patrick Venture9b534f02018-12-13 16:10:02 -08008namespace host_tool
9{
10
Patrick Venture1f09d412019-06-19 16:01:06 -070011class UpdateHandlerInterface
Patrick Venture55646de2019-05-16 10:06:26 -070012{
13 public:
Patrick Venture1f09d412019-06-19 16:01:06 -070014 virtual ~UpdateHandlerInterface() = default;
Patrick Venture55646de2019-05-16 10:06:26 -070015
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 Venture1f09d412019-06-19 16:01:06 -070023 virtual bool checkAvailable(const std::string& goalFirmware) = 0;
Patrick Venture55646de2019-05-16 10:06:26 -070024
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 Venture55646de2019-05-16 10:06:26 -070030 */
Patrick Venture1f09d412019-06-19 16:01:06 -070031 virtual void sendFile(const std::string& target,
32 const std::string& path) = 0;
Patrick Venture55646de2019-05-16 10:06:26 -070033
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 Venture1f09d412019-06-19 16:01:06 -070040 */
41 virtual bool verifyFile(const std::string& target) = 0;
Patrick Venture5f2fcc42019-06-20 07:21:05 -070042
43 /**
44 * Cleanup the artifacts by triggering this action.
45 */
46 virtual void cleanArtifacts() = 0;
Patrick Venture1f09d412019-06-19 16:01:06 -070047};
48
49/** Object that actually handles the update itself. */
50class 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 Venture55646de2019-05-16 10:06:26 -070068 * @throw ToolException on failure (TODO: throw on timeout.)
69 */
Patrick Venture1f09d412019-06-19 16:01:06 -070070 bool verifyFile(const std::string& target) override;
Patrick Venture55646de2019-05-16 10:06:26 -070071
Patrick Venture5f2fcc42019-06-20 07:21:05 -070072 void cleanArtifacts() override;
73
Patrick Venture55646de2019-05-16 10:06:26 -070074 private:
75 ipmiblob::BlobInterface* blob;
76 DataInterface* handler;
77};
78
Patrick Venturebf58cd62018-12-11 09:05:46 -080079/**
Patrick Ventured61b0ff2019-05-15 15:58:06 -070080 * 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 Venture14713be2019-06-05 13:42:28 -070086bool pollStatus(std::uint16_t session, ipmiblob::BlobInterface* blob);
Patrick Ventured61b0ff2019-05-15 15:58:06 -070087
88/**
Patrick Venturebf58cd62018-12-11 09:05:46 -080089 * Attempt to update the BMC's firmware using the interface provided.
90 *
Patrick Venture55646de2019-05-16 10:06:26 -070091 * @param[in] updater - update handler object.
Patrick Venturebf58cd62018-12-11 09:05:46 -080092 * @param[in] imagePath - the path to the image file.
93 * @param[in] signaturePath - the path to the signature file.
Patrick Venture2bc23fe2018-12-13 10:16:36 -080094 * @throws ToolException on failures.
Patrick Venturebf58cd62018-12-11 09:05:46 -080095 */
Patrick Venture1f09d412019-06-19 16:01:06 -070096void updaterMain(UpdateHandlerInterface* updater, const std::string& imagePath,
Patrick Venture2bc23fe2018-12-13 10:16:36 -080097 const std::string& signaturePath);
Patrick Venture9b534f02018-12-13 16:10:02 -080098
99} // namespace host_tool