1117af99bSBen Tyner #include <libpdbg.h>
2117af99bSBen Tyner
3d3cda742SBen Tyner #include <analyzer/analyzer_main.hpp>
4b1ebfcb1SBen Tyner #include <attn/attention.hpp>
5d3cda742SBen Tyner #include <attn/attn_config.hpp>
67029e525SBen Tyner #include <attn/attn_dump.hpp>
7b1ebfcb1SBen Tyner #include <attn/attn_handler.hpp>
8d3cda742SBen Tyner #include <attn/attn_main.hpp>
9eea45427SBen Tyner #include <buildinfo.hpp>
10d3cda742SBen Tyner #include <cli.hpp>
11*de220920SZane Shelley #include <hei_buildinfo.hpp>
126a62e40dSaustinfcui #include <util/pdbg_callback.hpp>
13d3cda742SBen Tyner
14d3cda742SBen Tyner /**
15d3cda742SBen Tyner * @brief Attention handler application main()
16d3cda742SBen Tyner *
17d3cda742SBen Tyner * This is the main interface to the hardware diagnostics application. This
18d3cda742SBen Tyner * application can be loaded as a daemon for monitoring the attention
19d3cda742SBen Tyner * gpio or it can be loaded as an application to analyze hardware and
20d3cda742SBen Tyner * diagnose hardware error conditions.
21d3cda742SBen Tyner *
22d3cda742SBen Tyner * Usage:
23d3cda742SBen Tyner * --analyze: Analyze the hardware
24d3cda742SBen Tyner * --daemon: Start the attention handler daemon
25d3cda742SBen Tyner *
26d3cda742SBen Tyner * @return 0 = success
27d3cda742SBen Tyner */
main(int argc,char * argv[])28d3cda742SBen Tyner int main(int argc, char* argv[])
29d3cda742SBen Tyner {
30d3cda742SBen Tyner int rc = 0; // assume success
31d3cda742SBen Tyner
32d3cda742SBen Tyner if (argc == 1)
33d3cda742SBen Tyner {
34d3cda742SBen Tyner printf("openpower-hw-diags <options>\n");
35d3cda742SBen Tyner printf("options:\n");
36d3cda742SBen Tyner printf(" --analyze: Analyze the hardware\n");
37d3cda742SBen Tyner printf(" --daemon: Start the attn handler daemon\n");
38*de220920SZane Shelley printf("hwdiag: %s, hei: %s\n", BUILDINFO, libhei::getBuildInfo());
39d3cda742SBen Tyner }
40d3cda742SBen Tyner else
41d3cda742SBen Tyner {
426a62e40dSaustinfcui // set PDBG log callback function.
436a62e40dSaustinfcui pdbg_set_logfunc(util::pdbg_log_callback);
446a62e40dSaustinfcui
4587eabc65SBen Tyner // Pdbg targets should only be initialized once according to
4687eabc65SBen Tyner // libpdbg documentation. Initializing them here will make sure
4787eabc65SBen Tyner // they are initialized for the attention handler, invocation of
4887eabc65SBen Tyner // the analyzer via attention handler and direct invocation of
4987eabc65SBen Tyner // the analyzer via command line (--analyze).
5087eabc65SBen Tyner
5187eabc65SBen Tyner pdbg_targets_init(nullptr); // nullptr == use default fdt
5287eabc65SBen Tyner
53d3cda742SBen Tyner // Either analyze (application mode) or daemon mode
54d3cda742SBen Tyner if (true == getCliOption(argv, argv + argc, "--analyze"))
55d3cda742SBen Tyner {
56ebff0d37SZane Shelley // Analyze the host hardware.
57ebff0d37SZane Shelley // TODO: At the moment, we'll only do MANUAL analysis (no service
58ebff0d37SZane Shelley // actions). It may be possible in the future to allow command
59ebff0d37SZane Shelley // line options to change the analysis type, if needed.
60ebff0d37SZane Shelley
617029e525SBen Tyner attn::DumpParameters dumpParameters;
62ebff0d37SZane Shelley analyzer::analyzeHardware(analyzer::AnalysisType::MANUAL,
63ebff0d37SZane Shelley dumpParameters);
64d3cda742SBen Tyner }
65d3cda742SBen Tyner // daemon mode
66d3cda742SBen Tyner else
67d3cda742SBen Tyner {
68d3cda742SBen Tyner if (true == getCliOption(argv, argv + argc, "--daemon"))
69d3cda742SBen Tyner {
70d3cda742SBen Tyner attn::Config attnConfig; // default config
71d3cda742SBen Tyner
72e4f5dbefSBen Tyner // convert remaining cmd line args to config values
73e4f5dbefSBen Tyner parseConfig(argv, argv + argc, &attnConfig);
74e4f5dbefSBen Tyner
75d70033a5SBen Tyner attn::attnHandler(&attnConfig); // handle pending attentions
76117af99bSBen Tyner
77d3cda742SBen Tyner attn::attnDaemon(&attnConfig); // start daemon
78d3cda742SBen Tyner }
79d3cda742SBen Tyner }
80d3cda742SBen Tyner }
81d3cda742SBen Tyner
82d3cda742SBen Tyner return rc;
83d3cda742SBen Tyner }
84