Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 1 | #include "activation.hpp" |
Gunnar Mills | b0ce996 | 2018-09-07 13:39:10 -0500 | [diff] [blame] | 2 | |
Lei YU | 1be8d50 | 2018-06-20 11:48:36 +0800 | [diff] [blame] | 3 | #include "images.hpp" |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 4 | #include "item_updater.hpp" |
Saqib Khan | 5d53267 | 2017-08-09 10:44:50 -0500 | [diff] [blame] | 5 | #include "serialize.hpp" |
Gunnar Mills | b0ce996 | 2018-09-07 13:39:10 -0500 | [diff] [blame] | 6 | |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 7 | #include <phosphor-logging/elog-errors.hpp> |
| 8 | #include <phosphor-logging/elog.hpp> |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 9 | #include <phosphor-logging/log.hpp> |
Adriana Kobylak | aea48f2 | 2018-07-10 10:20:56 -0500 | [diff] [blame] | 10 | #include <sdbusplus/exception.hpp> |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 11 | #include <xyz/openbmc_project/Common/error.hpp> |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 12 | |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 13 | #ifdef WANT_SIGNATURE_VERIFY |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 14 | #include "image_verify.hpp" |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 15 | #endif |
| 16 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 17 | namespace phosphor |
| 18 | { |
| 19 | namespace software |
| 20 | { |
| 21 | namespace updater |
| 22 | { |
| 23 | |
| 24 | namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server; |
| 25 | |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 26 | using namespace phosphor::logging; |
Adriana Kobylak | aea48f2 | 2018-07-10 10:20:56 -0500 | [diff] [blame] | 27 | using sdbusplus::exception::SdBusError; |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 28 | using InternalFailure = |
| 29 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 30 | |
| 31 | #ifdef WANT_SIGNATURE_VERIFY |
Jayanth Othayoth | 9a9d7c2 | 2018-03-28 10:05:26 -0500 | [diff] [blame] | 32 | namespace control = sdbusplus::xyz::openbmc_project::Control::server; |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 33 | #endif |
| 34 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 35 | void Activation::subscribeToSystemdSignals() |
| 36 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 37 | auto method = this->bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 38 | SYSTEMD_INTERFACE, "Subscribe"); |
Adriana Kobylak | aea48f2 | 2018-07-10 10:20:56 -0500 | [diff] [blame] | 39 | try |
| 40 | { |
| 41 | this->bus.call_noreply(method); |
| 42 | } |
| 43 | catch (const SdBusError& e) |
| 44 | { |
| 45 | if (e.name() != nullptr && |
| 46 | strcmp("org.freedesktop.systemd1.AlreadySubscribed", e.name()) == 0) |
| 47 | { |
| 48 | // If an Activation attempt fails, the Unsubscribe method is not |
| 49 | // called. This may lead to an AlreadySubscribed error if the |
| 50 | // Activation is re-attempted. |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | log<level::ERR>("Error subscribing to systemd", |
| 55 | entry("ERROR=%s", e.what())); |
| 56 | } |
| 57 | } |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 58 | |
| 59 | return; |
| 60 | } |
| 61 | |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 62 | void Activation::unsubscribeFromSystemdSignals() |
| 63 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 64 | auto method = this->bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 65 | SYSTEMD_INTERFACE, "Unsubscribe"); |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 66 | try |
| 67 | { |
| 68 | this->bus.call_noreply(method); |
| 69 | } |
| 70 | catch (const SdBusError& e) |
| 71 | { |
| 72 | log<level::ERR>("Error in unsubscribing from systemd signals", |
| 73 | entry("ERROR=%s", e.what())); |
| 74 | } |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 75 | |
| 76 | return; |
| 77 | } |
| 78 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 79 | auto Activation::activation(Activations value) -> Activations |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 80 | { |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 81 | |
Adriana Kobylak | 8bd84c8 | 2018-01-24 14:19:24 -0600 | [diff] [blame] | 82 | if ((value != softwareServer::Activation::Activations::Active) && |
| 83 | (value != softwareServer::Activation::Activations::Activating)) |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 84 | { |
| 85 | redundancyPriority.reset(nullptr); |
| 86 | } |
| 87 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 88 | if (value == softwareServer::Activation::Activations::Activating) |
| 89 | { |
Vijay Khemka | e9f6c84 | 2020-01-14 14:32:39 -0800 | [diff] [blame] | 90 | |
| 91 | #ifdef HOST_BIOS_UPGRADE |
| 92 | auto purpose = parent.versions.find(versionId)->second->purpose(); |
| 93 | if (purpose == VersionPurpose::Host) |
| 94 | { |
| 95 | if (!activationProgress) |
| 96 | { |
| 97 | activationProgress = |
| 98 | std::make_unique<ActivationProgress>(bus, path); |
| 99 | } |
| 100 | |
| 101 | // Enable systemd signals |
| 102 | subscribeToSystemdSignals(); |
| 103 | |
| 104 | // Set initial progress |
| 105 | activationProgress->progress(20); |
| 106 | |
| 107 | // Initiate image writing to flash |
| 108 | flashWriteHost(); |
| 109 | |
| 110 | return softwareServer::Activation::activation(value); |
| 111 | } |
| 112 | #endif |
| 113 | |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 114 | #ifdef UBIFS_LAYOUT |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 115 | if (rwVolumeCreated == false && roVolumeCreated == false) |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 116 | { |
Adriana Kobylak | aea48f2 | 2018-07-10 10:20:56 -0500 | [diff] [blame] | 117 | // Enable systemd signals |
| 118 | Activation::subscribeToSystemdSignals(); |
| 119 | |
Adriana Kobylak | a696359 | 2018-09-07 14:13:29 -0500 | [diff] [blame] | 120 | parent.freeSpace(*this); |
Adriana Kobylak | 204e1e7 | 2018-01-24 16:00:05 -0600 | [diff] [blame] | 121 | |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 122 | if (!activationProgress) |
| 123 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 124 | activationProgress = |
| 125 | std::make_unique<ActivationProgress>(bus, path); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 126 | } |
| 127 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 128 | if (!activationBlocksTransition) |
| 129 | { |
| 130 | activationBlocksTransition = |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 131 | std::make_unique<ActivationBlocksTransition>(bus, path); |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 132 | } |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 133 | |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 134 | #ifdef WANT_SIGNATURE_VERIFY |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 135 | fs::path uploadDir(IMG_UPLOAD_DIR); |
Lei YU | 9053225 | 2018-05-24 11:15:24 +0800 | [diff] [blame] | 136 | if (!verifySignature(uploadDir / versionId, SIGNED_IMAGE_CONF_PATH)) |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 137 | { |
Lei YU | 9053225 | 2018-05-24 11:15:24 +0800 | [diff] [blame] | 138 | onVerifyFailed(); |
Jayanth Othayoth | 9a9d7c2 | 2018-03-28 10:05:26 -0500 | [diff] [blame] | 139 | // Stop the activation process, if fieldMode is enabled. |
| 140 | if (parent.control::FieldMode::fieldModeEnabled()) |
| 141 | { |
| 142 | // Cleanup |
| 143 | activationBlocksTransition.reset(nullptr); |
| 144 | activationProgress.reset(nullptr); |
Jayanth Othayoth | 9a9d7c2 | 2018-03-28 10:05:26 -0500 | [diff] [blame] | 145 | return softwareServer::Activation::activation( |
| 146 | softwareServer::Activation::Activations::Failed); |
| 147 | } |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 148 | } |
| 149 | #endif |
| 150 | |
Adriana Kobylak | 9f89e2e | 2018-05-30 13:16:20 -0500 | [diff] [blame] | 151 | flashWrite(); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 152 | |
| 153 | activationProgress->progress(10); |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 154 | } |
| 155 | else if (rwVolumeCreated == true && roVolumeCreated == true) |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 156 | { |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 157 | if (ubootEnvVarsUpdated == false) |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 158 | { |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 159 | activationProgress->progress(90); |
| 160 | |
Adriana Kobylak | ec4eec3 | 2019-11-13 14:28:35 -0600 | [diff] [blame] | 161 | storePurpose( |
| 162 | versionId, |
| 163 | parent.versions.find(versionId)->second->purpose()); |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 164 | if (!redundancyPriority) |
| 165 | { |
| 166 | redundancyPriority = std::make_unique<RedundancyPriority>( |
| 167 | bus, path, *this, 0); |
| 168 | } |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 169 | } |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 170 | else |
| 171 | { |
| 172 | activationProgress->progress(100); |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 173 | |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 174 | activationBlocksTransition.reset(nullptr); |
| 175 | activationProgress.reset(nullptr); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 176 | |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 177 | rwVolumeCreated = false; |
| 178 | roVolumeCreated = false; |
| 179 | ubootEnvVarsUpdated = false; |
| 180 | Activation::unsubscribeFromSystemdSignals(); |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 181 | |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 182 | // Remove version object from image manager |
| 183 | Activation::deleteImageManagerObject(); |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 184 | |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 185 | // Create active association |
| 186 | parent.createActiveAssociation(path); |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 187 | |
AppaRao Puli | bbebec7 | 2020-01-28 23:57:41 +0530 | [diff] [blame] | 188 | // Create updateable association as this |
| 189 | // can be re-programmed. |
| 190 | parent.createUpdateableAssociation(path); |
| 191 | |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 192 | if (Activation::checkApplyTimeImmediate() == true) |
| 193 | { |
| 194 | log<level::INFO>("Image Active. ApplyTime is immediate, " |
| 195 | "rebooting BMC."); |
| 196 | Activation::rebootBmc(); |
| 197 | } |
| 198 | |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 199 | return softwareServer::Activation::activation( |
| 200 | softwareServer::Activation::Activations::Active); |
| 201 | } |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 202 | } |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 203 | #else // !UBIFS_LAYOUT |
| 204 | |
Lei YU | 9053225 | 2018-05-24 11:15:24 +0800 | [diff] [blame] | 205 | #ifdef WANT_SIGNATURE_VERIFY |
| 206 | fs::path uploadDir(IMG_UPLOAD_DIR); |
| 207 | if (!verifySignature(uploadDir / versionId, SIGNED_IMAGE_CONF_PATH)) |
| 208 | { |
| 209 | onVerifyFailed(); |
| 210 | // Stop the activation process, if fieldMode is enabled. |
| 211 | if (parent.control::FieldMode::fieldModeEnabled()) |
| 212 | { |
| 213 | return softwareServer::Activation::activation( |
| 214 | softwareServer::Activation::Activations::Failed); |
| 215 | } |
| 216 | } |
| 217 | #endif |
Adriana Kobylak | a696359 | 2018-09-07 14:13:29 -0500 | [diff] [blame] | 218 | parent.freeSpace(*this); |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 219 | |
| 220 | flashWrite(); |
| 221 | |
Adriana Kobylak | ec4eec3 | 2019-11-13 14:28:35 -0600 | [diff] [blame] | 222 | storePurpose(versionId, |
| 223 | parent.versions.find(versionId)->second->purpose()); |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 224 | if (!redundancyPriority) |
| 225 | { |
| 226 | redundancyPriority = |
| 227 | std::make_unique<RedundancyPriority>(bus, path, *this, 0); |
| 228 | } |
| 229 | |
| 230 | // Remove version object from image manager |
| 231 | Activation::deleteImageManagerObject(); |
| 232 | |
| 233 | // Create active association |
| 234 | parent.createActiveAssociation(path); |
| 235 | |
Bright Cheng | 0d7198f | 2019-11-18 16:45:01 +0800 | [diff] [blame^] | 236 | if (Activation::checkApplyTimeImmediate() == true) |
| 237 | { |
| 238 | log<level::INFO>("Image Active. ApplyTime is immediate, " |
| 239 | "rebooting BMC."); |
| 240 | Activation::rebootBmc(); |
| 241 | } |
| 242 | else |
| 243 | { |
| 244 | log<level::INFO>("BMC image ready, need reboot to get activated."); |
| 245 | } |
| 246 | |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 247 | return softwareServer::Activation::activation( |
| 248 | softwareServer::Activation::Activations::Active); |
| 249 | #endif |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 250 | } |
| 251 | else |
| 252 | { |
| 253 | activationBlocksTransition.reset(nullptr); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 254 | activationProgress.reset(nullptr); |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 255 | } |
| 256 | return softwareServer::Activation::activation(value); |
| 257 | } |
| 258 | |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 259 | void Activation::deleteImageManagerObject() |
| 260 | { |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 261 | // Call the Delete object for <versionID> inside image_manager |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 262 | auto method = this->bus.new_method_call(VERSION_BUSNAME, path.c_str(), |
| 263 | "xyz.openbmc_project.Object.Delete", |
| 264 | "Delete"); |
Adriana Kobylak | 3b6a4cd | 2018-12-10 13:45:09 -0600 | [diff] [blame] | 265 | try |
| 266 | { |
| 267 | bus.call_noreply(method); |
| 268 | } |
| 269 | catch (const SdBusError& e) |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 270 | { |
| 271 | log<level::ERR>("Error in Deleting image from image manager", |
Adriana Kobylak | 596466b | 2018-02-13 14:48:53 -0600 | [diff] [blame] | 272 | entry("VERSIONPATH=%s", path.c_str())); |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 273 | return; |
| 274 | } |
| 275 | } |
| 276 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 277 | auto Activation::requestedActivation(RequestedActivations value) |
| 278 | -> RequestedActivations |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 279 | { |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 280 | rwVolumeCreated = false; |
| 281 | roVolumeCreated = false; |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 282 | ubootEnvVarsUpdated = false; |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 283 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 284 | if ((value == softwareServer::Activation::RequestedActivations::Active) && |
| 285 | (softwareServer::Activation::requestedActivation() != |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 286 | softwareServer::Activation::RequestedActivations::Active)) |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 287 | { |
| 288 | if ((softwareServer::Activation::activation() == |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 289 | softwareServer::Activation::Activations::Ready) || |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 290 | (softwareServer::Activation::activation() == |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 291 | softwareServer::Activation::Activations::Failed)) |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 292 | { |
| 293 | Activation::activation( |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 294 | softwareServer::Activation::Activations::Activating); |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | return softwareServer::Activation::requestedActivation(value); |
| 298 | } |
| 299 | |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 300 | uint8_t RedundancyPriority::priority(uint8_t value) |
| 301 | { |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 302 | // Set the priority value so that the freePriority() function can order |
| 303 | // the versions by priority. |
| 304 | auto newPriority = softwareServer::RedundancyPriority::priority(value); |
Adriana Kobylak | bbcb7be | 2018-07-17 15:47:34 -0500 | [diff] [blame] | 305 | parent.parent.savePriority(parent.versionId, value); |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 306 | parent.parent.freePriority(value, parent.versionId); |
| 307 | return newPriority; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 308 | } |
| 309 | |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 310 | uint8_t RedundancyPriority::sdbusPriority(uint8_t value) |
Saqib Khan | f0382c3 | 2017-10-24 13:36:22 -0500 | [diff] [blame] | 311 | { |
Adriana Kobylak | bbcb7be | 2018-07-17 15:47:34 -0500 | [diff] [blame] | 312 | parent.parent.savePriority(parent.versionId, value); |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 313 | return softwareServer::RedundancyPriority::priority(value); |
Saqib Khan | f0382c3 | 2017-10-24 13:36:22 -0500 | [diff] [blame] | 314 | } |
| 315 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 316 | void Activation::unitStateChange(sdbusplus::message::message& msg) |
| 317 | { |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 318 | if (softwareServer::Activation::activation() != |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 319 | softwareServer::Activation::Activations::Activating) |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 320 | { |
| 321 | return; |
| 322 | } |
| 323 | |
Vijay Khemka | e9f6c84 | 2020-01-14 14:32:39 -0800 | [diff] [blame] | 324 | #ifdef HOST_BIOS_UPGRADE |
| 325 | auto purpose = parent.versions.find(versionId)->second->purpose(); |
| 326 | if (purpose == VersionPurpose::Host) |
| 327 | { |
| 328 | onStateChangesBios(msg); |
| 329 | return; |
| 330 | } |
| 331 | #endif |
| 332 | |
Adriana Kobylak | 3ce563a | 2018-06-06 16:41:15 -0500 | [diff] [blame] | 333 | onStateChanges(msg); |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 334 | |
| 335 | return; |
| 336 | } |
| 337 | |
Lei YU | 9053225 | 2018-05-24 11:15:24 +0800 | [diff] [blame] | 338 | #ifdef WANT_SIGNATURE_VERIFY |
| 339 | bool Activation::verifySignature(const fs::path& imageDir, |
| 340 | const fs::path& confDir) |
| 341 | { |
| 342 | using Signature = phosphor::software::image::Signature; |
| 343 | |
| 344 | Signature signature(imageDir, confDir); |
| 345 | |
| 346 | return signature.verify(); |
| 347 | } |
| 348 | |
| 349 | void Activation::onVerifyFailed() |
| 350 | { |
| 351 | log<level::ERR>("Error occurred during image validation"); |
| 352 | report<InternalFailure>(); |
| 353 | } |
| 354 | #endif |
| 355 | |
Saqib Khan | f37cefc | 2017-09-12 08:44:41 -0500 | [diff] [blame] | 356 | void ActivationBlocksTransition::enableRebootGuard() |
| 357 | { |
| 358 | log<level::INFO>("BMC image activating - BMC reboots are disabled."); |
| 359 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 360 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 361 | SYSTEMD_INTERFACE, "StartUnit"); |
Saqib Khan | f37cefc | 2017-09-12 08:44:41 -0500 | [diff] [blame] | 362 | method.append("reboot-guard-enable.service", "replace"); |
| 363 | bus.call_noreply(method); |
| 364 | } |
| 365 | |
| 366 | void ActivationBlocksTransition::disableRebootGuard() |
| 367 | { |
| 368 | log<level::INFO>("BMC activation has ended - BMC reboots are re-enabled."); |
| 369 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 370 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 371 | SYSTEMD_INTERFACE, "StartUnit"); |
Saqib Khan | f37cefc | 2017-09-12 08:44:41 -0500 | [diff] [blame] | 372 | method.append("reboot-guard-disable.service", "replace"); |
| 373 | bus.call_noreply(method); |
| 374 | } |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 375 | |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 376 | bool Activation::checkApplyTimeImmediate() |
| 377 | { |
| 378 | auto service = utils::getService(bus, applyTimeObjPath, applyTimeIntf); |
| 379 | if (service.empty()) |
| 380 | { |
| 381 | log<level::INFO>("Error getting the service name for BMC image " |
| 382 | "ApplyTime. The BMC needs to be manually rebooted to " |
| 383 | "complete the image activation if needed " |
| 384 | "immediately."); |
| 385 | } |
| 386 | else |
| 387 | { |
| 388 | |
| 389 | auto method = bus.new_method_call(service.c_str(), applyTimeObjPath, |
| 390 | dbusPropIntf, "Get"); |
| 391 | method.append(applyTimeIntf, applyTimeProp); |
| 392 | |
| 393 | try |
| 394 | { |
| 395 | auto reply = bus.call(method); |
| 396 | |
Patrick Williams | 24048b5 | 2020-05-13 17:51:30 -0500 | [diff] [blame] | 397 | std::variant<std::string> result; |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 398 | reply.read(result); |
Patrick Williams | e883fb8 | 2020-05-13 11:38:55 -0500 | [diff] [blame] | 399 | auto applyTime = std::get<std::string>(result); |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 400 | if (applyTime == applyTimeImmediate) |
| 401 | { |
| 402 | return true; |
| 403 | } |
| 404 | } |
| 405 | catch (const SdBusError& e) |
| 406 | { |
| 407 | log<level::ERR>("Error in getting ApplyTime", |
| 408 | entry("ERROR=%s", e.what())); |
| 409 | } |
| 410 | } |
| 411 | return false; |
| 412 | } |
| 413 | |
Vijay Khemka | e9f6c84 | 2020-01-14 14:32:39 -0800 | [diff] [blame] | 414 | #ifdef HOST_BIOS_UPGRADE |
| 415 | void Activation::flashWriteHost() |
| 416 | { |
| 417 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 418 | SYSTEMD_INTERFACE, "StartUnit"); |
| 419 | auto biosServiceFile = "obmc-flash-host-bios@" + versionId + ".service"; |
| 420 | method.append(biosServiceFile, "replace"); |
| 421 | try |
| 422 | { |
| 423 | auto reply = bus.call(method); |
| 424 | } |
| 425 | catch (const SdBusError& e) |
| 426 | { |
| 427 | log<level::ERR>("Error in trying to upgrade Host Bios."); |
| 428 | report<InternalFailure>(); |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | void Activation::onStateChangesBios(sdbusplus::message::message& msg) |
| 433 | { |
| 434 | uint32_t newStateID{}; |
| 435 | sdbusplus::message::object_path newStateObjPath; |
| 436 | std::string newStateUnit{}; |
| 437 | std::string newStateResult{}; |
| 438 | |
| 439 | // Read the msg and populate each variable |
| 440 | msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult); |
| 441 | |
| 442 | auto biosServiceFile = "obmc-flash-host-bios@" + versionId + ".service"; |
| 443 | |
| 444 | if (newStateUnit == biosServiceFile) |
| 445 | { |
| 446 | // unsubscribe to systemd signals |
| 447 | unsubscribeFromSystemdSignals(); |
| 448 | |
| 449 | // Remove version object from image manager |
| 450 | deleteImageManagerObject(); |
| 451 | |
| 452 | if (newStateResult == "done") |
| 453 | { |
| 454 | // Set activation progress to 100 |
| 455 | activationProgress->progress(100); |
| 456 | |
| 457 | // Set Activation value to active |
| 458 | activation(softwareServer::Activation::Activations::Active); |
| 459 | |
| 460 | log<level::INFO>("Bios upgrade completed successfully."); |
| 461 | } |
| 462 | else if (newStateResult == "failed") |
| 463 | { |
| 464 | // Set Activation value to Failed |
| 465 | activation(softwareServer::Activation::Activations::Failed); |
| 466 | |
| 467 | log<level::ERR>("Bios upgrade failed."); |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | return; |
| 472 | } |
| 473 | |
| 474 | #endif |
| 475 | |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 476 | void Activation::rebootBmc() |
| 477 | { |
| 478 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 479 | SYSTEMD_INTERFACE, "StartUnit"); |
| 480 | method.append("force-reboot.service", "replace"); |
| 481 | try |
| 482 | { |
| 483 | auto reply = bus.call(method); |
| 484 | } |
| 485 | catch (const SdBusError& e) |
| 486 | { |
| 487 | log<level::ALERT>("Error in trying to reboot the BMC. " |
| 488 | "The BMC needs to be manually rebooted to complete " |
| 489 | "the image activation."); |
| 490 | report<InternalFailure>(); |
| 491 | } |
| 492 | } |
| 493 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 494 | } // namespace updater |
| 495 | } // namespace software |
| 496 | } // namespace phosphor |