Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 3 | #include <sdbusplus/server.hpp> |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 4 | #include <xyz/openbmc_project/Software/Activation/server.hpp> |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 5 | #include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp> |
Adriana Kobylak | 9f89e2e | 2018-05-30 13:16:20 -0500 | [diff] [blame^] | 6 | #include "flash.hpp" |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 7 | #include "xyz/openbmc_project/Software/RedundancyPriority/server.hpp" |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 8 | #include "xyz/openbmc_project/Software/ActivationProgress/server.hpp" |
Gunnar Mills | f5eaf39 | 2017-08-22 16:36:55 -0500 | [diff] [blame] | 9 | #include "org/openbmc/Associations/server.hpp" |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 10 | |
| 11 | namespace phosphor |
| 12 | { |
| 13 | namespace software |
| 14 | { |
| 15 | namespace updater |
| 16 | { |
| 17 | |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 18 | using AssociationList = |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 19 | std::vector<std::tuple<std::string, std::string, std::string>>; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 20 | using ActivationInherit = sdbusplus::server::object::object< |
Gunnar Mills | f5eaf39 | 2017-08-22 16:36:55 -0500 | [diff] [blame] | 21 | sdbusplus::xyz::openbmc_project::Software::server::Activation, |
Michael Tritz | 4254bec | 2017-10-03 17:18:22 -0500 | [diff] [blame] | 22 | sdbusplus::org::openbmc::server::Associations>; |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 23 | using ActivationBlocksTransitionInherit = sdbusplus::server::object::object< |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 24 | sdbusplus::xyz::openbmc_project::Software::server:: |
| 25 | ActivationBlocksTransition>; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 26 | using RedundancyPriorityInherit = sdbusplus::server::object::object< |
| 27 | sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>; |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 28 | using ActivationProgressInherit = sdbusplus::server::object::object< |
| 29 | sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 30 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 31 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 32 | |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 33 | class ItemUpdater; |
| 34 | class Activation; |
| 35 | class RedundancyPriority; |
| 36 | |
| 37 | /** @class RedundancyPriority |
| 38 | * @brief OpenBMC RedundancyPriority implementation |
| 39 | * @details A concrete implementation for |
| 40 | * xyz.openbmc_project.Software.RedundancyPriority DBus API. |
| 41 | */ |
| 42 | class RedundancyPriority : public RedundancyPriorityInherit |
| 43 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 44 | public: |
| 45 | /** @brief Constructs RedundancyPriority. |
| 46 | * |
| 47 | * @param[in] bus - The Dbus bus object |
| 48 | * @param[in] path - The Dbus object path |
| 49 | * @param[in] parent - Parent object. |
| 50 | * @param[in] value - The redundancyPriority value |
| 51 | * @param[in] freePriority - Call freePriorioty, default to true |
| 52 | */ |
| 53 | RedundancyPriority(sdbusplus::bus::bus& bus, const std::string& path, |
| 54 | Activation& parent, uint8_t value, |
| 55 | bool freePriority = true) : |
| 56 | RedundancyPriorityInherit(bus, path.c_str(), true), |
| 57 | parent(parent), bus(bus), path(path) |
| 58 | { |
| 59 | // Set Property |
| 60 | if (freePriority) |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 61 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 62 | priority(value); |
| 63 | } |
| 64 | else |
| 65 | { |
| 66 | sdbusPriority(value); |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 67 | } |
| 68 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 69 | std::vector<std::string> interfaces({interface}); |
| 70 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 71 | } |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 72 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 73 | ~RedundancyPriority() |
| 74 | { |
| 75 | std::vector<std::string> interfaces({interface}); |
| 76 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 77 | } |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 78 | |
Gunnar Mills | e11a202 | 2018-03-23 12:04:48 -0500 | [diff] [blame] | 79 | /** @brief Overridden Priority property set function, calls freePriority |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 80 | * to bump the duplicated priority values. |
| 81 | * |
| 82 | * @param[in] value - uint8_t |
| 83 | * |
| 84 | * @return Success or exception thrown |
| 85 | */ |
| 86 | uint8_t priority(uint8_t value) override; |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 87 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 88 | /** @brief Non-Overriden Priority property set function |
| 89 | * |
| 90 | * @param[in] value - uint8_t |
| 91 | * |
| 92 | * @return Success or exception thrown |
| 93 | */ |
| 94 | uint8_t sdbusPriority(uint8_t value); |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 95 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 96 | /** @brief Priority property get function |
| 97 | * |
| 98 | * @returns uint8_t - The Priority value |
| 99 | */ |
| 100 | using RedundancyPriorityInherit::priority; |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 101 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 102 | /** @brief Parent Object. */ |
| 103 | Activation& parent; |
| 104 | |
| 105 | private: |
| 106 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 107 | static constexpr auto interface = |
| 108 | "xyz.openbmc_project.Software.RedundancyPriority"; |
| 109 | sdbusplus::bus::bus& bus; |
| 110 | std::string path; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 111 | }; |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 112 | |
| 113 | /** @class ActivationBlocksTransition |
| 114 | * @brief OpenBMC ActivationBlocksTransition implementation. |
| 115 | * @details A concrete implementation for |
| 116 | * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API. |
| 117 | */ |
| 118 | class ActivationBlocksTransition : public ActivationBlocksTransitionInherit |
| 119 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 120 | public: |
| 121 | /** @brief Constructs ActivationBlocksTransition. |
| 122 | * |
| 123 | * @param[in] bus - The Dbus bus object |
| 124 | * @param[in] path - The Dbus object path |
| 125 | */ |
| 126 | ActivationBlocksTransition(sdbusplus::bus::bus& bus, |
| 127 | const std::string& path) : |
| 128 | ActivationBlocksTransitionInherit(bus, path.c_str(), true), |
| 129 | bus(bus), path(path) |
| 130 | { |
| 131 | std::vector<std::string> interfaces({interface}); |
| 132 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 133 | enableRebootGuard(); |
| 134 | } |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 135 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 136 | ~ActivationBlocksTransition() |
| 137 | { |
| 138 | std::vector<std::string> interfaces({interface}); |
| 139 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 140 | disableRebootGuard(); |
| 141 | } |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 142 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 143 | private: |
| 144 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 145 | static constexpr auto interface = |
| 146 | "xyz.openbmc_project.Software.ActivationBlocksTransition"; |
| 147 | sdbusplus::bus::bus& bus; |
| 148 | std::string path; |
Saqib Khan | f37cefc | 2017-09-12 08:44:41 -0500 | [diff] [blame] | 149 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 150 | /** @brief Enables a Guard that blocks any BMC reboot commands */ |
| 151 | void enableRebootGuard(); |
Saqib Khan | f37cefc | 2017-09-12 08:44:41 -0500 | [diff] [blame] | 152 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 153 | /** @brief Disables any guard that was blocking the BMC reboot */ |
| 154 | void disableRebootGuard(); |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 155 | }; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 156 | |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 157 | class ActivationProgress : public ActivationProgressInherit |
| 158 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 159 | public: |
| 160 | /** @brief Constructs ActivationProgress. |
| 161 | * |
| 162 | * @param[in] bus - The Dbus bus object |
| 163 | * @param[in] path - The Dbus object path |
| 164 | */ |
| 165 | ActivationProgress(sdbusplus::bus::bus& bus, const std::string& path) : |
| 166 | ActivationProgressInherit(bus, path.c_str(), true), bus(bus), path(path) |
| 167 | { |
| 168 | progress(0); |
| 169 | std::vector<std::string> interfaces({interface}); |
| 170 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 171 | } |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 172 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 173 | ~ActivationProgress() |
| 174 | { |
| 175 | std::vector<std::string> interfaces({interface}); |
| 176 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 177 | } |
Saqib Khan | 140fcb1 | 2017-08-07 09:06:57 -0500 | [diff] [blame] | 178 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 179 | private: |
| 180 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 181 | static constexpr auto interface = |
| 182 | "xyz.openbmc_project.Software.ActivationProgress"; |
| 183 | sdbusplus::bus::bus& bus; |
| 184 | std::string path; |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 185 | }; |
| 186 | |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 187 | /** @class Activation |
| 188 | * @brief OpenBMC activation software management implementation. |
| 189 | * @details A concrete implementation for |
| 190 | * xyz.openbmc_project.Software.Activation DBus API. |
| 191 | */ |
Adriana Kobylak | 9f89e2e | 2018-05-30 13:16:20 -0500 | [diff] [blame^] | 192 | class Activation : public ActivationInherit, Flash |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 193 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 194 | public: |
| 195 | /** @brief Constructs Activation Software Manager |
| 196 | * |
| 197 | * @param[in] bus - The Dbus bus object |
| 198 | * @param[in] path - The Dbus object path |
| 199 | * @param[in] parent - Parent object. |
| 200 | * @param[in] versionId - The software version id |
| 201 | * @param[in] activationStatus - The status of Activation |
| 202 | * @param[in] assocs - Association objects |
| 203 | */ |
| 204 | Activation(sdbusplus::bus::bus& bus, const std::string& path, |
| 205 | ItemUpdater& parent, std::string& versionId, |
| 206 | sdbusplus::xyz::openbmc_project::Software::server::Activation:: |
| 207 | Activations activationStatus, |
| 208 | AssociationList& assocs) : |
| 209 | ActivationInherit(bus, path.c_str(), true), |
| 210 | bus(bus), path(path), parent(parent), versionId(versionId), |
| 211 | systemdSignals( |
| 212 | bus, |
| 213 | sdbusRule::type::signal() + sdbusRule::member("JobRemoved") + |
| 214 | sdbusRule::path("/org/freedesktop/systemd1") + |
| 215 | sdbusRule::interface("org.freedesktop.systemd1.Manager"), |
| 216 | std::bind(std::mem_fn(&Activation::unitStateChange), this, |
| 217 | std::placeholders::_1)) |
| 218 | { |
| 219 | // Enable systemd signals |
| 220 | subscribeToSystemdSignals(); |
| 221 | // Set Properties. |
| 222 | activation(activationStatus); |
| 223 | associations(assocs); |
Gunnar Mills | b60add1 | 2017-08-24 16:41:42 -0500 | [diff] [blame] | 224 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 225 | // Emit deferred signal. |
| 226 | emit_object_added(); |
| 227 | } |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 228 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 229 | /** @brief Overloaded Activation property setter function |
| 230 | * |
| 231 | * @param[in] value - One of Activation::Activations |
| 232 | * |
| 233 | * @return Success or exception thrown |
| 234 | */ |
| 235 | Activations activation(Activations value) override; |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 236 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 237 | /** @brief Activation */ |
| 238 | using ActivationInherit::activation; |
Leonel Gonzalez | e423368 | 2017-07-07 14:38:25 -0500 | [diff] [blame] | 239 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 240 | /** @brief Overloaded requestedActivation property setter function |
| 241 | * |
| 242 | * @param[in] value - One of Activation::RequestedActivations |
| 243 | * |
| 244 | * @return Success or exception thrown |
| 245 | */ |
| 246 | RequestedActivations |
| 247 | requestedActivation(RequestedActivations value) override; |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 248 | |
Adriana Kobylak | 9f89e2e | 2018-05-30 13:16:20 -0500 | [diff] [blame^] | 249 | /** @brief Overloaded write flash function */ |
| 250 | void flashWrite() override; |
| 251 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 252 | /** @brief Check if systemd state change is relevant to this object |
| 253 | * |
| 254 | * Instance specific interface to handle the detected systemd state |
| 255 | * change |
| 256 | * |
| 257 | * @param[in] msg - Data associated with subscribed signal |
| 258 | * |
| 259 | */ |
| 260 | void unitStateChange(sdbusplus::message::message& msg); |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 261 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 262 | /** |
| 263 | * @brief subscribe to the systemd signals |
| 264 | * |
| 265 | * This object needs to capture when it's systemd targets complete |
| 266 | * so it can keep it's state updated |
| 267 | * |
| 268 | */ |
| 269 | void subscribeToSystemdSignals(); |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 270 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 271 | /** |
| 272 | * @brief unsubscribe from the systemd signals |
| 273 | * |
| 274 | * systemd signals are only of interest during the activation process. |
| 275 | * Once complete, we want to unsubscribe to avoid unnecessary calls of |
| 276 | * unitStateChange(). |
| 277 | * |
| 278 | */ |
| 279 | void unsubscribeFromSystemdSignals(); |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 280 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 281 | /** |
| 282 | * @brief Deletes the version from Image Manager and the |
| 283 | * untar image from image upload dir. |
| 284 | */ |
| 285 | void deleteImageManagerObject(); |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 286 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 287 | /** @brief Persistent sdbusplus DBus bus connection */ |
| 288 | sdbusplus::bus::bus& bus; |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 289 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 290 | /** @brief Persistent DBus object path */ |
| 291 | std::string path; |
Gunnar Mills | 2ce7da2 | 2017-05-04 15:37:56 -0500 | [diff] [blame] | 292 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 293 | /** @brief Parent Object. */ |
| 294 | ItemUpdater& parent; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 295 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 296 | /** @brief Version id */ |
| 297 | std::string versionId; |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 298 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 299 | /** @brief Persistent ActivationBlocksTransition dbus object */ |
| 300 | std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 301 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 302 | /** @brief Persistent RedundancyPriority dbus object */ |
| 303 | std::unique_ptr<RedundancyPriority> redundancyPriority; |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 304 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 305 | /** @brief Persistent ActivationProgress dbus object */ |
| 306 | std::unique_ptr<ActivationProgress> activationProgress; |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 307 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 308 | /** @brief Used to subscribe to dbus systemd signals **/ |
| 309 | sdbusplus::bus::match_t systemdSignals; |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 310 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 311 | /** @brief Tracks whether the read-write volume has been created as |
| 312 | * part of the activation process. **/ |
| 313 | bool rwVolumeCreated = false; |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 314 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 315 | /** @brief Tracks whether the read-only volume has been created as |
| 316 | * part of the activation process. **/ |
| 317 | bool roVolumeCreated = false; |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 318 | |
| 319 | /** @brief Tracks if the service that updates the U-Boot environment |
| 320 | * variables has completed. **/ |
| 321 | bool ubootEnvVarsUpdated = false; |
Gunnar Mills | ec1b41c | 2017-05-02 12:20:36 -0500 | [diff] [blame] | 322 | }; |
| 323 | |
| 324 | } // namespace updater |
| 325 | } // namespace software |
| 326 | } // namespace phosphor |