12d8fa225SAdriana Kobylak #pragma once 22d8fa225SAdriana Kobylak 32d8fa225SAdriana Kobylak #include "activation.hpp" 4f6ed5897SGunnar Mills #include "version.hpp" 5f6ed5897SGunnar Mills #include "xyz/openbmc_project/Collection/DeleteAll/server.hpp" 6f6ed5897SGunnar Mills 7f6ed5897SGunnar Mills #include <sdbusplus/server.hpp> 8d05d4725SJohn Wang #include <xyz/openbmc_project/Association/Definitions/server.hpp> 9dd961b6cSMichael Tritz #include <xyz/openbmc_project/Common/FactoryReset/server.hpp> 107cb480edSAdriana Kobylak #include <xyz/openbmc_project/Object/Enable/server.hpp> 112d8fa225SAdriana Kobylak 128facccfaSBrad Bishop #include <string> 138facccfaSBrad Bishop 142d8fa225SAdriana Kobylak namespace openpower 152d8fa225SAdriana Kobylak { 162d8fa225SAdriana Kobylak namespace software 172d8fa225SAdriana Kobylak { 18befe5ce4SAdriana Kobylak namespace updater 192d8fa225SAdriana Kobylak { 202d8fa225SAdriana Kobylak 210dea1992SPatrick Williams using ItemUpdaterInherit = sdbusplus::server::object_t< 229741cd19SGunnar Mills sdbusplus::xyz::openbmc_project::Common::server::FactoryReset, 23d05d4725SJohn Wang sdbusplus::xyz::openbmc_project::Association::server::Definitions, 24234a07e8SMichael Tritz sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>; 250dea1992SPatrick Williams using GardResetInherit = sdbusplus::server::object_t< 26b541f1b6SMichael Tritz sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>; 270dea1992SPatrick Williams using ObjectEnable = sdbusplus::server::object_t< 287cb480edSAdriana Kobylak sdbusplus::xyz::openbmc_project::Object::server::Enable>; 293accb322SPatrick Williams namespace MatchRules = sdbusplus::bus::match::rules; 30dd961b6cSMichael Tritz 319741cd19SGunnar Mills using AssociationList = 329741cd19SGunnar Mills std::vector<std::tuple<std::string, std::string, std::string>>; 339741cd19SGunnar Mills 344ecea0f3SMichael Tritz constexpr auto GARD_PATH = "/org/open_power/control/gard"; 357cb480edSAdriana Kobylak constexpr static auto volatilePath = "/org/open_power/control/volatile"; 36b541f1b6SMichael Tritz 37b541f1b6SMichael Tritz /** @class GardReset 38*96442c88SManojkiran Eda * @brief OpenBMC GUARD factory reset implementation. 39b541f1b6SMichael Tritz * @details An implementation of xyz.openbmc_project.Common.FactoryReset under 40b541f1b6SMichael Tritz * /org/openpower/control/gard. 41b541f1b6SMichael Tritz */ 42b541f1b6SMichael Tritz class GardReset : public GardResetInherit 43b541f1b6SMichael Tritz { 44b541f1b6SMichael Tritz public: 45b541f1b6SMichael Tritz /** @brief Constructs GardReset. 46b541f1b6SMichael Tritz * 47b541f1b6SMichael Tritz * @param[in] bus - The Dbus bus object 48b541f1b6SMichael Tritz * @param[in] path - The Dbus object path 49b541f1b6SMichael Tritz */ GardReset(sdbusplus::bus_t & bus,const std::string & path)500dea1992SPatrick Williams GardReset(sdbusplus::bus_t& bus, const std::string& path) : 519c887d14SPatrick Williams GardResetInherit(bus, path.c_str(), 529c887d14SPatrick Williams GardResetInherit::action::emit_interface_added), 539c887d14SPatrick Williams bus(bus), path(path) 549c887d14SPatrick Williams {} 55b541f1b6SMichael Tritz ~GardReset()567fb6c346SPatrick Williams virtual ~GardReset() {} 57b541f1b6SMichael Tritz 582b31497eSMarri Devender Rao /** 59*96442c88SManojkiran Eda * @brief GUARD factory reset - clears the PNOR GUARD partition. 602b31497eSMarri Devender Rao */ 612b31497eSMarri Devender Rao virtual void reset() = 0; 622b31497eSMarri Devender Rao 63716de5b8SLei YU protected: 64b541f1b6SMichael Tritz // TODO Remove once openbmc/openbmc#1975 is resolved 6570dcb63aSAdriana Kobylak static constexpr auto interface = "xyz.openbmc_project.Common.FactoryReset"; 660dea1992SPatrick Williams sdbusplus::bus_t& bus; 67b541f1b6SMichael Tritz std::string path; 68b541f1b6SMichael Tritz }; 69b541f1b6SMichael Tritz 702d8fa225SAdriana Kobylak /** @class ItemUpdater 71139cf1a1SGunnar Mills * @brief Manages the activation of the host version items. 722d8fa225SAdriana Kobylak */ 73dd961b6cSMichael Tritz class ItemUpdater : public ItemUpdaterInherit 742d8fa225SAdriana Kobylak { 752d8fa225SAdriana Kobylak public: 762d8fa225SAdriana Kobylak /** @brief Constructs ItemUpdater 772d8fa225SAdriana Kobylak * 78139cf1a1SGunnar Mills * @param[in] bus - The D-Bus bus object 79139cf1a1SGunnar Mills * @param[in] path - The D-Bus path 802d8fa225SAdriana Kobylak */ ItemUpdater(sdbusplus::bus_t & bus,const std::string & path)810dea1992SPatrick Williams ItemUpdater(sdbusplus::bus_t& bus, const std::string& path) : 8270dcb63aSAdriana Kobylak ItemUpdaterInherit(bus, path.c_str()), bus(bus), 8370dcb63aSAdriana Kobylak versionMatch(bus, 843accb322SPatrick Williams MatchRules::interfacesAdded() + 853accb322SPatrick Williams MatchRules::path("/xyz/openbmc_project/software"), 8670dcb63aSAdriana Kobylak std::bind(std::mem_fn(&ItemUpdater::createActivation), 8770dcb63aSAdriana Kobylak this, std::placeholders::_1)) 888facccfaSBrad Bishop {} 892d8fa225SAdriana Kobylak 90f3ce4337SLei YU virtual ~ItemUpdater() = default; 91f3ce4337SLei YU 9281bac88cSSaqib Khan /** @brief Sets the given priority free by incrementing 93abe862aaSAdriana Kobylak * any existing priority with the same value by 1. It will then continue 94abe862aaSAdriana Kobylak * to resolve duplicate priorities caused by this increase, by increasing 95abe862aaSAdriana Kobylak * the priority by 1 until there are no more duplicate values. 9681bac88cSSaqib Khan * 9781bac88cSSaqib Khan * @param[in] value - The priority that needs to be set free. 98b8e7f313SSaqib Khan * @param[in] versionId - The Id of the version for which we 99b8e7f313SSaqib Khan * are trying to free up the priority. 10081bac88cSSaqib Khan * @return None 10181bac88cSSaqib Khan */ 102f3ce4337SLei YU virtual void freePriority(uint8_t value, const std::string& versionId) = 0; 10381bac88cSSaqib Khan 104167601b5SSaqib Khan /** 105167601b5SSaqib Khan * @brief Create and populate the active PNOR Version. 106167601b5SSaqib Khan */ 107f3ce4337SLei YU virtual void processPNORImage() = 0; 108167601b5SSaqib Khan 1099c8adfa3SLeonel Gonzalez /** @brief Deletes version 1109c8adfa3SLeonel Gonzalez * 1119c8adfa3SLeonel Gonzalez * @param[in] entryId - Id of the version to delete 1129c8adfa3SLeonel Gonzalez * 113f3ce4337SLei YU * @return - Returns true if the version is deleted. 1149c8adfa3SLeonel Gonzalez */ 115f3ce4337SLei YU virtual bool erase(std::string entryId); 1169c8adfa3SLeonel Gonzalez 117234a07e8SMichael Tritz /** 118234a07e8SMichael Tritz * @brief Erases any non-active pnor versions. 119234a07e8SMichael Tritz */ 120f3ce4337SLei YU virtual void deleteAll() = 0; 121234a07e8SMichael Tritz 122fedbf3d3SGunnar Mills /** @brief Brings the total number of active PNOR versions to 123fedbf3d3SGunnar Mills * ACTIVE_PNOR_MAX_ALLOWED -1. This function is intended to be 124fedbf3d3SGunnar Mills * run before activating a new PNOR version. If this function 125fedbf3d3SGunnar Mills * needs to delete any PNOR version(s) it will delete the 126fedbf3d3SGunnar Mills * version(s) with the highest priority, skipping the 127fedbf3d3SGunnar Mills * functional PNOR version. 1286da3dae3SLei YU * 1296da3dae3SLei YU * @return - Return if space is freed or not 1302cbfa035SSaqib Khan */ 1316da3dae3SLei YU virtual bool freeSpace() = 0; 1322cbfa035SSaqib Khan 1339741cd19SGunnar Mills /** @brief Creates an active association to the 1349741cd19SGunnar Mills * newly active software image 1359741cd19SGunnar Mills * 1369741cd19SGunnar Mills * @param[in] path - The path to create the association to. 1379741cd19SGunnar Mills */ 138f3ce4337SLei YU virtual void createActiveAssociation(const std::string& path); 1399741cd19SGunnar Mills 1403c81037eSAdriana Kobylak /** @brief Creates a updateable association to the 1413c81037eSAdriana Kobylak * "running" BMC software image 1423c81037eSAdriana Kobylak * 1433c81037eSAdriana Kobylak * @param[in] path - The path to create the association. 1443c81037eSAdriana Kobylak */ 1453c81037eSAdriana Kobylak virtual void createUpdateableAssociation(const std::string& path); 1463c81037eSAdriana Kobylak 147833e4f37SGunnar Mills /** @brief Updates the functional association to the 148833e4f37SGunnar Mills * new "running" PNOR image 149833e4f37SGunnar Mills * 150f3ce4337SLei YU * @param[in] versionId - The id of the image to update the association to. 151833e4f37SGunnar Mills */ 152f3ce4337SLei YU virtual void updateFunctionalAssociation(const std::string& versionId); 153833e4f37SGunnar Mills 154b5237174SAdriana Kobylak /** @brief Removes the associations from the provided software image path 1559741cd19SGunnar Mills * 1569741cd19SGunnar Mills * @param[in] path - The path to remove the association from. 1579741cd19SGunnar Mills */ 158f3ce4337SLei YU virtual void removeAssociation(const std::string& path); 1599741cd19SGunnar Mills 160b541f1b6SMichael Tritz /** @brief Persistent GardReset dbus object */ 161b541f1b6SMichael Tritz std::unique_ptr<GardReset> gardReset; 162b541f1b6SMichael Tritz 1635b75651bSMichael Tritz /** @brief Check whether the provided image id is the functional one 1645b75651bSMichael Tritz * 1655b75651bSMichael Tritz * @param[in] - versionId - The id of the image to check. 1665b75651bSMichael Tritz * 1675b75651bSMichael Tritz * @return - Returns true if this version is currently functional. 1685b75651bSMichael Tritz */ 169f3ce4337SLei YU virtual bool isVersionFunctional(const std::string& versionId) = 0; 1705b75651bSMichael Tritz 1717cb480edSAdriana Kobylak /** @brief Persistent ObjectEnable D-Bus object */ 1727cb480edSAdriana Kobylak std::unique_ptr<ObjectEnable> volatileEnable; 1737cb480edSAdriana Kobylak 174f3ce4337SLei YU protected: 1752d8fa225SAdriana Kobylak /** @brief Callback function for Software.Version match. 176139cf1a1SGunnar Mills * @details Creates an Activation D-Bus object. 1772d8fa225SAdriana Kobylak * 1782d8fa225SAdriana Kobylak * @param[in] msg - Data associated with subscribed signal 1792d8fa225SAdriana Kobylak */ 1800dea1992SPatrick Williams virtual void createActivation(sdbusplus::message_t& msg); 181a9ac9279SLei YU 182a9ac9279SLei YU /** @brief Create Activation object */ 183a9ac9279SLei YU virtual std::unique_ptr<Activation> createActivationObject( 184a9ac9279SLei YU const std::string& path, const std::string& versionId, 185a9ac9279SLei YU const std::string& extVersion, 186a9ac9279SLei YU sdbusplus::xyz::openbmc_project::Software::server::Activation:: 187a9ac9279SLei YU Activations activationStatus, 188a9ac9279SLei YU AssociationList& assocs) = 0; 189a9ac9279SLei YU 190a9ac9279SLei YU /** @brief Create Version object */ 191a9ac9279SLei YU virtual std::unique_ptr<Version> 192a9ac9279SLei YU createVersionObject(const std::string& objPath, 193a9ac9279SLei YU const std::string& versionId, 194a9ac9279SLei YU const std::string& versionString, 195a9ac9279SLei YU sdbusplus::xyz::openbmc_project::Software::server:: 196a9ac9279SLei YU Version::VersionPurpose versionPurpose, 197a9ac9279SLei YU const std::string& filePath) = 0; 198a9ac9279SLei YU 199a9ac9279SLei YU /** @brief Validate if image is valid or not */ 200a9ac9279SLei YU virtual bool validateImage(const std::string& path) = 0; 2017254f0eaSSaqib Khan 202139cf1a1SGunnar Mills /** @brief Persistent sdbusplus D-Bus bus connection. */ 2030dea1992SPatrick Williams sdbusplus::bus_t& bus; 2042d8fa225SAdriana Kobylak 205139cf1a1SGunnar Mills /** @brief Persistent map of Activation D-Bus objects and their 2062d8fa225SAdriana Kobylak * version id */ 207268616bfSAdriana Kobylak std::map<std::string, std::unique_ptr<Activation>> activations; 2082d8fa225SAdriana Kobylak 209139cf1a1SGunnar Mills /** @brief Persistent map of Version D-Bus objects and their 210ce148700SSaqib Khan * version id */ 211ce148700SSaqib Khan std::map<std::string, std::unique_ptr<Version>> versions; 212ce148700SSaqib Khan 2132d8fa225SAdriana Kobylak /** @brief sdbusplus signal match for Software.Version */ 2143accb322SPatrick Williams sdbusplus::bus::match_t versionMatch; 215dd961b6cSMichael Tritz 2169741cd19SGunnar Mills /** @brief This entry's associations */ 2179741cd19SGunnar Mills AssociationList assocs = {}; 2189741cd19SGunnar Mills 219dd961b6cSMichael Tritz /** @brief Host factory reset - clears PNOR partitions for each 220139cf1a1SGunnar Mills * Activation D-Bus object */ 221f3ce4337SLei YU void reset() override = 0; 22213fc66adSEddie James 22313fc66adSEddie James /** @brief Check whether the host is running 22413fc66adSEddie James * 22513fc66adSEddie James * @return - Returns true if the Chassis is powered on. 22613fc66adSEddie James */ 22713fc66adSEddie James bool isChassisOn(); 2282d8fa225SAdriana Kobylak }; 2292d8fa225SAdriana Kobylak 230befe5ce4SAdriana Kobylak } // namespace updater 2312d8fa225SAdriana Kobylak } // namespace software 2322d8fa225SAdriana Kobylak } // namespace openpower 233