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 | namespace phosphor |
| 8 | { |
| 9 | namespace software |
| 10 | { |
| 11 | namespace updater |
| 12 | { |
| 13 | |
| 14 | namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server; |
| 15 | |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 16 | using namespace phosphor::logging; |
| 17 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 18 | void Activation::subscribeToSystemdSignals() |
| 19 | { |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 20 | auto method = this->bus.new_method_call(SYSTEMD_BUSNAME, |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 21 | SYSTEMD_PATH, |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 22 | SYSTEMD_INTERFACE, |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 23 | "Subscribe"); |
| 24 | this->bus.call_noreply(method); |
| 25 | |
| 26 | return; |
| 27 | } |
| 28 | |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 29 | void Activation::unsubscribeFromSystemdSignals() |
| 30 | { |
| 31 | auto method = this->bus.new_method_call(SYSTEMD_BUSNAME, |
| 32 | SYSTEMD_PATH, |
| 33 | SYSTEMD_INTERFACE, |
| 34 | "Unsubscribe"); |
| 35 | this->bus.call_noreply(method); |
| 36 | |
| 37 | return; |
| 38 | } |
| 39 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 40 | auto Activation::activation(Activations value) -> |
| 41 | Activations |
| 42 | { |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 43 | |
Adriana Kobylak | 8bd84c8 | 2018-01-24 14:19:24 -0600 | [diff] [blame] | 44 | if ((value != softwareServer::Activation::Activations::Active) && |
| 45 | (value != softwareServer::Activation::Activations::Activating)) |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 46 | { |
| 47 | redundancyPriority.reset(nullptr); |
| 48 | } |
| 49 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 50 | if (value == softwareServer::Activation::Activations::Activating) |
| 51 | { |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 52 | if (rwVolumeCreated == false && roVolumeCreated == false) |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 53 | { |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 54 | if (!activationProgress) |
| 55 | { |
| 56 | activationProgress = std::make_unique<ActivationProgress>(bus, |
Gunnar Mills | 3fa3820 | 2017-10-08 17:07:43 -0500 | [diff] [blame] | 57 | path); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 58 | } |
| 59 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 60 | if (!activationBlocksTransition) |
| 61 | { |
| 62 | activationBlocksTransition = |
| 63 | std::make_unique<ActivationBlocksTransition>( |
| 64 | bus, |
| 65 | path); |
| 66 | } |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 67 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 68 | auto method = bus.new_method_call( |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 69 | SYSTEMD_BUSNAME, |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 70 | SYSTEMD_PATH, |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 71 | SYSTEMD_INTERFACE, |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 72 | "StartUnit"); |
| 73 | method.append("obmc-flash-bmc-ubirw.service", "replace"); |
| 74 | bus.call_noreply(method); |
| 75 | |
| 76 | auto roServiceFile = "obmc-flash-bmc-ubiro@" + versionId + |
| 77 | ".service"; |
| 78 | method = bus.new_method_call( |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 79 | SYSTEMD_BUSNAME, |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 80 | SYSTEMD_PATH, |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 81 | SYSTEMD_INTERFACE, |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 82 | "StartUnit"); |
| 83 | method.append(roServiceFile, "replace"); |
| 84 | bus.call_noreply(method); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 85 | |
| 86 | activationProgress->progress(10); |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 87 | } |
| 88 | else if (rwVolumeCreated == true && roVolumeCreated == true) |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 89 | { |
Adriana Kobylak | 4c3edc9 | 2018-01-24 14:50:15 -0600 | [diff] [blame] | 90 | if (ubootEnvVarsUpdated == false) |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 91 | { |
Adriana Kobylak | 4c3edc9 | 2018-01-24 14:50:15 -0600 | [diff] [blame] | 92 | activationProgress->progress(90); |
| 93 | |
| 94 | if (!redundancyPriority) |
| 95 | { |
| 96 | redundancyPriority = |
| 97 | std::make_unique<RedundancyPriority>( |
| 98 | bus, |
| 99 | path, |
| 100 | *this, |
| 101 | 0); |
| 102 | } |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 103 | } |
Adriana Kobylak | 4c3edc9 | 2018-01-24 14:50:15 -0600 | [diff] [blame] | 104 | else |
| 105 | { |
| 106 | activationProgress->progress(100); |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 107 | |
Adriana Kobylak | 4c3edc9 | 2018-01-24 14:50:15 -0600 | [diff] [blame] | 108 | activationBlocksTransition.reset(nullptr); |
| 109 | activationProgress.reset(nullptr); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 110 | |
Adriana Kobylak | 4c3edc9 | 2018-01-24 14:50:15 -0600 | [diff] [blame] | 111 | rwVolumeCreated = false; |
| 112 | roVolumeCreated = false; |
| 113 | ubootEnvVarsUpdated = false; |
| 114 | Activation::unsubscribeFromSystemdSignals(); |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 115 | |
Adriana Kobylak | 4c3edc9 | 2018-01-24 14:50:15 -0600 | [diff] [blame] | 116 | // Remove version object from image manager |
| 117 | Activation::deleteImageManagerObject(); |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 118 | |
Adriana Kobylak | 4c3edc9 | 2018-01-24 14:50:15 -0600 | [diff] [blame] | 119 | // Create active association |
| 120 | parent.createActiveAssociation(path); |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 121 | |
Adriana Kobylak | 4c3edc9 | 2018-01-24 14:50:15 -0600 | [diff] [blame] | 122 | return softwareServer::Activation::activation( |
| 123 | softwareServer::Activation::Activations::Active); |
| 124 | } |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 125 | } |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 126 | } |
| 127 | else |
| 128 | { |
| 129 | activationBlocksTransition.reset(nullptr); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 130 | activationProgress.reset(nullptr); |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 131 | } |
| 132 | return softwareServer::Activation::activation(value); |
| 133 | } |
| 134 | |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 135 | void Activation::deleteImageManagerObject() |
| 136 | { |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 137 | // Call the Delete object for <versionID> inside image_manager |
Adriana Kobylak | 00bd902 | 2018-01-24 13:55:58 -0600 | [diff] [blame] | 138 | auto method = this->bus.new_method_call(VERSION_BUSNAME, |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 139 | path.c_str(), |
| 140 | "xyz.openbmc_project.Object.Delete", |
| 141 | "Delete"); |
Adriana Kobylak | 00bd902 | 2018-01-24 13:55:58 -0600 | [diff] [blame] | 142 | auto mapperResponseMsg = bus.call(method); |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 143 | //Check that the bus call didn't result in an error |
| 144 | if (mapperResponseMsg.is_method_error()) |
| 145 | { |
| 146 | log<level::ERR>("Error in Deleting image from image manager", |
Adriana Kobylak | 596466b | 2018-02-13 14:48:53 -0600 | [diff] [blame^] | 147 | entry("VERSIONPATH=%s", path.c_str())); |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 148 | return; |
| 149 | } |
| 150 | } |
| 151 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 152 | auto Activation::requestedActivation(RequestedActivations value) -> |
| 153 | RequestedActivations |
| 154 | { |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 155 | rwVolumeCreated = false; |
| 156 | roVolumeCreated = false; |
Adriana Kobylak | 4c3edc9 | 2018-01-24 14:50:15 -0600 | [diff] [blame] | 157 | ubootEnvVarsUpdated = false; |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 158 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 159 | if ((value == softwareServer::Activation::RequestedActivations::Active) && |
| 160 | (softwareServer::Activation::requestedActivation() != |
| 161 | softwareServer::Activation::RequestedActivations::Active)) |
| 162 | { |
| 163 | if ((softwareServer::Activation::activation() == |
| 164 | softwareServer::Activation::Activations::Ready) || |
| 165 | (softwareServer::Activation::activation() == |
| 166 | softwareServer::Activation::Activations::Failed)) |
| 167 | { |
| 168 | Activation::activation( |
| 169 | softwareServer::Activation::Activations::Activating); |
| 170 | |
| 171 | } |
| 172 | } |
| 173 | return softwareServer::Activation::requestedActivation(value); |
| 174 | } |
| 175 | |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 176 | uint8_t RedundancyPriority::priority(uint8_t value) |
| 177 | { |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 178 | // Set the priority value so that the freePriority() function can order |
| 179 | // the versions by priority. |
| 180 | auto newPriority = softwareServer::RedundancyPriority::priority(value); |
Saqib Khan | 5d53267 | 2017-08-09 10:44:50 -0500 | [diff] [blame] | 181 | storeToFile(parent.versionId, value); |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 182 | parent.parent.freePriority(value, parent.versionId); |
| 183 | return newPriority; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 184 | } |
| 185 | |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 186 | uint8_t RedundancyPriority::sdbusPriority(uint8_t value) |
Saqib Khan | f0382c3 | 2017-10-24 13:36:22 -0500 | [diff] [blame] | 187 | { |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 188 | storeToFile(parent.versionId, value); |
| 189 | return softwareServer::RedundancyPriority::priority(value); |
Saqib Khan | f0382c3 | 2017-10-24 13:36:22 -0500 | [diff] [blame] | 190 | } |
| 191 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 192 | void Activation::unitStateChange(sdbusplus::message::message& msg) |
| 193 | { |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 194 | if (softwareServer::Activation::activation() != |
| 195 | softwareServer::Activation::Activations::Activating) |
| 196 | { |
| 197 | return; |
| 198 | } |
| 199 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 200 | uint32_t newStateID {}; |
| 201 | sdbusplus::message::object_path newStateObjPath; |
| 202 | std::string newStateUnit{}; |
| 203 | std::string newStateResult{}; |
| 204 | |
| 205 | //Read the msg and populate each variable |
| 206 | msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult); |
| 207 | |
| 208 | auto rwServiceFile = "obmc-flash-bmc-ubirw.service"; |
| 209 | auto roServiceFile = "obmc-flash-bmc-ubiro@" + versionId + ".service"; |
Adriana Kobylak | 4c3edc9 | 2018-01-24 14:50:15 -0600 | [diff] [blame] | 210 | auto ubootVarsServiceFile = "obmc-flash-bmc-updateubootvars@" + versionId + |
| 211 | ".service"; |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 212 | |
Gunnar Mills | 3fa3820 | 2017-10-08 17:07:43 -0500 | [diff] [blame] | 213 | if (newStateUnit == rwServiceFile && newStateResult == "done") |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 214 | { |
| 215 | rwVolumeCreated = true; |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 216 | activationProgress->progress(activationProgress->progress() + 20); |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 217 | } |
| 218 | |
Gunnar Mills | 3fa3820 | 2017-10-08 17:07:43 -0500 | [diff] [blame] | 219 | if (newStateUnit == roServiceFile && newStateResult == "done") |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 220 | { |
| 221 | roVolumeCreated = true; |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 222 | activationProgress->progress(activationProgress->progress() + 50); |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 223 | } |
| 224 | |
Adriana Kobylak | 4c3edc9 | 2018-01-24 14:50:15 -0600 | [diff] [blame] | 225 | if (newStateUnit == ubootVarsServiceFile && newStateResult == "done") |
| 226 | { |
| 227 | ubootEnvVarsUpdated = true; |
| 228 | } |
| 229 | |
| 230 | if (newStateUnit == rwServiceFile || |
| 231 | newStateUnit == roServiceFile || |
| 232 | newStateUnit == ubootVarsServiceFile) |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 233 | { |
Adriana Kobylak | 8bd84c8 | 2018-01-24 14:19:24 -0600 | [diff] [blame] | 234 | if (newStateResult == "failed" || newStateResult == "dependency") |
| 235 | { |
| 236 | Activation::activation( |
| 237 | softwareServer::Activation::Activations::Failed); |
| 238 | } |
Adriana Kobylak | 4c3edc9 | 2018-01-24 14:50:15 -0600 | [diff] [blame] | 239 | else if ((rwVolumeCreated && roVolumeCreated) || // Volumes were created |
| 240 | (ubootEnvVarsUpdated)) // Enviroment variables were updated |
Adriana Kobylak | 8bd84c8 | 2018-01-24 14:19:24 -0600 | [diff] [blame] | 241 | { |
| 242 | Activation::activation( |
| 243 | softwareServer::Activation::Activations::Activating); |
| 244 | } |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | return; |
| 248 | } |
| 249 | |
| 250 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 251 | } // namespace updater |
| 252 | } // namespace software |
| 253 | } // namespace phosphor |