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