xref: /openbmc/ipmi-fru-parser/readeeprom.cpp (revision 0968237b)
1 #include "writefrudata.hpp"
2 
3 #include <CLI/CLI.hpp>
4 #include <cstdlib>
5 #include <cstring>
6 #include <iostream>
7 #include <memory>
8 #include <phosphor-logging/log.hpp>
9 
10 using namespace phosphor::logging;
11 
12 //--------------------------------------------------------------------------
13 // This gets called by udev monitor soon after seeing hog plugs for EEPROMS.
14 //--------------------------------------------------------------------------
15 int main(int argc, char** argv)
16 {
17     int rc = 0;
18     uint8_t fruid;
19     std::string eeprom_file;
20     const int MAX_FRU_ID = 0xfe;
21 
22     CLI::App app{"OpenBMC IPMI-FRU-Parser"};
23     app.add_option("-e,--eeprom", eeprom_file, "Absolute file name of eeprom")
24         ->check(CLI::ExistingFile);
25     app.add_option("-f,--fruid", fruid, "valid fru id in integer")
26         ->check(CLI::Range(0, MAX_FRU_ID));
27 
28     // Read the arguments.
29     CLI11_PARSE(app, argc, argv);
30 
31     // Now that we have the file that contains the eeprom data, go read it
32     // and update the Inventory DB.
33     auto bus = sdbusplus::bus::new_default();
34     bool bmc_fru = true;
35     rc = validateFRUArea(fruid, eeprom_file.c_str(), bus, bmc_fru);
36 
37     return (rc < 0 ? EXIT_FAILURE : EXIT_SUCCESS);
38 }
39