blob: ced828c000a145f90c2e51b3fdc9591ed3643a9b [file] [log] [blame]
Ben Tyner117af992020-05-22 13:32:11 -05001#include <libpdbg.h>
2
Ben Tynerd3cda742020-05-04 08:00:28 -05003#include <analyzer/analyzer_main.hpp>
Ben Tynerb1ebfcb2020-05-08 18:52:48 -05004#include <attn/attention.hpp>
Ben Tynerd3cda742020-05-04 08:00:28 -05005#include <attn/attn_config.hpp>
Ben Tyner7029e522021-08-09 19:18:24 -05006#include <attn/attn_dump.hpp>
Ben Tynerb1ebfcb2020-05-08 18:52:48 -05007#include <attn/attn_handler.hpp>
Ben Tynerd3cda742020-05-04 08:00:28 -05008#include <attn/attn_main.hpp>
Ben Tynereea45422021-04-15 10:54:14 -05009#include <buildinfo.hpp>
Ben Tynerd3cda742020-05-04 08:00:28 -050010#include <cli.hpp>
Zane Shelleyde220922022-12-05 22:10:43 -060011#include <hei_buildinfo.hpp>
austinfcui6a62e402021-12-01 11:52:45 -060012#include <util/pdbg_callback.hpp>
Ben Tynerd3cda742020-05-04 08:00:28 -050013
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 */
28int 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 Shelleyde220922022-12-05 22:10:43 -060038 printf("hwdiag: %s, hei: %s\n", BUILDINFO, libhei::getBuildInfo());
Ben Tynerd3cda742020-05-04 08:00:28 -050039 }
40 else
41 {
austinfcui6a62e402021-12-01 11:52:45 -060042 // set PDBG log callback function.
43 pdbg_set_logfunc(util::pdbg_log_callback);
44
Ben Tyner87eabc62020-05-14 17:56:54 -050045 // 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 Tynerd3cda742020-05-04 08:00:28 -050053 // Either analyze (application mode) or daemon mode
54 if (true == getCliOption(argv, argv + argc, "--analyze"))
55 {
Zane Shelleyebff0d32021-11-21 10:52:07 -060056 // 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 Tyner7029e522021-08-09 19:18:24 -050061 attn::DumpParameters dumpParameters;
Zane Shelleyebff0d32021-11-21 10:52:07 -060062 analyzer::analyzeHardware(analyzer::AnalysisType::MANUAL,
63 dumpParameters);
Ben Tynerd3cda742020-05-04 08:00:28 -050064 }
65 // daemon mode
66 else
67 {
68 if (true == getCliOption(argv, argv + argc, "--daemon"))
69 {
70 attn::Config attnConfig; // default config
71
Ben Tynere4f5dbe2020-10-19 07:19:33 -050072 // convert remaining cmd line args to config values
73 parseConfig(argv, argv + argc, &attnConfig);
74
Ben Tynerd70033a2020-06-09 15:59:29 -050075 attn::attnHandler(&attnConfig); // handle pending attentions
Ben Tyner117af992020-05-22 13:32:11 -050076
Patrick Williams27dd6362023-05-10 07:51:20 -050077 attn::attnDaemon(&attnConfig); // start daemon
Ben Tynerd3cda742020-05-04 08:00:28 -050078 }
79 }
80 }
81
82 return rc;
83}