generate bmc dump if hw indicates host running

This situation has been hit a few times and it has been requested a BMC
dump be generated when the condition is hit. This dump will help debug
why the BMC is unable to communicate with the host.

Tested:
- Caused the error path and verified a BMC dump was requested

Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: I44cc4066b9b7c4eddb04348c2caf6493fb3af31a
diff --git a/procedures/phal/check_host_running.cpp b/procedures/phal/check_host_running.cpp
index d096193..69bf422 100644
--- a/procedures/phal/check_host_running.cpp
+++ b/procedures/phal/check_host_running.cpp
@@ -10,6 +10,7 @@
 #include "registration.hpp"
 
 #include <phosphor-logging/log.hpp>
+#include <sdbusplus/bus.hpp>
 
 #include <cstdio>
 #include <fstream>
@@ -23,6 +24,30 @@
 using namespace openpower::cfam::p10;
 using namespace phosphor::logging;
 
+/** Best effort function to create a BMC dump */
+void createBmcDump()
+{
+    auto bus = sdbusplus::bus::new_default();
+
+    auto method = bus.new_method_call(
+        "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump/bmc",
+        "xyz.openbmc_project.Dump.Create", "CreateDump");
+    method.append(
+        std::vector<
+            std::pair<std::string, std::variant<std::string, uint64_t>>>());
+    try
+    {
+        bus.call_noreply(method);
+    }
+    catch (const sdbusplus::exception_t& e)
+    {
+        log<level::ERR>("Exception raised creating BMC dump",
+                        entry("EXCEPTION=%s", e.what()));
+        // just continue, failing to collect a dump should not cause further
+        // issues in this path
+    }
+}
+
 /**
  * This is the backup plan to ensuring the host is not running before the
  * BMC issues a power off to the system. Prior to this procedure being called,
@@ -96,6 +121,10 @@
         std::snprintf(buf.get(), size, HOST_RUNNING_FILE, 0);
         std::ofstream outfile(buf.get());
         outfile.close();
+
+        // Try to create BMC dump for further debug
+        createBmcDump();
+
         return;
     }