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