Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 1 | #include <config.h> |
| 2 | |
| 3 | #include <CLI/CLI.hpp> |
| 4 | |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 5 | #ifdef WATCHDOG_DUMP_COLLECTION |
| 6 | extern "C" |
| 7 | { |
| 8 | #include <libpdbg.h> |
| 9 | #include <libpdbg_sbe.h> |
| 10 | } |
| 11 | |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 12 | #include <libphal.H> |
| 13 | |
Dhruvaraj Subhashchandran | ca9236c | 2024-04-17 01:56:04 -0500 | [diff] [blame] | 14 | #include <phosphor-logging/lg2.hpp> |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 15 | #include <watchdog/watchdog_common.hpp> |
| 16 | #include <watchdog/watchdog_dbus.hpp> |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 17 | #include <watchdog/watchdog_main.hpp> |
Patrick Williams | 40fccd5 | 2023-07-17 11:24:09 -0500 | [diff] [blame] | 18 | |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 19 | #else |
Patrick Williams | b9142c0 | 2023-09-01 15:08:34 -0500 | [diff] [blame] | 20 | #include <org/open_power/Host/Boot/error.hpp> |
| 21 | #include <phosphor-logging/elog-errors.hpp> |
Jayanth Othayoth | b618ccb | 2018-10-22 21:55:29 -0500 | [diff] [blame] | 22 | #include <phosphor-logging/elog.hpp> |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 23 | #endif |
Vishwanatha Subbanna | 0eff609 | 2017-06-12 21:03:36 +0530 | [diff] [blame] | 24 | |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 25 | int main(int argc, char* argv[]) |
Vishwanatha Subbanna | 0eff609 | 2017-06-12 21:03:36 +0530 | [diff] [blame] | 26 | { |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 27 | CLI::App app{"Hostboot dump collector for watchdog timeout"}; |
| 28 | |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 29 | #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 Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 33 | "Set timeout interval for watchdog timeout in seconds"); |
| 34 | #endif |
| 35 | |
| 36 | CLI11_PARSE(app, argc, argv); |
| 37 | |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 38 | #ifdef WATCHDOG_DUMP_COLLECTION |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 39 | using namespace watchdog::dump; |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 40 | |
Dhruvaraj Subhashchandran | ca9236c | 2024-04-17 01:56:04 -0500 | [diff] [blame] | 41 | lg2::info("Host did not respond within watchdog timeout interval"); |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 42 | 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 Teekappanavar | e6978e5 | 2022-03-03 18:34:25 -0600 | [diff] [blame] | 56 | // Collect hostboot dump only if the host is in 'Running' state |
| 57 | if (!isHostStateRunning()) |
| 58 | { |
Dhruvaraj Subhashchandran | ca9236c | 2024-04-17 01:56:04 -0500 | [diff] [blame] | 59 | lg2::info( |
Shantappa Teekappanavar | e6978e5 | 2022-03-03 18:34:25 -0600 | [diff] [blame] | 60 | "CurrentHostState is not in 'Running' state. Dump maybe " |
| 61 | "already occurring, skipping this dump request..."); |
| 62 | return EXIT_SUCCESS; |
| 63 | } |
| 64 | |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 65 | // SBE boot done, Need to collect hostboot dump |
Dhruvaraj Subhashchandran | ca9236c | 2024-04-17 01:56:04 -0500 | [diff] [blame] | 66 | lg2::info("Handle Hostboot boot failure"); |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 67 | triggerHostbootDump(timeout); |
| 68 | } |
| 69 | else |
| 70 | { |
| 71 | // SBE boot window, handle SBE boot failure |
Dhruvaraj Subhashchandran | ca9236c | 2024-04-17 01:56:04 -0500 | [diff] [blame] | 72 | lg2::info("Handle SBE boot failure"); |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 73 | handleSbeBootError(procTarget, timeout); |
| 74 | } |
| 75 | } |
| 76 | catch (const std::exception& e) |
| 77 | { |
Dhruvaraj Subhashchandran | ca9236c | 2024-04-17 01:56:04 -0500 | [diff] [blame] | 78 | lg2::error("Exception {ERROR} occurred", "ERROR", e); |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 79 | std::string eventType = |
deepakala-k | 4f4e36d | 2023-04-24 09:08:18 -0500 | [diff] [blame] | 80 | "org.open_power.Host.Boot.Error.WatchdogTimedOut"; |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 81 | auto ffdc = std::vector<FFDCTuple>{}; |
| 82 | std::map<std::string, std::string> additionalData; |
| 83 | |
| 84 | if (!createPel(eventType, additionalData, ffdc)) |
| 85 | { |
Dhruvaraj Subhashchandran | ca9236c | 2024-04-17 01:56:04 -0500 | [diff] [blame] | 86 | lg2::error("Failed to create PEL"); |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | return EXIT_SUCCESS; |
| 90 | } |
| 91 | |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 92 | #else |
Vishwanatha Subbanna | 0eff609 | 2017-06-12 21:03:36 +0530 | [diff] [blame] | 93 | using namespace phosphor::logging; |
Jayanth Othayoth | b618ccb | 2018-10-22 21:55:29 -0500 | [diff] [blame] | 94 | using error = |
| 95 | sdbusplus::org::open_power::Host::Boot::Error::WatchdogTimedOut; |
Vishwanatha Subbanna | 0eff609 | 2017-06-12 21:03:36 +0530 | [diff] [blame] | 96 | report<error>(); |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 97 | #endif |
Vishwanatha Subbanna | 0eff609 | 2017-06-12 21:03:36 +0530 | [diff] [blame] | 98 | |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 99 | return EXIT_SUCCESS; |
Vishwanatha Subbanna | 0eff609 | 2017-06-12 21:03:36 +0530 | [diff] [blame] | 100 | } |