blob: 319309a709568fd183f8fcce6abf4069d651ec90 [file] [log] [blame]
Dhruvaraj Subhashchandran858d1aa2021-10-27 03:26:06 -05001#include "sbe_consts.hpp"
2#include "sbe_dump_collector.hpp"
3
Dhruvaraj Subhashchandran62881c52021-09-20 20:25:51 -05004#include <libphal.H>
5
Dhruvaraj Subhashchandran858d1aa2021-10-27 03:26:06 -05006#include <CLI/App.hpp>
7#include <CLI/Config.hpp>
8#include <CLI/Formatter.hpp>
9
10#include <filesystem>
11#include <iostream>
12
13int main(int argc, char** argv)
14{
15 using namespace openpower::dump::sbe_chipop;
16 using std::filesystem::path;
17 using namespace openpower::dump::SBE;
Dhruvaraj Subhashchandran62881c52021-09-20 20:25:51 -050018 using namespace openpower::phal::dump;
Dhruvaraj Subhashchandran858d1aa2021-10-27 03:26:06 -050019
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()
Patrick Williams540521e2024-08-16 15:20:03 -040033 ->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}));
Dhruvaraj Subhashchandran858d1aa2021-10-27 03:26:06 -050036
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
Dhruvaraj Subhashchandran6f1be972024-04-01 00:42:38 -050054 if (((type == SBE_DUMP_TYPE_HARDWARE) || (type == SBE_DUMP_TYPE_SBE) ||
55 (type == SBE_DUMP_TYPE_MSBE)) &&
Dhruvaraj Subhashchandran62881c52021-09-20 20:25:51 -050056 !failingUnit.has_value())
Dhruvaraj Subhashchandran858d1aa2021-10-27 03:26:06 -050057 {
Dhruvaraj Subhashchandran62881c52021-09-20 20:25:51 -050058 std::cerr
59 << "Failing unit ID is required for Hardware and SBE type dumps\n";
Dhruvaraj Subhashchandran858d1aa2021-10-27 03:26:06 -050060 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 {
Dhruvaraj Subhashchandran6f1be972024-04-01 00:42:38 -050080 if ((type == SBE_DUMP_TYPE_SBE) || (type == SBE_DUMP_TYPE_MSBE))
Dhruvaraj Subhashchandran62881c52021-09-20 20:25:51 -050081 {
82 collectSBEDump(id, failingUnitId, pathStr, type);
83 }
84 else
85 {
86 dumpCollector.collectDump(type, id, failingUnitId, pathStr);
87 }
Dhruvaraj Subhashchandran858d1aa2021-10-27 03:26:06 -050088 }
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}