Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Gunnar Mills | f6ed589 | 2018-09-07 17:08:02 -0500 | [diff] [blame] | 3 | #include "config.h" |
| 4 | |
Jayashankar Padath | 4d3d912 | 2019-07-24 16:46:22 +0530 | [diff] [blame] | 5 | #include "utils.hpp" |
Gunnar Mills | f6ed589 | 2018-09-07 17:08:02 -0500 | [diff] [blame] | 6 | #include "xyz/openbmc_project/Software/ActivationProgress/server.hpp" |
| 7 | #include "xyz/openbmc_project/Software/ExtendedVersion/server.hpp" |
| 8 | #include "xyz/openbmc_project/Software/RedundancyPriority/server.hpp" |
| 9 | |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 10 | #include <sdbusplus/server.hpp> |
John Wang | d05d472 | 2019-09-11 15:18:15 +0800 | [diff] [blame] | 11 | #include <xyz/openbmc_project/Association/Definitions/server.hpp> |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 12 | #include <xyz/openbmc_project/Software/Activation/server.hpp> |
Adriana Kobylak | ea9626f | 2017-04-05 15:37:40 -0500 | [diff] [blame] | 13 | #include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp> |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 14 | |
| 15 | namespace openpower |
| 16 | { |
| 17 | namespace software |
| 18 | { |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 19 | namespace updater |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 20 | { |
| 21 | |
Gunnar Mills | 3edb84b | 2017-08-18 15:13:15 -0500 | [diff] [blame] | 22 | using AssociationList = |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 23 | std::vector<std::tuple<std::string, std::string, std::string>>; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 24 | using ActivationInherit = sdbusplus::server::object::object< |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 25 | sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion, |
Saqib Khan | c350c61 | 2017-08-13 13:36:44 -0500 | [diff] [blame] | 26 | sdbusplus::xyz::openbmc_project::Software::server::Activation, |
John Wang | d05d472 | 2019-09-11 15:18:15 +0800 | [diff] [blame] | 27 | sdbusplus::xyz::openbmc_project::Association::server::Definitions>; |
Adriana Kobylak | ea9626f | 2017-04-05 15:37:40 -0500 | [diff] [blame] | 28 | using ActivationBlocksTransitionInherit = sdbusplus::server::object::object< |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 29 | sdbusplus::xyz::openbmc_project::Software::server:: |
| 30 | ActivationBlocksTransition>; |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 31 | using RedundancyPriorityInherit = sdbusplus::server::object::object< |
| 32 | sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>; |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 33 | using ActivationProgressInherit = sdbusplus::server::object::object< |
| 34 | sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>; |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 35 | |
Jayashankar Padath | 4d3d912 | 2019-07-24 16:46:22 +0530 | [diff] [blame] | 36 | constexpr auto applyTimeImmediate = |
| 37 | "xyz.openbmc_project.Software.ApplyTime.RequestedApplyTimes.Immediate"; |
| 38 | constexpr auto applyTimeIntf = "xyz.openbmc_project.Software.ApplyTime"; |
| 39 | constexpr auto dbusPropIntf = "org.freedesktop.DBus.Properties"; |
| 40 | constexpr auto applyTimeObjPath = "/xyz/openbmc_project/software/apply_time"; |
| 41 | constexpr auto applyTimeProp = "RequestedApplyTime"; |
| 42 | |
| 43 | constexpr auto hostStateIntf = "xyz.openbmc_project.State.Host"; |
| 44 | constexpr auto hostStateObjPath = "/xyz/openbmc_project/state/host0"; |
| 45 | constexpr auto hostStateRebootProp = "RequestedHostTransition"; |
| 46 | constexpr auto hostStateRebootVal = |
| 47 | "xyz.openbmc_project.State.Host.Transition.Reboot"; |
| 48 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 49 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 50 | |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 51 | class ItemUpdater; |
| 52 | class Activation; |
| 53 | class RedundancyPriority; |
| 54 | |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 55 | /** @class RedundancyPriority |
| 56 | * @brief OpenBMC RedundancyPriority implementation |
| 57 | * @details A concrete implementation for |
| 58 | * xyz.openbmc_project.Software.RedundancyPriority DBus API. |
| 59 | */ |
| 60 | class RedundancyPriority : public RedundancyPriorityInherit |
| 61 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 62 | public: |
| 63 | /** @brief Constructs RedundancyPriority. |
| 64 | * |
| 65 | * @param[in] bus - The Dbus bus object |
| 66 | * @param[in] path - The Dbus object path |
| 67 | * @param[in] parent - Parent object. |
| 68 | * @param[in] value - The redundancyPriority value |
| 69 | */ |
| 70 | RedundancyPriority(sdbusplus::bus::bus& bus, const std::string& path, |
| 71 | Activation& parent, uint8_t value) : |
Albert Zhang | 7f1967d | 2020-03-02 14:12:08 +0800 | [diff] [blame] | 72 | RedundancyPriorityInherit(bus, path.c_str(), |
| 73 | action::emit_interface_added), |
| 74 | parent(parent) |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 75 | { |
| 76 | // Set Property |
| 77 | priority(value); |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 78 | } |
Saqib Khan | 2021b4c | 2017-06-07 14:37:36 -0500 | [diff] [blame] | 79 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 80 | /** @brief Overloaded Priority property set function |
| 81 | * |
| 82 | * @param[in] value - uint8_t |
| 83 | * |
| 84 | * @return Success or exception thrown |
| 85 | */ |
| 86 | uint8_t priority(uint8_t value) override; |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 87 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 88 | /** @brief Priority property get function |
| 89 | * |
| 90 | * @returns uint8_t - The Priority value |
| 91 | */ |
| 92 | using RedundancyPriorityInherit::priority; |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 93 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 94 | /** @brief Parent Object. */ |
| 95 | Activation& parent; |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 96 | }; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 97 | |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 98 | /** @class ActivationBlocksTransition |
| 99 | * @brief OpenBMC ActivationBlocksTransition implementation. |
| 100 | * @details A concrete implementation for |
| 101 | * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API. |
| 102 | */ |
| 103 | class ActivationBlocksTransition : public ActivationBlocksTransitionInherit |
| 104 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 105 | public: |
| 106 | /** @brief Constructs ActivationBlocksTransition. |
| 107 | * |
| 108 | * @param[in] bus - The Dbus bus object |
| 109 | * @param[in] path - The Dbus object path |
| 110 | */ |
| 111 | ActivationBlocksTransition(sdbusplus::bus::bus& bus, |
| 112 | const std::string& path) : |
Albert Zhang | 7f1967d | 2020-03-02 14:12:08 +0800 | [diff] [blame] | 113 | ActivationBlocksTransitionInherit(bus, path.c_str(), |
| 114 | action::emit_interface_added) |
Adriana Kobylak | a8eda56 | 2017-07-17 15:24:29 -0500 | [diff] [blame] | 115 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 116 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 117 | } |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 118 | }; |
| 119 | |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 120 | class ActivationProgress : public ActivationProgressInherit |
| 121 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 122 | public: |
| 123 | /** @brief Constructs ActivationProgress. |
| 124 | * |
| 125 | * @param[in] bus - The Dbus bus object |
| 126 | * @param[in] path - The Dbus object path |
| 127 | */ |
| 128 | ActivationProgress(sdbusplus::bus::bus& bus, const std::string& path) : |
Albert Zhang | 7f1967d | 2020-03-02 14:12:08 +0800 | [diff] [blame] | 129 | ActivationProgressInherit(bus, path.c_str(), |
| 130 | action::emit_interface_added) |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 131 | { |
| 132 | progress(0); |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 133 | } |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 134 | }; |
| 135 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 136 | /** @class Activation |
| 137 | * @brief OpenBMC activation software management implementation. |
| 138 | * @details A concrete implementation for |
| 139 | * xyz.openbmc_project.Software.Activation DBus API. |
| 140 | */ |
| 141 | class Activation : public ActivationInherit |
| 142 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 143 | public: |
| 144 | /** @brief Constructs Activation Software Manager |
| 145 | * |
| 146 | * @param[in] bus - The Dbus bus object |
| 147 | * @param[in] path - The Dbus object path |
| 148 | * @param[in] parent - Parent object. |
| 149 | * @param[in] versionId - The software version id |
| 150 | * @param[in] extVersion - The extended version |
| 151 | * @param[in] activationStatus - The status of Activation |
| 152 | * @param[in] assocs - Association objects |
| 153 | */ |
| 154 | Activation(sdbusplus::bus::bus& bus, const std::string& path, |
Lei YU | a9ac927 | 2019-02-22 16:38:35 +0800 | [diff] [blame] | 155 | ItemUpdater& parent, const std::string& versionId, |
| 156 | const std::string& extVersion, |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 157 | sdbusplus::xyz::openbmc_project::Software::server::Activation:: |
| 158 | Activations activationStatus, |
| 159 | AssociationList& assocs) : |
| 160 | ActivationInherit(bus, path.c_str(), true), |
| 161 | bus(bus), path(path), parent(parent), versionId(versionId), |
| 162 | systemdSignals( |
| 163 | bus, |
| 164 | sdbusRule::type::signal() + sdbusRule::member("JobRemoved") + |
| 165 | sdbusRule::path("/org/freedesktop/systemd1") + |
| 166 | sdbusRule::interface("org.freedesktop.systemd1.Manager"), |
| 167 | std::bind(std::mem_fn(&Activation::unitStateChange), this, |
| 168 | std::placeholders::_1)) |
| 169 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 170 | // Set Properties. |
| 171 | extendedVersion(extVersion); |
| 172 | activation(activationStatus); |
| 173 | associations(assocs); |
Gunnar Mills | 3edb84b | 2017-08-18 15:13:15 -0500 | [diff] [blame] | 174 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 175 | // Emit deferred signal. |
| 176 | emit_object_added(); |
| 177 | } |
Lei YU | 9b21efc | 2019-02-21 15:52:53 +0800 | [diff] [blame] | 178 | virtual ~Activation() = default; |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 179 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 180 | /** @brief Activation property get function |
| 181 | * |
| 182 | * @returns One of Activation::Activations |
| 183 | */ |
| 184 | using ActivationInherit::activation; |
Saqib Khan | 2cbfa03 | 2017-08-17 14:52:37 -0500 | [diff] [blame] | 185 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 186 | /** @brief Overloaded requestedActivation property setter function |
| 187 | * |
| 188 | * @param[in] value - One of Activation::RequestedActivations |
| 189 | * |
| 190 | * @return Success or exception thrown |
| 191 | */ |
| 192 | RequestedActivations |
| 193 | requestedActivation(RequestedActivations value) override; |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 194 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 195 | /** |
| 196 | * @brief subscribe to the systemd signals |
| 197 | * |
| 198 | * This object needs to capture when it's systemd targets complete |
| 199 | * so it can keep it's state updated |
| 200 | * |
| 201 | **/ |
| 202 | void subscribeToSystemdSignals(); |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 203 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 204 | /** |
| 205 | * @brief unsubscribe from the systemd signals |
| 206 | * |
| 207 | * Once the activation process has completed successfully, we can |
| 208 | * safely unsubscribe from systemd signals. |
| 209 | * |
| 210 | **/ |
| 211 | void unsubscribeFromSystemdSignals(); |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 212 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 213 | /** @brief Persistent sdbusplus DBus bus connection */ |
| 214 | sdbusplus::bus::bus& bus; |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 215 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 216 | /** @brief Persistent DBus object path */ |
| 217 | std::string path; |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 218 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 219 | /** @brief Parent Object. */ |
| 220 | ItemUpdater& parent; |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 221 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 222 | /** @brief Version id */ |
| 223 | std::string versionId; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 224 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 225 | /** @brief Persistent ActivationBlocksTransition dbus object */ |
| 226 | std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition; |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 227 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 228 | /** @brief Persistent ActivationProgress dbus object */ |
| 229 | std::unique_ptr<ActivationProgress> activationProgress; |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 230 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 231 | /** @brief Persistent RedundancyPriority dbus object */ |
| 232 | std::unique_ptr<RedundancyPriority> redundancyPriority; |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 233 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 234 | /** @brief Used to subscribe to dbus systemd signals **/ |
| 235 | sdbusplus::bus::match_t systemdSignals; |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 236 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 237 | /** @brief activation status property get function |
| 238 | * |
| 239 | * @returns Activations - The activation value |
| 240 | */ |
| 241 | using ActivationInherit::activation; |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 242 | |
Jayashankar Padath | 4d3d912 | 2019-07-24 16:46:22 +0530 | [diff] [blame] | 243 | /** |
| 244 | * @brief Determine the configured image apply time value |
| 245 | * |
| 246 | * @return true if the image apply time value is immediate |
| 247 | **/ |
| 248 | bool checkApplyTimeImmediate(); |
| 249 | |
| 250 | /** |
| 251 | * @brief Reboot the Host. Called when ApplyTime is immediate. |
| 252 | * |
| 253 | * @return none |
| 254 | **/ |
| 255 | void rebootHost(); |
| 256 | |
Lei YU | 9b21efc | 2019-02-21 15:52:53 +0800 | [diff] [blame] | 257 | protected: |
| 258 | /** @brief Check if systemd state change is relevant to this object |
| 259 | * |
| 260 | * Instance specific interface to handle the detected systemd state |
| 261 | * change |
| 262 | * |
| 263 | * @param[in] msg - Data associated with subscribed signal |
| 264 | * |
| 265 | */ |
| 266 | virtual void unitStateChange(sdbusplus::message::message& msg) = 0; |
| 267 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 268 | /** |
| 269 | * @brief Deletes the version from Image Manager and the |
| 270 | * untar image from image upload dir. |
| 271 | */ |
| 272 | void deleteImageManagerObject(); |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 273 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 274 | /** @brief Member function for clarity & brevity at activation start */ |
Lei YU | 9b21efc | 2019-02-21 15:52:53 +0800 | [diff] [blame] | 275 | virtual void startActivation() = 0; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 276 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 277 | /** @brief Member function for clarity & brevity at activation end */ |
Lei YU | 9b21efc | 2019-02-21 15:52:53 +0800 | [diff] [blame] | 278 | virtual void finishActivation() = 0; |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 279 | |
| 280 | #ifdef WANT_SIGNATURE_VERIFY |
| 281 | /** |
| 282 | * @brief Wrapper function for the signature verify function. |
| 283 | * Signature class verify function used for validating |
| 284 | * signed image. Also added additional logic to continue |
| 285 | * update process in lab environment by checking the |
| 286 | * fieldModeEnabled property. |
| 287 | * |
Lei YU | 2b2d229 | 2019-03-18 15:22:56 +0800 | [diff] [blame] | 288 | * @param[in] pnorFileName - The PNOR filename in image dir |
| 289 | * |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 290 | * @return true if successful signature validation or field |
| 291 | * mode is disabled. |
| 292 | * false for unsuccessful signature validation or |
| 293 | * any internal failure during the mapper call. |
| 294 | */ |
Lei YU | 2b2d229 | 2019-03-18 15:22:56 +0800 | [diff] [blame] | 295 | bool validateSignature(const std::string& pnorFileName); |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 296 | |
| 297 | /** |
| 298 | * @brief Gets the fieldModeEnabled property value. |
| 299 | * |
| 300 | * @return fieldModeEnabled property value |
| 301 | * @error InternalFailure exception thrown |
| 302 | */ |
| 303 | bool fieldModeEnabled(); |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 304 | #endif |
Adriana Kobylak | ea9626f | 2017-04-05 15:37:40 -0500 | [diff] [blame] | 305 | }; |
| 306 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 307 | } // namespace updater |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 308 | } // namespace software |
| 309 | } // namespace openpower |