ipmi: start implementing flashStartTransfer
Change-Id: I1f8b1498d517c0661e98b1ba895e7152f7a9ed8e
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/flash-ipmi.hpp b/flash-ipmi.hpp
index 43cafe1..deef582 100644
--- a/flash-ipmi.hpp
+++ b/flash-ipmi.hpp
@@ -1,5 +1,10 @@
#pragma once
+#include "host-ipmid/ipmid-api.h"
+
+/* Clearer way to represent the subcommand size. */
+#define SUBCMD_SZ sizeof(uint8_t)
+
/*
* flashStartTransfer -- starts file upload.
* flashDataBlock -- adds data to image file.
@@ -55,3 +60,52 @@
flashHashExtData = 12,
flashMapRegionLpc = 13,
};
+
+/*
+ * StartTransfer expects a basic structure providing some information.
+ */
+struct StartTx
+{
+ uint8_t cmd;
+ uint32_t length; /* Maximum image length is 4GiB (little-endian) */
+} __attribute__((packed));
+
+class UpdateInterface
+{
+ public:
+ virtual ~UpdateInterface() = default;
+
+ virtual bool start(uint32_t length) = 0;
+};
+
+class FlashUpdate : public UpdateInterface
+{
+ public:
+ FlashUpdate() = default;
+ ~FlashUpdate() = default;
+ FlashUpdate(const FlashUpdate&) = default;
+ FlashUpdate& operator=(const FlashUpdate&) = default;
+ FlashUpdate(FlashUpdate&&) = default;
+ FlashUpdate& operator=(FlashUpdate&&) = default;
+
+ /**
+ * Prepare to receive a BMC image and then a signature.
+ *
+ * @param[in] length - the size of the flash image.
+ * @return true on success, false otherwise.
+ */
+ bool start(uint32_t length) override;
+
+ private:
+ /**
+ * Tries to close out and delete anything staged.
+ */
+ void abortEverything();
+
+ /**
+ * Open all staged file handles you expect to use.
+ *
+ * @return false on failure.
+ */
+ bool openEverything();
+};