blob: d66e378522291bba28b39cf685bb9f00ffb57b54 [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 Tynerb1ebfcb2020-05-08 18:52:48 -05006#include <attn/attn_handler.hpp>
Ben Tynerd3cda742020-05-04 08:00:28 -05007#include <attn/attn_main.hpp>
8#include <cli.hpp>
9
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050010// FIXME TEMP CODE - begin
11
12namespace attn
13{
14int handleCheckstop(Attention* i_attention);
15} // namespace attn
16
17// FIXME TEMP CODE - end
18
19//
Ben Tynerd3cda742020-05-04 08:00:28 -050020/**
21 * @brief Attention handler application main()
22 *
23 * This is the main interface to the hardware diagnostics application. This
24 * application can be loaded as a daemon for monitoring the attention
25 * gpio or it can be loaded as an application to analyze hardware and
26 * diagnose hardware error conditions.
27 *
28 * Usage:
29 * --analyze: Analyze the hardware
30 * --daemon: Start the attention handler daemon
31 *
32 * @return 0 = success
33 */
34int main(int argc, char* argv[])
35{
36 int rc = 0; // assume success
37
38 if (argc == 1)
39 {
40 printf("openpower-hw-diags <options>\n");
41 printf("options:\n");
42 printf(" --analyze: Analyze the hardware\n");
43 printf(" --daemon: Start the attn handler daemon\n");
44 }
45 else
46 {
Ben Tyner87eabc62020-05-14 17:56:54 -050047 // Pdbg targets should only be initialized once according to
48 // libpdbg documentation. Initializing them here will make sure
49 // they are initialized for the attention handler, invocation of
50 // the analyzer via attention handler and direct invocation of
51 // the analyzer via command line (--analyze).
52
53 pdbg_targets_init(nullptr); // nullptr == use default fdt
54
Ben Tynerd3cda742020-05-04 08:00:28 -050055 // Either analyze (application mode) or daemon mode
56 if (true == getCliOption(argv, argv + argc, "--analyze"))
57 {
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050058 // errors that were isolated
59 std::map<std::string, std::string> errors;
60
61 rc = analyzer::analyzeHardware(errors); // analyze hardware
62
Ben Tyner87eabc62020-05-14 17:56:54 -050063 printf("analyzer isolated %i error(s)\n", (int)errors.size());
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 Tyner117af992020-05-22 13:32:11 -050072 pdbg_targets_init(nullptr); // initialize pdbg targets
73
Ben Tynerd3cda742020-05-04 08:00:28 -050074 attn::attnDaemon(&attnConfig); // start daemon
75 }
76 }
77 }
78
79 return rc;
80}