PHAL: added createSbePEL wrapper function

Added wrapper function to create SBE PEL based on event type
and user provided additional SBE provided FFDC information

Refer phosphor-logging/extensions/openpower-pels/README.md section
"Self Boot Engine(SBE) First Failure Data Capture(FFDC) Support"
for details on this implementation.

Tested: verified PEL log

Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
Change-Id: Ice41e224d92a773090d601d3154b4c30bdd09c02
diff --git a/extensions/phal/create_pel.cpp b/extensions/phal/create_pel.cpp
index 14d796d..c10f32c 100644
--- a/extensions/phal/create_pel.cpp
+++ b/extensions/phal/create_pel.cpp
@@ -86,6 +86,64 @@
     }
 }
 
+void createSbeErrorPEL(const std::string& event, const sbeError_t& sbeError,
+                       const FFDCData& ffdcData)
+{
+    std::map<std::string, std::string> additionalData;
+    auto bus = sdbusplus::bus::new_default();
+
+    additionalData.emplace("_PID", std::to_string(getpid()));
+    additionalData.emplace("SBE_ERR_MSG", sbeError.what());
+
+    for (auto& data : ffdcData)
+    {
+        additionalData.emplace(data);
+    }
+
+    std::vector<std::tuple<
+        sdbusplus::xyz::openbmc_project::Logging::server::Create::FFDCFormat,
+        uint8_t, uint8_t, sdbusplus::message::unix_fd>>
+        pelFFDCInfo;
+
+    // Refer phosphor-logging/extensions/openpower-pels/README.md section
+    // "Self Boot Engine(SBE) First Failure Data Capture(FFDC) Support"
+    // for details of related to createPEL with SBE FFDC information
+    // usin g CreateWithFFDCFiles api.
+    pelFFDCInfo.push_back(
+        std::make_tuple(sdbusplus::xyz::openbmc_project::Logging::server::
+                            Create::FFDCFormat::Custom,
+                        static_cast<uint8_t>(0xCB), static_cast<uint8_t>(0x01),
+                        sbeError.getFd()));
+    try
+    {
+        std::string service =
+            util::getService(bus, loggingObjectPath, loggingInterface);
+        auto method =
+            bus.new_method_call(service.c_str(), loggingObjectPath,
+                                loggingInterface, "CreateWithFFDCFiles");
+        auto level =
+            sdbusplus::xyz::openbmc_project::Logging::server::convertForMessage(
+                sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level::
+                    Error);
+        method.append(event, level, additionalData, pelFFDCInfo);
+        auto resp = bus.call(method);
+    }
+    catch (const sdbusplus::exception::exception& e)
+    {
+        log<level::ERR>(fmt::format("D-Bus call exception",
+                                    "OBJPATH={}, INTERFACE={}, EXCEPTION={}",
+                                    loggingObjectPath, loggingInterface,
+                                    e.what())
+                            .c_str());
+        throw std::runtime_error(
+            "Error in invoking D-Bus logging create interface");
+    }
+    catch (std::exception& e)
+    {
+        throw e;
+    }
+}
+
 void createPEL(const std::string& event, const FFDCData& ffdcData)
 {
     std::map<std::string, std::string> additionalData;
diff --git a/extensions/phal/create_pel.hpp b/extensions/phal/create_pel.hpp
index 0081c68..e6d49a5 100644
--- a/extensions/phal/create_pel.hpp
+++ b/extensions/phal/create_pel.hpp
@@ -1,5 +1,7 @@
 #pragma once
 
+#include <phal_exception.H>
+
 #include <nlohmann/json.hpp>
 
 #include <string>
@@ -12,8 +14,10 @@
 
 using json = nlohmann::json;
 
+using namespace openpower::phal;
+
 /**
- * Create boot error PEL
+ * @brief Create boot error PEL
  *
  * @param[in] ffdcData - failure data to append to PEL
  * @param[in] calloutData - callout data to append to PEL
@@ -21,9 +25,19 @@
 void createBootErrorPEL(const FFDCData& ffdcData, const json& calloutData);
 
 /**
+ * @brief Create SBE boot error PEL
+ *
+ * @param[in] event - the event type
+ * @param[in] sbeError - SBE error object
+ * @param[in] ffdcData - failure data to append to PEL
+ */
+void createSbeErrorPEL(const std::string& event, const sbeError_t& sbeError,
+                       const FFDCData& ffdcData);
+
+/**
  * @brief Create a PEL for the specified event type and additional data
  *
- *  @param  event - the event type
+ *  @param[in]  event - the event type
  *  @param[in] ffdcData - failure data to append to PEL
  */
 void createPEL(const std::string& event, const FFDCData& ffdcData = {});