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