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> |
Adriana Kobylak | aea48f2 | 2018-07-10 10:20:56 -0500 | [diff] [blame^] | 6 | #include <sdbusplus/exception.hpp> |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 7 | |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 8 | #ifdef WANT_SIGNATURE_VERIFY |
| 9 | #include <phosphor-logging/elog.hpp> |
| 10 | #include <phosphor-logging/elog-errors.hpp> |
| 11 | #include <xyz/openbmc_project/Common/error.hpp> |
| 12 | #include "image_verify.hpp" |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 13 | #endif |
| 14 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 15 | namespace phosphor |
| 16 | { |
| 17 | namespace software |
| 18 | { |
| 19 | namespace updater |
| 20 | { |
| 21 | |
| 22 | namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server; |
| 23 | |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 24 | using namespace phosphor::logging; |
Adriana Kobylak | aea48f2 | 2018-07-10 10:20:56 -0500 | [diff] [blame^] | 25 | using sdbusplus::exception::SdBusError; |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 26 | |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 27 | #ifdef WANT_SIGNATURE_VERIFY |
| 28 | using InternalFailure = |
| 29 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
Jayanth Othayoth | 9a9d7c2 | 2018-03-28 10:05:26 -0500 | [diff] [blame] | 30 | namespace control = sdbusplus::xyz::openbmc_project::Control::server; |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 31 | #endif |
| 32 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 33 | void Activation::subscribeToSystemdSignals() |
| 34 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 35 | auto method = this->bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 36 | SYSTEMD_INTERFACE, "Subscribe"); |
Adriana Kobylak | aea48f2 | 2018-07-10 10:20:56 -0500 | [diff] [blame^] | 37 | try |
| 38 | { |
| 39 | this->bus.call_noreply(method); |
| 40 | } |
| 41 | catch (const SdBusError& e) |
| 42 | { |
| 43 | if (e.name() != nullptr && |
| 44 | strcmp("org.freedesktop.systemd1.AlreadySubscribed", e.name()) == 0) |
| 45 | { |
| 46 | // If an Activation attempt fails, the Unsubscribe method is not |
| 47 | // called. This may lead to an AlreadySubscribed error if the |
| 48 | // Activation is re-attempted. |
| 49 | } |
| 50 | else |
| 51 | { |
| 52 | log<level::ERR>("Error subscribing to systemd", |
| 53 | entry("ERROR=%s", e.what())); |
| 54 | } |
| 55 | } |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 56 | |
| 57 | return; |
| 58 | } |
| 59 | |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 60 | void Activation::unsubscribeFromSystemdSignals() |
| 61 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 62 | auto method = this->bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 63 | SYSTEMD_INTERFACE, "Unsubscribe"); |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 64 | this->bus.call_noreply(method); |
| 65 | |
| 66 | return; |
| 67 | } |
| 68 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 69 | auto Activation::activation(Activations value) -> Activations |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 70 | { |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 71 | |
Adriana Kobylak | 8bd84c8 | 2018-01-24 14:19:24 -0600 | [diff] [blame] | 72 | if ((value != softwareServer::Activation::Activations::Active) && |
| 73 | (value != softwareServer::Activation::Activations::Activating)) |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 74 | { |
| 75 | redundancyPriority.reset(nullptr); |
| 76 | } |
| 77 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 78 | if (value == softwareServer::Activation::Activations::Activating) |
| 79 | { |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 80 | if (rwVolumeCreated == false && roVolumeCreated == false) |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 81 | { |
Adriana Kobylak | aea48f2 | 2018-07-10 10:20:56 -0500 | [diff] [blame^] | 82 | // Enable systemd signals |
| 83 | Activation::subscribeToSystemdSignals(); |
| 84 | |
Adriana Kobylak | 204e1e7 | 2018-01-24 16:00:05 -0600 | [diff] [blame] | 85 | parent.freeSpace(); |
| 86 | |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 87 | if (!activationProgress) |
| 88 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 89 | activationProgress = |
| 90 | std::make_unique<ActivationProgress>(bus, path); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 91 | } |
| 92 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 93 | if (!activationBlocksTransition) |
| 94 | { |
| 95 | activationBlocksTransition = |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 96 | std::make_unique<ActivationBlocksTransition>(bus, path); |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 97 | } |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 98 | |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 99 | #ifdef WANT_SIGNATURE_VERIFY |
| 100 | using Signature = phosphor::software::image::Signature; |
| 101 | |
| 102 | fs::path uploadDir(IMG_UPLOAD_DIR); |
| 103 | |
| 104 | Signature signature(uploadDir / versionId, SIGNED_IMAGE_CONF_PATH); |
| 105 | |
| 106 | // Validate the signed image. |
| 107 | if (!signature.verify()) |
| 108 | { |
| 109 | log<level::ERR>("Error occurred during image validation"); |
| 110 | report<InternalFailure>(); |
| 111 | |
Jayanth Othayoth | 9a9d7c2 | 2018-03-28 10:05:26 -0500 | [diff] [blame] | 112 | // Stop the activation process, if fieldMode is enabled. |
| 113 | if (parent.control::FieldMode::fieldModeEnabled()) |
| 114 | { |
| 115 | // Cleanup |
| 116 | activationBlocksTransition.reset(nullptr); |
| 117 | activationProgress.reset(nullptr); |
| 118 | |
| 119 | return softwareServer::Activation::activation( |
| 120 | softwareServer::Activation::Activations::Failed); |
| 121 | } |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 122 | } |
| 123 | #endif |
| 124 | |
Adriana Kobylak | 9f89e2e | 2018-05-30 13:16:20 -0500 | [diff] [blame] | 125 | flashWrite(); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 126 | |
| 127 | activationProgress->progress(10); |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 128 | } |
| 129 | else if (rwVolumeCreated == true && roVolumeCreated == true) |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 130 | { |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 131 | if (ubootEnvVarsUpdated == false) |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 132 | { |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 133 | activationProgress->progress(90); |
| 134 | |
| 135 | if (!redundancyPriority) |
| 136 | { |
| 137 | redundancyPriority = std::make_unique<RedundancyPriority>( |
| 138 | bus, path, *this, 0); |
| 139 | } |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 140 | } |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 141 | else |
| 142 | { |
| 143 | activationProgress->progress(100); |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 144 | |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 145 | activationBlocksTransition.reset(nullptr); |
| 146 | activationProgress.reset(nullptr); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 147 | |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 148 | rwVolumeCreated = false; |
| 149 | roVolumeCreated = false; |
| 150 | ubootEnvVarsUpdated = false; |
| 151 | Activation::unsubscribeFromSystemdSignals(); |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 152 | |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 153 | // Remove version object from image manager |
| 154 | Activation::deleteImageManagerObject(); |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 155 | |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 156 | // Create active association |
| 157 | parent.createActiveAssociation(path); |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 158 | |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 159 | return softwareServer::Activation::activation( |
| 160 | softwareServer::Activation::Activations::Active); |
| 161 | } |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 162 | } |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 163 | } |
| 164 | else |
| 165 | { |
| 166 | activationBlocksTransition.reset(nullptr); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 167 | activationProgress.reset(nullptr); |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 168 | } |
| 169 | return softwareServer::Activation::activation(value); |
| 170 | } |
| 171 | |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 172 | void Activation::deleteImageManagerObject() |
| 173 | { |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 174 | // Call the Delete object for <versionID> inside image_manager |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 175 | auto method = this->bus.new_method_call(VERSION_BUSNAME, path.c_str(), |
| 176 | "xyz.openbmc_project.Object.Delete", |
| 177 | "Delete"); |
Adriana Kobylak | 00bd902 | 2018-01-24 13:55:58 -0600 | [diff] [blame] | 178 | auto mapperResponseMsg = bus.call(method); |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 179 | // Check that the bus call didn't result in an error |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 180 | if (mapperResponseMsg.is_method_error()) |
| 181 | { |
| 182 | log<level::ERR>("Error in Deleting image from image manager", |
Adriana Kobylak | 596466b | 2018-02-13 14:48:53 -0600 | [diff] [blame] | 183 | entry("VERSIONPATH=%s", path.c_str())); |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 184 | return; |
| 185 | } |
| 186 | } |
| 187 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 188 | auto Activation::requestedActivation(RequestedActivations value) |
| 189 | -> RequestedActivations |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 190 | { |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 191 | rwVolumeCreated = false; |
| 192 | roVolumeCreated = false; |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 193 | ubootEnvVarsUpdated = false; |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 194 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 195 | if ((value == softwareServer::Activation::RequestedActivations::Active) && |
| 196 | (softwareServer::Activation::requestedActivation() != |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 197 | softwareServer::Activation::RequestedActivations::Active)) |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 198 | { |
| 199 | if ((softwareServer::Activation::activation() == |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 200 | softwareServer::Activation::Activations::Ready) || |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 201 | (softwareServer::Activation::activation() == |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 202 | softwareServer::Activation::Activations::Failed)) |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 203 | { |
| 204 | Activation::activation( |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 205 | softwareServer::Activation::Activations::Activating); |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | return softwareServer::Activation::requestedActivation(value); |
| 209 | } |
| 210 | |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 211 | uint8_t RedundancyPriority::priority(uint8_t value) |
| 212 | { |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 213 | // Set the priority value so that the freePriority() function can order |
| 214 | // the versions by priority. |
| 215 | auto newPriority = softwareServer::RedundancyPriority::priority(value); |
Saqib Khan | 5d53267 | 2017-08-09 10:44:50 -0500 | [diff] [blame] | 216 | storeToFile(parent.versionId, value); |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 217 | parent.parent.freePriority(value, parent.versionId); |
| 218 | return newPriority; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 219 | } |
| 220 | |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 221 | uint8_t RedundancyPriority::sdbusPriority(uint8_t value) |
Saqib Khan | f0382c3 | 2017-10-24 13:36:22 -0500 | [diff] [blame] | 222 | { |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 223 | storeToFile(parent.versionId, value); |
| 224 | return softwareServer::RedundancyPriority::priority(value); |
Saqib Khan | f0382c3 | 2017-10-24 13:36:22 -0500 | [diff] [blame] | 225 | } |
| 226 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 227 | void Activation::unitStateChange(sdbusplus::message::message& msg) |
| 228 | { |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 229 | if (softwareServer::Activation::activation() != |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 230 | softwareServer::Activation::Activations::Activating) |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 231 | { |
| 232 | return; |
| 233 | } |
| 234 | |
Adriana Kobylak | 3ce563a | 2018-06-06 16:41:15 -0500 | [diff] [blame] | 235 | onStateChanges(msg); |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 236 | |
| 237 | return; |
| 238 | } |
| 239 | |
Saqib Khan | f37cefc | 2017-09-12 08:44:41 -0500 | [diff] [blame] | 240 | void ActivationBlocksTransition::enableRebootGuard() |
| 241 | { |
| 242 | log<level::INFO>("BMC image activating - BMC reboots are disabled."); |
| 243 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 244 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 245 | SYSTEMD_INTERFACE, "StartUnit"); |
Saqib Khan | f37cefc | 2017-09-12 08:44:41 -0500 | [diff] [blame] | 246 | method.append("reboot-guard-enable.service", "replace"); |
| 247 | bus.call_noreply(method); |
| 248 | } |
| 249 | |
| 250 | void ActivationBlocksTransition::disableRebootGuard() |
| 251 | { |
| 252 | log<level::INFO>("BMC activation has ended - BMC reboots are re-enabled."); |
| 253 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 254 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 255 | SYSTEMD_INTERFACE, "StartUnit"); |
Saqib Khan | f37cefc | 2017-09-12 08:44:41 -0500 | [diff] [blame] | 256 | method.append("reboot-guard-disable.service", "replace"); |
| 257 | bus.call_noreply(method); |
| 258 | } |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 259 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 260 | } // namespace updater |
| 261 | } // namespace software |
| 262 | } // namespace phosphor |