Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 1 | #include "activation.hpp" |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 2 | #include "item_updater.hpp" |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 3 | #include "config.h" |
Saqib Khan | 5d53267 | 2017-08-09 10:44:50 -0500 | [diff] [blame] | 4 | #include "serialize.hpp" |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 5 | #include <phosphor-logging/log.hpp> |
| 6 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 7 | |
| 8 | namespace phosphor |
| 9 | { |
| 10 | namespace software |
| 11 | { |
| 12 | namespace updater |
| 13 | { |
| 14 | |
| 15 | namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server; |
| 16 | |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 17 | using namespace phosphor::logging; |
| 18 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 19 | void Activation::subscribeToSystemdSignals() |
| 20 | { |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 21 | auto method = this->bus.new_method_call(SYSTEMD_BUSNAME, |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 22 | SYSTEMD_PATH, |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 23 | SYSTEMD_INTERFACE, |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 24 | "Subscribe"); |
| 25 | this->bus.call_noreply(method); |
| 26 | |
| 27 | return; |
| 28 | } |
| 29 | |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 30 | void Activation::unsubscribeFromSystemdSignals() |
| 31 | { |
| 32 | auto method = this->bus.new_method_call(SYSTEMD_BUSNAME, |
| 33 | SYSTEMD_PATH, |
| 34 | SYSTEMD_INTERFACE, |
| 35 | "Unsubscribe"); |
| 36 | this->bus.call_noreply(method); |
| 37 | |
| 38 | return; |
| 39 | } |
| 40 | |
Eddie James | 9440f49 | 2017-08-30 11:34:16 -0500 | [diff] [blame] | 41 | void Activation::delete_() |
| 42 | { |
| 43 | parent.erase(versionId); |
| 44 | } |
| 45 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 46 | auto Activation::activation(Activations value) -> |
| 47 | Activations |
| 48 | { |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 49 | |
| 50 | if (value != softwareServer::Activation::Activations::Active) |
| 51 | { |
| 52 | redundancyPriority.reset(nullptr); |
| 53 | } |
| 54 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 55 | if (value == softwareServer::Activation::Activations::Activating) |
| 56 | { |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 57 | if (rwVolumeCreated == false && roVolumeCreated == false) |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 58 | { |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 59 | if (!activationProgress) |
| 60 | { |
| 61 | activationProgress = std::make_unique<ActivationProgress>(bus, |
| 62 | path); |
| 63 | } |
| 64 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 65 | if (!activationBlocksTransition) |
| 66 | { |
| 67 | activationBlocksTransition = |
| 68 | std::make_unique<ActivationBlocksTransition>( |
| 69 | bus, |
| 70 | path); |
| 71 | } |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 72 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 73 | auto method = bus.new_method_call( |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 74 | SYSTEMD_BUSNAME, |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 75 | SYSTEMD_PATH, |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 76 | SYSTEMD_INTERFACE, |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 77 | "StartUnit"); |
| 78 | method.append("obmc-flash-bmc-ubirw.service", "replace"); |
| 79 | bus.call_noreply(method); |
| 80 | |
| 81 | auto roServiceFile = "obmc-flash-bmc-ubiro@" + versionId + |
| 82 | ".service"; |
| 83 | method = bus.new_method_call( |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 84 | SYSTEMD_BUSNAME, |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 85 | SYSTEMD_PATH, |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 86 | SYSTEMD_INTERFACE, |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 87 | "StartUnit"); |
| 88 | method.append(roServiceFile, "replace"); |
| 89 | bus.call_noreply(method); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 90 | |
| 91 | activationProgress->progress(10); |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 92 | } |
| 93 | else if (rwVolumeCreated == true && roVolumeCreated == true) |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 94 | { |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 95 | activationProgress->progress(90); |
| 96 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 97 | if (!redundancyPriority) |
| 98 | { |
| 99 | redundancyPriority = |
| 100 | std::make_unique<RedundancyPriority>( |
| 101 | bus, |
| 102 | path, |
| 103 | *this, |
| 104 | 0); |
| 105 | } |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 106 | |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 107 | activationProgress->progress(100); |
| 108 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 109 | activationBlocksTransition.reset(nullptr); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 110 | activationProgress.reset(nullptr); |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 111 | |
| 112 | rwVolumeCreated = false; |
| 113 | roVolumeCreated = false; |
| 114 | Activation::unsubscribeFromSystemdSignals(); |
| 115 | |
Gunnar Mills | ded875d | 2017-08-28 16:44:52 -0500 | [diff] [blame] | 116 | // Create active association |
| 117 | parent.createActiveAssociation(path); |
| 118 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 119 | return softwareServer::Activation::activation( |
| 120 | softwareServer::Activation::Activations::Active); |
| 121 | } |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 122 | } |
| 123 | else |
| 124 | { |
| 125 | activationBlocksTransition.reset(nullptr); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 126 | activationProgress.reset(nullptr); |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 127 | } |
| 128 | return softwareServer::Activation::activation(value); |
| 129 | } |
| 130 | |
| 131 | auto Activation::requestedActivation(RequestedActivations value) -> |
| 132 | RequestedActivations |
| 133 | { |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 134 | rwVolumeCreated = false; |
| 135 | roVolumeCreated = false; |
| 136 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 137 | if ((value == softwareServer::Activation::RequestedActivations::Active) && |
| 138 | (softwareServer::Activation::requestedActivation() != |
| 139 | softwareServer::Activation::RequestedActivations::Active)) |
| 140 | { |
| 141 | if ((softwareServer::Activation::activation() == |
| 142 | softwareServer::Activation::Activations::Ready) || |
| 143 | (softwareServer::Activation::activation() == |
| 144 | softwareServer::Activation::Activations::Failed)) |
| 145 | { |
| 146 | Activation::activation( |
| 147 | softwareServer::Activation::Activations::Activating); |
| 148 | |
| 149 | } |
| 150 | } |
| 151 | return softwareServer::Activation::requestedActivation(value); |
| 152 | } |
| 153 | |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 154 | uint8_t RedundancyPriority::priority(uint8_t value) |
| 155 | { |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 156 | parent.parent.freePriority(value, parent.versionId); |
Saqib Khan | 5d53267 | 2017-08-09 10:44:50 -0500 | [diff] [blame] | 157 | storeToFile(parent.versionId, value); |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 158 | |
| 159 | if(parent.parent.isLowestPriority(value)) |
| 160 | { |
| 161 | parent.updateUbootEnvVars(); |
| 162 | } |
| 163 | |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 164 | return softwareServer::RedundancyPriority::priority(value); |
| 165 | } |
| 166 | |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 167 | // TODO: openbmc/openbmc#2369 Add recovery policy to updateubootvars |
| 168 | // unit template. |
| 169 | // TODO: openbmc/openbmc#2370 Call StartUnit synchronously to handle |
| 170 | // Errors more gracefully. |
| 171 | void Activation::updateUbootEnvVars() |
| 172 | { |
| 173 | auto method = bus.new_method_call( |
| 174 | SYSTEMD_BUSNAME, |
| 175 | SYSTEMD_PATH, |
| 176 | SYSTEMD_INTERFACE, |
| 177 | "StartUnit"); |
| 178 | auto updateEnvVarsFile = "obmc-flash-bmc-updateubootvars@" + versionId + |
| 179 | ".service"; |
| 180 | method.append(updateEnvVarsFile, "replace"); |
| 181 | auto result = bus.call(method); |
| 182 | |
| 183 | //Check that the bus call didn't result in an error |
| 184 | if (result.is_method_error()) |
| 185 | { |
| 186 | log<level::ERR>("Failed to update u-boot env variables", |
| 187 | entry(" %s", SYSTEMD_INTERFACE)); |
| 188 | } |
| 189 | } |
| 190 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 191 | void Activation::unitStateChange(sdbusplus::message::message& msg) |
| 192 | { |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 193 | if (softwareServer::Activation::activation() != |
| 194 | softwareServer::Activation::Activations::Activating) |
| 195 | { |
| 196 | return; |
| 197 | } |
| 198 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 199 | uint32_t newStateID {}; |
| 200 | sdbusplus::message::object_path newStateObjPath; |
| 201 | std::string newStateUnit{}; |
| 202 | std::string newStateResult{}; |
| 203 | |
| 204 | //Read the msg and populate each variable |
| 205 | msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult); |
| 206 | |
| 207 | auto rwServiceFile = "obmc-flash-bmc-ubirw.service"; |
| 208 | auto roServiceFile = "obmc-flash-bmc-ubiro@" + versionId + ".service"; |
| 209 | |
| 210 | if(newStateUnit == rwServiceFile && newStateResult == "done") |
| 211 | { |
| 212 | rwVolumeCreated = true; |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 213 | activationProgress->progress(activationProgress->progress() + 20); |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | if(newStateUnit == roServiceFile && newStateResult == "done") |
| 217 | { |
| 218 | roVolumeCreated = true; |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 219 | activationProgress->progress(activationProgress->progress() + 50); |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | if(rwVolumeCreated && roVolumeCreated) |
| 223 | { |
| 224 | Activation::activation( |
| 225 | softwareServer::Activation::Activations::Activating); |
| 226 | } |
| 227 | |
| 228 | if((newStateUnit == rwServiceFile || newStateUnit == roServiceFile) && |
| 229 | (newStateResult == "failed" || newStateResult == "dependency")) |
| 230 | { |
| 231 | Activation::activation(softwareServer::Activation::Activations::Failed); |
| 232 | } |
| 233 | |
| 234 | return; |
| 235 | } |
| 236 | |
| 237 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 238 | } // namespace updater |
| 239 | } // namespace software |
| 240 | } // namespace phosphor |