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 | |
| 14 | #include <phosphor-logging/log.hpp> |
| 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 | |
| 19 | #include <format> |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 20 | #else |
Marri Devender Rao | 0947c65 | 2017-10-24 02:27:15 -0500 | [diff] [blame] | 21 | #include "org/open_power/Host/Boot/error.hpp" |
Jayanth Othayoth | b618ccb | 2018-10-22 21:55:29 -0500 | [diff] [blame] | 22 | #include "phosphor-logging/elog-errors.hpp" |
| 23 | |
| 24 | #include <phosphor-logging/elog.hpp> |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 25 | #endif |
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 | int main(int argc, char* argv[]) |
Vishwanatha Subbanna | 0eff609 | 2017-06-12 21:03:36 +0530 | [diff] [blame] | 28 | { |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 29 | CLI::App app{"Hostboot dump collector for watchdog timeout"}; |
| 30 | |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 31 | #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 Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 35 | "Set timeout interval for watchdog timeout in seconds"); |
| 36 | #endif |
| 37 | |
| 38 | CLI11_PARSE(app, argc, argv); |
| 39 | |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 40 | #ifdef WATCHDOG_DUMP_COLLECTION |
| 41 | using namespace phosphor::logging; |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 42 | using namespace watchdog::dump; |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 43 | |
| 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 Teekappanavar | e6978e5 | 2022-03-03 18:34:25 -0600 | [diff] [blame] | 59 | // 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 Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 68 | // 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 Williams | 40fccd5 | 2023-07-17 11:24:09 -0500 | [diff] [blame] | 81 | log<level::ERR>(std::format("Exception {} occurred", e.what()).c_str()); |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 82 | std::string eventType = |
deepakala-k | 4f4e36d | 2023-04-24 09:08:18 -0500 | [diff] [blame] | 83 | "org.open_power.Host.Boot.Error.WatchdogTimedOut"; |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 84 | 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 Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 95 | #else |
Vishwanatha Subbanna | 0eff609 | 2017-06-12 21:03:36 +0530 | [diff] [blame] | 96 | using namespace phosphor::logging; |
Jayanth Othayoth | b618ccb | 2018-10-22 21:55:29 -0500 | [diff] [blame] | 97 | using error = |
| 98 | sdbusplus::org::open_power::Host::Boot::Error::WatchdogTimedOut; |
Vishwanatha Subbanna | 0eff609 | 2017-06-12 21:03:36 +0530 | [diff] [blame] | 99 | report<error>(); |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 100 | #endif |
Vishwanatha Subbanna | 0eff609 | 2017-06-12 21:03:36 +0530 | [diff] [blame] | 101 | |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 102 | return EXIT_SUCCESS; |
Vishwanatha Subbanna | 0eff609 | 2017-06-12 21:03:36 +0530 | [diff] [blame] | 103 | } |