blob: 1b47cb845ffe33d9deef45793f9655f855271534 [file] [log] [blame]
vishwa13555bd2015-11-10 12:10:38 -06001#include <iostream>
2#include <memory>
Matthew Barth155c34f2016-10-18 14:33:17 -05003#include "argument.hpp"
4#include "writefrudata.hpp"
vishwa13555bd2015-11-10 12:10:38 -06005
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;
20 uint8_t fruid = 0;
21
22 // Handle to per process system bus
23 sd_bus *bus_type = NULL;
vishwac93d6d42015-12-16 11:55:16 -060024
vishwa13555bd2015-11-10 12:10:38 -060025 // Read the arguments.
26 auto cli_options = std::make_unique<ArgumentParser>(argc, argv);
27
28 // Parse out each argument.
29 auto eeprom_file = (*cli_options)["eeprom"];
30 if (eeprom_file == ArgumentParser::empty_string)
31 {
32 // User has not passed in the appropriate argument value
33 exit_with_error("eeprom data not found.", argv);
34 }
35
36 auto fruid_str = (*cli_options)["fruid"];
37 if (eeprom_file == ArgumentParser::empty_string)
38 {
39 // User has not passed in the appropriate argument value
40 exit_with_error("fruid data not found.", argv);
41 }
42
43 // Extract the fruid
44 fruid = strtol(fruid_str.c_str(), NULL, 16);
45 if(fruid == 0)
46 {
47 // User has not passed in the appropriate argument value
48 exit_with_error("Invalid fruid.", argv);
49 }
50
51 // Finished getting options out, so release the parser.
52 cli_options.release();
53
54 // Get a handle to System Bus
55 rc = sd_bus_open_system(&bus_type);
vishwac93d6d42015-12-16 11:55:16 -060056 if (rc < 0)
vishwa13555bd2015-11-10 12:10:38 -060057 {
58 fprintf(stderr, "Failed to connect to system bus: %s\n",strerror(-rc));
59 }
60 else
61 {
62 // Now that we have the file that contains the eeprom data, go read it and
63 // update the Inventory DB.
vishwac93d6d42015-12-16 11:55:16 -060064 bool bmc_fru = true;
65 rc = ipmi_validate_fru_area(fruid, eeprom_file.c_str(), bus_type, bmc_fru);
vishwa13555bd2015-11-10 12:10:38 -060066 }
67
68 // Cleanup
69 sd_bus_unref(bus_type);
70
71 return (rc < 0 ? EXIT_FAILURE : EXIT_SUCCESS);
72}