blob: 36c6e662fe93186f2567f577263929ed48f5a0b5 [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
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050012#include <libphal.H>
13
14#include <phosphor-logging/log.hpp>
15#include <watchdog/watchdog_common.hpp>
16#include <watchdog/watchdog_dbus.hpp>
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050017#include <watchdog/watchdog_main.hpp>
Patrick Williams40fccd52023-07-17 11:24:09 -050018
19#include <format>
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050020#else
Marri Devender Rao0947c652017-10-24 02:27:15 -050021#include "org/open_power/Host/Boot/error.hpp"
Jayanth Othayothb618ccb2018-10-22 21:55:29 -050022#include "phosphor-logging/elog-errors.hpp"
23
24#include <phosphor-logging/elog.hpp>
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050025#endif
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +053026
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050027int main(int argc, char* argv[])
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +053028{
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050029 CLI::App app{"Hostboot dump collector for watchdog timeout"};
30
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050031#ifdef WATCHDOG_DUMP_COLLECTION
32 constexpr uint32_t dumpTimeout = 1500; // in seconds
33 uint32_t timeout = dumpTimeout;
34 app.add_option("-t,--timeout", timeout,
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050035 "Set timeout interval for watchdog timeout in seconds");
36#endif
37
38 CLI11_PARSE(app, argc, argv);
39
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050040#ifdef WATCHDOG_DUMP_COLLECTION
41 using namespace phosphor::logging;
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050042 using namespace watchdog::dump;
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050043
44 log<level::INFO>("Host did not respond within watchdog timeout interval");
45 try
46 {
47 using namespace openpower::phal;
48
49 // Initialize pdbg library, default parameters are used for init()
50 pdbg::init();
51
52 // Get Primary Proc
53 struct pdbg_target* procTarget = pdbg::getPrimaryProc();
54
55 // Check Primary IPL done
56 bool primaryIplDone = sbe::isPrimaryIplDone();
57 if (primaryIplDone)
58 {
Shantappa Teekappanavare6978e52022-03-03 18:34:25 -060059 // Collect hostboot dump only if the host is in 'Running' state
60 if (!isHostStateRunning())
61 {
62 log<level::INFO>(
63 "CurrentHostState is not in 'Running' state. Dump maybe "
64 "already occurring, skipping this dump request...");
65 return EXIT_SUCCESS;
66 }
67
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050068 // SBE boot done, Need to collect hostboot dump
69 log<level::INFO>("Handle Hostboot boot failure");
70 triggerHostbootDump(timeout);
71 }
72 else
73 {
74 // SBE boot window, handle SBE boot failure
75 log<level::INFO>("Handle SBE boot failure");
76 handleSbeBootError(procTarget, timeout);
77 }
78 }
79 catch (const std::exception& e)
80 {
Patrick Williams40fccd52023-07-17 11:24:09 -050081 log<level::ERR>(std::format("Exception {} occurred", e.what()).c_str());
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050082 std::string eventType =
deepakala-k4f4e36d2023-04-24 09:08:18 -050083 "org.open_power.Host.Boot.Error.WatchdogTimedOut";
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050084 auto ffdc = std::vector<FFDCTuple>{};
85 std::map<std::string, std::string> additionalData;
86
87 if (!createPel(eventType, additionalData, ffdc))
88 {
89 log<level::ERR>("Failed to create PEL");
90 }
91
92 return EXIT_SUCCESS;
93 }
94
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050095#else
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +053096 using namespace phosphor::logging;
Jayanth Othayothb618ccb2018-10-22 21:55:29 -050097 using error =
98 sdbusplus::org::open_power::Host::Boot::Error::WatchdogTimedOut;
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +053099 report<error>();
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -0500100#endif
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +0530101
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -0500102 return EXIT_SUCCESS;
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +0530103}