use ipmiblob library from ipmi-blob-tool
Drop all code that is now handled by the ipmiblob library provided by
the new ipmi-blob-tool. This is a library that can be included on the
BMC if necessary, but relies on nothing that is strictly meant for the
BMC.
Change-Id: Iadbf0bd89c58cafc436fba05ea43e21c49e2b669
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/test/Makefile.am b/test/Makefile.am
index e5ea1ff..568b361 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -33,12 +33,9 @@
firmware_sessionstat_unittest \
firmware_commit_unittest \
file_handler_unittest \
- tools_blob_unittest \
tools_bt_unittest \
tools_lpc_unittest \
- tools_updater_unittest \
- tools_ipmi_unittest \
- tools_ipmi_error_unittest
+ tools_updater_unittest
TESTS = $(check_PROGRAMS)
@@ -78,9 +75,6 @@
file_handler_unittest_SOURCES = file_handler_unittest.cpp
file_handler_unittest_LDADD = $(top_builddir)/file_handler.o -lstdc++fs
-tools_blob_unittest_SOURCES = tools_blob_unittest.cpp
-tools_blob_unittest_LDADD = $(top_builddir)/tools/blob_handler.o
-
tools_bt_unittest_SOURCES = tools_bt_unittest.cpp
tools_bt_unittest_LDADD = $(top_builddir)/tools/bt.o
@@ -89,9 +83,3 @@
tools_updater_unittest_SOURCES = tools_updater_unittest.cpp
tools_updater_unittest_LDADD = $(top_builddir)/tools/updater.o
-
-tools_ipmi_unittest_SOURCES = tools_ipmi_unittest.cpp
-tools_ipmi_unittest_LDADD = $(top_builddir)/tools/ipmi_handler.o
-
-tools_ipmi_error_unittest_SOURCES = tools_ipmi_error_unittest.cpp
-tools_ipmi_error_unittest_LDADD =
diff --git a/test/blob_interface_mock.hpp b/test/blob_interface_mock.hpp
deleted file mode 100644
index 845d7c1..0000000
--- a/test/blob_interface_mock.hpp
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "blob_interface.hpp"
-
-#include <gmock/gmock.h>
-
-namespace host_tool
-{
-
-class BlobInterfaceMock : public BlobInterface
-{
- public:
- virtual ~BlobInterfaceMock() = default;
- MOCK_METHOD3(writeMeta, void(std::uint16_t, std::uint32_t,
- const std::vector<std::uint8_t>&));
- MOCK_METHOD3(writeBytes, void(std::uint16_t, std::uint32_t,
- const std::vector<std::uint8_t>&));
- MOCK_METHOD0(getBlobList, std::vector<std::string>());
- MOCK_METHOD1(getStat, StatResponse(const std::string&));
- MOCK_METHOD2(openBlob,
- std::uint16_t(const std::string&,
- blobs::FirmwareBlobHandler::UpdateFlags));
- MOCK_METHOD1(closeBlob, void(std::uint16_t));
- MOCK_METHOD3(readBytes,
- std::vector<std::uint8_t>(std::uint16_t, std::uint32_t,
- std::uint32_t));
-};
-
-} // namespace host_tool
diff --git a/test/ipmi_interface_mock.hpp b/test/ipmi_interface_mock.hpp
deleted file mode 100644
index 374dc93..0000000
--- a/test/ipmi_interface_mock.hpp
+++ /dev/null
@@ -1,18 +0,0 @@
-#pragma once
-
-#include "ipmi_interface.hpp"
-
-#include <gmock/gmock.h>
-
-namespace host_tool
-{
-
-class IpmiInterfaceMock : public IpmiInterface
-{
- public:
- virtual ~IpmiInterfaceMock() = default;
- MOCK_METHOD1(sendPacket,
- std::vector<std::uint8_t>(std::vector<std::uint8_t>&));
-};
-
-} // namespace host_tool
diff --git a/test/tools_blob_unittest.cpp b/test/tools_blob_unittest.cpp
deleted file mode 100644
index a51eb25..0000000
--- a/test/tools_blob_unittest.cpp
+++ /dev/null
@@ -1,286 +0,0 @@
-#include "blob_handler.hpp"
-#include "crc_mock.hpp"
-#include "ipmi_interface_mock.hpp"
-
-#include <gtest/gtest.h>
-
-namespace host_tool
-{
-CrcInterface* crcIntf = nullptr;
-
-std::uint16_t generateCrc(const std::vector<std::uint8_t>& data)
-{
- return (crcIntf) ? crcIntf->generateCrc(data) : 0x00;
-}
-
-using ::testing::Eq;
-using ::testing::Return;
-
-class BlobHandlerTest : public ::testing::Test
-{
- protected:
- void SetUp() override
- {
- crcIntf = &crcMock;
- }
-
- CrcMock crcMock;
-};
-
-TEST_F(BlobHandlerTest, getCountIpmiHappy)
-{
- /* Verify returns the value specified by the IPMI response. */
- IpmiInterfaceMock ipmiMock;
- BlobHandler blob(&ipmiMock);
- std::vector<std::uint8_t> request = {
- 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobGetCount};
-
- /* return 1 blob count. */
- std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00,
- 0x01, 0x00, 0x00, 0x00};
-
- std::vector<std::uint8_t> bytes = {0x01, 0x00, 0x00, 0x00};
- EXPECT_CALL(crcMock, generateCrc(Eq(bytes))).WillOnce(Return(0x00));
-
- EXPECT_CALL(ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
- EXPECT_EQ(1, blob.getBlobCount());
-}
-
-TEST_F(BlobHandlerTest, enumerateBlobIpmiHappy)
-{
- /* Verify returns the name specified by the IPMI response. */
- IpmiInterfaceMock ipmiMock;
- BlobHandler blob(&ipmiMock);
- std::vector<std::uint8_t> request = {
- 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobEnumerate,
- 0x00, 0x00, 0x01, 0x00,
- 0x00, 0x00};
-
- /* return value. */
- std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00,
- 'a', 'b', 'c', 'd', 0x00};
-
- std::vector<std::uint8_t> bytes = {'a', 'b', 'c', 'd', 0x00};
- std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00};
- EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00));
- EXPECT_CALL(crcMock, generateCrc(Eq(bytes))).WillOnce(Return(0x00));
-
- EXPECT_CALL(ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
- EXPECT_STREQ("abcd", blob.enumerateBlob(1).c_str());
-}
-
-TEST_F(BlobHandlerTest, enumerateBlobIpmiNoBytes)
-{
- /* Simulate a case where the IPMI command returns no data. */
- IpmiInterfaceMock ipmiMock;
- BlobHandler blob(&ipmiMock);
- std::vector<std::uint8_t> request = {
- 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobEnumerate,
- 0x00, 0x00, 0x01, 0x00,
- 0x00, 0x00};
-
- /* return value. */
- std::vector<std::uint8_t> resp = {};
-
- std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00};
- EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00));
-
- EXPECT_CALL(ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
- EXPECT_STREQ("", blob.enumerateBlob(1).c_str());
-}
-
-TEST_F(BlobHandlerTest, getBlobListIpmiHappy)
-{
- /* Verify returns the list built via the above two commands. */
- IpmiInterfaceMock ipmiMock;
- BlobHandler blob(&ipmiMock);
-
- std::vector<std::uint8_t> request1 = {
- 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobGetCount};
-
- /* return 1 blob count. */
- std::vector<std::uint8_t> resp1 = {0xcf, 0xc2, 0x00, 0x00, 0x00,
- 0x01, 0x00, 0x00, 0x00};
-
- std::vector<std::uint8_t> bytes1 = {0x01, 0x00, 0x00, 0x00};
- EXPECT_CALL(crcMock, generateCrc(Eq(bytes1))).WillOnce(Return(0x00));
-
- EXPECT_CALL(ipmiMock, sendPacket(Eq(request1))).WillOnce(Return(resp1));
-
- std::vector<std::uint8_t> request2 = {
- 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobEnumerate,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00};
-
- /* return value. */
- std::vector<std::uint8_t> resp2 = {0xcf, 0xc2, 0x00, 0x00, 0x00,
- 'a', 'b', 'c', 'd', 0x00};
-
- std::vector<std::uint8_t> reqCrc = {0x00, 0x00, 0x00, 0x00};
- std::vector<std::uint8_t> bytes2 = {'a', 'b', 'c', 'd', 0x00};
- EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00));
- EXPECT_CALL(crcMock, generateCrc(Eq(bytes2))).WillOnce(Return(0x00));
-
- EXPECT_CALL(ipmiMock, sendPacket(Eq(request2))).WillOnce(Return(resp2));
-
- /* A std::string is not nul-terminated by default. */
- std::vector<std::string> expectedList = {std::string{"abcd"}};
-
- EXPECT_EQ(expectedList, blob.getBlobList());
-}
-
-TEST_F(BlobHandlerTest, getStatWithMetadata)
-{
- /* Stat received metadata. */
- IpmiInterfaceMock ipmiMock;
- BlobHandler blob(&ipmiMock);
- std::vector<std::uint8_t> request = {
- 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobStat,
- 0x00, 0x00, 'a', 'b',
- 'c', 'd', 0x00};
-
- /* return blob_state: 0xffff, size: 0x00, metadata 0x3445 */
- std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0x00, 0x02, 0x34, 0x45};
-
- std::vector<std::uint8_t> reqCrc = {'a', 'b', 'c', 'd', 0x00};
- std::vector<std::uint8_t> respCrc = {0xff, 0xff, 0x00, 0x00, 0x00,
- 0x00, 0x02, 0x34, 0x45};
- EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00));
- EXPECT_CALL(crcMock, generateCrc(Eq(respCrc))).WillOnce(Return(0x00));
-
- EXPECT_CALL(ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
-
- auto meta = blob.getStat("abcd");
- EXPECT_EQ(meta.blob_state, 0xffff);
- EXPECT_EQ(meta.size, 0x00);
- std::vector<std::uint8_t> metadata = {0x34, 0x45};
- EXPECT_EQ(metadata, meta.metadata);
-}
-
-TEST_F(BlobHandlerTest, getStatNoMetadata)
-{
- /* Stat received no metadata. */
- IpmiInterfaceMock ipmiMock;
- BlobHandler blob(&ipmiMock);
- std::vector<std::uint8_t> request = {
- 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobStat,
- 0x00, 0x00, 'a', 'b',
- 'c', 'd', 0x00};
-
- /* return blob_state: 0xffff, size: 0x00, metadata 0x3445 */
- std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xff,
- 0xff, 0x00, 0x00, 0x00, 0x00, 0x00};
-
- std::vector<std::uint8_t> reqCrc = {'a', 'b', 'c', 'd', 0x00};
- std::vector<std::uint8_t> respCrc = {0xff, 0xff, 0x00, 0x00,
- 0x00, 0x00, 0x00};
-
- EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00));
- EXPECT_CALL(crcMock, generateCrc(Eq(respCrc))).WillOnce(Return(0x00));
-
- EXPECT_CALL(ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
-
- auto meta = blob.getStat("abcd");
- EXPECT_EQ(meta.blob_state, 0xffff);
- EXPECT_EQ(meta.size, 0x00);
- std::vector<std::uint8_t> metadata = {};
- EXPECT_EQ(metadata, meta.metadata);
-}
-
-TEST_F(BlobHandlerTest, openBlobSucceeds)
-{
- /* The open blob succeeds. */
- IpmiInterfaceMock ipmiMock;
- BlobHandler blob(&ipmiMock);
-
- std::vector<std::uint8_t> request = {
- 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobOpen,
- 0x00, 0x00, 0x02, 0x04,
- 'a', 'b', 'c', 'd',
- 0x00};
-
- std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xfe, 0xed};
-
- std::vector<std::uint8_t> reqCrc = {0x02, 0x04, 'a', 'b', 'c', 'd', 0x00};
- std::vector<std::uint8_t> respCrc = {0xfe, 0xed};
- EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00));
- EXPECT_CALL(crcMock, generateCrc(Eq(respCrc))).WillOnce(Return(0x00));
-
- EXPECT_CALL(ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
-
- auto session =
- blob.openBlob("abcd", blobs::FirmwareBlobHandler::UpdateFlags::lpc);
- EXPECT_EQ(0xedfe, session);
-}
-
-TEST_F(BlobHandlerTest, closeBlobSucceeds)
-{
- /* The close succeeds. */
- IpmiInterfaceMock ipmiMock;
- BlobHandler blob(&ipmiMock);
-
- std::vector<std::uint8_t> request = {
- 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobClose,
- 0x00, 0x00, 0x01, 0x00};
- std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00};
- std::vector<std::uint8_t> reqCrc = {0x01, 0x00};
- EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00));
-
- EXPECT_CALL(ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
-
- blob.closeBlob(0x0001);
-}
-
-TEST_F(BlobHandlerTest, writeBytesSucceeds)
-{
- /* The write bytes succeeds. */
- IpmiInterfaceMock ipmiMock;
- BlobHandler blob(&ipmiMock);
-
- std::vector<std::uint8_t> request = {
- 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobWrite,
- 0x00, 0x00, 0x01, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 'a', 'b', 'c', 'd'};
-
- std::vector<std::uint8_t> bytes = {'a', 'b', 'c', 'd'};
- std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00};
- std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00, 0x00,
- 0x00, 'a', 'b', 'c', 'd'};
- EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00));
-
- EXPECT_CALL(ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
-
- blob.writeBytes(0x0001, 0, bytes);
-}
-
-TEST_F(BlobHandlerTest, readBytesSucceeds)
-{
- /* The reading of bytes succeeds. */
-
- IpmiInterfaceMock ipmiMock;
- BlobHandler blob(&ipmiMock);
-
- std::vector<std::uint8_t> request = {
- 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobRead,
- 0x00, 0x00, 0x01, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x04, 0x00, 0x00, 0x00};
-
- std::vector<std::uint8_t> expectedBytes = {'a', 'b', 'c', 'd'};
- std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00,
- 'a', 'b', 'c', 'd'};
- std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x04, 0x00, 0x00, 0x00};
- std::vector<std::uint8_t> respCrc = {'a', 'b', 'c', 'd'};
-
- EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00));
- EXPECT_CALL(crcMock, generateCrc(Eq(respCrc))).WillOnce(Return(0x00));
-
- EXPECT_CALL(ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
-
- EXPECT_EQ(blob.readBytes(0x0001, 0, 4), expectedBytes);
-}
-
-} // namespace host_tool
diff --git a/test/tools_bt_unittest.cpp b/test/tools_bt_unittest.cpp
index 24511c3..1a364d3 100644
--- a/test/tools_bt_unittest.cpp
+++ b/test/tools_bt_unittest.cpp
@@ -1,8 +1,8 @@
-#include "blob_interface_mock.hpp"
#include "bt.hpp"
#include "internal_sys_mock.hpp"
#include <cstring>
+#include <ipmiblob/test/blob_interface_mock.hpp>
#include <gtest/gtest.h>
@@ -22,7 +22,7 @@
* syscall mock and catch the writes via the blob mock.
*/
internal::InternalSysMock sysMock;
- BlobInterfaceMock blobMock;
+ ipmiblob::BlobInterfaceMock blobMock;
BtDataHandler handler(&blobMock, &sysMock);
std::string filePath = "/asdf";
diff --git a/test/tools_ipmi_error_unittest.cpp b/test/tools_ipmi_error_unittest.cpp
deleted file mode 100644
index 86264a1..0000000
--- a/test/tools_ipmi_error_unittest.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-#include "ipmi_errors.hpp"
-
-#include <gtest/gtest.h>
-
-namespace host_tool
-{
-
-TEST(IpmiExceptionTest, VerifyTimedOutIsString)
-{
- /* Verify that throwing the exception with the cc code for timed out gets
- * converted to the human readable string.
- */
- bool verified = false;
-
- try
- {
- throw IpmiException(0xc3);
- }
- catch (const IpmiException& i)
- {
- EXPECT_STREQ("Received IPMI_CC: timeout", i.what());
- verified = true;
- }
-
- EXPECT_TRUE(verified);
-}
-
-} // namespace host_tool
diff --git a/test/tools_ipmi_unittest.cpp b/test/tools_ipmi_unittest.cpp
deleted file mode 100644
index d0c9911..0000000
--- a/test/tools_ipmi_unittest.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "internal_sys_mock.hpp"
-#include "ipmi_errors.hpp"
-#include "ipmi_handler.hpp"
-
-namespace host_tool
-{
-
-using ::testing::_;
-using ::testing::Return;
-
-TEST(IpmiHandlerTest, OpenAllFails)
-{
- /* Open against all device files fail. */
- internal::InternalSysMock sysMock;
- IpmiHandler ipmi(&sysMock);
-
- EXPECT_CALL(sysMock, open(_, _)).WillRepeatedly(Return(-1));
- EXPECT_THROW(ipmi.open(), IpmiException);
-}
-
-} // namespace host_tool
diff --git a/test/tools_lpc_unittest.cpp b/test/tools_lpc_unittest.cpp
index 3a9d80e..1645ea5 100644
--- a/test/tools_lpc_unittest.cpp
+++ b/test/tools_lpc_unittest.cpp
@@ -1,9 +1,9 @@
-#include "blob_interface_mock.hpp"
#include "internal_sys_mock.hpp"
#include "io_mock.hpp"
#include "lpc.hpp"
#include <cstring>
+#include <ipmiblob/test/blob_interface_mock.hpp>
#include <gtest/gtest.h>
@@ -15,7 +15,7 @@
TEST(LpcHandleTest, verifySendsFileContents)
{
internal::InternalSysMock sysMock;
- BlobInterfaceMock blobMock;
+ ipmiblob::BlobInterfaceMock blobMock;
HostIoInterfaceMock ioMock;
LpcDataHandler handler(&blobMock, &ioMock, &sysMock);
diff --git a/test/tools_updater_unittest.cpp b/test/tools_updater_unittest.cpp
index 0f49494..158ce47 100644
--- a/test/tools_updater_unittest.cpp
+++ b/test/tools_updater_unittest.cpp
@@ -1,7 +1,8 @@
-#include "blob_interface_mock.hpp"
#include "data_interface_mock.hpp"
#include "updater.hpp"
+#include <blobs-ipmid/blobs.hpp>
+#include <ipmiblob/test/blob_interface_mock.hpp>
#include <string>
#include <gtest/gtest.h>
@@ -17,25 +18,28 @@
{
/* Call updaterMain and have everything respond happily. */
DataInterfaceMock handlerMock;
- BlobInterfaceMock blobMock;
+ ipmiblob::BlobInterfaceMock blobMock;
std::string firmwareImage = "image.bin";
std::string signatureFile = "image.sig";
std::string expectedBlob = "/flash/image";
std::vector<std::string> blobList = {expectedBlob};
- StatResponse statObj;
+ ipmiblob::StatResponse statObj;
statObj.blob_state = blobs::FirmwareBlobHandler::UpdateFlags::ipmi |
blobs::FirmwareBlobHandler::UpdateFlags::lpc;
statObj.size = 0;
- blobs::FirmwareBlobHandler::UpdateFlags supported =
- blobs::FirmwareBlobHandler::UpdateFlags::lpc;
+ std::uint16_t supported =
+ static_cast<std::uint16_t>(
+ blobs::FirmwareBlobHandler::UpdateFlags::lpc) |
+ static_cast<std::uint16_t>(blobs::OpenFlags::write);
std::uint16_t session = 0xbeef;
EXPECT_CALL(blobMock, getBlobList()).WillOnce(Return(blobList));
EXPECT_CALL(blobMock, getStat(Eq(expectedBlob))).WillOnce(Return(statObj));
- EXPECT_CALL(handlerMock, supportedType()).WillOnce(Return(supported));
+ EXPECT_CALL(handlerMock, supportedType())
+ .WillOnce(Return(blobs::FirmwareBlobHandler::UpdateFlags::lpc));
EXPECT_CALL(blobMock, openBlob(StrEq(expectedBlob.c_str()), Eq(supported)))
.WillOnce(Return(session));
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 11ec485..d8a593d 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -5,14 +5,11 @@
burn_my_bmc_CXXFLAGS = -I$(top_srcdir) $(CODE_COVERAGE_CXXFLAGS)
noinst_LTLIBRARIES = libupdater.la
-libupdater_la_LDFLAGS = -static $(CODE_COVERAGE_LIBS)
-libupdater_la_CXXFLAGS = -I$(top_srcdir) $(CODE_COVERAGE_CXXFLAGS)
+libupdater_la_LDFLAGS = -static $(CODE_COVERAGE_LIBS) $(IPMIBLOB_LIBS)
+libupdater_la_CXXFLAGS = -I$(top_srcdir) $(CODE_COVERAGE_CXXFLAGS) $(IPMIBLOB_CFLAGS)
libupdater_la_SOURCES = \
updater.cpp \
bt.cpp \
lpc.cpp \
- blob_handler.cpp \
- ipmi_handler.cpp \
- crc.cpp \
io.cpp \
../internal/sys.cpp
diff --git a/tools/blob_errors.hpp b/tools/blob_errors.hpp
deleted file mode 100644
index 45f0e46..0000000
--- a/tools/blob_errors.hpp
+++ /dev/null
@@ -1,23 +0,0 @@
-#pragma once
-
-#include <exception>
-#include <string>
-
-namespace host_tool
-{
-
-class BlobException : public std::exception
-{
- public:
- explicit BlobException(const std::string& message) : message(message){};
-
- virtual const char* what() const noexcept override
- {
- return message.c_str();
- }
-
- private:
- std::string message;
-};
-
-} // namespace host_tool
diff --git a/tools/blob_handler.cpp b/tools/blob_handler.cpp
deleted file mode 100644
index 12fbaaa..0000000
--- a/tools/blob_handler.cpp
+++ /dev/null
@@ -1,318 +0,0 @@
-/*
- * Copyright 2018 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "blob_handler.hpp"
-
-#include "blob_errors.hpp"
-#include "crc.hpp"
-#include "ipmi_errors.hpp"
-
-#include <array>
-#include <cstring>
-
-namespace host_tool
-{
-
-namespace
-{
-const std::array<std::uint8_t, 3> ipmiPhosphorOen = {0xcf, 0xc2, 0x00};
-}
-
-std::vector<std::uint8_t>
- BlobHandler::sendIpmiPayload(BlobOEMCommands command,
- const std::vector<std::uint8_t>& payload)
-{
- std::vector<std::uint8_t> request, reply, bytes;
-
- std::copy(ipmiPhosphorOen.begin(), ipmiPhosphorOen.end(),
- std::back_inserter(request));
- request.push_back(command);
-
- if (payload.size() > 0)
- {
- /* Grow the vector to hold the bytes. */
- request.reserve(request.size() + sizeof(std::uint16_t));
-
- /* CRC required. */
- std::uint16_t crc = generateCrc(payload);
- auto src = reinterpret_cast<const std::uint8_t*>(&crc);
-
- std::copy(src, src + sizeof(crc), std::back_inserter(request));
-
- /* Copy the payload. */
- std::copy(payload.begin(), payload.end(), std::back_inserter(request));
- }
-
- try
- {
- reply = ipmi->sendPacket(request);
- }
- catch (const IpmiException& e)
- {
- throw BlobException(e.what());
- }
-
- /* IPMI_CC was OK, and it returned no bytes, so let's be happy with that for
- * now.
- */
- if (reply.size() == 0)
- {
- return reply;
- }
-
- /* This cannot be a response because it's smaller than the smallest
- * response.
- */
- if (reply.size() < ipmiPhosphorOen.size())
- {
- throw BlobException("Invalid response length");
- }
-
- /* Verify the OEN. */
- if (std::memcmp(ipmiPhosphorOen.data(), reply.data(),
- ipmiPhosphorOen.size()) != 0)
- {
- throw BlobException("Invalid OEN received");
- }
-
- /* In this case there was no data, as there was no CRC. */
- std::size_t headerSize = ipmiPhosphorOen.size() + sizeof(std::uint16_t);
- if (reply.size() < headerSize)
- {
- return {};
- }
-
- /* Validate CRC. */
- std::uint16_t crc;
- auto ptr = reinterpret_cast<std::uint8_t*>(&crc);
- std::memcpy(ptr, &reply[ipmiPhosphorOen.size()], sizeof(crc));
-
- for (const auto& byte : reply)
- {
- std::fprintf(stderr, "0x%02x ", byte);
- }
- std::fprintf(stderr, "\n");
-
- bytes.insert(bytes.begin(), reply.begin() + headerSize, reply.end());
-
- auto computed = generateCrc(bytes);
- if (crc != computed)
- {
- std::fprintf(stderr, "Invalid CRC, received: 0x%x, computed: 0x%x\n",
- crc, computed);
- throw BlobException("Invalid CRC on received data.");
- }
-
- return bytes;
-}
-
-int BlobHandler::getBlobCount()
-{
- std::uint32_t count;
- try
- {
- auto resp = sendIpmiPayload(BlobOEMCommands::bmcBlobGetCount, {});
- if (resp.size() != sizeof(count))
- {
- return 0;
- }
-
- /* LE to LE (need to make this portable as some point. */
- std::memcpy(&count, resp.data(), sizeof(count));
- }
- catch (const BlobException& b)
- {
- return 0;
- }
-
- std::fprintf(stderr, "BLOB Count: %d\n", count);
- return count;
-}
-
-std::string BlobHandler::enumerateBlob(std::uint32_t index)
-{
- std::vector<std::uint8_t> payload;
- auto data = reinterpret_cast<const std::uint8_t*>(&index);
-
- std::copy(data, data + sizeof(std::uint32_t), std::back_inserter(payload));
-
- try
- {
- auto resp = sendIpmiPayload(BlobOEMCommands::bmcBlobEnumerate, payload);
- return (resp.size() > 0) ? std::string(&resp[0], &resp[resp.size() - 1])
- : "";
- }
- catch (const BlobException& b)
- {
- return "";
- }
-}
-
-void BlobHandler::writeGeneric(BlobOEMCommands command, std::uint16_t session,
- std::uint32_t offset,
- const std::vector<std::uint8_t>& bytes)
-{
- std::vector<std::uint8_t> payload;
-
- payload.reserve(sizeof(std::uint16_t) + sizeof(std::uint32_t) +
- bytes.size());
-
- auto data = reinterpret_cast<const std::uint8_t*>(&session);
- std::copy(data, data + sizeof(std::uint16_t), std::back_inserter(payload));
-
- data = reinterpret_cast<const std::uint8_t*>(&offset);
- std::copy(data, data + sizeof(std::uint32_t), std::back_inserter(payload));
-
- std::copy(bytes.begin(), bytes.end(), std::back_inserter(payload));
-
- auto resp = sendIpmiPayload(command, payload);
-}
-
-void BlobHandler::writeMeta(std::uint16_t session, std::uint32_t offset,
- const std::vector<std::uint8_t>& bytes)
-{
- return writeGeneric(BlobOEMCommands::bmcBlobWriteMeta, session, offset,
- bytes);
-}
-
-void BlobHandler::writeBytes(std::uint16_t session, std::uint32_t offset,
- const std::vector<std::uint8_t>& bytes)
-{
- return writeGeneric(BlobOEMCommands::bmcBlobWrite, session, offset, bytes);
-}
-
-std::vector<std::string> BlobHandler::getBlobList()
-{
- std::vector<std::string> list;
- int blobCount = getBlobCount();
-
- for (int i = 0; i < blobCount; i++)
- {
- auto name = enumerateBlob(i);
- /* Currently ignore failures. */
- if (!name.empty())
- {
- list.push_back(name);
- }
- }
-
- return list;
-}
-
-StatResponse BlobHandler::getStat(const std::string& id)
-{
- StatResponse meta;
- std::vector<std::uint8_t> name, resp;
-
- std::copy(id.begin(), id.end(), std::back_inserter(name));
- name.push_back(0x00); /* need to add nul-terminator. */
-
- try
- {
- resp = sendIpmiPayload(BlobOEMCommands::bmcBlobStat, name);
- }
- catch (const BlobException& b)
- {
- throw;
- }
-
- std::memcpy(&meta.blob_state, &resp[0], sizeof(meta.blob_state));
- std::memcpy(&meta.size, &resp[sizeof(meta.blob_state)], sizeof(meta.size));
- int offset = sizeof(meta.blob_state) + sizeof(meta.size);
- std::uint8_t len = resp[offset];
- if (len > 0)
- {
- std::copy(&resp[offset + 1], &resp[resp.size()],
- std::back_inserter(meta.metadata));
- }
-
- return meta;
-}
-
-std::uint16_t
- BlobHandler::openBlob(const std::string& id,
- blobs::FirmwareBlobHandler::UpdateFlags handlerFlags)
-{
- std::uint16_t session;
- std::vector<std::uint8_t> request, resp;
- std::uint16_t flags =
- blobs::FirmwareBlobHandler::UpdateFlags::openWrite | handlerFlags;
- auto addrFlags = reinterpret_cast<const std::uint8_t*>(&flags);
-
- std::copy(addrFlags, addrFlags + sizeof(flags),
- std::back_inserter(request));
- std::copy(id.begin(), id.end(), std::back_inserter(request));
- request.push_back(0x00); /* need to add nul-terminator. */
-
- try
- {
- resp = sendIpmiPayload(BlobOEMCommands::bmcBlobOpen, request);
- }
- catch (const BlobException& b)
- {
- throw;
- }
-
- if (resp.size() != sizeof(session))
- {
- throw BlobException("Did not receive session.");
- }
-
- std::memcpy(&session, resp.data(), sizeof(session));
- return session;
-}
-
-void BlobHandler::closeBlob(std::uint16_t session)
-{
- std::vector<std::uint8_t> request, resp;
- auto addrSession = reinterpret_cast<const std::uint8_t*>(&session);
- std::copy(addrSession, addrSession + sizeof(session),
- std::back_inserter(request));
-
- try
- {
- resp = sendIpmiPayload(BlobOEMCommands::bmcBlobClose, request);
- }
- catch (const BlobException& b)
- {
- std::fprintf(stderr, "Received failure on close: %s\n", b.what());
- }
-
- 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));
-
- auto data = reinterpret_cast<const std::uint8_t*>(&session);
- std::copy(data, data + sizeof(std::uint16_t), std::back_inserter(payload));
-
- data = reinterpret_cast<const std::uint8_t*>(&offset);
- std::copy(data, data + sizeof(std::uint32_t), std::back_inserter(payload));
-
- data = reinterpret_cast<const 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
deleted file mode 100644
index 1cbc963..0000000
--- a/tools/blob_handler.hpp
+++ /dev/null
@@ -1,109 +0,0 @@
-#pragma once
-
-#include "blob_interface.hpp"
-#include "ipmi_interface.hpp"
-
-namespace host_tool
-{
-
-class BlobHandler : public BlobInterface
-{
- public:
- enum BlobOEMCommands
- {
- bmcBlobGetCount = 0,
- bmcBlobEnumerate = 1,
- bmcBlobOpen = 2,
- bmcBlobRead = 3,
- bmcBlobWrite = 4,
- bmcBlobCommit = 5,
- bmcBlobClose = 6,
- bmcBlobDelete = 7,
- bmcBlobStat = 8,
- bmcBlobSessionStat = 9,
- bmcBlobWriteMeta = 10,
- };
-
- explicit BlobHandler(IpmiInterface* ipmi) : ipmi(ipmi){};
-
- /**
- * Retrieve the blob count.
- *
- * @return the number of blob_ids found (0 on failure).
- */
- int getBlobCount();
-
- /**
- * Given an index into the list of blobs, return the name.
- *
- * @param[in] index - the index into the list of blob ids.
- * @return the name as a string or empty on failure.
- */
- std::string enumerateBlob(std::uint32_t index);
-
- /**
- * @throws BlobException.
- */
- void writeMeta(std::uint16_t session, std::uint32_t offset,
- const std::vector<std::uint8_t>& bytes) override;
-
- /**
- * @throw BlobException.
- */
- void writeBytes(std::uint16_t session, std::uint32_t offset,
- const std::vector<std::uint8_t>& bytes) override;
-
- std::vector<std::string> getBlobList() override;
-
- /**
- * @throws BlobException.
- */
- StatResponse getStat(const std::string& id) override;
-
- /**
- * @throws BlobException.
- */
- std::uint16_t
- openBlob(const std::string& id,
- blobs::FirmwareBlobHandler::UpdateFlags handlerFlags) override;
-
- 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
- * with the OEN, subcommand and CRC.
- *
- * @param[in] command - the blob command.
- * @param[in] payload - the payload bytes.
- * @return the bytes returned from the ipmi interface.
- * @throws BlobException.
- */
- std::vector<std::uint8_t>
- sendIpmiPayload(BlobOEMCommands command,
- const std::vector<std::uint8_t>& payload);
-
- /**
- * Generic blob byte writer.
- *
- * @param[in] command - the command associated with this write.
- * @param[in] session - the session id.
- * @param[in] offset - the offset for the metadata to write.
- * @param[in] bytes - the bytes to send.
- * @throws BlobException on failure.
- */
- void writeGeneric(BlobOEMCommands command, std::uint16_t session,
- std::uint32_t offset,
- const std::vector<std::uint8_t>& bytes);
-
- IpmiInterface* ipmi;
-};
-
-} // namespace host_tool
diff --git a/tools/blob_interface.hpp b/tools/blob_interface.hpp
deleted file mode 100644
index 61ee5eb..0000000
--- a/tools/blob_interface.hpp
+++ /dev/null
@@ -1,94 +0,0 @@
-#pragma once
-
-#include "firmware_handler.hpp"
-
-#include <cstdint>
-#include <string>
-#include <vector>
-
-namespace host_tool
-{
-
-struct StatResponse
-{
- std::uint16_t blob_state;
- std::uint32_t size;
- std::vector<std::uint8_t> metadata;
-};
-
-class BlobInterface
-{
- public:
- virtual ~BlobInterface() = default;
-
- /**
- * Write metadata to a blob.
- *
- * @param[in] session - the session id.
- * @param[in] offset - the offset for the metadata to write.
- * @param[in] bytes - the bytes to send.
- * @throws BlobException on failure.
- */
- virtual void writeMeta(std::uint16_t session, std::uint32_t offset,
- const std::vector<std::uint8_t>& bytes) = 0;
-
- /**
- * Write bytes to a blob.
- *
- * @param[in] session - the session id.
- * @param[in] offset - the offset to which to write the bytes.
- * @param[in] bytes - the bytes to send.
- * @throws BlobException on failure.
- */
- virtual void writeBytes(std::uint16_t session, std::uint32_t offset,
- const std::vector<std::uint8_t>& bytes) = 0;
-
- /**
- * Get a list of the blob_ids provided by the BMC.
- *
- * @return list of strings, each representing a blob_id returned.
- */
- virtual std::vector<std::string> getBlobList() = 0;
-
- /**
- * Get the stat() on the blob_id.
- *
- * @param[in] id - the blob_id.
- * @return metadata structure.
- */
- virtual StatResponse getStat(const std::string& id) = 0;
-
- /**
- * Attempt to open the file using the specific data interface flag.
- *
- * @param[in] blob - the blob_id to open.
- * @param[in] handlerFlags - the data interface flag, if relevant.
- * @return the session id on success.
- * @throws BlobException on failure.
- */
- virtual std::uint16_t
- openBlob(const std::string& id,
- blobs::FirmwareBlobHandler::UpdateFlags handlerFlags) = 0;
-
- /**
- * Attempt to close the open session.
- *
- * @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
diff --git a/tools/bt.cpp b/tools/bt.cpp
index 297bc30..c49aecf 100644
--- a/tools/bt.cpp
+++ b/tools/bt.cpp
@@ -1,8 +1,7 @@
#include "bt.hpp"
-#include "blob_errors.hpp"
-
#include <cstdint>
+#include <ipmiblob/blob_errors.hpp>
#include <vector>
namespace host_tool
@@ -37,7 +36,7 @@
}
} while (bytesRead > 0);
}
- catch (const BlobException& b)
+ catch (const ipmiblob::BlobException& b)
{
sys->close(inputFd);
return false;
diff --git a/tools/bt.hpp b/tools/bt.hpp
index 0b0187f..811c81d 100644
--- a/tools/bt.hpp
+++ b/tools/bt.hpp
@@ -1,16 +1,17 @@
#pragma once
-#include "blob_interface.hpp"
#include "interface.hpp"
#include "internal/sys.hpp"
+#include <ipmiblob/blob_interface.hpp>
+
namespace host_tool
{
class BtDataHandler : public DataInterface
{
public:
- BtDataHandler(BlobInterface* blob,
+ BtDataHandler(ipmiblob::BlobInterface* blob,
const internal::Sys* sys = &internal::sys_impl) :
blob(blob),
sys(sys){};
@@ -22,7 +23,7 @@
}
private:
- BlobInterface* blob;
+ ipmiblob::BlobInterface* blob;
const internal::Sys* sys;
};
diff --git a/tools/crc.cpp b/tools/crc.cpp
deleted file mode 100644
index d6f59ef..0000000
--- a/tools/crc.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-#include "crc.hpp"
-
-namespace host_tool
-{
-
-/*
- * This implementation tracks the specification given at
- * http://srecord.sourceforge.net/crc16-ccitt.html
- * Code copied from internal portable sources.
- */
-std::uint16_t generateCrc(const std::vector<std::uint8_t>& data)
-{
- const std::uint16_t kPoly = 0x1021;
- const std::uint16_t kLeftBit = 0x8000;
- const int kExtraRounds = 2;
- const std::uint8_t* bytes = data.data();
- std::uint16_t crc = 0xFFFF;
- std::size_t i;
- std::size_t j;
- std::size_t size = data.size();
-
- for (i = 0; i < size + kExtraRounds; ++i)
- {
- for (j = 0; j < 8; ++j)
- {
- bool xor_flag = (crc & kLeftBit) ? 1 : 0;
- crc <<= 1;
- // If this isn't an extra round and the current byte's j'th bit from
- // the left is set, increment the CRC.
- if (i < size && (bytes[i] & (1 << (7 - j))))
- {
- crc++;
- }
- if (xor_flag)
- {
- crc ^= kPoly;
- }
- }
- }
-
- return crc;
-}
-
-} // namespace host_tool
diff --git a/tools/crc.hpp b/tools/crc.hpp
deleted file mode 100644
index c335ed2..0000000
--- a/tools/crc.hpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#pragma once
-
-#include <cstdint>
-#include <vector>
-
-namespace host_tool
-{
-
-/**
- * Generate the CRC for a payload (really any bytes).
- *
- * This is meant to only be called on the payload and not the CRC or the OEM
- * header, etc.
- *
- * @param[in] data - the bytes against to run the CRC
- * @return the CRC value
- */
-std::uint16_t generateCrc(const std::vector<std::uint8_t>& data);
-
-} // namespace host_tool
diff --git a/tools/ipmi_errors.hpp b/tools/ipmi_errors.hpp
deleted file mode 100644
index 9f1a9f9..0000000
--- a/tools/ipmi_errors.hpp
+++ /dev/null
@@ -1,47 +0,0 @@
-#pragma once
-
-#include <exception>
-#include <map>
-#include <sstream>
-#include <string>
-
-namespace host_tool
-{
-
-class IpmiException : public std::exception
-{
- public:
- const std::map<int, std::string> commonFailures = {
- {0xc0, "busy"},
- {0xc1, "invalid"},
- {0xc3, "timeout"},
- };
-
- explicit IpmiException(int cc)
- {
- std::ostringstream smessage;
-
- auto search = commonFailures.find(cc);
- if (search != commonFailures.end())
- {
- smessage << "Received IPMI_CC: " << search->second;
- }
- else
- {
- smessage << "Received IPMI_CC: " << cc;
- }
-
- message = smessage.str();
- }
- explicit IpmiException(const std::string& message) : message(message){};
-
- virtual const char* what() const noexcept override
- {
- return message.c_str();
- }
-
- private:
- std::string message;
-};
-
-} // namespace host_tool
diff --git a/tools/ipmi_handler.cpp b/tools/ipmi_handler.cpp
deleted file mode 100644
index 9278338..0000000
--- a/tools/ipmi_handler.cpp
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright 2018 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "ipmi_handler.hpp"
-
-#include "ipmi_errors.hpp"
-
-#include <fcntl.h>
-#include <linux/ipmi.h>
-#include <linux/ipmi_msgdefs.h>
-#include <sys/ioctl.h>
-
-#include <array>
-#include <cstdint>
-#include <cstring>
-#include <sstream>
-#include <string>
-#include <vector>
-
-namespace host_tool
-{
-
-void IpmiHandler::open()
-{
- const int device = 0;
- const std::vector<std::string> formats = {"/dev/ipmi", "/dev/ipmi/",
- "/dev/ipmidev/"};
-
- for (const auto& format : formats)
- {
- std::ostringstream path;
- path << format << device;
-
- fd = sys->open(path.str().c_str(), O_RDWR);
- if (fd < 0)
- {
- continue;
- }
- break;
- }
-
- if (fd < 0)
- {
- throw IpmiException("Unable to open any ipmi devices");
- }
-}
-
-std::vector<std::uint8_t>
- IpmiHandler::sendPacket(std::vector<std::uint8_t>& data)
-{
- if (fd < 0)
- {
- open();
- }
-
- constexpr int ipmiOEMNetFn = 46;
- constexpr int ipmiOEMLun = 0;
- /* /openbmc/phosphor-host-ipmid/blob/master/host-ipmid/oemopenbmc.hpp */
- constexpr int ipmiOEMBlobCmd = 128;
- constexpr int fifteenMs = 15 * 1000;
- constexpr int ipmiReadTimeout = fifteenMs;
- constexpr int ipmiResponseBufferLen = IPMI_MAX_MSG_LENGTH;
- constexpr int ipmiOk = 0;
-
- /* We have a handle to the IPMI device. */
- std::array<std::uint8_t, ipmiResponseBufferLen> responseBuffer;
-
- /* Build address. */
- struct ipmi_system_interface_addr systemAddress;
- systemAddress.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
- systemAddress.channel = IPMI_BMC_CHANNEL;
- systemAddress.lun = ipmiOEMLun;
-
- /* Build request. */
- struct ipmi_req request;
- std::memset(&request, 0, sizeof(request));
- request.addr = reinterpret_cast<unsigned char*>(&systemAddress);
- request.addr_len = sizeof(systemAddress);
- request.msgid = sequence++;
- request.msg.data = reinterpret_cast<unsigned char*>(data.data());
- request.msg.data_len = data.size();
- request.msg.netfn = ipmiOEMNetFn;
- request.msg.cmd = ipmiOEMBlobCmd;
-
- struct ipmi_recv reply;
- reply.addr = reinterpret_cast<unsigned char*>(&systemAddress);
- reply.addr_len = sizeof(systemAddress);
- reply.msg.data = reinterpret_cast<unsigned char*>(responseBuffer.data());
- reply.msg.data_len = responseBuffer.size();
-
- /* Try to send request. */
- int rc = sys->ioctl(fd, IPMICTL_SEND_COMMAND, &request);
- if (rc < 0)
- {
- throw IpmiException("Unable to send IPMI request.");
- }
-
- /* Could use sdeventplus, but for only one type of event is it worth it? */
- struct pollfd pfd;
- pfd.fd = fd;
- pfd.events = POLLIN;
-
- do
- {
- rc = sys->poll(&pfd, 1, ipmiReadTimeout);
- if (rc < 0)
- {
- if (errno == EINTR)
- {
- continue;
- }
- throw IpmiException("Error occurred.");
- }
- else if (rc == 0)
- {
- throw IpmiException("Timeout waiting for reply.");
- }
-
- /* Yay, happy case! */
- rc = sys->ioctl(fd, IPMICTL_RECEIVE_MSG_TRUNC, &reply);
- if (rc < 0)
- {
- throw IpmiException("Unable to read reply.");
- }
-
- if (request.msgid != reply.msgid)
- {
- std::fprintf(stderr, "Received wrong message, trying again.\n");
- }
- } while (request.msgid != reply.msgid);
-
- if (responseBuffer[0] != ipmiOk)
- {
- throw IpmiException(static_cast<int>(responseBuffer[0]));
- }
-
- std::vector<std::uint8_t> returning;
- auto dataLen = reply.msg.data_len - 1;
-
- returning.insert(returning.begin(), responseBuffer.begin() + 1,
- responseBuffer.begin() + dataLen + 1);
-
- for (const auto& byte : returning)
- {
- std::fprintf(stderr, "0x%02x ", byte);
- }
- std::fprintf(stderr, "\n");
-
- return returning;
-}
-
-} // namespace host_tool
diff --git a/tools/ipmi_handler.hpp b/tools/ipmi_handler.hpp
deleted file mode 100644
index 1c91bff..0000000
--- a/tools/ipmi_handler.hpp
+++ /dev/null
@@ -1,46 +0,0 @@
-#pragma once
-
-#include "internal/sys.hpp"
-#include "ipmi_interface.hpp"
-
-#include <vector>
-
-namespace host_tool
-{
-
-class IpmiHandler : public IpmiInterface
-{
- public:
- explicit IpmiHandler(const internal::Sys* sys = &internal::sys_impl) :
- sys(sys){};
-
- ~IpmiHandler() = default;
- IpmiHandler(const IpmiHandler&) = delete;
- IpmiHandler& operator=(const IpmiHandler&) = delete;
- IpmiHandler(IpmiHandler&&) = default;
- IpmiHandler& operator=(IpmiHandler&&) = default;
-
- /**
- * Attempt to open the device node.
- *
- * @throws IpmiException on failure.
- */
- void open();
-
- /**
- * @throws IpmiException on failure.
- */
- std::vector<std::uint8_t>
- sendPacket(std::vector<std::uint8_t>& data) override;
-
- private:
- const internal::Sys* sys;
- /** TODO: Use a smart file descriptor when it's ready. Until then only
- * allow moving this object.
- */
- int fd = -1;
- /* The last IPMI sequence number we used. */
- int sequence = 0;
-};
-
-} // namespace host_tool
diff --git a/tools/ipmi_interface.hpp b/tools/ipmi_interface.hpp
deleted file mode 100644
index 6bad7db..0000000
--- a/tools/ipmi_interface.hpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#pragma once
-
-#include <cstdint>
-#include <vector>
-
-namespace host_tool
-{
-
-class IpmiInterface
-{
- public:
- virtual ~IpmiInterface() = default;
-
- /**
- * Send an IPMI packet to the BMC.
- *
- * @param[in] data - a vector of the IPMI packet contents.
- * @return the bytes returned.
- * @throws IpmiException on failure.
- */
- virtual std::vector<std::uint8_t>
- sendPacket(std::vector<std::uint8_t>& data) = 0;
-};
-
-} // namespace host_tool
diff --git a/tools/lpc.hpp b/tools/lpc.hpp
index 1ccecc2..fc8ca4b 100644
--- a/tools/lpc.hpp
+++ b/tools/lpc.hpp
@@ -1,11 +1,11 @@
#pragma once
-#include "blob_interface.hpp"
#include "interface.hpp"
#include "internal/sys.hpp"
#include "io.hpp"
#include <cstdint>
+#include <ipmiblob/blob_interface.hpp>
namespace host_tool
{
@@ -21,7 +21,7 @@
class LpcDataHandler : public DataInterface
{
public:
- LpcDataHandler(BlobInterface* blob, HostIoInterface* io,
+ LpcDataHandler(ipmiblob::BlobInterface* blob, HostIoInterface* io,
const internal::Sys* sys = &internal::sys_impl) :
blob(blob),
io(io), sys(sys){};
@@ -33,7 +33,7 @@
}
private:
- BlobInterface* blob;
+ ipmiblob::BlobInterface* blob;
HostIoInterface* io;
const internal::Sys* sys;
};
diff --git a/tools/main.cpp b/tools/main.cpp
index ada34bb..f676f6a 100644
--- a/tools/main.cpp
+++ b/tools/main.cpp
@@ -14,10 +14,8 @@
* limitations under the License.
*/
-#include "blob_handler.hpp"
#include "bt.hpp"
#include "io.hpp"
-#include "ipmi_handler.hpp"
#include "lpc.hpp"
#include "tool_errors.hpp"
#include "updater.hpp"
@@ -28,6 +26,8 @@
#include <algorithm>
#include <cstdio>
#include <iostream>
+#include <ipmiblob/blob_handler.hpp>
+#include <ipmiblob/ipmi_handler.hpp>
#include <iterator>
#include <memory>
#include <string>
@@ -137,8 +137,8 @@
exit(EXIT_FAILURE);
}
- host_tool::IpmiHandler ipmi;
- host_tool::BlobHandler blob(&ipmi);
+ ipmiblob::IpmiHandler ipmi;
+ ipmiblob::BlobHandler blob(&ipmi);
host_tool::DevMemDevice devmem;
std::unique_ptr<host_tool::DataInterface> handler;
diff --git a/tools/updater.cpp b/tools/updater.cpp
index 2620715..d7e5f96 100644
--- a/tools/updater.cpp
+++ b/tools/updater.cpp
@@ -16,18 +16,19 @@
#include "updater.hpp"
-#include "blob_errors.hpp"
#include "tool_errors.hpp"
#include <algorithm>
+#include <blobs-ipmid/blobs.hpp>
#include <cstring>
+#include <ipmiblob/blob_errors.hpp>
#include <memory>
#include <string>
namespace host_tool
{
-void updaterMain(BlobInterface* blob, DataInterface* handler,
+void updaterMain(ipmiblob::BlobInterface* blob, DataInterface* handler,
const std::string& imagePath, const std::string& signaturePath)
{
/* TODO(venture): Add optional parameter to specify the flash type, default
@@ -58,12 +59,12 @@
/* Call stat on /flash/image (or /flash/tarball) and check if data interface
* is supported.
*/
- StatResponse stat;
+ ipmiblob::StatResponse stat;
try
{
stat = blob->getStat(goalFirmware);
}
- catch (const BlobException& b)
+ catch (const ipmiblob::BlobException& b)
{
throw ToolException("blob exception received: " +
std::string(b.what()));
@@ -79,9 +80,12 @@
std::uint16_t session;
try
{
- session = blob->openBlob(goalFirmware, supported);
+ session = blob->openBlob(
+ goalFirmware,
+ static_cast<std::uint16_t>(supported) |
+ static_cast<std::uint16_t>(blobs::OpenFlags::write));
}
- catch (const BlobException& b)
+ catch (const ipmiblob::BlobException& b)
{
throw ToolException("blob exception received: " +
std::string(b.what()));
diff --git a/tools/updater.hpp b/tools/updater.hpp
index adee496..0a66f34 100644
--- a/tools/updater.hpp
+++ b/tools/updater.hpp
@@ -1,8 +1,8 @@
#pragma once
-#include "blob_interface.hpp"
#include "interface.hpp"
+#include <ipmiblob/blob_interface.hpp>
#include <string>
namespace host_tool
@@ -17,7 +17,7 @@
* @param[in] signaturePath - the path to the signature file.
* @throws ToolException on failures.
*/
-void updaterMain(BlobInterface* blob, DataInterface* handler,
+void updaterMain(ipmiblob::BlobInterface* blob, DataInterface* handler,
const std::string& imagePath,
const std::string& signaturePath);