blob: 948decd027b80c9e97ca37f8c672c48c44a92536 [file] [log] [blame]
#include "args.hpp"
#include "defines.hpp"
#include "parser.hpp"
#include "write.hpp"
#include <exception>
#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
int main(int argc, char** argv)
{
int rc = 0;
try
{
using namespace openpower::vpd;
args::Args arguments = args::parse(argc, argv);
bool haveVpd = arguments.count("vpd");
bool doDump = arguments.count("dump");
bool doFru = arguments.count("fru") && arguments.count("object");
if (!haveVpd)
{
std::cerr << "VPD file required (--vpd=<filename>)\n";
return -1;
}
if (!doDump && !doFru)
{
std::cerr << "No task to perform\n\n";
std::cerr << " Update FRU: --fru <type> --object <path>\n";
std::cerr << " --fru <t1>,<t2> --object <p1>,<p2>\n\n";
std::cerr << " Dump VPD: --dump\n\n";
return -1;
}
// Read binary VPD file
auto file = arguments.at("vpd")[0];
std::ifstream vpdFile(file, std::ios::binary);
Binary vpd((std::istreambuf_iterator<char>(vpdFile)),
std::istreambuf_iterator<char>());
// Parse VPD
auto vpdStore = parse(std::move(vpd));
if (doDump)
{
vpdStore.dump();
}
// Set FRU based on FRU type and object path
if (doFru)
{
using argList = std::vector<std::string>;
argList frus = std::move(arguments.at("fru"));
argList objects = std::move(arguments.at("object"));
if (frus.size() != objects.size())
{
std::cerr << "Unequal number of FRU types and object paths "
"specified\n";
rc = -1;
}
else
{
// Write VPD to FRU inventory
for (std::size_t index = 0; index < frus.size(); ++index)
{
inventory::write(frus[index], vpdStore, objects[index]);
}
}
}
}
catch (std::exception& e)
{
std::cerr << e.what() << "\n";
}
return rc;
}