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