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