Matthew Barth | 155c34f | 2016-10-18 14:33:17 -0500 | [diff] [blame] | 1 | #include "argument.hpp" |
| 2 | #include "writefrudata.hpp" |
vishwa | 13555bd | 2015-11-10 12:10:38 -0600 | [diff] [blame] | 3 | |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame^] | 4 | #include <iostream> |
| 5 | #include <memory> |
| 6 | |
vishwa | 13555bd | 2015-11-10 12:10:38 -0600 | [diff] [blame] | 7 | static 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 | //-------------------------------------------------------------------------- |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 16 | // This gets called by udev monitor soon after seeing hog plugs for EEPROMS. |
vishwa | 13555bd | 2015-11-10 12:10:38 -0600 | [diff] [blame] | 17 | //-------------------------------------------------------------------------- |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame^] | 18 | int main(int argc, char** argv) |
vishwa | 13555bd | 2015-11-10 12:10:38 -0600 | [diff] [blame] | 19 | { |
| 20 | int rc = 0; |
| 21 | uint8_t fruid = 0; |
| 22 | |
| 23 | // Handle to per process system bus |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame^] | 24 | sd_bus* bus_type = NULL; |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 25 | |
vishwa | 13555bd | 2015-11-10 12:10:38 -0600 | [diff] [blame] | 26 | // 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 Bazhenov | 05261aa | 2017-08-02 13:09:48 +0500 | [diff] [blame] | 38 | if (fruid_str == ArgumentParser::empty_string) |
vishwa | 13555bd | 2015-11-10 12:10:38 -0600 | [diff] [blame] | 39 | { |
| 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 Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame^] | 46 | if (fruid == 0) |
vishwa | 13555bd | 2015-11-10 12:10:38 -0600 | [diff] [blame] | 47 | { |
| 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); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 57 | if (rc < 0) |
vishwa | 13555bd | 2015-11-10 12:10:38 -0600 | [diff] [blame] | 58 | { |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame^] | 59 | fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-rc)); |
vishwa | 13555bd | 2015-11-10 12:10:38 -0600 | [diff] [blame] | 60 | } |
| 61 | else |
| 62 | { |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame^] | 63 | // Now that we have the file that contains the eeprom data, go read it |
| 64 | // and update the Inventory DB. |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 65 | bool bmc_fru = true; |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame^] | 66 | rc = ipmi_validate_fru_area(fruid, eeprom_file.c_str(), bus_type, |
| 67 | bmc_fru); |
vishwa | 13555bd | 2015-11-10 12:10:38 -0600 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | // Cleanup |
| 71 | sd_bus_unref(bus_type); |
| 72 | |
| 73 | return (rc < 0 ? EXIT_FAILURE : EXIT_SUCCESS); |
| 74 | } |