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