Ben Tyner | 117af99 | 2020-05-22 13:32:11 -0500 | [diff] [blame] | 1 | #include <libpdbg.h> |
| 2 | |
Ben Tyner | d3cda74 | 2020-05-04 08:00:28 -0500 | [diff] [blame] | 3 | #include <analyzer/analyzer_main.hpp> |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 4 | #include <attn/attention.hpp> |
Ben Tyner | d3cda74 | 2020-05-04 08:00:28 -0500 | [diff] [blame] | 5 | #include <attn/attn_config.hpp> |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 6 | #include <attn/attn_dump.hpp> |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 7 | #include <attn/attn_handler.hpp> |
Ben Tyner | d3cda74 | 2020-05-04 08:00:28 -0500 | [diff] [blame] | 8 | #include <attn/attn_main.hpp> |
Ben Tyner | eea4542 | 2021-04-15 10:54:14 -0500 | [diff] [blame] | 9 | #include <buildinfo.hpp> |
Ben Tyner | d3cda74 | 2020-05-04 08:00:28 -0500 | [diff] [blame] | 10 | #include <cli.hpp> |
Zane Shelley | de22092 | 2022-12-05 22:10:43 -0600 | [diff] [blame] | 11 | #include <hei_buildinfo.hpp> |
austinfcui | 6a62e40 | 2021-12-01 11:52:45 -0600 | [diff] [blame] | 12 | #include <util/pdbg_callback.hpp> |
Ben Tyner | d3cda74 | 2020-05-04 08:00:28 -0500 | [diff] [blame] | 13 | |
| 14 | /** |
| 15 | * @brief Attention handler application main() |
| 16 | * |
| 17 | * This is the main interface to the hardware diagnostics application. This |
| 18 | * application can be loaded as a daemon for monitoring the attention |
| 19 | * gpio or it can be loaded as an application to analyze hardware and |
| 20 | * diagnose hardware error conditions. |
| 21 | * |
| 22 | * Usage: |
| 23 | * --analyze: Analyze the hardware |
| 24 | * --daemon: Start the attention handler daemon |
| 25 | * |
| 26 | * @return 0 = success |
| 27 | */ |
| 28 | int main(int argc, char* argv[]) |
| 29 | { |
| 30 | int rc = 0; // assume success |
| 31 | |
| 32 | if (argc == 1) |
| 33 | { |
| 34 | printf("openpower-hw-diags <options>\n"); |
| 35 | printf("options:\n"); |
| 36 | printf(" --analyze: Analyze the hardware\n"); |
| 37 | printf(" --daemon: Start the attn handler daemon\n"); |
Zane Shelley | de22092 | 2022-12-05 22:10:43 -0600 | [diff] [blame] | 38 | printf("hwdiag: %s, hei: %s\n", BUILDINFO, libhei::getBuildInfo()); |
Ben Tyner | d3cda74 | 2020-05-04 08:00:28 -0500 | [diff] [blame] | 39 | } |
| 40 | else |
| 41 | { |
austinfcui | 6a62e40 | 2021-12-01 11:52:45 -0600 | [diff] [blame] | 42 | // set PDBG log callback function. |
| 43 | pdbg_set_logfunc(util::pdbg_log_callback); |
| 44 | |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 45 | // Pdbg targets should only be initialized once according to |
| 46 | // libpdbg documentation. Initializing them here will make sure |
| 47 | // they are initialized for the attention handler, invocation of |
| 48 | // the analyzer via attention handler and direct invocation of |
| 49 | // the analyzer via command line (--analyze). |
| 50 | |
| 51 | pdbg_targets_init(nullptr); // nullptr == use default fdt |
| 52 | |
Ben Tyner | d3cda74 | 2020-05-04 08:00:28 -0500 | [diff] [blame] | 53 | // Either analyze (application mode) or daemon mode |
| 54 | if (true == getCliOption(argv, argv + argc, "--analyze")) |
| 55 | { |
Zane Shelley | ebff0d3 | 2021-11-21 10:52:07 -0600 | [diff] [blame] | 56 | // Analyze the host hardware. |
| 57 | // TODO: At the moment, we'll only do MANUAL analysis (no service |
| 58 | // actions). It may be possible in the future to allow command |
| 59 | // line options to change the analysis type, if needed. |
| 60 | |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 61 | attn::DumpParameters dumpParameters; |
Zane Shelley | ebff0d3 | 2021-11-21 10:52:07 -0600 | [diff] [blame] | 62 | analyzer::analyzeHardware(analyzer::AnalysisType::MANUAL, |
| 63 | dumpParameters); |
Ben Tyner | d3cda74 | 2020-05-04 08:00:28 -0500 | [diff] [blame] | 64 | } |
| 65 | // daemon mode |
| 66 | else |
| 67 | { |
| 68 | if (true == getCliOption(argv, argv + argc, "--daemon")) |
| 69 | { |
| 70 | attn::Config attnConfig; // default config |
| 71 | |
Ben Tyner | e4f5dbe | 2020-10-19 07:19:33 -0500 | [diff] [blame] | 72 | // convert remaining cmd line args to config values |
| 73 | parseConfig(argv, argv + argc, &attnConfig); |
| 74 | |
Ben Tyner | d70033a | 2020-06-09 15:59:29 -0500 | [diff] [blame] | 75 | attn::attnHandler(&attnConfig); // handle pending attentions |
Ben Tyner | 117af99 | 2020-05-22 13:32:11 -0500 | [diff] [blame] | 76 | |
Ben Tyner | d3cda74 | 2020-05-04 08:00:28 -0500 | [diff] [blame] | 77 | attn::attnDaemon(&attnConfig); // start daemon |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | return rc; |
| 83 | } |