1155c34fbSMatthew Barth #include "argument.hpp" 2155c34fbSMatthew Barth #include "writefrudata.hpp" 3155c34fbSMatthew Barth 452f1f189SPatrick Venture #include <cstdlib> 552f1f189SPatrick Venture #include <cstring> 6c9508db8SPatrick Venture #include <iostream> 7c9508db8SPatrick Venture #include <memory> 807f635c8SPatrick Venture #include <phosphor-logging/log.hpp> 907f635c8SPatrick Venture 1007f635c8SPatrick Venture using namespace phosphor::logging; 11c9508db8SPatrick Venture 12155c34fbSMatthew Barth static void exit_with_error(const char* err, char** argv) 13155c34fbSMatthew Barth { 14155c34fbSMatthew Barth ArgumentParser::usage(argv); 15155c34fbSMatthew Barth std::cerr << std::endl; 16155c34fbSMatthew Barth std::cerr << "ERROR: " << err << std::endl; 17155c34fbSMatthew Barth exit(-1); 18155c34fbSMatthew Barth } 19155c34fbSMatthew Barth 20155c34fbSMatthew Barth //-------------------------------------------------------------------------- 21155c34fbSMatthew Barth // This gets called by udev monitor soon after seeing hog plugs for EEPROMS. 22155c34fbSMatthew Barth //-------------------------------------------------------------------------- 23155c34fbSMatthew Barth int main(int argc, char** argv) 24155c34fbSMatthew Barth { 25155c34fbSMatthew Barth int rc = 0; 26155c34fbSMatthew Barth uint8_t fruid = 0; 27155c34fbSMatthew Barth 28155c34fbSMatthew Barth // Read the arguments. 29155c34fbSMatthew Barth auto cli_options = std::make_unique<ArgumentParser>(argc, argv); 30155c34fbSMatthew Barth 31155c34fbSMatthew Barth // Parse out each argument. 32155c34fbSMatthew Barth auto eeprom_file = (*cli_options)["eeprom"]; 33155c34fbSMatthew Barth if (eeprom_file == ArgumentParser::empty_string) 34155c34fbSMatthew Barth { 35155c34fbSMatthew Barth // User has not passed in the appropriate argument value 36155c34fbSMatthew Barth exit_with_error("eeprom data not found.", argv); 37155c34fbSMatthew Barth } 38155c34fbSMatthew Barth 39155c34fbSMatthew Barth auto fruid_str = (*cli_options)["fruid"]; 4005261aa5SDmitry Bazhenov if (fruid_str == ArgumentParser::empty_string) 41155c34fbSMatthew Barth { 42155c34fbSMatthew Barth // User has not passed in the appropriate argument value 43155c34fbSMatthew Barth exit_with_error("fruid data not found.", argv); 44155c34fbSMatthew Barth } 45155c34fbSMatthew Barth 46155c34fbSMatthew Barth // Extract the fruid 4752f1f189SPatrick Venture fruid = std::strtol(fruid_str.c_str(), NULL, 16); 48155c34fbSMatthew Barth if (fruid == 0) 49155c34fbSMatthew Barth { 50155c34fbSMatthew Barth // User has not passed in the appropriate argument value 51155c34fbSMatthew Barth exit_with_error("Invalid fruid.", argv); 52155c34fbSMatthew Barth } 53155c34fbSMatthew Barth 54155c34fbSMatthew Barth // Finished getting options out, so release the parser. 55155c34fbSMatthew Barth cli_options.release(); 56155c34fbSMatthew Barth 57c9508db8SPatrick Venture // Now that we have the file that contains the eeprom data, go read it 58c9508db8SPatrick Venture // and update the Inventory DB. 59*a8093a25SPatrick Venture auto bus = sdbusplus::bus::new_default(); 60155c34fbSMatthew Barth bool bmc_fru = true; 61*a8093a25SPatrick Venture rc = validateFRUArea(fruid, eeprom_file.c_str(), bus, bmc_fru); 62155c34fbSMatthew Barth 63155c34fbSMatthew Barth return (rc < 0 ? EXIT_FAILURE : EXIT_SUCCESS); 64155c34fbSMatthew Barth } 65