xref: /openbmc/ipmi-fru-parser/readeeprom.cpp (revision cfa96afa)
1155c34fbSMatthew Barth #include "writefrudata.hpp"
2155c34fbSMatthew Barth 
3d847f508SPatrick Venture #include <CLI/CLI.hpp>
4*cfa96afaSPatrick Williams #include <phosphor-logging/log.hpp>
5*cfa96afaSPatrick Williams 
652f1f189SPatrick Venture #include <cstdlib>
752f1f189SPatrick Venture #include <cstring>
8c9508db8SPatrick Venture #include <iostream>
9c9508db8SPatrick Venture #include <memory>
1007f635c8SPatrick Venture 
1107f635c8SPatrick Venture using namespace phosphor::logging;
12c9508db8SPatrick Venture 
13155c34fbSMatthew Barth //--------------------------------------------------------------------------
14155c34fbSMatthew Barth // This gets called by udev monitor soon after seeing hog plugs for EEPROMS.
15155c34fbSMatthew Barth //--------------------------------------------------------------------------
main(int argc,char ** argv)16155c34fbSMatthew Barth int main(int argc, char** argv)
17155c34fbSMatthew Barth {
18155c34fbSMatthew Barth     int rc = 0;
198f51109dSOskar Senft     uint8_t fruid;
20d847f508SPatrick Venture     std::string eeprom_file;
21d847f508SPatrick Venture     const int MAX_FRU_ID = 0xfe;
22d847f508SPatrick Venture 
23d847f508SPatrick Venture     CLI::App app{"OpenBMC IPMI-FRU-Parser"};
24d847f508SPatrick Venture     app.add_option("-e,--eeprom", eeprom_file, "Absolute file name of eeprom")
25d847f508SPatrick Venture         ->check(CLI::ExistingFile);
26d847f508SPatrick Venture     app.add_option("-f,--fruid", fruid, "valid fru id in integer")
27d847f508SPatrick Venture         ->check(CLI::Range(0, MAX_FRU_ID));
28155c34fbSMatthew Barth 
29155c34fbSMatthew Barth     // Read the arguments.
30d847f508SPatrick Venture     CLI11_PARSE(app, argc, argv);
31155c34fbSMatthew Barth 
32c9508db8SPatrick Venture     // Now that we have the file that contains the eeprom data, go read it
33c9508db8SPatrick Venture     // and update the Inventory DB.
34a8093a25SPatrick Venture     auto bus = sdbusplus::bus::new_default();
35155c34fbSMatthew Barth     bool bmc_fru = true;
36a8093a25SPatrick Venture     rc = validateFRUArea(fruid, eeprom_file.c_str(), bus, bmc_fru);
37155c34fbSMatthew Barth 
38155c34fbSMatthew Barth     return (rc < 0 ? EXIT_FAILURE : EXIT_SUCCESS);
39155c34fbSMatthew Barth }
40