diff options
-rw-r--r-- | item_updater.cpp | 20 | ||||
-rw-r--r-- | item_updater.hpp | 20 | ||||
-rw-r--r-- | item_updater_main.cpp | 2 |
3 files changed, 32 insertions, 10 deletions
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 @@ namespace fs = std::experimental::filesystem; 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::freePriority(uint8_t value) } } +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 software 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 @@ class ItemUpdater * * @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 @@ class ItemUpdater */ 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 @@ int main(int argc, char* argv[]) // 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); |