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 | |
| 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 Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 18 | #include <watchdog/watchdog_main.hpp> |
| 19 | #else |
Marri Devender Rao | 0947c65 | 2017-10-24 02:27:15 -0500 | [diff] [blame] | 20 | #include "org/open_power/Host/Boot/error.hpp" |
Jayanth Othayoth | b618ccb | 2018-10-22 21:55:29 -0500 | [diff] [blame] | 21 | #include "phosphor-logging/elog-errors.hpp" |
| 22 | |
| 23 | #include <phosphor-logging/elog.hpp> |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 24 | #endif |
Vishwanatha Subbanna | 0eff609 | 2017-06-12 21:03:36 +0530 | [diff] [blame] | 25 | |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 26 | int main(int argc, char* argv[]) |
Vishwanatha Subbanna | 0eff609 | 2017-06-12 21:03:36 +0530 | [diff] [blame] | 27 | { |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 28 | CLI::App app{"Hostboot dump collector for watchdog timeout"}; |
| 29 | |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 30 | #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 Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 34 | "Set timeout interval for watchdog timeout in seconds"); |
| 35 | #endif |
| 36 | |
| 37 | CLI11_PARSE(app, argc, argv); |
| 38 | |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 39 | #ifdef WATCHDOG_DUMP_COLLECTION |
| 40 | using namespace phosphor::logging; |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 41 | using namespace watchdog::dump; |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 42 | |
| 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 Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 85 | #else |
Vishwanatha Subbanna | 0eff609 | 2017-06-12 21:03:36 +0530 | [diff] [blame] | 86 | using namespace phosphor::logging; |
Jayanth Othayoth | b618ccb | 2018-10-22 21:55:29 -0500 | [diff] [blame] | 87 | using error = |
| 88 | sdbusplus::org::open_power::Host::Boot::Error::WatchdogTimedOut; |
Vishwanatha Subbanna | 0eff609 | 2017-06-12 21:03:36 +0530 | [diff] [blame] | 89 | report<error>(); |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 90 | #endif |
Vishwanatha Subbanna | 0eff609 | 2017-06-12 21:03:36 +0530 | [diff] [blame] | 91 | |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 92 | return EXIT_SUCCESS; |
Vishwanatha Subbanna | 0eff609 | 2017-06-12 21:03:36 +0530 | [diff] [blame] | 93 | } |