blob: 08830f51440482aa6d83a9b2ba9a7b29ec14a872 [file] [log] [blame]
vishwa13555bd2015-11-10 12:10:38 -06001#include <iostream>
2#include <memory>
3#include "argument.H"
4#include "writefrudata.H"
5
6static void exit_with_error(const char* err, char** argv)
7{
8 ArgumentParser::usage(argv);
9 std::cerr << std::endl;
10 std::cerr << "ERROR: " << err << std::endl;
11 exit(-1);
12}
13
14//--------------------------------------------------------------------------
vishwac93d6d42015-12-16 11:55:16 -060015// This gets called by udev monitor soon after seeing hog plugs for EEPROMS.
vishwa13555bd2015-11-10 12:10:38 -060016//--------------------------------------------------------------------------
17int main(int argc, char **argv)
18{
19 int rc = 0;
Adriana Kobylake64ceb92016-06-28 15:14:09 -050020 bool iob = false;
vishwa13555bd2015-11-10 12:10:38 -060021 uint8_t fruid = 0;
22
23 // Handle to per process system bus
24 sd_bus *bus_type = NULL;
vishwac93d6d42015-12-16 11:55:16 -060025
vishwa13555bd2015-11-10 12:10:38 -060026 // Read the arguments.
27 auto cli_options = std::make_unique<ArgumentParser>(argc, argv);
28
29 // Parse out each argument.
30 auto eeprom_file = (*cli_options)["eeprom"];
31 if (eeprom_file == ArgumentParser::empty_string)
32 {
33 // User has not passed in the appropriate argument value
34 exit_with_error("eeprom data not found.", argv);
35 }
36
37 auto fruid_str = (*cli_options)["fruid"];
Adriana Kobylake64ceb92016-06-28 15:14:09 -050038 if (fruid_str == ArgumentParser::empty_string)
vishwa13555bd2015-11-10 12:10:38 -060039 {
40 // User has not passed in the appropriate argument value
41 exit_with_error("fruid data not found.", argv);
42 }
43
44 // Extract the fruid
45 fruid = strtol(fruid_str.c_str(), NULL, 16);
46 if(fruid == 0)
47 {
48 // User has not passed in the appropriate argument value
49 exit_with_error("Invalid fruid.", argv);
50 }
51
Adriana Kobylake64ceb92016-06-28 15:14:09 -050052 auto iob_str = (*cli_options)["iob"];
53 if (iob_str == ArgumentParser::true_string)
54 {
55 iob = true;
56 }
57
vishwa13555bd2015-11-10 12:10:38 -060058 // Finished getting options out, so release the parser.
59 cli_options.release();
60
61 // Get a handle to System Bus
62 rc = sd_bus_open_system(&bus_type);
vishwac93d6d42015-12-16 11:55:16 -060063 if (rc < 0)
vishwa13555bd2015-11-10 12:10:38 -060064 {
65 fprintf(stderr, "Failed to connect to system bus: %s\n",strerror(-rc));
66 }
67 else
68 {
69 // Now that we have the file that contains the eeprom data, go read it and
70 // update the Inventory DB.
vishwac93d6d42015-12-16 11:55:16 -060071 bool bmc_fru = true;
Adriana Kobylake64ceb92016-06-28 15:14:09 -050072 rc = ipmi_validate_fru_area(fruid, eeprom_file.c_str(), bus_type, bmc_fru, iob);
vishwa13555bd2015-11-10 12:10:38 -060073 }
74
75 // Cleanup
76 sd_bus_unref(bus_type);
77
78 return (rc < 0 ? EXIT_FAILURE : EXIT_SUCCESS);
79}