| #include "config.h" |
| |
| #include "extensions/phal/create_pel.hpp" |
| #include "extensions/phal/pdbg_utils.hpp" |
| #include "registration.hpp" |
| |
| #include <fmt/format.h> |
| #include <sys/wait.h> |
| #include <unistd.h> |
| |
| #include <phosphor-logging/elog-errors.hpp> |
| #include <phosphor-logging/elog.hpp> |
| #include <phosphor-logging/log.hpp> |
| #include <xyz/openbmc_project/Common/error.hpp> |
| |
| #include <filesystem> |
| |
| namespace openpower |
| { |
| namespace phal |
| { |
| |
| using namespace phosphor::logging; |
| |
| void importDevtree() |
| { |
| namespace fs = std::filesystem; |
| |
| // check import data file is present |
| auto path = fs::path(DEVTREE_EXP_FILE); |
| if (!fs::exists(path)) |
| { |
| // No import data file skip devtree import |
| return; |
| } |
| |
| // Update PDBG_DTB value |
| openpower::phal::setDevtreeEnv(); |
| |
| // Update PDATA_INFODB value |
| openpower::phal::setPdataInfoDBEnv(); |
| |
| int status = 0; |
| pid_t pid = fork(); |
| if (pid == 0) |
| { |
| std::string cmd("/usr/bin/attributes "); |
| cmd += "import "; |
| cmd += DEVTREE_EXP_FILE; |
| cmd += " 2>"; |
| cmd += " /dev/null"; |
| execl("/bin/sh", "sh", "-c", cmd.c_str(), 0); |
| |
| auto error = errno; |
| log<level::ERR>(fmt::format("Error occurred during attributes import " |
| "execution, errno({})", |
| error) |
| .c_str()); |
| } |
| else if (pid > 0) |
| { |
| waitpid(pid, &status, 0); |
| if (WEXITSTATUS(status)) |
| { |
| log<level::ERR>("Failed to import attribute data"); |
| openpower::pel::createPEL("org.open_power.PHAL.Error.devtreeSync"); |
| return; |
| } |
| } |
| else |
| { |
| log<level::ERR>("fork() failed."); |
| throw std::runtime_error("importDevtree: fork() failed."); |
| } |
| |
| try |
| { |
| // Delete attribute data file once updated. |
| if (fs::exists(path)) |
| { |
| // delete export data file |
| fs::remove_all(path); |
| } |
| } |
| catch (fs::filesystem_error& e) |
| { // Log message and continue. Data already applied successfully. |
| log<level::ERR>(fmt::format("File({}) delete failed Error:({})", |
| DEVTREE_EXP_FILE, e.what()) |
| .c_str()); |
| } |
| |
| log<level::INFO>("Successfully imported devtree attribute data"); |
| } |
| |
| REGISTER_PROCEDURE("importDevtree", importDevtree) |
| |
| } // namespace phal |
| } // namespace openpower |