blob: ff71fd8e59896c01234b1e8bcdf5f56d47bad5ea [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>
austinfcui6a62e402021-12-01 11:52:45 -060011#include <util/pdbg_callback.hpp>
Ben Tynerd3cda742020-05-04 08:00:28 -050012
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 */
27int 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 Tynereea45422021-04-15 10:54:14 -050037 printf("hwdiag: %s, hei: %s\n", BUILDINFO, analyzer::getBuildInfo());
Ben Tynerd3cda742020-05-04 08:00:28 -050038 }
39 else
40 {
austinfcui6a62e402021-12-01 11:52:45 -060041 // set PDBG log callback function.
42 pdbg_set_logfunc(util::pdbg_log_callback);
43
Ben Tyner87eabc62020-05-14 17:56:54 -050044 // 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 Tynerd3cda742020-05-04 08:00:28 -050052 // Either analyze (application mode) or daemon mode
53 if (true == getCliOption(argv, argv + argc, "--analyze"))
54 {
Zane Shelleyebff0d32021-11-21 10:52:07 -060055 // 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 Tyner7029e522021-08-09 19:18:24 -050060 attn::DumpParameters dumpParameters;
Zane Shelleyebff0d32021-11-21 10:52:07 -060061 analyzer::analyzeHardware(analyzer::AnalysisType::MANUAL,
62 dumpParameters);
Ben Tynerd3cda742020-05-04 08:00:28 -050063 }
64 // daemon mode
65 else
66 {
67 if (true == getCliOption(argv, argv + argc, "--daemon"))
68 {
69 attn::Config attnConfig; // default config
70
Ben Tynere4f5dbe2020-10-19 07:19:33 -050071 // convert remaining cmd line args to config values
72 parseConfig(argv, argv + argc, &attnConfig);
73
Ben Tynerd70033a2020-06-09 15:59:29 -050074 attn::attnHandler(&attnConfig); // handle pending attentions
Ben Tyner117af992020-05-22 13:32:11 -050075
Ben Tynerd3cda742020-05-04 08:00:28 -050076 attn::attnDaemon(&attnConfig); // start daemon
77 }
78 }
79 }
80
81 return rc;
82}