blob: 670d98165b171d9d857a799d04fd21c845c97660 [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;
42};
43
44/** Object that actually handles the update itself. */
45class UpdateHandler : public UpdateHandlerInterface
46{
47 public:
48 UpdateHandler(ipmiblob::BlobInterface* blob, DataInterface* handler) :
49 blob(blob), handler(handler)
50 {
51 }
52
53 ~UpdateHandler() = default;
54
55 bool checkAvailable(const std::string& goalFirmware) override;
56
57 /**
58 * @throw ToolException on failure.
59 */
60 void sendFile(const std::string& target, const std::string& path) override;
61
62 /**
Patrick Venture55646de2019-05-16 10:06:26 -070063 * @throw ToolException on failure (TODO: throw on timeout.)
64 */
Patrick Venture1f09d412019-06-19 16:01:06 -070065 bool verifyFile(const std::string& target) override;
Patrick Venture55646de2019-05-16 10:06:26 -070066
67 private:
68 ipmiblob::BlobInterface* blob;
69 DataInterface* handler;
70};
71
Patrick Venturebf58cd62018-12-11 09:05:46 -080072/**
Patrick Ventured61b0ff2019-05-15 15:58:06 -070073 * Poll an open verification session.
74 *
75 * @param[in] session - the open verification session
76 * @param[in] blob - pointer to blob interface implementation object.
77 * @return true if the verification was successul.
78 */
Patrick Venture14713be2019-06-05 13:42:28 -070079bool pollStatus(std::uint16_t session, ipmiblob::BlobInterface* blob);
Patrick Ventured61b0ff2019-05-15 15:58:06 -070080
81/**
Patrick Venturebf58cd62018-12-11 09:05:46 -080082 * Attempt to update the BMC's firmware using the interface provided.
83 *
Patrick Venture55646de2019-05-16 10:06:26 -070084 * @param[in] updater - update handler object.
Patrick Venturebf58cd62018-12-11 09:05:46 -080085 * @param[in] imagePath - the path to the image file.
86 * @param[in] signaturePath - the path to the signature file.
Patrick Venture2bc23fe2018-12-13 10:16:36 -080087 * @throws ToolException on failures.
Patrick Venturebf58cd62018-12-11 09:05:46 -080088 */
Patrick Venture1f09d412019-06-19 16:01:06 -070089void updaterMain(UpdateHandlerInterface* updater, const std::string& imagePath,
Patrick Venture2bc23fe2018-12-13 10:16:36 -080090 const std::string& signaturePath);
Patrick Venture9b534f02018-12-13 16:10:02 -080091
92} // namespace host_tool