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