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