tools: implement blob read
Implement blob read. This isn't currently used by the flash update
process however, it is useful.
Tested: Verified it read back bytes written to another blob handler.
Change-Id: Ib1590448d0bfaa3d4fde20ae8bae353c9107e5c4
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/tools/blob_handler.cpp b/tools/blob_handler.cpp
index e1a995d..081c32f 100644
--- a/tools/blob_handler.cpp
+++ b/tools/blob_handler.cpp
@@ -294,4 +294,25 @@
return;
}
+std::vector<std::uint8_t> BlobHandler::readBytes(std::uint16_t session,
+ std::uint32_t offset,
+ std::uint32_t length)
+{
+ std::vector<std::uint8_t> payload;
+
+ payload.reserve(sizeof(std::uint16_t) + sizeof(std::uint32_t) +
+ sizeof(std::uint32_t));
+
+ std::uint8_t* data = reinterpret_cast<std::uint8_t*>(&session);
+ std::copy(data, data + sizeof(std::uint16_t), std::back_inserter(payload));
+
+ data = reinterpret_cast<std::uint8_t*>(&offset);
+ std::copy(data, data + sizeof(std::uint32_t), std::back_inserter(payload));
+
+ data = reinterpret_cast<std::uint8_t*>(&length);
+ std::copy(data, data + sizeof(std::uint32_t), std::back_inserter(payload));
+
+ return sendIpmiPayload(BlobOEMCommands::bmcBlobRead, payload);
+}
+
} // namespace host_tool
diff --git a/tools/blob_handler.hpp b/tools/blob_handler.hpp
index e7da30f..1cbc963 100644
--- a/tools/blob_handler.hpp
+++ b/tools/blob_handler.hpp
@@ -69,6 +69,13 @@
void closeBlob(std::uint16_t session) override;
+ /**
+ * @throws BlobException.
+ */
+ std::vector<std::uint8_t> readBytes(std::uint16_t session,
+ std::uint32_t offset,
+ std::uint32_t length) override;
+
private:
/**
* Send the contents of the payload to IPMI, this method handles wrapping
diff --git a/tools/blob_interface.hpp b/tools/blob_interface.hpp
index 07525c9..61ee5eb 100644
--- a/tools/blob_interface.hpp
+++ b/tools/blob_interface.hpp
@@ -76,6 +76,19 @@
* @param[in] session - the session to close.
*/
virtual void closeBlob(std::uint16_t session) = 0;
+
+ /**
+ * Read bytes from a blob.
+ *
+ * @param[in] session - the session id.
+ * @param[in] offset - the offset to which to write the bytes.
+ * @param[in] length - the number of bytes to read.
+ * @return the bytes read
+ * @throws BlobException on failure.
+ */
+ virtual std::vector<std::uint8_t> readBytes(std::uint16_t session,
+ std::uint32_t offset,
+ std::uint32_t length) = 0;
};
} // namespace host_tool