tool: LPC data handler needs an address and length
The host needs to have memory set aside for this purpose, and this
enables the caller to provide those values.
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: If40ec3b08bd1932cba91d3f770c7fde6f280463d
diff --git a/tools/lpc.hpp b/tools/lpc.hpp
index bdcf7be..7343648 100644
--- a/tools/lpc.hpp
+++ b/tools/lpc.hpp
@@ -22,9 +22,10 @@
{
public:
LpcDataHandler(ipmiblob::BlobInterface* blob, HostIoInterface* io,
+ long address, long length,
const internal::Sys* sys = &internal::sys_impl) :
blob(blob),
- io(io), sys(sys){};
+ io(io), address(address), length(length), sys(sys){};
bool sendContents(const std::string& input, std::uint16_t session) override;
ipmi_flash::FirmwareBlobHandler::UpdateFlags supportedType() const override
@@ -35,6 +36,8 @@
private:
ipmiblob::BlobInterface* blob;
HostIoInterface* io;
+ long address;
+ long length;
const internal::Sys* sys;
};
diff --git a/tools/main.cpp b/tools/main.cpp
index 536cde1..ff00dd4 100644
--- a/tools/main.cpp
+++ b/tools/main.cpp
@@ -27,6 +27,7 @@
#include <algorithm>
#include <cstdio>
+#include <cstdlib>
#include <exception>
#include <iostream>
#include <ipmiblob/blob_handler.hpp>
@@ -74,6 +75,9 @@
int main(int argc, char* argv[])
{
std::string command, interface, imagePath, signaturePath;
+ char* valueEnd = nullptr;
+ long address = 0;
+ long length = 0;
while (1)
{
@@ -83,13 +87,15 @@
{"interface", required_argument, 0, 'i'},
{"image", required_argument, 0, 'm'},
{"sig", required_argument, 0, 's'},
+ {"address", required_argument, 0, 'a'},
+ {"length", required_argument, 0, 'l'},
{0, 0, 0, 0}
};
// clang-format on
int option_index = 0;
int c =
- getopt_long(argc, argv, "c:i:m:s:", long_options, &option_index);
+ getopt_long(argc, argv, "c:i:m:s:a:l", long_options, &option_index);
if (c == -1)
{
break;
@@ -120,6 +126,22 @@
case 's':
signaturePath = std::string{optarg};
break;
+ case 'a':
+ address = std::strtol(&optarg[0], &valueEnd, 0);
+ if (valueEnd == nullptr)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 'l':
+ length = std::strtol(&optarg[0], &valueEnd, 0);
+ if (valueEnd == nullptr)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ break;
default:
usage(argv[0]);
exit(EXIT_FAILURE);
@@ -155,8 +177,13 @@
}
else if (interface == IPMILPC)
{
- handler =
- std::make_unique<host_tool::LpcDataHandler>(&blob, &devmem);
+ if (address == 0 || length == 0)
+ {
+ std::fprintf(stderr, "Address or Length were 0\n");
+ exit(EXIT_FAILURE);
+ }
+ handler = std::make_unique<host_tool::LpcDataHandler>(
+ &blob, &devmem, address, length);
}
else if (interface == IPMIPCI)
{
diff --git a/tools/test/tools_lpc_unittest.cpp b/tools/test/tools_lpc_unittest.cpp
index 1645ea5..4a18273 100644
--- a/tools/test/tools_lpc_unittest.cpp
+++ b/tools/test/tools_lpc_unittest.cpp
@@ -18,7 +18,7 @@
ipmiblob::BlobInterfaceMock blobMock;
HostIoInterfaceMock ioMock;
- LpcDataHandler handler(&blobMock, &ioMock, &sysMock);
+ LpcDataHandler handler(&blobMock, &ioMock, 0, 0, &sysMock);
std::uint16_t session = 0xbeef;
std::string filePath = "/asdf";