blob: b8b2fd8584f47203db851f478903c710b1768b32 [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 Venturec9508db2018-10-16 17:18:43 -07004#include <iostream>
5#include <memory>
6
vishwa13555bd2015-11-10 12:10:38 -06007static void exit_with_error(const char* err, char** argv)
8{
9 ArgumentParser::usage(argv);
10 std::cerr << std::endl;
11 std::cerr << "ERROR: " << err << std::endl;
12 exit(-1);
13}
14
15//--------------------------------------------------------------------------
vishwac93d6d42015-12-16 11:55:16 -060016// This gets called by udev monitor soon after seeing hog plugs for EEPROMS.
vishwa13555bd2015-11-10 12:10:38 -060017//--------------------------------------------------------------------------
Patrick Venturec9508db2018-10-16 17:18:43 -070018int main(int argc, char** argv)
vishwa13555bd2015-11-10 12:10:38 -060019{
20 int rc = 0;
21 uint8_t fruid = 0;
22
23 // Handle to per process system bus
Patrick Venturec9508db2018-10-16 17:18:43 -070024 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"];
Dmitry Bazhenov05261aa2017-08-02 13:09:48 +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);
Patrick Venturec9508db2018-10-16 17:18:43 -070046 if (fruid == 0)
vishwa13555bd2015-11-10 12:10:38 -060047 {
48 // User has not passed in the appropriate argument value
49 exit_with_error("Invalid fruid.", argv);
50 }
51
52 // Finished getting options out, so release the parser.
53 cli_options.release();
54
55 // Get a handle to System Bus
56 rc = sd_bus_open_system(&bus_type);
vishwac93d6d42015-12-16 11:55:16 -060057 if (rc < 0)
vishwa13555bd2015-11-10 12:10:38 -060058 {
Patrick Venturec9508db2018-10-16 17:18:43 -070059 fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-rc));
vishwa13555bd2015-11-10 12:10:38 -060060 }
61 else
62 {
Patrick Venturec9508db2018-10-16 17:18:43 -070063 // Now that we have the file that contains the eeprom data, go read it
64 // and update the Inventory DB.
vishwac93d6d42015-12-16 11:55:16 -060065 bool bmc_fru = true;
Patrick Venturec9508db2018-10-16 17:18:43 -070066 rc = ipmi_validate_fru_area(fruid, eeprom_file.c_str(), bus_type,
67 bmc_fru);
vishwa13555bd2015-11-10 12:10:38 -060068 }
69
70 // Cleanup
71 sd_bus_unref(bus_type);
72
73 return (rc < 0 ? EXIT_FAILURE : EXIT_SUCCESS);
74}