PHAL: export devtree attribute support
Added function to export devtree data based on the
filter file using attributes tool based infrastructure.
Data is stored in pre defined location in BMC to restore
in the reboot path.
Tested: verified devtree data exported manually.
Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
Change-Id: I9c708483708f443a910e272615ec4c66b31e2603
diff --git a/extensions/phal/fw_update_watch.cpp b/extensions/phal/fw_update_watch.cpp
index a49cc9c..af9dd3f 100644
--- a/extensions/phal/fw_update_watch.cpp
+++ b/extensions/phal/fw_update_watch.cpp
@@ -1,10 +1,22 @@
+#include "config.h"
+
#include "fw_update_watch.hpp"
-#include <fmt/format.h>
+#include "common_utils.hpp"
+#include "create_pel.hpp"
+#include "pdbg_utils.hpp"
+#include <fmt/format.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
#include <sdbusplus/exception.hpp>
+#include <filesystem>
+
namespace openpower
{
namespace phal
@@ -12,6 +24,8 @@
namespace fwupdate
{
using namespace phosphor::logging;
+namespace fs = std::filesystem;
+
using Message = std::string;
using Attributes = std::variant<Message>;
using PropertyName = std::string;
@@ -72,15 +86,90 @@
// Device tree data collection is required only for the first trigger
setSoftwareUpdateProgress(true);
- // Colect device tree data
- openpower::phal::fwupdate::exportDevtree();
+ try
+ {
+ // Colect device tree data
+ openpower::phal::fwupdate::exportDevtree();
+ }
+ catch (fs::filesystem_error& e)
+ {
+ log<level::ERR>(
+ fmt::format("Filesystem error reported Error:({})", e.what())
+ .c_str());
+ throw std::runtime_error(e.what());
+ }
+
+ log<level::INFO>("Successfully exported devtree attribute data");
}
return;
}
void exportDevtree()
-{}
+{
+ constexpr auto ERROR_DEVTREE_BACKUP =
+ "org.open_power.PHAL.Error.devtreeBackup";
+
+ // Check devtree export filter file is present
+ auto path = fs::path(DEVTREE_EXPORT_FILTER_FILE);
+ if (!fs::exists(path))
+ {
+ log<level::ERR>(
+ fmt::format("devtree export filter file is not available: ({})",
+ DEVTREE_EXPORT_FILTER_FILE)
+ .c_str());
+ openpower::pel::createPEL(ERROR_DEVTREE_BACKUP);
+ return;
+ }
+
+ // delete export data file if present
+ auto expFile = fs::path(DEVTREE_EXP_FILE);
+ if (fs::exists(expFile))
+ {
+ fs::remove_all(expFile);
+ }
+ else
+ {
+ // create directory
+ fs::create_directory(expFile.parent_path());
+ }
+
+ // Update PDBG_DTB value
+ openpower::phal::setDevtreeEnv();
+
+ int status = 0;
+ pid_t pid = fork();
+ if (pid == 0)
+ {
+ std::string cmd("/usr/bin/attributes ");
+ cmd += "export ";
+ cmd += DEVTREE_EXPORT_FILTER_FILE;
+ cmd += " > ";
+ cmd += DEVTREE_EXP_FILE;
+ execl("/bin/sh", "sh", "-c", cmd.c_str(), 0);
+
+ auto error = errno;
+ log<level::ERR>(fmt::format("Error occurred during attributes function "
+ "execution, errno({})",
+ error)
+ .c_str());
+ // Creating PEL at one place.
+ }
+ else if (pid > 0)
+ {
+ waitpid(pid, &status, 0);
+ if (WEXITSTATUS(status))
+ {
+ log<level::ERR>("Failed to collect attribute export data");
+ openpower::pel::createPEL(ERROR_DEVTREE_BACKUP);
+ }
+ }
+ else
+ {
+ log<level::ERR>("exportDevtree fork() failed");
+ std::runtime_error("exportDevtree fork() failed");
+ }
+}
} // namespace fwupdate
} // namespace phal
diff --git a/meson.build b/meson.build
index c1ff741..8a2d7bd 100644
--- a/meson.build
+++ b/meson.build
@@ -27,6 +27,21 @@
extra_dependencies = []
extra_unit_files = []
+# Configuration header file(config.h) generation
+conf_data = configuration_data()
+
+conf_data.set_quoted('DEVTREE_EXPORT_FILTER_FILE', get_option('DEVTREE_EXPORT_FILTER_FILE'),
+ description : 'Path to the phal devtree export filter file'
+ )
+
+conf_data.set_quoted('DEVTREE_EXP_FILE', get_option('DEVTREE_EXP_FILE'),
+ description : 'Path to the devtree export copy file'
+ )
+
+configure_file(configuration : conf_data,
+ output : 'config.h'
+ )
+
unit_subs = configuration_data()
unit_subs.set('bindir', join_paths(get_option('prefix'), get_option('bindir')))
unit_subs.set('ENABLE_PHAL_TRUE', '#')
@@ -133,12 +148,17 @@
[
'extensions/phal/devtree_export.cpp',
'extensions/phal/fw_update_watch.cpp',
+ 'extensions/phal/pdbg_utils.cpp',
+ 'extensions/phal/create_pel.cpp',
+ 'util.cpp',
],
dependencies: [
dependency('phosphor-logging'),
dependency('sdbusplus'),
dependency('sdeventplus'),
dependency('fmt'),
+ dependency('phosphor-dbus-interfaces'),
+ cxx.find_library('pdbg'),
],
install: true
)
diff --git a/meson_options.txt b/meson_options.txt
index 60c1f97..36117a6 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -2,3 +2,12 @@
option('p9', type: 'feature', description: 'Enable support for POWER9')
option('openfsi', type: 'feature', description: 'Enable support for OpenFSI')
option('phal', type: 'feature', description: 'Enable support for PHAL')
+
+option('DEVTREE_EXPORT_FILTER_FILE', type : 'string',
+ value : '/usr/share/pdata/preserved_attrs_list',
+ description : 'Path to the phal devtree export filter file'
+)
+option('DEVTREE_EXP_FILE', type : 'string',
+ value : '/var/lib/phal/exportdevtree',
+ description : 'Path to the devtree export copy file'
+)