blob: 4ead47494744644ead6d70e1cd76284b22f1334a [file] [log] [blame]
Chirag Sharmaa2576932020-12-05 23:17:41 -06001extern "C"
2{
3#include <libpdbg.h>
4}
5
6#include "phalerror/phal_error.hpp"
7#include "procedures/phal/common_utils.hpp"
8
Jayanth Othayoth583a9ed2021-06-29 05:42:45 -05009#include <fmt/format.h>
Chirag Sharmaa2576932020-12-05 23:17:41 -060010#include <libekb.H>
11
12#include <phosphor-logging/log.hpp>
13
14namespace openpower
15{
16namespace phal
17{
18
19using namespace phosphor::logging;
20
21void phal_init(enum ipl_mode mode)
22{
23 // TODO: Setting boot error callback should not be in common code
24 // because, we wont get proper reason in PEL for failure.
25 // So, need to make code like caller of this function pass error
26 // handling callback.
27 // add callback methods for debug traces and for boot failures
28 openpower::pel::addBootErrorCallbacks();
29
Jayanth Othayoth583a9ed2021-06-29 05:42:45 -050030 // PDBG_DTB environment variable set to CEC device tree path
31 static constexpr auto PDBG_DTB_PATH =
32 "/var/lib/phosphor-software-manager/pnor/rw/DEVTREE";
33
34 if (setenv("PDBG_DTB", PDBG_DTB_PATH, 1))
35 {
36 log<level::ERR>(
37 fmt::format("Failed to set PDBG_DTB: ({})", strerror(errno))
38 .c_str());
39 throw std::runtime_error("Failed to set PDBG_DTB");
40 }
41
Chirag Sharmaa2576932020-12-05 23:17:41 -060042 if (!pdbg_targets_init(NULL))
43 {
44 log<level::ERR>("pdbg_targets_init failed");
45 throw std::runtime_error("pdbg target initialization failed");
46 }
47
48 if (libekb_init())
49 {
50 log<level::ERR>("libekb_init failed");
51 throw std::runtime_error("libekb initialization failed");
52 }
53
54 if (ipl_init(mode) != 0)
55 {
56 log<level::ERR>("ipl_init failed");
57 throw std::runtime_error("libipl initialization failed");
58 }
59}
60
61} // namespace phal
62} // namespace openpower