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