Chirag Sharma | a257693 | 2020-12-05 23:17:41 -0600 | [diff] [blame] | 1 | extern "C" |
| 2 | { |
| 3 | #include <libpdbg.h> |
| 4 | } |
| 5 | |
| 6 | #include "phalerror/phal_error.hpp" |
| 7 | #include "procedures/phal/common_utils.hpp" |
| 8 | |
Jayanth Othayoth | 583a9ed | 2021-06-29 05:42:45 -0500 | [diff] [blame] | 9 | #include <fmt/format.h> |
Chirag Sharma | a257693 | 2020-12-05 23:17:41 -0600 | [diff] [blame] | 10 | #include <libekb.H> |
| 11 | |
| 12 | #include <phosphor-logging/log.hpp> |
| 13 | |
| 14 | namespace openpower |
| 15 | { |
| 16 | namespace phal |
| 17 | { |
| 18 | |
| 19 | using namespace phosphor::logging; |
| 20 | |
| 21 | void 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 Othayoth | 583a9ed | 2021-06-29 05:42:45 -0500 | [diff] [blame] | 30 | // 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 Sharma | a257693 | 2020-12-05 23:17:41 -0600 | [diff] [blame] | 42 | 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 |