blob: 16baa36805d45f0eb3f97b0c55c6bd47a2bf692b [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>
11
12/**
13 * @brief Attention handler application main()
14 *
15 * This is the main interface to the hardware diagnostics application. This
16 * application can be loaded as a daemon for monitoring the attention
17 * gpio or it can be loaded as an application to analyze hardware and
18 * diagnose hardware error conditions.
19 *
20 * Usage:
21 * --analyze: Analyze the hardware
22 * --daemon: Start the attention handler daemon
23 *
24 * @return 0 = success
25 */
26int main(int argc, char* argv[])
27{
28 int rc = 0; // assume success
29
30 if (argc == 1)
31 {
32 printf("openpower-hw-diags <options>\n");
33 printf("options:\n");
34 printf(" --analyze: Analyze the hardware\n");
35 printf(" --daemon: Start the attn handler daemon\n");
Ben Tynereea45422021-04-15 10:54:14 -050036 printf("hwdiag: %s, hei: %s\n", BUILDINFO, analyzer::getBuildInfo());
Ben Tynerd3cda742020-05-04 08:00:28 -050037 }
38 else
39 {
Ben Tyner87eabc62020-05-14 17:56:54 -050040 // Pdbg targets should only be initialized once according to
41 // libpdbg documentation. Initializing them here will make sure
42 // they are initialized for the attention handler, invocation of
43 // the analyzer via attention handler and direct invocation of
44 // the analyzer via command line (--analyze).
45
46 pdbg_targets_init(nullptr); // nullptr == use default fdt
47
Ben Tynerd3cda742020-05-04 08:00:28 -050048 // Either analyze (application mode) or daemon mode
49 if (true == getCliOption(argv, argv + argc, "--analyze"))
50 {
Ben Tyner7029e522021-08-09 19:18:24 -050051 attn::DumpParameters dumpParameters;
52 rc = analyzer::analyzeHardware(dumpParameters); // analyze hardware
Ben Tynerd3cda742020-05-04 08:00:28 -050053 }
54 // daemon mode
55 else
56 {
57 if (true == getCliOption(argv, argv + argc, "--daemon"))
58 {
59 attn::Config attnConfig; // default config
60
Ben Tynere4f5dbe2020-10-19 07:19:33 -050061 // convert remaining cmd line args to config values
62 parseConfig(argv, argv + argc, &attnConfig);
63
Ben Tynerd70033a2020-06-09 15:59:29 -050064 attn::attnHandler(&attnConfig); // handle pending attentions
Ben Tyner117af992020-05-22 13:32:11 -050065
Ben Tynerd3cda742020-05-04 08:00:28 -050066 attn::attnDaemon(&attnConfig); // start daemon
67 }
68 }
69 }
70
71 return rc;
72}