blob: 1208f24aa89b7f90b5c01bc849afdf4d6360e705 [file] [log] [blame]
/**
* Copyright © 2019 IBM Corporation
*
* 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 "../pel.hpp"
#include <CLI/CLI.hpp>
#include <iostream>
#include <string>
using namespace phosphor::logging;
using namespace openpower::pels;
/**
* @brief get data form raw PEL file.
* @param[in] std::string Name of file with raw PEL
* @return std::vector<uint8_t> char vector read from raw PEL file.
*/
std::vector<uint8_t> getFileData(std::string name)
{
std::ifstream file(name, std::ifstream::in);
if (file.good())
{
std::vector<uint8_t> data{std::istreambuf_iterator<char>(file),
std::istreambuf_iterator<char>()};
return data;
}
else
{
printf("Can't open raw PEL file");
return {};
}
}
static void exitWithError(const std::string& help, const char* err)
{
std::cerr << "ERROR: " << err << std::endl << help << std::endl;
exit(-1);
}
int main(int argc, char** argv)
{
CLI::App app{"OpenBMC PEL Tool"};
std::string fileName;
app.add_option("-f,--file", fileName, "Raw PEL File");
CLI11_PARSE(app, argc, argv);
if (!fileName.empty())
{
std::vector<uint8_t> data = getFileData(fileName);
if (!data.empty())
{
PEL pel{data};
pel.toJSON();
}
else
{
exitWithError(app.help("", CLI::AppFormatMode::All),
"Raw PEL file can't be read.");
}
}
else
{
exitWithError(app.help("", CLI::AppFormatMode::All),
"Raw PEL file path not specified.");
}
return 0;
}