1 #include <libpdbg.h> 2 3 #include <analyzer/analyzer_main.hpp> 4 #include <attn/attention.hpp> 5 #include <attn/attn_config.hpp> 6 #include <attn/attn_dump.hpp> 7 #include <attn/attn_handler.hpp> 8 #include <attn/attn_main.hpp> 9 #include <buildinfo.hpp> 10 #include <cli.hpp> 11 #include <util/pdbg_callback.hpp> 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"); 37 printf("hwdiag: %s, hei: %s\n", BUILDINFO, analyzer::getBuildInfo()); 38 } 39 else 40 { 41 // set PDBG log callback function. 42 pdbg_set_logfunc(util::pdbg_log_callback); 43 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 52 // Either analyze (application mode) or daemon mode 53 if (true == getCliOption(argv, argv + argc, "--analyze")) 54 { 55 attn::DumpParameters dumpParameters; 56 analyzer::analyzeHardware(dumpParameters); // analyze hardware 57 } 58 // daemon mode 59 else 60 { 61 if (true == getCliOption(argv, argv + argc, "--daemon")) 62 { 63 attn::Config attnConfig; // default config 64 65 // convert remaining cmd line args to config values 66 parseConfig(argv, argv + argc, &attnConfig); 67 68 attn::attnHandler(&attnConfig); // handle pending attentions 69 70 attn::attnDaemon(&attnConfig); // start daemon 71 } 72 } 73 } 74 75 return rc; 76 } 77