summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2018-05-01 15:13:53 -0500
committerMatt Spinler <spinler@us.ibm.com>2018-05-01 15:31:46 -0500
commit1275bd13cc207167b489f661d10a7263b211bbcb (patch)
tree198f0a845ba7dd9e930a5cd207326326d3a33934
parent5f4247f05d528345c56ca64a97d3ba571f26611d (diff)
downloadphosphor-logging-1275bd13cc207167b489f661d10a7263b211bbcb.tar.gz
phosphor-logging-1275bd13cc207167b489f661d10a7263b211bbcb.zip
Add function to read code version
Read the BMC code version once at startup. This will be added to error logs in future commits. The code is getting the version from a file instead of from D-Bus in order to reduce dependencies. Tested: Call the function and check that it returned the correct thing. Change-Id: I9a4729e946a130ec32c375c283fd22a7658121f5 Signed-off-by: Matt Spinler <spinler@us.ibm.com>
-rw-r--r--configure.ac1
-rw-r--r--log_manager.cpp25
-rw-r--r--log_manager.hpp12
3 files changed, 37 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 9e40b41..2e4cdd1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -75,6 +75,7 @@ AC_DEFINE(OBJ_ENTRY, "/xyz/openbmc_project/logging/entry", [The log entry DBus o
AC_DEFINE(INVENTORY_ROOT, "/xyz/openbmc_project/inventory", [The inventory root.])
AC_DEFINE(CALLOUT_FWD_ASSOCIATION, "callout", [The name of the callout's forward association.])
AC_DEFINE(CALLOUT_REV_ASSOCIATION, "fault", [The name of the callout's reverse association.])
+AC_DEFINE(BMC_VERSION_FILE, "/etc/os-release", [The file that contains the BMC firmware version])
AC_ARG_VAR(YAML_DIR_TEST, [The path to the test error yaml files.])
AS_IF([test "x$YAML_DIR_TEST" == "x"], \
diff --git a/log_manager.cpp b/log_manager.cpp
index 6717a7a..641ed7b 100644
--- a/log_manager.cpp
+++ b/log_manager.cpp
@@ -446,6 +446,31 @@ void Manager::journalSync()
return;
}
+std::string Manager::readFWVersion()
+{
+ std::string version;
+ std::ifstream versionFile{BMC_VERSION_FILE};
+ std::string line;
+ static constexpr auto VERSION_ID = "VERSION_ID=";
+
+ while (std::getline(versionFile, line))
+ {
+ if (line.find(VERSION_ID) != std::string::npos)
+ {
+ auto pos = line.find_first_of('"') + 1;
+ version = line.substr(pos, line.find_last_of('"') - pos);
+ break;
+ }
+ }
+
+ if (version.empty())
+ {
+ log<level::ERR>("Unable to read BMC firmware version");
+ }
+
+ return version;
+}
+
} // namespace internal
} // namespace logging
} // namepsace phosphor
diff --git a/log_manager.hpp b/log_manager.hpp
index d62a25e..d5ca4e9 100644
--- a/log_manager.hpp
+++ b/log_manager.hpp
@@ -54,7 +54,8 @@ class Manager : public details::ServerObject<details::ManagerIface>
Manager(sdbusplus::bus::bus& bus, const char* objPath) :
details::ServerObject<details::ManagerIface>(bus, objPath),
busLog(bus),
- entryId(0){};
+ entryId(0),
+ fwVersion(readFWVersion()) {};
/*
* @fn commit()
@@ -136,6 +137,12 @@ class Manager : public details::ServerObject<details::ManagerIface>
*/
void journalSync();
+ /** @brief Reads the BMC code level
+ *
+ * @return std::string - the version string
+ */
+ static std::string readFWVersion();
+
/** @brief Persistent sdbusplus DBus bus connection. */
sdbusplus::bus::bus& busLog;
@@ -150,6 +157,9 @@ class Manager : public details::ServerObject<details::ManagerIface>
/** @brief Id of last error log entry */
uint32_t entryId;
+
+ /** @brief The BMC firmware version */
+ const std::string fwVersion;
};
} //namespace internal
OpenPOWER on IntegriCloud