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