Item Updater: Implement BMC factory reset

This commit implements the generic factory reset interface for the BMC
software updater. When the reset function is called, a service file is
called which sets the environmental variable to reset the RW volume.

Change-Id: Ic69b5d145edd654ed75295a9e9aeef9f53779dad
Signed-off-by: Michael Tritz <mtritz@us.ibm.com>
diff --git a/item_updater.cpp b/item_updater.cpp
index 667c4b6..fe9af2f 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -22,6 +22,10 @@
 
 constexpr auto bmcImage = "image-rofs";
 
+constexpr auto SYSTEMD_BUSNAME = "org.freedesktop.systemd1";
+constexpr auto SYSTEMD_PATH = "/org/freedesktop/systemd1";
+constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager";
+
 void ItemUpdater::createActivation(sdbusplus::message::message& msg)
 {
 
@@ -182,6 +186,22 @@
     }
 }
 
+void ItemUpdater::reset()
+{
+    // Mark the read-write partition for recreation upon reboot.
+    auto method = bus.new_method_call(
+            SYSTEMD_BUSNAME,
+            SYSTEMD_PATH,
+            SYSTEMD_INTERFACE,
+            "StartUnit");
+    method.append("obmc-flash-bmc-setenv@rwreset=true.service", "replace");
+    bus.call_noreply(method);
+
+    log<level::INFO>("BMC factory reset will take effect upon reboot.");
+
+    return;
+}
+
 } // namespace updater
 } // namespace software
 } // namespace phosphor
diff --git a/item_updater.hpp b/item_updater.hpp
index 75b2a68..e4fdd69 100644
--- a/item_updater.hpp
+++ b/item_updater.hpp
@@ -3,6 +3,7 @@
 #include <sdbusplus/server.hpp>
 #include "activation.hpp"
 #include "version.hpp"
+#include <xyz/openbmc_project/Common/FactoryReset/server.hpp>
 
 namespace phosphor
 {
@@ -11,21 +12,17 @@
 namespace updater
 {
 
+using ItemUpdaterInherit = sdbusplus::server::object::object<
+    sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
+
 namespace MatchRules = sdbusplus::bus::match::rules;
 
 /** @class ItemUpdater
  *  @brief Manages the activation of the BMC version items.
  */
-class ItemUpdater
+class ItemUpdater : public ItemUpdaterInherit
 {
     public:
-        ItemUpdater() = delete;
-        ~ItemUpdater() = default;
-        ItemUpdater(const ItemUpdater&) = delete;
-        ItemUpdater& operator=(const ItemUpdater&) = delete;
-        ItemUpdater(ItemUpdater&&) = delete;
-        ItemUpdater& operator=(ItemUpdater&&) = delete;
-
         /*
          * @brief Types of Activation status for image validation.
          */
@@ -40,7 +37,8 @@
          *
          * @param[in] bus    - The Dbus bus object
          */
-        ItemUpdater(sdbusplus::bus::bus& bus) :
+        ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) :
+                    ItemUpdaterInherit(bus, path.c_str()),
                     bus(bus),
                     versionMatch(
                             bus,
@@ -88,6 +86,10 @@
          */
         ActivationStatus validateSquashFSImage(const std::string& filePath);
 
+        /** @brief BMC factory reset - marks the read-write partition for
+          * recreation upon reboot. */
+        void reset() override;
+
         /** @brief Persistent sdbusplus DBus bus connection. */
         sdbusplus::bus::bus& bus;
 
diff --git a/item_updater_main.cpp b/item_updater_main.cpp
index 8426e46..42343bb 100644
--- a/item_updater_main.cpp
+++ b/item_updater_main.cpp
@@ -10,7 +10,7 @@
     // Add sdbusplus ObjectManager.
     sdbusplus::server::manager::manager objManager(bus, SOFTWARE_OBJPATH);
 
-    phosphor::software::updater::ItemUpdater updater(bus);
+    phosphor::software::updater::ItemUpdater updater(bus, SOFTWARE_OBJPATH);
 
     bus.request_name(BUSNAME_UPDATER);