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