blob: 5c374ef09e0c23a31db17bef06a436cef17e07fd [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 {
58 // SBE boot done, Need to collect hostboot dump
59 log<level::INFO>("Handle Hostboot boot failure");
60 triggerHostbootDump(timeout);
61 }
62 else
63 {
64 // SBE boot window, handle SBE boot failure
65 log<level::INFO>("Handle SBE boot failure");
66 handleSbeBootError(procTarget, timeout);
67 }
68 }
69 catch (const std::exception& e)
70 {
71 log<level::ERR>(fmt::format("Exception {} occurred", e.what()).c_str());
72 std::string eventType =
73 "org.open_power.Processor.Error.WatchdogTimeout";
74 auto ffdc = std::vector<FFDCTuple>{};
75 std::map<std::string, std::string> additionalData;
76
77 if (!createPel(eventType, additionalData, ffdc))
78 {
79 log<level::ERR>("Failed to create PEL");
80 }
81
82 return EXIT_SUCCESS;
83 }
84
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050085#else
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +053086 using namespace phosphor::logging;
Jayanth Othayothb618ccb2018-10-22 21:55:29 -050087 using error =
88 sdbusplus::org::open_power::Host::Boot::Error::WatchdogTimedOut;
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +053089 report<error>();
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050090#endif
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +053091
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050092 return EXIT_SUCCESS;
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +053093}