blob: ac43fb1a3b8bac0814648e974d5269301ceafe7c [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()
Dhruvaraj Subhashchandran62881c52021-09-20 20:25:51 -050033 ->check(CLI::IsMember({SBE_DUMP_TYPE_HARDWARE, SBE_DUMP_TYPE_HOSTBOOT,
Dhruvaraj Subhashchandran9098d8c2022-12-01 00:40:20 -060034 SBE_DUMP_TYPE_SBE, SBE_DUMP_TYPE_PERFORMANCE}));
Dhruvaraj Subhashchandran858d1aa2021-10-27 03:26:06 -050035
36 app.add_option("--id, -i", id, "ID of the dump")->required();
37
38 app.add_option("--path, -p", pathStr,
39 "Path to store the collected dump files")
40 ->required();
41
42 app.add_option("--failingunit, -f", failingUnit, "ID of the failing unit");
43
44 try
45 {
46 CLI11_PARSE(app, argc, argv);
47 }
48 catch (const CLI::ParseError& e)
49 {
50 return app.exit(e);
51 }
52
Dhruvaraj Subhashchandran62881c52021-09-20 20:25:51 -050053 if (((type == SBE_DUMP_TYPE_HARDWARE) || (type == SBE_DUMP_TYPE_SBE)) &&
54 !failingUnit.has_value())
Dhruvaraj Subhashchandran858d1aa2021-10-27 03:26:06 -050055 {
Dhruvaraj Subhashchandran62881c52021-09-20 20:25:51 -050056 std::cerr
57 << "Failing unit ID is required for Hardware and SBE type dumps\n";
Dhruvaraj Subhashchandran858d1aa2021-10-27 03:26:06 -050058 return EXIT_FAILURE;
59 }
60
61 // Directory creation should happen here, after successful parsing
62 std::filesystem::path dirPath{pathStr};
63 if (!std::filesystem::exists(dirPath))
64 {
65 std::filesystem::create_directories(dirPath);
66 }
67
68 SbeDumpCollector dumpCollector;
69
70 auto failingUnitId = 0xFFFFFF; // Default or unspecified value
71 if (failingUnit.has_value())
72 {
73 failingUnitId = failingUnit.value();
74 }
75
76 try
77 {
Dhruvaraj Subhashchandran62881c52021-09-20 20:25:51 -050078 if (type == SBE_DUMP_TYPE_SBE)
79 {
80 collectSBEDump(id, failingUnitId, pathStr, type);
81 }
82 else
83 {
84 dumpCollector.collectDump(type, id, failingUnitId, pathStr);
85 }
Dhruvaraj Subhashchandran858d1aa2021-10-27 03:26:06 -050086 }
87 catch (const std::exception& e)
88 {
89 std::cerr << "Failed to collect dump: " << e.what() << std::endl;
90 std::exit(EXIT_FAILURE);
91 }
92
93 return 0;
94}