101539e7eSLei YU #pragma once 201539e7eSLei YU 301539e7eSLei YU #include "config.h" 401539e7eSLei YU 5ffb36539SLei YU #include "activation_listener.hpp" 67f2a2152SLei YU #include "association_interface.hpp" 791029448SLei YU #include "types.hpp" 89edb7330SLei YU #include "version.hpp" 991029448SLei YU 1001539e7eSLei YU #include <sdbusplus/server.hpp> 1191029448SLei YU #include <xyz/openbmc_project/Association/Definitions/server.hpp> 129930137bSLei YU #include <xyz/openbmc_project/Common/FilePath/server.hpp> 1301539e7eSLei YU #include <xyz/openbmc_project/Software/Activation/server.hpp> 1481c67725SLei YU #include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp> 1590c8a8b9SLei YU #include <xyz/openbmc_project/Software/ActivationProgress/server.hpp> 1601539e7eSLei YU #include <xyz/openbmc_project/Software/ExtendedVersion/server.hpp> 1701539e7eSLei YU 185670b188SPatrick Williams #include <queue> 19487e2e19SShawn McCarney #include <string> 205670b188SPatrick Williams 21ff83c2a0SLei YU class TestActivation; 22ff83c2a0SLei YU 2301539e7eSLei YU namespace phosphor 2401539e7eSLei YU { 2501539e7eSLei YU namespace software 2601539e7eSLei YU { 2701539e7eSLei YU namespace updater 2801539e7eSLei YU { 2901539e7eSLei YU 3012c9f4c4SLei YU namespace sdbusRule = sdbusplus::bus::match::rules; 3112c9f4c4SLei YU 32374fae56SPatrick Williams using ActivationBlocksTransitionInherit = 33374fae56SPatrick Williams sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::Software:: 34374fae56SPatrick Williams server::ActivationBlocksTransition>; 3581c67725SLei YU 3681c67725SLei YU /** @class ActivationBlocksTransition 3781c67725SLei YU * @brief OpenBMC ActivationBlocksTransition implementation. 3881c67725SLei YU * @details A concrete implementation for 3981c67725SLei YU * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API. 4081c67725SLei YU */ 4181c67725SLei YU class ActivationBlocksTransition : public ActivationBlocksTransitionInherit 4281c67725SLei YU { 4381c67725SLei YU public: 4466a54ad4SGeorge Liu ActivationBlocksTransition() = delete; 4566a54ad4SGeorge Liu ActivationBlocksTransition(const ActivationBlocksTransition&) = delete; 4666a54ad4SGeorge Liu ActivationBlocksTransition& 4766a54ad4SGeorge Liu operator=(const ActivationBlocksTransition&) = delete; 4866a54ad4SGeorge Liu ActivationBlocksTransition(ActivationBlocksTransition&&) = delete; 4966a54ad4SGeorge Liu ActivationBlocksTransition& 5066a54ad4SGeorge Liu operator=(ActivationBlocksTransition&&) = delete; 5166a54ad4SGeorge Liu 5281c67725SLei YU /** @brief Constructs ActivationBlocksTransition. 5381c67725SLei YU * 5481c67725SLei YU * @param[in] bus - The Dbus bus object 5581c67725SLei YU * @param[in] path - The Dbus object path 5681c67725SLei YU */ ActivationBlocksTransition(sdbusplus::bus_t & bus,const std::string & path)57374fae56SPatrick Williams ActivationBlocksTransition(sdbusplus::bus_t& bus, const std::string& path) : 58f356fdc9SAlbert Zhang ActivationBlocksTransitionInherit(bus, path.c_str(), 59f356fdc9SAlbert Zhang action::emit_interface_added), 60f356fdc9SAlbert Zhang bus(bus) 6181c67725SLei YU { 628afeee56SLei YU enableRebootGuard(); 6381c67725SLei YU } 6481c67725SLei YU ~ActivationBlocksTransition()65047d9944SGeorge Liu ~ActivationBlocksTransition() override 6681c67725SLei YU { 678afeee56SLei YU disableRebootGuard(); 6881c67725SLei YU } 6981c67725SLei YU 7081c67725SLei YU private: 71374fae56SPatrick Williams sdbusplus::bus_t& bus; 728afeee56SLei YU 738afeee56SLei YU /** @brief Enables a Guard that blocks any BMC reboot commands */ 748afeee56SLei YU void enableRebootGuard(); 758afeee56SLei YU 768afeee56SLei YU /** @brief Disables any guard that was blocking the BMC reboot */ 778afeee56SLei YU void disableRebootGuard(); 7881c67725SLei YU }; 7981c67725SLei YU 80374fae56SPatrick Williams using ActivationProgressInherit = sdbusplus::server::object_t< 8190c8a8b9SLei YU sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>; 8290c8a8b9SLei YU 8390c8a8b9SLei YU class ActivationProgress : public ActivationProgressInherit 8490c8a8b9SLei YU { 8590c8a8b9SLei YU public: 8690c8a8b9SLei YU /** @brief Constructs ActivationProgress. 8790c8a8b9SLei YU * 8890c8a8b9SLei YU * @param[in] bus - The Dbus bus object 8990c8a8b9SLei YU * @param[in] path - The Dbus object path 9090c8a8b9SLei YU */ ActivationProgress(sdbusplus::bus_t & bus,const std::string & path)91374fae56SPatrick Williams ActivationProgress(sdbusplus::bus_t& bus, const std::string& path) : 92f356fdc9SAlbert Zhang ActivationProgressInherit(bus, path.c_str(), 93f356fdc9SAlbert Zhang action::emit_interface_added) 9490c8a8b9SLei YU { 9590c8a8b9SLei YU progress(0); 9690c8a8b9SLei YU } 9790c8a8b9SLei YU }; 9890c8a8b9SLei YU 99374fae56SPatrick Williams using ActivationInherit = sdbusplus::server::object_t< 10001539e7eSLei YU sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion, 10191029448SLei YU sdbusplus::xyz::openbmc_project::Software::server::Activation, 1029930137bSLei YU sdbusplus::xyz::openbmc_project::Association::server::Definitions, 1039930137bSLei YU sdbusplus::xyz::openbmc_project::Common::server::FilePath>; 10401539e7eSLei YU 10501539e7eSLei YU /** @class Activation 10601539e7eSLei YU * @brief OpenBMC activation software management implementation. 10701539e7eSLei YU * @details A concrete implementation for 10801539e7eSLei YU * xyz.openbmc_project.Software.Activation DBus API. 10901539e7eSLei YU */ 11001539e7eSLei YU class Activation : public ActivationInherit 11101539e7eSLei YU { 11201539e7eSLei YU public: 113ff83c2a0SLei YU friend class ::TestActivation; 11412c9f4c4SLei YU using Status = Activations; 115ff83c2a0SLei YU 11601539e7eSLei YU /** @brief Constructs Activation Software Manager 11701539e7eSLei YU * 11801539e7eSLei YU * @param[in] bus - The Dbus bus object 11901539e7eSLei YU * @param[in] path - The Dbus object path 12001539e7eSLei YU * @param[in] versionId - The software version id 12101539e7eSLei YU * @param[in] extVersion - The extended version 12201539e7eSLei YU * @param[in] activationStatus - The status of Activation 12391029448SLei YU * @param[in] assocs - Association objects 1249930137bSLei YU * @param[in] filePath - The image filesystem path 12501539e7eSLei YU */ Activation(sdbusplus::bus_t & bus,const std::string & objPath,const std::string & versionId,const std::string & extVersion,Status activationStatus,const AssociationList & assocs,const std::string & filePath,AssociationInterface * associationInterface,ActivationListener * activationListener)126374fae56SPatrick Williams Activation(sdbusplus::bus_t& bus, const std::string& objPath, 12701539e7eSLei YU const std::string& versionId, const std::string& extVersion, 1287f2a2152SLei YU Status activationStatus, const AssociationList& assocs, 129ffb36539SLei YU const std::string& filePath, 1309930137bSLei YU AssociationInterface* associationInterface, 131ffb36539SLei YU ActivationListener* activationListener) : 132434ae483STang Yiwei ActivationInherit(bus, objPath.c_str(), 133434ae483STang Yiwei ActivationInherit::action::defer_emit), 1349930137bSLei YU bus(bus), objPath(objPath), versionId(versionId), 13512c9f4c4SLei YU systemdSignals( 13612c9f4c4SLei YU bus, 13712c9f4c4SLei YU sdbusRule::type::signal() + sdbusRule::member("JobRemoved") + 13812c9f4c4SLei YU sdbusRule::path("/org/freedesktop/systemd1") + 13912c9f4c4SLei YU sdbusRule::interface("org.freedesktop.systemd1.Manager"), 14012c9f4c4SLei YU std::bind(&Activation::unitStateChange, this, 1417f2a2152SLei YU std::placeholders::_1)), 142ffb36539SLei YU associationInterface(associationInterface), 143ffb36539SLei YU activationListener(activationListener) 14401539e7eSLei YU { 14501539e7eSLei YU // Set Properties. 14601539e7eSLei YU extendedVersion(extVersion); 14701539e7eSLei YU activation(activationStatus); 14891029448SLei YU associations(assocs); 1499930137bSLei YU path(filePath); 15001539e7eSLei YU 15101539e7eSLei YU // Emit deferred signal. 15201539e7eSLei YU emit_object_added(); 15301539e7eSLei YU } 15401539e7eSLei YU 15501539e7eSLei YU /** @brief Overloaded Activation property setter function 15601539e7eSLei YU * 15701539e7eSLei YU * @param[in] value - One of Activation::Activations 15801539e7eSLei YU * 15901539e7eSLei YU * @return Success or exception thrown 16001539e7eSLei YU */ 161ff83c2a0SLei YU Status activation(Status value) override; 16201539e7eSLei YU 16301539e7eSLei YU /** @brief Activation */ 16401539e7eSLei YU using ActivationInherit::activation; 16501539e7eSLei YU 16601539e7eSLei YU /** @brief Overloaded requestedActivation property setter function 16701539e7eSLei YU * 16801539e7eSLei YU * @param[in] value - One of Activation::RequestedActivations 16901539e7eSLei YU * 17001539e7eSLei YU * @return Success or exception thrown 17101539e7eSLei YU */ 17201539e7eSLei YU RequestedActivations 17301539e7eSLei YU requestedActivation(RequestedActivations value) override; 17401539e7eSLei YU 17517c2c94eSShawn McCarney /** @brief Overloaded ExtendedVersion property setter function 17617c2c94eSShawn McCarney * 17717c2c94eSShawn McCarney * @param[in] value - Extended version value 17817c2c94eSShawn McCarney * 17917c2c94eSShawn McCarney * @return New value of property 18017c2c94eSShawn McCarney */ 18117c2c94eSShawn McCarney std::string extendedVersion(std::string value) override; 18217c2c94eSShawn McCarney 18363f9e712SLei YU /** @brief Get the object path */ getObjectPath() const18463f9e712SLei YU const std::string& getObjectPath() const 18563f9e712SLei YU { 18663f9e712SLei YU return objPath; 18763f9e712SLei YU } 18863f9e712SLei YU 189a5c47bb3SLei YU /** @brief Get the version ID */ getVersionId() const190a5c47bb3SLei YU const std::string& getVersionId() const 191a5c47bb3SLei YU { 192a5c47bb3SLei YU return versionId; 193a5c47bb3SLei YU } 19412c9f4c4SLei YU 19512c9f4c4SLei YU private: 19612c9f4c4SLei YU /** @brief Check if systemd state change is relevant to this object 19712c9f4c4SLei YU * 19812c9f4c4SLei YU * Instance specific interface to handle the detected systemd state 19912c9f4c4SLei YU * change 20012c9f4c4SLei YU * 20112c9f4c4SLei YU * @param[in] msg - Data associated with subscribed signal 20212c9f4c4SLei YU * 20312c9f4c4SLei YU */ 204374fae56SPatrick Williams void unitStateChange(sdbusplus::message_t& msg); 20512c9f4c4SLei YU 206d0bbfa9eSLei YU /** 207d0bbfa9eSLei YU * @brief Delete the version from Image Manager and the 208d0bbfa9eSLei YU * untar image from image upload dir. 209d0bbfa9eSLei YU */ 210d0bbfa9eSLei YU void deleteImageManagerObject(); 211d0bbfa9eSLei YU 212ff83c2a0SLei YU /** @brief Invoke the update service for the PSU 213ff83c2a0SLei YU * 214ff83c2a0SLei YU * @param[in] psuInventoryPath - The PSU inventory to be updated. 215ff83c2a0SLei YU * 216ff83c2a0SLei YU * @return true if the update starts, and false if it fails. 217ff83c2a0SLei YU */ 218ff83c2a0SLei YU bool doUpdate(const std::string& psuInventoryPath); 219ff83c2a0SLei YU 220ff83c2a0SLei YU /** @brief Do PSU update one-by-one 221ff83c2a0SLei YU * 222ff83c2a0SLei YU * @return true if the update starts, and false if it fails. 223ff83c2a0SLei YU */ 224ff83c2a0SLei YU bool doUpdate(); 225ff83c2a0SLei YU 226ff83c2a0SLei YU /** @brief Handle an update done event */ 227ff83c2a0SLei YU void onUpdateDone(); 228ff83c2a0SLei YU 229ff83c2a0SLei YU /** @brief Handle an update failure event */ 230ff83c2a0SLei YU void onUpdateFailed(); 231ff83c2a0SLei YU 23212c9f4c4SLei YU /** @brief Start PSU update */ 233ff83c2a0SLei YU Status startActivation(); 23412c9f4c4SLei YU 23512c9f4c4SLei YU /** @brief Finish PSU update */ 23612c9f4c4SLei YU void finishActivation(); 23712c9f4c4SLei YU 23846ea388cSShawn McCarney /** @brief Check if the PSU is present */ 23946ea388cSShawn McCarney bool isPresent(const std::string& psuInventoryPath); 24046ea388cSShawn McCarney 24133cf9f08SManojkiran Eda /** @brief Check if the PSU is compatible with this software*/ 2429edb7330SLei YU bool isCompatible(const std::string& psuInventoryPath); 2439edb7330SLei YU 2442e0e2de5SLei YU /** @brief Store the updated PSU image to persistent dir */ 2452e0e2de5SLei YU void storeImage(); 2462e0e2de5SLei YU 247e8945ea6SLei YU /** @brief Construct the systemd service name 248e8945ea6SLei YU * 249487e2e19SShawn McCarney * @details Throws an exception if an error occurs 250487e2e19SShawn McCarney * 251e8945ea6SLei YU * @param[in] psuInventoryPath - The PSU inventory to be updated. 252e8945ea6SLei YU * 253e8945ea6SLei YU * @return The escaped string of systemd unit to do the PSU update. 254e8945ea6SLei YU */ 255e8945ea6SLei YU std::string getUpdateService(const std::string& psuInventoryPath); 256e8945ea6SLei YU 25701539e7eSLei YU /** @brief Persistent sdbusplus DBus bus connection */ 258374fae56SPatrick Williams sdbusplus::bus_t& bus; 25901539e7eSLei YU 26001539e7eSLei YU /** @brief Persistent DBus object path */ 2619930137bSLei YU std::string objPath; 26201539e7eSLei YU 263a5c47bb3SLei YU /** @brief Version id */ 264a5c47bb3SLei YU std::string versionId; 265a5c47bb3SLei YU 26612c9f4c4SLei YU /** @brief Used to subscribe to dbus systemd signals */ 26712c9f4c4SLei YU sdbusplus::bus::match_t systemdSignals; 26812c9f4c4SLei YU 269ff83c2a0SLei YU /** @brief The queue of psu objects to be updated */ 270ff83c2a0SLei YU std::queue<std::string> psuQueue; 271ff83c2a0SLei YU 272ff83c2a0SLei YU /** @brief The progress step for each PSU update is done */ 273ff83c2a0SLei YU uint32_t progressStep; 274ff83c2a0SLei YU 27512c9f4c4SLei YU /** @brief The PSU update systemd unit */ 27612c9f4c4SLei YU std::string psuUpdateUnit; 27781c67725SLei YU 2787f2a2152SLei YU /** @brief The PSU Inventory path of the current updating PSU */ 2797f2a2152SLei YU std::string currentUpdatingPsu; 2807f2a2152SLei YU 28181c67725SLei YU /** @brief Persistent ActivationBlocksTransition dbus object */ 28281c67725SLei YU std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition; 28390c8a8b9SLei YU 28490c8a8b9SLei YU /** @brief Persistent ActivationProgress dbus object */ 28590c8a8b9SLei YU std::unique_ptr<ActivationProgress> activationProgress; 2867f2a2152SLei YU 2877f2a2152SLei YU /** @brief The AssociationInterface pointer */ 2887f2a2152SLei YU AssociationInterface* associationInterface; 2899edb7330SLei YU 290ffb36539SLei YU /** @brief The activationListener pointer */ 291ffb36539SLei YU ActivationListener* activationListener; 292ffb36539SLei YU 2939edb7330SLei YU /** @brief The PSU manufacturer of the software */ 2949edb7330SLei YU std::string manufacturer; 2959edb7330SLei YU 2969edb7330SLei YU /** @brief The PSU model of the software */ 2979edb7330SLei YU std::string model; 298*7cb5d05eSShawn McCarney 299*7cb5d05eSShawn McCarney /** @brief Indicates whether to automatically activate again after current 300*7cb5d05eSShawn McCarney * request finishes */ 301*7cb5d05eSShawn McCarney bool shouldActivateAgain{false}; 30201539e7eSLei YU }; 30301539e7eSLei YU 30401539e7eSLei YU } // namespace updater 30501539e7eSLei YU } // namespace software 30601539e7eSLei YU } // namespace phosphor 307