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