phal: Added proc-pre-poweroff support

Changes:
-Adding new service which will be called during
chassis poweroff.

Test:
-Did poweroff to check, if the service file
is getting picked up or not and new added
procedure is getting called.

Signed-off-by: Chirag Sharma <chirshar@in.ibm.com>
Signed-off-by: Ramesh Iyyar <rameshi1@in.ibm.com>
Change-Id: Ic533433c4771216e5681b61cccf154f7ed029457
diff --git a/procedures/phal/common_utils.cpp b/procedures/phal/common_utils.cpp
new file mode 100644
index 0000000..99daa7b
--- /dev/null
+++ b/procedures/phal/common_utils.cpp
@@ -0,0 +1,49 @@
+extern "C"
+{
+#include <libpdbg.h>
+}
+
+#include "phalerror/phal_error.hpp"
+#include "procedures/phal/common_utils.hpp"
+
+#include <libekb.H>
+
+#include <phosphor-logging/log.hpp>
+
+namespace openpower
+{
+namespace phal
+{
+
+using namespace phosphor::logging;
+
+void phal_init(enum ipl_mode mode)
+{
+    // TODO: Setting boot error callback should not be in common code
+    //       because, we wont get proper reason in PEL for failure.
+    //       So, need to make code like caller of this function pass error
+    //       handling callback.
+    // add callback methods for debug traces and for boot failures
+    openpower::pel::addBootErrorCallbacks();
+
+    if (!pdbg_targets_init(NULL))
+    {
+        log<level::ERR>("pdbg_targets_init failed");
+        throw std::runtime_error("pdbg target initialization failed");
+    }
+
+    if (libekb_init())
+    {
+        log<level::ERR>("libekb_init failed");
+        throw std::runtime_error("libekb initialization failed");
+    }
+
+    if (ipl_init(mode) != 0)
+    {
+        log<level::ERR>("ipl_init failed");
+        throw std::runtime_error("libipl initialization failed");
+    }
+}
+
+} // namespace phal
+} // namespace openpower