Add the BMC code version to error logs

Add the xyz.openbmc_project.Software.Version interface to
the elog entries.  This allows a user to know what BMC code
level was running when the error was created.  The level is
persisted along with the other elog fields.

If this code is flashed on a system that was running older code,
and there were existing error logs, the version property will
be left empty in the restored log entries.

Older code is still able to restore logs created by this code
as the version property is at the end of the serialized data
and so is just ignored by Cereal.

Resolves openbmc/openbmc#3133

Tested:  Check that new error logs have the code level, and that
         restarting phosphor-log-manager preserves that property
         on the existing logs.  Various incantations of running
         the older code with logs created by this code, and running
         this code with logs created by older code.

Change-Id: I682aa3bf97c8352ce6dda05dfdf55d33173de891
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/elog_entry.hpp b/elog_entry.hpp
index 8dcc2a2..5ee8f5f 100644
--- a/elog_entry.hpp
+++ b/elog_entry.hpp
@@ -4,6 +4,7 @@
 #include <sdbusplus/server/object.hpp>
 #include "xyz/openbmc_project/Logging/Entry/server.hpp"
 #include "xyz/openbmc_project/Object/Delete/server.hpp"
+#include "xyz/openbmc_project/Software/Version/server.hpp"
 #include "org/openbmc/Associations/server.hpp"
 
 namespace phosphor
@@ -14,7 +15,8 @@
 using EntryIfaces = sdbusplus::server::object::object<
     sdbusplus::xyz::openbmc_project::Logging::server::Entry,
     sdbusplus::xyz::openbmc_project::Object::server::Delete,
-    sdbusplus::org::openbmc::server::Associations>;
+    sdbusplus::org::openbmc::server::Associations,
+    sdbusplus::xyz::openbmc_project::Software::server::Version>;
 
 using AssociationList =
      std::vector<std::tuple<std::string, std::string, std::string>>;
@@ -50,6 +52,8 @@
          *  @param[in] severityErr - The severity of the error.
          *  @param[in] msgErr - The message of the error.
          *  @param[in] additionalDataErr - The error metadata.
+         *  @param[in] objects - The list of associations.
+         *  @param[in] fwVersion - The BMC code version.
          *  @param[in] parent - The error's parent.
          */
         Entry(sdbusplus::bus::bus& bus,
@@ -60,6 +64,7 @@
               std::string&& msgErr,
               std::vector<std::string>&& additionalDataErr,
               AssociationList&& objects,
+              const std::string& fwVersion,
               internal::Manager& parent) :
               EntryIfaces(bus, path.c_str(), true),
               parent(parent)
@@ -75,6 +80,9 @@
             sdbusplus::xyz::openbmc_project::
                 Logging::server::Entry::resolved(false);
 
+            version(fwVersion);
+            purpose(VersionPurpose::BMC);
+
             // Emit deferred signal.
             this->emit_object_added();
         };