blob: d518a834774b954b542b34a159d450b5c0aee96e [file] [log] [blame]
Matthew Barth155c34f2016-10-18 14:33:17 -05001#include "argument.hpp"
2#include "writefrudata.hpp"
vishwa13555bd2015-11-10 12:10:38 -06003
Patrick Venture52f1f182018-10-17 13:05:03 -07004#include <cstdlib>
5#include <cstring>
Patrick Venturec9508db2018-10-16 17:18:43 -07006#include <iostream>
7#include <memory>
Patrick Venture07f635c2018-10-19 09:19:39 -07008#include <phosphor-logging/log.hpp>
9
10using namespace phosphor::logging;
Patrick Venturec9508db2018-10-16 17:18:43 -070011
vishwa13555bd2015-11-10 12:10:38 -060012static void exit_with_error(const char* err, char** argv)
13{
14 ArgumentParser::usage(argv);
15 std::cerr << std::endl;
16 std::cerr << "ERROR: " << err << std::endl;
17 exit(-1);
18}
19
20//--------------------------------------------------------------------------
vishwac93d6d42015-12-16 11:55:16 -060021// This gets called by udev monitor soon after seeing hog plugs for EEPROMS.
vishwa13555bd2015-11-10 12:10:38 -060022//--------------------------------------------------------------------------
Patrick Venturec9508db2018-10-16 17:18:43 -070023int main(int argc, char** argv)
vishwa13555bd2015-11-10 12:10:38 -060024{
25 int rc = 0;
26 uint8_t fruid = 0;
27
vishwa13555bd2015-11-10 12:10:38 -060028 // Read the arguments.
29 auto cli_options = std::make_unique<ArgumentParser>(argc, argv);
30
31 // Parse out each argument.
32 auto eeprom_file = (*cli_options)["eeprom"];
33 if (eeprom_file == ArgumentParser::empty_string)
34 {
35 // User has not passed in the appropriate argument value
36 exit_with_error("eeprom data not found.", argv);
37 }
38
39 auto fruid_str = (*cli_options)["fruid"];
Dmitry Bazhenov05261aa2017-08-02 13:09:48 +050040 if (fruid_str == ArgumentParser::empty_string)
vishwa13555bd2015-11-10 12:10:38 -060041 {
42 // User has not passed in the appropriate argument value
43 exit_with_error("fruid data not found.", argv);
44 }
45
46 // Extract the fruid
Patrick Venture52f1f182018-10-17 13:05:03 -070047 fruid = std::strtol(fruid_str.c_str(), NULL, 16);
Patrick Venturec9508db2018-10-16 17:18:43 -070048 if (fruid == 0)
vishwa13555bd2015-11-10 12:10:38 -060049 {
50 // User has not passed in the appropriate argument value
51 exit_with_error("Invalid fruid.", argv);
52 }
53
54 // Finished getting options out, so release the parser.
55 cli_options.release();
56
Patrick Venturea8093a22018-10-21 09:07:11 -070057 // Now that we have the file that contains the eeprom data, go read it
58 // and update the Inventory DB.
59 auto bus = sdbusplus::bus::new_default();
60 bool bmc_fru = true;
61 rc = validateFRUArea(fruid, eeprom_file.c_str(), bus, bmc_fru);
vishwa13555bd2015-11-10 12:10:38 -060062
63 return (rc < 0 ? EXIT_FAILURE : EXIT_SUCCESS);
64}