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;