blob: f6163120c704a1e43a348431ae321daabd21f6e7 [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
Dhruvaraj Subhashchandranca9236c2024-04-17 01:56:04 -050014#include <phosphor-logging/lg2.hpp>
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050015#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
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050019#else
Patrick Williamsb9142c02023-09-01 15:08:34 -050020#include <org/open_power/Host/Boot/error.hpp>
21#include <phosphor-logging/elog-errors.hpp>
Jayanth Othayothb618ccb2018-10-22 21:55:29 -050022#include <phosphor-logging/elog.hpp>
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050023#endif
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +053024
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050025int main(int argc, char* argv[])
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +053026{
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050027 CLI::App app{"Hostboot dump collector for watchdog timeout"};
28
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050029#ifdef WATCHDOG_DUMP_COLLECTION
30 constexpr uint32_t dumpTimeout = 1500; // in seconds
31 uint32_t timeout = dumpTimeout;
32 app.add_option("-t,--timeout", timeout,
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050033 "Set timeout interval for watchdog timeout in seconds");
34#endif
35
36 CLI11_PARSE(app, argc, argv);
37
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050038#ifdef WATCHDOG_DUMP_COLLECTION
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050039 using namespace watchdog::dump;
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050040
Dhruvaraj Subhashchandranca9236c2024-04-17 01:56:04 -050041 lg2::info("Host did not respond within watchdog timeout interval");
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050042 try
43 {
44 using namespace openpower::phal;
45
46 // Initialize pdbg library, default parameters are used for init()
47 pdbg::init();
48
49 // Get Primary Proc
50 struct pdbg_target* procTarget = pdbg::getPrimaryProc();
51
52 // Check Primary IPL done
53 bool primaryIplDone = sbe::isPrimaryIplDone();
54 if (primaryIplDone)
55 {
Shantappa Teekappanavare6978e52022-03-03 18:34:25 -060056 // Collect hostboot dump only if the host is in 'Running' state
57 if (!isHostStateRunning())
58 {
Dhruvaraj Subhashchandranca9236c2024-04-17 01:56:04 -050059 lg2::info(
Shantappa Teekappanavare6978e52022-03-03 18:34:25 -060060 "CurrentHostState is not in 'Running' state. Dump maybe "
61 "already occurring, skipping this dump request...");
62 return EXIT_SUCCESS;
63 }
64
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050065 // SBE boot done, Need to collect hostboot dump
Dhruvaraj Subhashchandranca9236c2024-04-17 01:56:04 -050066 lg2::info("Handle Hostboot boot failure");
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050067 triggerHostbootDump(timeout);
68 }
69 else
70 {
71 // SBE boot window, handle SBE boot failure
Dhruvaraj Subhashchandranca9236c2024-04-17 01:56:04 -050072 lg2::info("Handle SBE boot failure");
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050073 handleSbeBootError(procTarget, timeout);
74 }
75 }
76 catch (const std::exception& e)
77 {
Dhruvaraj Subhashchandranca9236c2024-04-17 01:56:04 -050078 lg2::error("Exception {ERROR} occurred", "ERROR", e);
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050079 std::string eventType =
deepakala-k4f4e36d2023-04-24 09:08:18 -050080 "org.open_power.Host.Boot.Error.WatchdogTimedOut";
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050081 auto ffdc = std::vector<FFDCTuple>{};
82 std::map<std::string, std::string> additionalData;
83
84 if (!createPel(eventType, additionalData, ffdc))
85 {
Dhruvaraj Subhashchandranca9236c2024-04-17 01:56:04 -050086 lg2::error("Failed to create PEL");
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050087 }
88
89 return EXIT_SUCCESS;
90 }
91
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050092#else
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +053093 using namespace phosphor::logging;
Jayanth Othayothb618ccb2018-10-22 21:55:29 -050094 using error =
95 sdbusplus::org::open_power::Host::Boot::Error::WatchdogTimedOut;
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +053096 report<error>();
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050097#endif
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +053098
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050099 return EXIT_SUCCESS;
Vishwanatha Subbanna0eff6092017-06-12 21:03:36 +0530100}