blob: 3899924148d9fa975a7d606a653a08f9015bf2c3 [file] [log] [blame]
Ramesh Iyyarc98bab52020-04-16 04:04:29 -05001extern "C" {
2#include <libpdbg.h>
3}
4
Marri Devender Rao78479602020-01-06 03:45:11 -06005#include "phalerror/phal_error.hpp"
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -05006
Ramesh Iyyarc98bab52020-04-16 04:04:29 -05007#include <libekb.H>
Marri Devender Rao78479602020-01-06 03:45:11 -06008#include <libipl.H>
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -05009
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -050010#include <phosphor-logging/log.hpp>
11#include <registration.hpp>
12namespace openpower
13{
14namespace phal
15{
16
17using namespace phosphor::logging;
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -050018
19/**
20 * @brief Starts the self boot engine on POWER processor position 0
21 * to kick off a boot.
22 * @return void
23 */
24void startHost()
25{
Marri Devender Rao78479602020-01-06 03:45:11 -060026 // add callback methods for debug traces and for boot failures
27 openpower::pel::addBootErrorCallbacks();
28
Ramesh Iyyarc98bab52020-04-16 04:04:29 -050029 if (!pdbg_targets_init(NULL))
30 {
31 log<level::ERR>("pdbg_targets_init failed");
32 openpower::pel::detail::processBootErrorCallback(false);
33 throw std::runtime_error("pdbg target initialization failed");
34 }
35 // To clear trace if success
36 openpower::pel::detail::processBootErrorCallback(true);
37
38 if (libekb_init())
39 {
40 log<level::ERR>("libekb_init failed");
41 openpower::pel::detail::processBootErrorCallback(false);
42 throw std::runtime_error("libekb initialization failed");
43 }
44 // To clear trace if success
45 openpower::pel::detail::processBootErrorCallback(true);
46
47 if (ipl_init(IPL_AUTOBOOT) != 0)
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -050048 {
49 log<level::ERR>("ipl_init failed");
Ramesh Iyyarc98bab52020-04-16 04:04:29 -050050 openpower::pel::detail::processBootErrorCallback(false);
Marri Devender Rao78479602020-01-06 03:45:11 -060051 throw std::runtime_error("Boot initialization failed");
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -050052 }
Ramesh Iyyarc98bab52020-04-16 04:04:29 -050053 // To clear trace if success
54 openpower::pel::detail::processBootErrorCallback(true);
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -050055
Marri Devender Rao78479602020-01-06 03:45:11 -060056 // callback method will be called upon failure which will create the PEL
57 int rc = ipl_run_major(0);
58 if (rc > 0)
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -050059 {
60 log<level::ERR>("step 0 failed to start the host");
Marri Devender Rao78479602020-01-06 03:45:11 -060061 throw std::runtime_error("Failed to execute host start boot step");
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -050062 }
63}
64
65REGISTER_PROCEDURE("startHost", startHost);
66
67} // namespace phal
68} // namespace openpower