Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "config.h" |
| 4 | |
Lei YU | ffb3653 | 2019-10-15 13:55:24 +0800 | [diff] [blame] | 5 | #include "activation_listener.hpp" |
Lei YU | 7f2a215 | 2019-09-16 16:50:18 +0800 | [diff] [blame] | 6 | #include "association_interface.hpp" |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 7 | #include "types.hpp" |
Lei YU | 9edb733 | 2019-09-19 14:46:19 +0800 | [diff] [blame] | 8 | #include "version.hpp" |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 9 | |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 10 | #include <queue> |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 11 | #include <sdbusplus/server.hpp> |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 12 | #include <xyz/openbmc_project/Association/Definitions/server.hpp> |
Lei YU | 9930137 | 2019-09-29 16:27:12 +0800 | [diff] [blame] | 13 | #include <xyz/openbmc_project/Common/FilePath/server.hpp> |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 14 | #include <xyz/openbmc_project/Software/Activation/server.hpp> |
Lei YU | 81c6772 | 2019-09-11 16:47:29 +0800 | [diff] [blame] | 15 | #include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp> |
Lei YU | 90c8a8b | 2019-09-11 17:20:03 +0800 | [diff] [blame] | 16 | #include <xyz/openbmc_project/Software/ActivationProgress/server.hpp> |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 17 | #include <xyz/openbmc_project/Software/ExtendedVersion/server.hpp> |
| 18 | |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 19 | class TestActivation; |
| 20 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 21 | namespace phosphor |
| 22 | { |
| 23 | namespace software |
| 24 | { |
| 25 | namespace updater |
| 26 | { |
| 27 | |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 28 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 29 | |
Patrick Williams | 374fae5 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 30 | using ActivationBlocksTransitionInherit = |
| 31 | sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::Software:: |
| 32 | server::ActivationBlocksTransition>; |
Lei YU | 81c6772 | 2019-09-11 16:47:29 +0800 | [diff] [blame] | 33 | |
| 34 | /** @class ActivationBlocksTransition |
| 35 | * @brief OpenBMC ActivationBlocksTransition implementation. |
| 36 | * @details A concrete implementation for |
| 37 | * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API. |
| 38 | */ |
| 39 | class ActivationBlocksTransition : public ActivationBlocksTransitionInherit |
| 40 | { |
| 41 | public: |
| 42 | /** @brief Constructs ActivationBlocksTransition. |
| 43 | * |
| 44 | * @param[in] bus - The Dbus bus object |
| 45 | * @param[in] path - The Dbus object path |
| 46 | */ |
Patrick Williams | 374fae5 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 47 | ActivationBlocksTransition(sdbusplus::bus_t& bus, const std::string& path) : |
Albert Zhang | f356fdc | 2020-03-02 09:24:17 +0800 | [diff] [blame] | 48 | ActivationBlocksTransitionInherit(bus, path.c_str(), |
| 49 | action::emit_interface_added), |
| 50 | bus(bus) |
Lei YU | 81c6772 | 2019-09-11 16:47:29 +0800 | [diff] [blame] | 51 | { |
Lei YU | 8afeee5 | 2019-10-21 15:25:35 +0800 | [diff] [blame] | 52 | enableRebootGuard(); |
Lei YU | 81c6772 | 2019-09-11 16:47:29 +0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | ~ActivationBlocksTransition() |
| 56 | { |
Lei YU | 8afeee5 | 2019-10-21 15:25:35 +0800 | [diff] [blame] | 57 | disableRebootGuard(); |
Lei YU | 81c6772 | 2019-09-11 16:47:29 +0800 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | private: |
Patrick Williams | 374fae5 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 61 | sdbusplus::bus_t& bus; |
Lei YU | 8afeee5 | 2019-10-21 15:25:35 +0800 | [diff] [blame] | 62 | |
| 63 | /** @brief Enables a Guard that blocks any BMC reboot commands */ |
| 64 | void enableRebootGuard(); |
| 65 | |
| 66 | /** @brief Disables any guard that was blocking the BMC reboot */ |
| 67 | void disableRebootGuard(); |
Lei YU | 81c6772 | 2019-09-11 16:47:29 +0800 | [diff] [blame] | 68 | }; |
| 69 | |
Patrick Williams | 374fae5 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 70 | using ActivationProgressInherit = sdbusplus::server::object_t< |
Lei YU | 90c8a8b | 2019-09-11 17:20:03 +0800 | [diff] [blame] | 71 | sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>; |
| 72 | |
| 73 | class ActivationProgress : public ActivationProgressInherit |
| 74 | { |
| 75 | public: |
| 76 | /** @brief Constructs ActivationProgress. |
| 77 | * |
| 78 | * @param[in] bus - The Dbus bus object |
| 79 | * @param[in] path - The Dbus object path |
| 80 | */ |
Patrick Williams | 374fae5 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 81 | ActivationProgress(sdbusplus::bus_t& bus, const std::string& path) : |
Albert Zhang | f356fdc | 2020-03-02 09:24:17 +0800 | [diff] [blame] | 82 | ActivationProgressInherit(bus, path.c_str(), |
| 83 | action::emit_interface_added) |
Lei YU | 90c8a8b | 2019-09-11 17:20:03 +0800 | [diff] [blame] | 84 | { |
| 85 | progress(0); |
Lei YU | 90c8a8b | 2019-09-11 17:20:03 +0800 | [diff] [blame] | 86 | } |
Lei YU | 90c8a8b | 2019-09-11 17:20:03 +0800 | [diff] [blame] | 87 | }; |
| 88 | |
Patrick Williams | 374fae5 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 89 | using ActivationInherit = sdbusplus::server::object_t< |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 90 | sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion, |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 91 | sdbusplus::xyz::openbmc_project::Software::server::Activation, |
Lei YU | 9930137 | 2019-09-29 16:27:12 +0800 | [diff] [blame] | 92 | sdbusplus::xyz::openbmc_project::Association::server::Definitions, |
| 93 | sdbusplus::xyz::openbmc_project::Common::server::FilePath>; |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 94 | |
| 95 | /** @class Activation |
| 96 | * @brief OpenBMC activation software management implementation. |
| 97 | * @details A concrete implementation for |
| 98 | * xyz.openbmc_project.Software.Activation DBus API. |
| 99 | */ |
| 100 | class Activation : public ActivationInherit |
| 101 | { |
| 102 | public: |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 103 | friend class ::TestActivation; |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 104 | using Status = Activations; |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 105 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 106 | /** @brief Constructs Activation Software Manager |
| 107 | * |
| 108 | * @param[in] bus - The Dbus bus object |
| 109 | * @param[in] path - The Dbus object path |
| 110 | * @param[in] versionId - The software version id |
| 111 | * @param[in] extVersion - The extended version |
| 112 | * @param[in] activationStatus - The status of Activation |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 113 | * @param[in] assocs - Association objects |
Lei YU | 9930137 | 2019-09-29 16:27:12 +0800 | [diff] [blame] | 114 | * @param[in] filePath - The image filesystem path |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 115 | */ |
Patrick Williams | 374fae5 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 116 | Activation(sdbusplus::bus_t& bus, const std::string& objPath, |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 117 | const std::string& versionId, const std::string& extVersion, |
Lei YU | 7f2a215 | 2019-09-16 16:50:18 +0800 | [diff] [blame] | 118 | Status activationStatus, const AssociationList& assocs, |
Lei YU | ffb3653 | 2019-10-15 13:55:24 +0800 | [diff] [blame] | 119 | const std::string& filePath, |
Lei YU | 9930137 | 2019-09-29 16:27:12 +0800 | [diff] [blame] | 120 | AssociationInterface* associationInterface, |
Lei YU | ffb3653 | 2019-10-15 13:55:24 +0800 | [diff] [blame] | 121 | ActivationListener* activationListener) : |
Tang Yiwei | 434ae48 | 2022-04-16 13:55:21 +0800 | [diff] [blame] | 122 | ActivationInherit(bus, objPath.c_str(), |
| 123 | ActivationInherit::action::defer_emit), |
Lei YU | 9930137 | 2019-09-29 16:27:12 +0800 | [diff] [blame] | 124 | bus(bus), objPath(objPath), versionId(versionId), |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 125 | systemdSignals( |
| 126 | bus, |
| 127 | sdbusRule::type::signal() + sdbusRule::member("JobRemoved") + |
| 128 | sdbusRule::path("/org/freedesktop/systemd1") + |
| 129 | sdbusRule::interface("org.freedesktop.systemd1.Manager"), |
| 130 | std::bind(&Activation::unitStateChange, this, |
Lei YU | 7f2a215 | 2019-09-16 16:50:18 +0800 | [diff] [blame] | 131 | std::placeholders::_1)), |
Lei YU | ffb3653 | 2019-10-15 13:55:24 +0800 | [diff] [blame] | 132 | associationInterface(associationInterface), |
| 133 | activationListener(activationListener) |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 134 | { |
| 135 | // Set Properties. |
| 136 | extendedVersion(extVersion); |
| 137 | activation(activationStatus); |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 138 | associations(assocs); |
Lei YU | 9930137 | 2019-09-29 16:27:12 +0800 | [diff] [blame] | 139 | path(filePath); |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 140 | |
Lei YU | 9edb733 | 2019-09-19 14:46:19 +0800 | [diff] [blame] | 141 | auto info = Version::getExtVersionInfo(extVersion); |
| 142 | manufacturer = info["manufacturer"]; |
| 143 | model = info["model"]; |
| 144 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 145 | // Emit deferred signal. |
| 146 | emit_object_added(); |
| 147 | } |
| 148 | |
| 149 | /** @brief Overloaded Activation property setter function |
| 150 | * |
| 151 | * @param[in] value - One of Activation::Activations |
| 152 | * |
| 153 | * @return Success or exception thrown |
| 154 | */ |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 155 | Status activation(Status value) override; |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 156 | |
| 157 | /** @brief Activation */ |
| 158 | using ActivationInherit::activation; |
| 159 | |
| 160 | /** @brief Overloaded requestedActivation property setter function |
| 161 | * |
| 162 | * @param[in] value - One of Activation::RequestedActivations |
| 163 | * |
| 164 | * @return Success or exception thrown |
| 165 | */ |
| 166 | RequestedActivations |
| 167 | requestedActivation(RequestedActivations value) override; |
| 168 | |
Lei YU | 63f9e71 | 2019-10-12 15:16:55 +0800 | [diff] [blame] | 169 | /** @brief Get the object path */ |
| 170 | const std::string& getObjectPath() const |
| 171 | { |
| 172 | return objPath; |
| 173 | } |
| 174 | |
Lei YU | a5c47bb | 2019-09-29 11:28:53 +0800 | [diff] [blame] | 175 | /** @brief Get the version ID */ |
| 176 | const std::string& getVersionId() const |
| 177 | { |
| 178 | return versionId; |
| 179 | } |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 180 | |
| 181 | private: |
| 182 | /** @brief Check if systemd state change is relevant to this object |
| 183 | * |
| 184 | * Instance specific interface to handle the detected systemd state |
| 185 | * change |
| 186 | * |
| 187 | * @param[in] msg - Data associated with subscribed signal |
| 188 | * |
| 189 | */ |
Patrick Williams | 374fae5 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 190 | void unitStateChange(sdbusplus::message_t& msg); |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 191 | |
Lei YU | d0bbfa9 | 2019-09-11 16:10:54 +0800 | [diff] [blame] | 192 | /** |
| 193 | * @brief Delete the version from Image Manager and the |
| 194 | * untar image from image upload dir. |
| 195 | */ |
| 196 | void deleteImageManagerObject(); |
| 197 | |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 198 | /** @brief Invoke the update service for the PSU |
| 199 | * |
| 200 | * @param[in] psuInventoryPath - The PSU inventory to be updated. |
| 201 | * |
| 202 | * @return true if the update starts, and false if it fails. |
| 203 | */ |
| 204 | bool doUpdate(const std::string& psuInventoryPath); |
| 205 | |
| 206 | /** @brief Do PSU update one-by-one |
| 207 | * |
| 208 | * @return true if the update starts, and false if it fails. |
| 209 | */ |
| 210 | bool doUpdate(); |
| 211 | |
| 212 | /** @brief Handle an update done event */ |
| 213 | void onUpdateDone(); |
| 214 | |
| 215 | /** @brief Handle an update failure event */ |
| 216 | void onUpdateFailed(); |
| 217 | |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 218 | /** @brief Start PSU update */ |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 219 | Status startActivation(); |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 220 | |
| 221 | /** @brief Finish PSU update */ |
| 222 | void finishActivation(); |
| 223 | |
Lei YU | 9edb733 | 2019-09-19 14:46:19 +0800 | [diff] [blame] | 224 | /** @brief Check if the PSU is comaptible with this software*/ |
| 225 | bool isCompatible(const std::string& psuInventoryPath); |
| 226 | |
Lei YU | 2e0e2de | 2019-09-26 16:42:23 +0800 | [diff] [blame] | 227 | /** @brief Store the updated PSU image to persistent dir */ |
| 228 | void storeImage(); |
| 229 | |
Lei YU | e8945ea | 2019-09-29 17:25:31 +0800 | [diff] [blame] | 230 | /** @brief Construct the systemd service name |
| 231 | * |
| 232 | * @param[in] psuInventoryPath - The PSU inventory to be updated. |
| 233 | * |
| 234 | * @return The escaped string of systemd unit to do the PSU update. |
| 235 | */ |
| 236 | std::string getUpdateService(const std::string& psuInventoryPath); |
| 237 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 238 | /** @brief Persistent sdbusplus DBus bus connection */ |
Patrick Williams | 374fae5 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 239 | sdbusplus::bus_t& bus; |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 240 | |
| 241 | /** @brief Persistent DBus object path */ |
Lei YU | 9930137 | 2019-09-29 16:27:12 +0800 | [diff] [blame] | 242 | std::string objPath; |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 243 | |
Lei YU | a5c47bb | 2019-09-29 11:28:53 +0800 | [diff] [blame] | 244 | /** @brief Version id */ |
| 245 | std::string versionId; |
| 246 | |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 247 | /** @brief Used to subscribe to dbus systemd signals */ |
| 248 | sdbusplus::bus::match_t systemdSignals; |
| 249 | |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 250 | /** @brief The queue of psu objects to be updated */ |
| 251 | std::queue<std::string> psuQueue; |
| 252 | |
| 253 | /** @brief The progress step for each PSU update is done */ |
| 254 | uint32_t progressStep; |
| 255 | |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 256 | /** @brief The PSU update systemd unit */ |
| 257 | std::string psuUpdateUnit; |
Lei YU | 81c6772 | 2019-09-11 16:47:29 +0800 | [diff] [blame] | 258 | |
Lei YU | 7f2a215 | 2019-09-16 16:50:18 +0800 | [diff] [blame] | 259 | /** @brief The PSU Inventory path of the current updating PSU */ |
| 260 | std::string currentUpdatingPsu; |
| 261 | |
Lei YU | 81c6772 | 2019-09-11 16:47:29 +0800 | [diff] [blame] | 262 | /** @brief Persistent ActivationBlocksTransition dbus object */ |
| 263 | std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition; |
Lei YU | 90c8a8b | 2019-09-11 17:20:03 +0800 | [diff] [blame] | 264 | |
| 265 | /** @brief Persistent ActivationProgress dbus object */ |
| 266 | std::unique_ptr<ActivationProgress> activationProgress; |
Lei YU | 7f2a215 | 2019-09-16 16:50:18 +0800 | [diff] [blame] | 267 | |
| 268 | /** @brief The AssociationInterface pointer */ |
| 269 | AssociationInterface* associationInterface; |
Lei YU | 9edb733 | 2019-09-19 14:46:19 +0800 | [diff] [blame] | 270 | |
Lei YU | ffb3653 | 2019-10-15 13:55:24 +0800 | [diff] [blame] | 271 | /** @brief The activationListener pointer */ |
| 272 | ActivationListener* activationListener; |
| 273 | |
Lei YU | 9edb733 | 2019-09-19 14:46:19 +0800 | [diff] [blame] | 274 | /** @brief The PSU manufacturer of the software */ |
| 275 | std::string manufacturer; |
| 276 | |
| 277 | /** @brief The PSU model of the software */ |
| 278 | std::string model; |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 279 | }; |
| 280 | |
| 281 | } // namespace updater |
| 282 | } // namespace software |
| 283 | } // namespace phosphor |