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