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 | 9053225 | 2018-05-24 11:15:24 +0800 | [diff] [blame] | 114 | #ifdef WANT_SIGNATURE_VERIFY |
| 115 | fs::path uploadDir(IMG_UPLOAD_DIR); |
| 116 | if (!verifySignature(uploadDir / versionId, SIGNED_IMAGE_CONF_PATH)) |
| 117 | { |
| 118 | onVerifyFailed(); |
| 119 | // Stop the activation process, if fieldMode is enabled. |
| 120 | if (parent.control::FieldMode::fieldModeEnabled()) |
| 121 | { |
| 122 | return softwareServer::Activation::activation( |
| 123 | softwareServer::Activation::Activations::Failed); |
| 124 | } |
| 125 | } |
| 126 | #endif |
Adriana Kobylak | b824b2f | 2020-05-14 14:57:53 -0500 | [diff] [blame] | 127 | |
| 128 | if (!activationProgress) |
| 129 | { |
| 130 | activationProgress = |
| 131 | std::make_unique<ActivationProgress>(bus, path); |
| 132 | } |
| 133 | |
| 134 | if (!activationBlocksTransition) |
| 135 | { |
| 136 | activationBlocksTransition = |
| 137 | std::make_unique<ActivationBlocksTransition>(bus, path); |
| 138 | } |
| 139 | |
| 140 | activationProgress->progress(10); |
| 141 | |
Adriana Kobylak | a696359 | 2018-09-07 14:13:29 -0500 | [diff] [blame] | 142 | parent.freeSpace(*this); |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 143 | |
Adriana Kobylak | b824b2f | 2020-05-14 14:57:53 -0500 | [diff] [blame] | 144 | // Enable systemd signals |
| 145 | Activation::subscribeToSystemdSignals(); |
| 146 | |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 147 | flashWrite(); |
| 148 | |
Adriana Kobylak | 70f5bc0 | 2020-05-13 14:08:14 -0500 | [diff] [blame] | 149 | #if defined UBIFS_LAYOUT || defined MMC_LAYOUT |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 150 | |
Adriana Kobylak | b824b2f | 2020-05-14 14:57:53 -0500 | [diff] [blame] | 151 | return softwareServer::Activation::activation(value); |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 152 | |
Adriana Kobylak | 70f5bc0 | 2020-05-13 14:08:14 -0500 | [diff] [blame] | 153 | #else // STATIC_LAYOUT |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 154 | |
Adriana Kobylak | b824b2f | 2020-05-14 14:57:53 -0500 | [diff] [blame] | 155 | onFlashWriteSuccess(); |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 156 | return softwareServer::Activation::activation( |
| 157 | softwareServer::Activation::Activations::Active); |
| 158 | #endif |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 159 | } |
| 160 | else |
| 161 | { |
| 162 | activationBlocksTransition.reset(nullptr); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 163 | activationProgress.reset(nullptr); |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 164 | } |
| 165 | return softwareServer::Activation::activation(value); |
| 166 | } |
| 167 | |
Adriana Kobylak | b824b2f | 2020-05-14 14:57:53 -0500 | [diff] [blame] | 168 | void Activation::onFlashWriteSuccess() |
| 169 | { |
| 170 | activationProgress->progress(100); |
| 171 | |
| 172 | activationBlocksTransition.reset(nullptr); |
| 173 | activationProgress.reset(nullptr); |
| 174 | |
| 175 | rwVolumeCreated = false; |
| 176 | roVolumeCreated = false; |
| 177 | ubootEnvVarsUpdated = false; |
| 178 | Activation::unsubscribeFromSystemdSignals(); |
| 179 | |
| 180 | storePurpose(versionId, parent.versions.find(versionId)->second->purpose()); |
| 181 | |
| 182 | if (!redundancyPriority) |
| 183 | { |
| 184 | redundancyPriority = |
| 185 | std::make_unique<RedundancyPriority>(bus, path, *this, 0); |
| 186 | } |
| 187 | |
| 188 | // Remove version object from image manager |
| 189 | Activation::deleteImageManagerObject(); |
| 190 | |
| 191 | // Create active association |
| 192 | parent.createActiveAssociation(path); |
| 193 | |
| 194 | // Create updateable association as this |
| 195 | // can be re-programmed. |
| 196 | parent.createUpdateableAssociation(path); |
| 197 | |
| 198 | if (Activation::checkApplyTimeImmediate() == true) |
| 199 | { |
| 200 | log<level::INFO>("Image Active. ApplyTime is immediate, " |
| 201 | "rebooting BMC."); |
| 202 | Activation::rebootBmc(); |
| 203 | } |
| 204 | else |
| 205 | { |
| 206 | log<level::INFO>("BMC image ready, need reboot to get activated."); |
| 207 | } |
| 208 | |
| 209 | activation(softwareServer::Activation::Activations::Active); |
| 210 | } |
| 211 | |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 212 | void Activation::deleteImageManagerObject() |
| 213 | { |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 214 | // Call the Delete object for <versionID> inside image_manager |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 215 | auto method = this->bus.new_method_call(VERSION_BUSNAME, path.c_str(), |
| 216 | "xyz.openbmc_project.Object.Delete", |
| 217 | "Delete"); |
Adriana Kobylak | 3b6a4cd | 2018-12-10 13:45:09 -0600 | [diff] [blame] | 218 | try |
| 219 | { |
| 220 | bus.call_noreply(method); |
| 221 | } |
| 222 | catch (const SdBusError& e) |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 223 | { |
| 224 | log<level::ERR>("Error in Deleting image from image manager", |
Adriana Kobylak | 596466b | 2018-02-13 14:48:53 -0600 | [diff] [blame] | 225 | entry("VERSIONPATH=%s", path.c_str())); |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 226 | return; |
| 227 | } |
| 228 | } |
| 229 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 230 | auto Activation::requestedActivation(RequestedActivations value) |
| 231 | -> RequestedActivations |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 232 | { |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 233 | rwVolumeCreated = false; |
| 234 | roVolumeCreated = false; |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 235 | ubootEnvVarsUpdated = false; |
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 | if ((value == softwareServer::Activation::RequestedActivations::Active) && |
| 238 | (softwareServer::Activation::requestedActivation() != |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 239 | softwareServer::Activation::RequestedActivations::Active)) |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 240 | { |
| 241 | if ((softwareServer::Activation::activation() == |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 242 | softwareServer::Activation::Activations::Ready) || |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 243 | (softwareServer::Activation::activation() == |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 244 | softwareServer::Activation::Activations::Failed)) |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 245 | { |
| 246 | Activation::activation( |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 247 | softwareServer::Activation::Activations::Activating); |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | return softwareServer::Activation::requestedActivation(value); |
| 251 | } |
| 252 | |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 253 | uint8_t RedundancyPriority::priority(uint8_t value) |
| 254 | { |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 255 | // Set the priority value so that the freePriority() function can order |
| 256 | // the versions by priority. |
| 257 | auto newPriority = softwareServer::RedundancyPriority::priority(value); |
Adriana Kobylak | bbcb7be | 2018-07-17 15:47:34 -0500 | [diff] [blame] | 258 | parent.parent.savePriority(parent.versionId, value); |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 259 | parent.parent.freePriority(value, parent.versionId); |
| 260 | return newPriority; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 261 | } |
| 262 | |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 263 | uint8_t RedundancyPriority::sdbusPriority(uint8_t value) |
Saqib Khan | f0382c3 | 2017-10-24 13:36:22 -0500 | [diff] [blame] | 264 | { |
Adriana Kobylak | bbcb7be | 2018-07-17 15:47:34 -0500 | [diff] [blame] | 265 | parent.parent.savePriority(parent.versionId, value); |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 266 | return softwareServer::RedundancyPriority::priority(value); |
Saqib Khan | f0382c3 | 2017-10-24 13:36:22 -0500 | [diff] [blame] | 267 | } |
| 268 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 269 | void Activation::unitStateChange(sdbusplus::message::message& msg) |
| 270 | { |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 271 | if (softwareServer::Activation::activation() != |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 272 | softwareServer::Activation::Activations::Activating) |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 273 | { |
| 274 | return; |
| 275 | } |
| 276 | |
Vijay Khemka | e9f6c84 | 2020-01-14 14:32:39 -0800 | [diff] [blame] | 277 | #ifdef HOST_BIOS_UPGRADE |
| 278 | auto purpose = parent.versions.find(versionId)->second->purpose(); |
| 279 | if (purpose == VersionPurpose::Host) |
| 280 | { |
| 281 | onStateChangesBios(msg); |
| 282 | return; |
| 283 | } |
| 284 | #endif |
| 285 | |
Adriana Kobylak | 3ce563a | 2018-06-06 16:41:15 -0500 | [diff] [blame] | 286 | onStateChanges(msg); |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 287 | |
| 288 | return; |
| 289 | } |
| 290 | |
Lei YU | 9053225 | 2018-05-24 11:15:24 +0800 | [diff] [blame] | 291 | #ifdef WANT_SIGNATURE_VERIFY |
| 292 | bool Activation::verifySignature(const fs::path& imageDir, |
| 293 | const fs::path& confDir) |
| 294 | { |
| 295 | using Signature = phosphor::software::image::Signature; |
| 296 | |
| 297 | Signature signature(imageDir, confDir); |
| 298 | |
| 299 | return signature.verify(); |
| 300 | } |
| 301 | |
| 302 | void Activation::onVerifyFailed() |
| 303 | { |
| 304 | log<level::ERR>("Error occurred during image validation"); |
| 305 | report<InternalFailure>(); |
| 306 | } |
| 307 | #endif |
| 308 | |
Saqib Khan | f37cefc | 2017-09-12 08:44:41 -0500 | [diff] [blame] | 309 | void ActivationBlocksTransition::enableRebootGuard() |
| 310 | { |
| 311 | log<level::INFO>("BMC image activating - BMC reboots are disabled."); |
| 312 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 313 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 314 | SYSTEMD_INTERFACE, "StartUnit"); |
Saqib Khan | f37cefc | 2017-09-12 08:44:41 -0500 | [diff] [blame] | 315 | method.append("reboot-guard-enable.service", "replace"); |
| 316 | bus.call_noreply(method); |
| 317 | } |
| 318 | |
| 319 | void ActivationBlocksTransition::disableRebootGuard() |
| 320 | { |
| 321 | log<level::INFO>("BMC activation has ended - BMC reboots are re-enabled."); |
| 322 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 323 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 324 | SYSTEMD_INTERFACE, "StartUnit"); |
Saqib Khan | f37cefc | 2017-09-12 08:44:41 -0500 | [diff] [blame] | 325 | method.append("reboot-guard-disable.service", "replace"); |
| 326 | bus.call_noreply(method); |
| 327 | } |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 328 | |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 329 | bool Activation::checkApplyTimeImmediate() |
| 330 | { |
| 331 | auto service = utils::getService(bus, applyTimeObjPath, applyTimeIntf); |
| 332 | if (service.empty()) |
| 333 | { |
| 334 | log<level::INFO>("Error getting the service name for BMC image " |
| 335 | "ApplyTime. The BMC needs to be manually rebooted to " |
| 336 | "complete the image activation if needed " |
| 337 | "immediately."); |
| 338 | } |
| 339 | else |
| 340 | { |
| 341 | |
| 342 | auto method = bus.new_method_call(service.c_str(), applyTimeObjPath, |
| 343 | dbusPropIntf, "Get"); |
| 344 | method.append(applyTimeIntf, applyTimeProp); |
| 345 | |
| 346 | try |
| 347 | { |
| 348 | auto reply = bus.call(method); |
| 349 | |
Patrick Williams | 24048b5 | 2020-05-13 17:51:30 -0500 | [diff] [blame] | 350 | std::variant<std::string> result; |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 351 | reply.read(result); |
Patrick Williams | e883fb8 | 2020-05-13 11:38:55 -0500 | [diff] [blame] | 352 | auto applyTime = std::get<std::string>(result); |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 353 | if (applyTime == applyTimeImmediate) |
| 354 | { |
| 355 | return true; |
| 356 | } |
| 357 | } |
| 358 | catch (const SdBusError& e) |
| 359 | { |
| 360 | log<level::ERR>("Error in getting ApplyTime", |
| 361 | entry("ERROR=%s", e.what())); |
| 362 | } |
| 363 | } |
| 364 | return false; |
| 365 | } |
| 366 | |
Vijay Khemka | e9f6c84 | 2020-01-14 14:32:39 -0800 | [diff] [blame] | 367 | #ifdef HOST_BIOS_UPGRADE |
| 368 | void Activation::flashWriteHost() |
| 369 | { |
| 370 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 371 | SYSTEMD_INTERFACE, "StartUnit"); |
| 372 | auto biosServiceFile = "obmc-flash-host-bios@" + versionId + ".service"; |
| 373 | method.append(biosServiceFile, "replace"); |
| 374 | try |
| 375 | { |
| 376 | auto reply = bus.call(method); |
| 377 | } |
| 378 | catch (const SdBusError& e) |
| 379 | { |
| 380 | log<level::ERR>("Error in trying to upgrade Host Bios."); |
| 381 | report<InternalFailure>(); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | void Activation::onStateChangesBios(sdbusplus::message::message& msg) |
| 386 | { |
| 387 | uint32_t newStateID{}; |
| 388 | sdbusplus::message::object_path newStateObjPath; |
| 389 | std::string newStateUnit{}; |
| 390 | std::string newStateResult{}; |
| 391 | |
| 392 | // Read the msg and populate each variable |
| 393 | msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult); |
| 394 | |
| 395 | auto biosServiceFile = "obmc-flash-host-bios@" + versionId + ".service"; |
| 396 | |
| 397 | if (newStateUnit == biosServiceFile) |
| 398 | { |
| 399 | // unsubscribe to systemd signals |
| 400 | unsubscribeFromSystemdSignals(); |
| 401 | |
| 402 | // Remove version object from image manager |
| 403 | deleteImageManagerObject(); |
| 404 | |
| 405 | if (newStateResult == "done") |
| 406 | { |
| 407 | // Set activation progress to 100 |
| 408 | activationProgress->progress(100); |
| 409 | |
| 410 | // Set Activation value to active |
| 411 | activation(softwareServer::Activation::Activations::Active); |
| 412 | |
| 413 | log<level::INFO>("Bios upgrade completed successfully."); |
| 414 | } |
| 415 | else if (newStateResult == "failed") |
| 416 | { |
| 417 | // Set Activation value to Failed |
| 418 | activation(softwareServer::Activation::Activations::Failed); |
| 419 | |
| 420 | log<level::ERR>("Bios upgrade failed."); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | return; |
| 425 | } |
| 426 | |
| 427 | #endif |
| 428 | |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 429 | void Activation::rebootBmc() |
| 430 | { |
| 431 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 432 | SYSTEMD_INTERFACE, "StartUnit"); |
| 433 | method.append("force-reboot.service", "replace"); |
| 434 | try |
| 435 | { |
| 436 | auto reply = bus.call(method); |
| 437 | } |
| 438 | catch (const SdBusError& e) |
| 439 | { |
| 440 | log<level::ALERT>("Error in trying to reboot the BMC. " |
| 441 | "The BMC needs to be manually rebooted to complete " |
| 442 | "the image activation."); |
| 443 | report<InternalFailure>(); |
| 444 | } |
| 445 | } |
| 446 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 447 | } // namespace updater |
| 448 | } // namespace software |
| 449 | } // namespace phosphor |