blob: dbebc1ed38dc65f5eb034383be5d0e6a9a0198c9 [file] [log] [blame]
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -05001#include <config.h>
2
3#include <CLI/CLI.hpp>
4
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -05005#ifdef WATCHDOG_DUMP_COLLECTION
6extern "C"
7{
8#include <libpdbg.h>
9#include <libpdbg_sbe.h>
10}
11
12#include <fmt/format.h>
13#include <libphal.H>
14
15#include <phosphor-logging/log.hpp>
16#include <watchdog/watchdog_common.hpp>
17#include <watchdog/watchdog_dbus.hpp>
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050018#include <watchdog/watchdog_main.hpp>
19#else
Marri Devender Rao0947c652017-10-24 02:27:15 -050020#include "org/open_power/Host/Boot/error.hpp"
Jayanth Othayothb618ccb2018-10-22 21:55:29 -050021#include "phosphor-logging/elog-errors.hpp"
22
23#include <phosphor-logging/elog.hpp>
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050024#endif
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +053025
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050026int main(int argc, char* argv[])
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +053027{
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050028 CLI::App app{"Hostboot dump collector for watchdog timeout"};
29
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050030#ifdef WATCHDOG_DUMP_COLLECTION
31 constexpr uint32_t dumpTimeout = 1500; // in seconds
32 uint32_t timeout = dumpTimeout;
33 app.add_option("-t,--timeout", timeout,
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050034 "Set timeout interval for watchdog timeout in seconds");
35#endif
36
37 CLI11_PARSE(app, argc, argv);
38
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050039#ifdef WATCHDOG_DUMP_COLLECTION
40 using namespace phosphor::logging;
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050041 using namespace watchdog::dump;
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050042
43 log<level::INFO>("Host did not respond within watchdog timeout interval");
44 try
45 {
46 using namespace openpower::phal;
47
48 // Initialize pdbg library, default parameters are used for init()
49 pdbg::init();
50
51 // Get Primary Proc
52 struct pdbg_target* procTarget = pdbg::getPrimaryProc();
53
54 // Check Primary IPL done
55 bool primaryIplDone = sbe::isPrimaryIplDone();
56 if (primaryIplDone)
57 {
Shantappa Teekappanavare6978e52022-03-03 18:34:25 -060058 // Collect hostboot dump only if the host is in 'Running' state
59 if (!isHostStateRunning())
60 {
61 log<level::INFO>(
62 "CurrentHostState is not in 'Running' state. Dump maybe "
63 "already occurring, skipping this dump request...");
64 return EXIT_SUCCESS;
65 }
66
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050067 // SBE boot done, Need to collect hostboot dump
68 log<level::INFO>("Handle Hostboot boot failure");
69 triggerHostbootDump(timeout);
70 }
71 else
72 {
73 // SBE boot window, handle SBE boot failure
74 log<level::INFO>("Handle SBE boot failure");
75 handleSbeBootError(procTarget, timeout);
76 }
77 }
78 catch (const std::exception& e)
79 {
80 log<level::ERR>(fmt::format("Exception {} occurred", e.what()).c_str());
81 std::string eventType =
deepakala-k4f4e36d2023-04-24 09:08:18 -050082 "org.open_power.Host.Boot.Error.WatchdogTimedOut";
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050083 auto ffdc = std::vector<FFDCTuple>{};
84 std::map<std::string, std::string> additionalData;
85
86 if (!createPel(eventType, additionalData, ffdc))
87 {
88 log<level::ERR>("Failed to create PEL");
89 }
90
91 return EXIT_SUCCESS;
92 }
93
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050094#else
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +053095 using namespace phosphor::logging;
Jayanth Othayothb618ccb2018-10-22 21:55:29 -050096 using error =
97 sdbusplus::org::open_power::Host::Boot::Error::WatchdogTimedOut;
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +053098 report<error>();
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050099#endif
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +0530100
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -0500101 return EXIT_SUCCESS;
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +0530102}