Host updater: implement GUARD factory reset
This commit extends the functionality of the host updater with a second
implementation of FactoryReset. This implementation is placed under the
/org/openpower/control/guard path and clears the PNOR GUARD partition.
Resolves openbmc/openbmc#2389
Change-Id: Id89aafe9211b48aee5238ff06b957fa7a99324ab
Signed-off-by: Michael Tritz <mtritz@us.ibm.com>
diff --git a/item_updater.hpp b/item_updater.hpp
index 3c8698f..893e8b9 100755
--- a/item_updater.hpp
+++ b/item_updater.hpp
@@ -18,11 +18,57 @@
sdbusplus::xyz::openbmc_project::Common::server::FactoryReset,
sdbusplus::org::openbmc::server::Associations,
sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>;
+using GardResetInherit = sdbusplus::server::object::object<
+ sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
namespace MatchRules = sdbusplus::bus::match::rules;
using AssociationList =
std::vector<std::tuple<std::string, std::string, std::string>>;
+constexpr auto GARD_PATH = "/org/openpower/control/gard";
+
+/** @class GardReset
+ * @brief OpenBMC GARD factory reset implementation.
+ * @details An implementation of xyz.openbmc_project.Common.FactoryReset under
+ * /org/openpower/control/gard.
+ */
+class GardReset : public GardResetInherit
+{
+ public:
+ /** @brief Constructs GardReset.
+ *
+ * @param[in] bus - The Dbus bus object
+ * @param[in] path - The Dbus object path
+ */
+ GardReset(sdbusplus::bus::bus& bus,
+ const std::string& path) :
+ GardResetInherit(bus, path.c_str(), true),
+ bus(bus),
+ path(path)
+ {
+ std::vector<std::string> interfaces({interface});
+ bus.emit_interfaces_added(path.c_str(), interfaces);
+ }
+
+ ~GardReset()
+ {
+ std::vector<std::string> interfaces({interface});
+ bus.emit_interfaces_removed(path.c_str(), interfaces);
+ }
+
+ private:
+ // TODO Remove once openbmc/openbmc#1975 is resolved
+ static constexpr auto interface =
+ "xyz.openbmc_project.Common.FactoryReset";
+ sdbusplus::bus::bus& bus;
+ std::string path;
+
+ /**
+ * @brief GARD factory reset - clears the PNOR GARD partition.
+ */
+ void reset() override;
+};
+
/** @class ItemUpdater
* @brief Manages the activation of the host version items.
*/
@@ -47,6 +93,10 @@
std::placeholders::_1))
{
processPNORImage();
+ gardReset = std::make_unique<GardReset>(bus, GARD_PATH);
+
+ // Emit deferred signal.
+ emit_object_added();
}
/** @brief Sets the given priority free by incrementing
@@ -119,6 +169,9 @@
*/
void removeActiveAssociation(const std::string& path);
+ /** @brief Persistent GardReset dbus object */
+ std::unique_ptr<GardReset> gardReset;
+
private:
/** @brief Callback function for Software.Version match.
* @details Creates an Activation D-Bus object.