1 #include "sbe_consts.hpp" 2 #include "sbe_dump_collector.hpp" 3 4 #include <libphal.H> 5 6 #include <CLI/App.hpp> 7 #include <CLI/Config.hpp> 8 #include <CLI/Formatter.hpp> 9 10 #include <filesystem> 11 #include <iostream> 12 13 int main(int argc, char** argv) 14 { 15 using namespace openpower::dump::sbe_chipop; 16 using std::filesystem::path; 17 using namespace openpower::dump::SBE; 18 using namespace openpower::phal::dump; 19 20 CLI::App app{"Dump Collector Application", "dump-collect"}; 21 app.description( 22 "Collects dumps from the Self Boot Engine (SBE) based on " 23 "provided parameters.\nSupports different types of dumps and requires " 24 "specific options based on the dump type."); 25 26 int type = 0; 27 uint32_t id; 28 std::string pathStr; 29 std::optional<uint64_t> failingUnit; 30 31 app.add_option("--type, -t", type, "Type of the dump") 32 ->required() 33 ->check(CLI::IsMember( 34 {SBE_DUMP_TYPE_HARDWARE, SBE_DUMP_TYPE_HOSTBOOT, SBE_DUMP_TYPE_SBE, 35 SBE_DUMP_TYPE_PERFORMANCE, SBE_DUMP_TYPE_MSBE})); 36 37 app.add_option("--id, -i", id, "ID of the dump")->required(); 38 39 app.add_option("--path, -p", pathStr, 40 "Path to store the collected dump files") 41 ->required(); 42 43 app.add_option("--failingunit, -f", failingUnit, "ID of the failing unit"); 44 45 try 46 { 47 CLI11_PARSE(app, argc, argv); 48 } 49 catch (const CLI::ParseError& e) 50 { 51 return app.exit(e); 52 } 53 54 if (((type == SBE_DUMP_TYPE_HARDWARE) || (type == SBE_DUMP_TYPE_SBE) || 55 (type == SBE_DUMP_TYPE_MSBE)) && 56 !failingUnit.has_value()) 57 { 58 std::cerr 59 << "Failing unit ID is required for Hardware and SBE type dumps\n"; 60 return EXIT_FAILURE; 61 } 62 63 // Directory creation should happen here, after successful parsing 64 std::filesystem::path dirPath{pathStr}; 65 if (!std::filesystem::exists(dirPath)) 66 { 67 std::filesystem::create_directories(dirPath); 68 } 69 70 SbeDumpCollector dumpCollector; 71 72 auto failingUnitId = 0xFFFFFF; // Default or unspecified value 73 if (failingUnit.has_value()) 74 { 75 failingUnitId = failingUnit.value(); 76 } 77 78 try 79 { 80 if ((type == SBE_DUMP_TYPE_SBE) || (type == SBE_DUMP_TYPE_MSBE)) 81 { 82 collectSBEDump(id, failingUnitId, pathStr, type); 83 } 84 else 85 { 86 dumpCollector.collectDump(type, id, failingUnitId, pathStr); 87 } 88 } 89 catch (const std::exception& e) 90 { 91 std::cerr << "Failed to collect dump: " << e.what() << std::endl; 92 std::exit(EXIT_FAILURE); 93 } 94 95 return 0; 96 } 97