Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 3 | #include "activation.hpp" |
| 4 | |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 5 | #include "utils.hpp" |
| 6 | |
Lei YU | d0bbfa9 | 2019-09-11 16:10:54 +0800 | [diff] [blame] | 7 | #include <phosphor-logging/elog-errors.hpp> |
Shawn McCarney | cdf86de | 2024-11-26 10:02:14 -0600 | [diff] [blame] | 8 | #include <phosphor-logging/lg2.hpp> |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 9 | |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 10 | #include <exception> |
Patrick Williams | 5670b18 | 2023-05-10 07:50:50 -0500 | [diff] [blame] | 11 | #include <filesystem> |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 12 | #include <format> |
| 13 | #include <stdexcept> |
| 14 | #include <vector> |
Patrick Williams | 5670b18 | 2023-05-10 07:50:50 -0500 | [diff] [blame] | 15 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 16 | namespace phosphor |
| 17 | { |
| 18 | namespace software |
| 19 | { |
| 20 | namespace updater |
| 21 | { |
| 22 | |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 23 | constexpr auto SYSTEMD_BUSNAME = "org.freedesktop.systemd1"; |
| 24 | constexpr auto SYSTEMD_PATH = "/org/freedesktop/systemd1"; |
| 25 | constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager"; |
| 26 | |
| 27 | namespace fs = std::filesystem; |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 28 | namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server; |
| 29 | |
Lei YU | d0bbfa9 | 2019-09-11 16:10:54 +0800 | [diff] [blame] | 30 | using namespace phosphor::logging; |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 31 | using SoftwareActivation = softwareServer::Activation; |
| 32 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 33 | auto Activation::activation(Activations value) -> Activations |
| 34 | { |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 35 | if (value == Status::Activating) |
| 36 | { |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 37 | value = startActivation(); |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 38 | } |
| 39 | else |
| 40 | { |
Lei YU | 81c6772 | 2019-09-11 16:47:29 +0800 | [diff] [blame] | 41 | activationBlocksTransition.reset(); |
Lei YU | 90c8a8b | 2019-09-11 17:20:03 +0800 | [diff] [blame] | 42 | activationProgress.reset(); |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | return SoftwareActivation::activation(value); |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | auto Activation::requestedActivation(RequestedActivations value) |
| 49 | -> RequestedActivations |
| 50 | { |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 51 | if ((value == SoftwareActivation::RequestedActivations::Active) && |
| 52 | (SoftwareActivation::requestedActivation() != |
| 53 | SoftwareActivation::RequestedActivations::Active)) |
| 54 | { |
Lei YU | 63f9e71 | 2019-10-12 15:16:55 +0800 | [diff] [blame] | 55 | // PSU image could be activated even when it's in active, |
| 56 | // e.g. in case a PSU is replaced and has a older image, it will be |
| 57 | // updated with the running PSU image that is stored in BMC. |
| 58 | if ((activation() == Status::Ready) || |
| 59 | (activation() == Status::Failed) || activation() == Status::Active) |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 60 | { |
| 61 | activation(Status::Activating); |
| 62 | } |
| 63 | } |
| 64 | return SoftwareActivation::requestedActivation(value); |
| 65 | } |
| 66 | |
Patrick Williams | 374fae5 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 67 | void Activation::unitStateChange(sdbusplus::message_t& msg) |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 68 | { |
| 69 | uint32_t newStateID{}; |
| 70 | sdbusplus::message::object_path newStateObjPath; |
| 71 | std::string newStateUnit{}; |
| 72 | std::string newStateResult{}; |
| 73 | |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 74 | try |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 75 | { |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 76 | // Read the msg and populate each variable |
| 77 | msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult); |
| 78 | |
| 79 | if (newStateUnit == psuUpdateUnit) |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 80 | { |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 81 | if (newStateResult == "done") |
| 82 | { |
| 83 | onUpdateDone(); |
| 84 | } |
| 85 | if (newStateResult == "failed" || newStateResult == "dependency") |
| 86 | { |
| 87 | onUpdateFailed(); |
| 88 | } |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 89 | } |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 90 | } |
| 91 | catch (const std::exception& e) |
| 92 | { |
| 93 | lg2::error("Unable to handle unit state change event: {ERROR}", "ERROR", |
| 94 | e); |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 98 | bool Activation::doUpdate(const std::string& psuInventoryPath) |
| 99 | { |
Lei YU | 7f2a215 | 2019-09-16 16:50:18 +0800 | [diff] [blame] | 100 | currentUpdatingPsu = psuInventoryPath; |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 101 | try |
| 102 | { |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 103 | psuUpdateUnit = getUpdateService(currentUpdatingPsu); |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 104 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 105 | SYSTEMD_INTERFACE, "StartUnit"); |
| 106 | method.append(psuUpdateUnit, "replace"); |
| 107 | bus.call_noreply(method); |
| 108 | return true; |
| 109 | } |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 110 | catch (const std::exception& e) |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 111 | { |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 112 | lg2::error("Error starting update service for PSU {PSU}: {ERROR}", |
| 113 | "PSU", psuInventoryPath, "ERROR", e); |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 114 | onUpdateFailed(); |
| 115 | return false; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | bool Activation::doUpdate() |
| 120 | { |
| 121 | // When the queue is empty, all updates are done |
| 122 | if (psuQueue.empty()) |
| 123 | { |
| 124 | finishActivation(); |
| 125 | return true; |
| 126 | } |
| 127 | |
| 128 | // Do the update on a PSU |
| 129 | const auto& psu = psuQueue.front(); |
| 130 | return doUpdate(psu); |
| 131 | } |
| 132 | |
| 133 | void Activation::onUpdateDone() |
| 134 | { |
| 135 | auto progress = activationProgress->progress() + progressStep; |
| 136 | activationProgress->progress(progress); |
| 137 | |
Lei YU | 7f2a215 | 2019-09-16 16:50:18 +0800 | [diff] [blame] | 138 | // Update the activation association |
| 139 | auto assocs = associations(); |
| 140 | assocs.emplace_back(ACTIVATION_FWD_ASSOCIATION, ACTIVATION_REV_ASSOCIATION, |
| 141 | currentUpdatingPsu); |
Lei YU | 7f2a215 | 2019-09-16 16:50:18 +0800 | [diff] [blame] | 142 | associations(assocs); |
| 143 | |
Lei YU | ffb3653 | 2019-10-15 13:55:24 +0800 | [diff] [blame] | 144 | activationListener->onUpdateDone(versionId, currentUpdatingPsu); |
| 145 | currentUpdatingPsu.clear(); |
| 146 | |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 147 | psuQueue.pop(); |
| 148 | doUpdate(); // Update the next psu |
| 149 | } |
| 150 | |
| 151 | void Activation::onUpdateFailed() |
| 152 | { |
| 153 | // TODO: report an event |
Shawn McCarney | cdf86de | 2024-11-26 10:02:14 -0600 | [diff] [blame] | 154 | lg2::error("Failed to update PSU {PSU}", "PSU", psuQueue.front()); |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 155 | std::queue<std::string>().swap(psuQueue); // Clear the queue |
| 156 | activation(Status::Failed); |
| 157 | } |
| 158 | |
| 159 | Activation::Status Activation::startActivation() |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 160 | { |
Lei YU | 63f9e71 | 2019-10-12 15:16:55 +0800 | [diff] [blame] | 161 | // Check if the activation has file path |
| 162 | if (path().empty()) |
| 163 | { |
Shawn McCarney | cdf86de | 2024-11-26 10:02:14 -0600 | [diff] [blame] | 164 | lg2::warning( |
| 165 | "No image for the activation, skipped version {VERSION_ID}", |
| 166 | "VERSION_ID", versionId); |
Lei YU | 63f9e71 | 2019-10-12 15:16:55 +0800 | [diff] [blame] | 167 | return activation(); // Return the previous activation status |
| 168 | } |
Lei YU | 81c6772 | 2019-09-11 16:47:29 +0800 | [diff] [blame] | 169 | |
Shawn McCarney | d57bd2f | 2024-12-02 18:40:28 -0600 | [diff] [blame] | 170 | auto psuPaths = utils::getPSUInventoryPaths(bus); |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 171 | if (psuPaths.empty()) |
| 172 | { |
Shawn McCarney | cdf86de | 2024-11-26 10:02:14 -0600 | [diff] [blame] | 173 | lg2::warning("No PSU inventory found"); |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 174 | return Status::Failed; |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 175 | } |
| 176 | |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 177 | for (const auto& p : psuPaths) |
| 178 | { |
Shawn McCarney | 46ea388 | 2024-12-10 11:25:38 -0600 | [diff] [blame^] | 179 | if (!isPresent(p)) |
| 180 | { |
| 181 | continue; |
| 182 | } |
Lei YU | 9edb733 | 2019-09-19 14:46:19 +0800 | [diff] [blame] | 183 | if (isCompatible(p)) |
| 184 | { |
Lei YU | 63f9e71 | 2019-10-12 15:16:55 +0800 | [diff] [blame] | 185 | if (utils::isAssociated(p, associations())) |
| 186 | { |
Shawn McCarney | cdf86de | 2024-11-26 10:02:14 -0600 | [diff] [blame] | 187 | lg2::notice("PSU {PSU} is already running the image, skipping", |
| 188 | "PSU", p); |
Lei YU | 63f9e71 | 2019-10-12 15:16:55 +0800 | [diff] [blame] | 189 | continue; |
| 190 | } |
Lei YU | 9edb733 | 2019-09-19 14:46:19 +0800 | [diff] [blame] | 191 | psuQueue.push(p); |
| 192 | } |
| 193 | else |
| 194 | { |
Shawn McCarney | cdf86de | 2024-11-26 10:02:14 -0600 | [diff] [blame] | 195 | lg2::notice("PSU {PSU} is not compatible", "PSU", p); |
Lei YU | 9edb733 | 2019-09-19 14:46:19 +0800 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | |
| 199 | if (psuQueue.empty()) |
| 200 | { |
Shawn McCarney | cdf86de | 2024-11-26 10:02:14 -0600 | [diff] [blame] | 201 | lg2::warning("No PSU compatible with the software"); |
Lei YU | 63f9e71 | 2019-10-12 15:16:55 +0800 | [diff] [blame] | 202 | return activation(); // Return the previous activation status |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 203 | } |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 204 | |
Lei YU | 8afeee5 | 2019-10-21 15:25:35 +0800 | [diff] [blame] | 205 | if (!activationProgress) |
| 206 | { |
| 207 | activationProgress = std::make_unique<ActivationProgress>(bus, objPath); |
| 208 | } |
| 209 | if (!activationBlocksTransition) |
| 210 | { |
| 211 | activationBlocksTransition = |
| 212 | std::make_unique<ActivationBlocksTransition>(bus, objPath); |
| 213 | } |
| 214 | |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 215 | // The progress to be increased for each successful update of PSU |
| 216 | // E.g. in case we have 4 PSUs: |
Manojkiran Eda | 33cf9f0 | 2024-06-17 14:40:44 +0530 | [diff] [blame] | 217 | // 1. Initial progress is 10 |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 218 | // 2. Add 20 after each update is done, so we will see progress to be 30, |
| 219 | // 50, 70, 90 |
| 220 | // 3. When all PSUs are updated, it will be 100 and the interface is |
| 221 | // removed. |
| 222 | progressStep = 80 / psuQueue.size(); |
| 223 | if (doUpdate()) |
| 224 | { |
| 225 | activationProgress->progress(10); |
| 226 | return Status::Activating; |
| 227 | } |
| 228 | else |
| 229 | { |
| 230 | return Status::Failed; |
| 231 | } |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | void Activation::finishActivation() |
| 235 | { |
Lei YU | 2e0e2de | 2019-09-26 16:42:23 +0800 | [diff] [blame] | 236 | storeImage(); |
Lei YU | 90c8a8b | 2019-09-11 17:20:03 +0800 | [diff] [blame] | 237 | activationProgress->progress(100); |
Lei YU | 81c6772 | 2019-09-11 16:47:29 +0800 | [diff] [blame] | 238 | |
Lei YU | d0bbfa9 | 2019-09-11 16:10:54 +0800 | [diff] [blame] | 239 | deleteImageManagerObject(); |
Lei YU | 7f2a215 | 2019-09-16 16:50:18 +0800 | [diff] [blame] | 240 | |
Lei YU | 9930137 | 2019-09-29 16:27:12 +0800 | [diff] [blame] | 241 | associationInterface->createActiveAssociation(objPath); |
| 242 | associationInterface->addFunctionalAssociation(objPath); |
Lei YU | a8b966f | 2020-03-18 10:32:24 +0800 | [diff] [blame] | 243 | associationInterface->addUpdateableAssociation(objPath); |
Lei YU | 7f2a215 | 2019-09-16 16:50:18 +0800 | [diff] [blame] | 244 | |
Lei YU | 1517f5f | 2019-10-14 16:44:42 +0800 | [diff] [blame] | 245 | // Reset RequestedActivations to none so that it could be activated in |
| 246 | // future |
| 247 | requestedActivation(SoftwareActivation::RequestedActivations::None); |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 248 | activation(Status::Active); |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 249 | } |
| 250 | |
Lei YU | d0bbfa9 | 2019-09-11 16:10:54 +0800 | [diff] [blame] | 251 | void Activation::deleteImageManagerObject() |
| 252 | { |
| 253 | // Get the Delete object for <versionID> inside image_manager |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 254 | std::vector<std::string> services; |
Lei YU | d0bbfa9 | 2019-09-11 16:10:54 +0800 | [diff] [blame] | 255 | constexpr auto deleteInterface = "xyz.openbmc_project.Object.Delete"; |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 256 | try |
| 257 | { |
| 258 | services = utils::getServices(bus, objPath.c_str(), deleteInterface); |
| 259 | } |
| 260 | catch (const std::exception& e) |
| 261 | { |
| 262 | lg2::error( |
| 263 | "Unable to find services to Delete object path {PATH}: {ERROR}", |
| 264 | "PATH", objPath, "ERROR", e); |
| 265 | } |
Lei YU | d0bbfa9 | 2019-09-11 16:10:54 +0800 | [diff] [blame] | 266 | |
| 267 | // We need to find the phosphor-version-software-manager's version service |
| 268 | // to invoke the delete interface |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 269 | constexpr auto versionServiceStr = "xyz.openbmc_project.Software.Version"; |
| 270 | std::string versionService; |
Lei YU | d0bbfa9 | 2019-09-11 16:10:54 +0800 | [diff] [blame] | 271 | for (const auto& service : services) |
| 272 | { |
| 273 | if (service.find(versionServiceStr) != std::string::npos) |
| 274 | { |
| 275 | versionService = service; |
| 276 | break; |
| 277 | } |
| 278 | } |
| 279 | if (versionService.empty()) |
| 280 | { |
Lei YU | e8945ea | 2019-09-29 17:25:31 +0800 | [diff] [blame] | 281 | // When updating a stored image, there is no version object created by |
| 282 | // "xyz.openbmc_project.Software.Version" service, so skip it. |
Lei YU | d0bbfa9 | 2019-09-11 16:10:54 +0800 | [diff] [blame] | 283 | return; |
| 284 | } |
| 285 | |
| 286 | // Call the Delete object for <versionID> inside image_manager |
Lei YU | d0bbfa9 | 2019-09-11 16:10:54 +0800 | [diff] [blame] | 287 | try |
| 288 | { |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 289 | auto method = bus.new_method_call( |
| 290 | versionService.c_str(), objPath.c_str(), deleteInterface, "Delete"); |
Lei YU | d0bbfa9 | 2019-09-11 16:10:54 +0800 | [diff] [blame] | 291 | bus.call(method); |
| 292 | } |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 293 | catch (const std::exception& e) |
Lei YU | d0bbfa9 | 2019-09-11 16:10:54 +0800 | [diff] [blame] | 294 | { |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 295 | lg2::error("Unable to Delete object path {PATH}: {ERROR}", "PATH", |
| 296 | objPath, "ERROR", e); |
Lei YU | d0bbfa9 | 2019-09-11 16:10:54 +0800 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | |
Shawn McCarney | 46ea388 | 2024-12-10 11:25:38 -0600 | [diff] [blame^] | 300 | bool Activation::isPresent(const std::string& psuInventoryPath) |
| 301 | { |
| 302 | bool isPres{false}; |
| 303 | try |
| 304 | { |
| 305 | auto service = |
| 306 | utils::getService(bus, psuInventoryPath.c_str(), ITEM_IFACE); |
| 307 | isPres = utils::getProperty<bool>(bus, service.c_str(), |
| 308 | psuInventoryPath.c_str(), ITEM_IFACE, |
| 309 | PRESENT); |
| 310 | } |
| 311 | catch (const std::exception& e) |
| 312 | { |
| 313 | // Treat as a warning condition and assume the PSU is missing. The |
| 314 | // D-Bus information might not be available if the PSU is missing. |
| 315 | lg2::warning("Unable to determine if PSU {PSU} is present: {ERROR}", |
| 316 | "PSU", psuInventoryPath, "ERROR", e); |
| 317 | } |
| 318 | return isPres; |
| 319 | } |
| 320 | |
Lei YU | 9edb733 | 2019-09-19 14:46:19 +0800 | [diff] [blame] | 321 | bool Activation::isCompatible(const std::string& psuInventoryPath) |
| 322 | { |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 323 | bool isCompat{false}; |
| 324 | try |
Lei YU | 9edb733 | 2019-09-19 14:46:19 +0800 | [diff] [blame] | 325 | { |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 326 | auto service = |
| 327 | utils::getService(bus, psuInventoryPath.c_str(), ASSET_IFACE); |
| 328 | auto psuManufacturer = utils::getProperty<std::string>( |
| 329 | bus, service.c_str(), psuInventoryPath.c_str(), ASSET_IFACE, |
| 330 | MANUFACTURER); |
| 331 | auto psuModel = utils::getModel(psuInventoryPath); |
Lei YU | 9edb733 | 2019-09-19 14:46:19 +0800 | [diff] [blame] | 332 | // The model shall match |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 333 | if (psuModel == model) |
| 334 | { |
| 335 | // If PSU inventory has manufacturer property, it shall match |
| 336 | if (psuManufacturer.empty() || (psuManufacturer == manufacturer)) |
| 337 | { |
| 338 | isCompat = true; |
| 339 | } |
| 340 | } |
Lei YU | 9edb733 | 2019-09-19 14:46:19 +0800 | [diff] [blame] | 341 | } |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 342 | catch (const std::exception& e) |
Lei YU | 9edb733 | 2019-09-19 14:46:19 +0800 | [diff] [blame] | 343 | { |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 344 | lg2::error( |
| 345 | "Unable to determine if PSU {PSU} is compatible with firmware " |
| 346 | "versionId {VERSION_ID}: {ERROR}", |
| 347 | "PSU", psuInventoryPath, "VERSION_ID", versionId, "ERROR", e); |
Lei YU | 9edb733 | 2019-09-19 14:46:19 +0800 | [diff] [blame] | 348 | } |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 349 | return isCompat; |
Lei YU | 9edb733 | 2019-09-19 14:46:19 +0800 | [diff] [blame] | 350 | } |
| 351 | |
Lei YU | 2e0e2de | 2019-09-26 16:42:23 +0800 | [diff] [blame] | 352 | void Activation::storeImage() |
| 353 | { |
Shawn McCarney | ddf525f | 2024-09-27 09:27:06 -0500 | [diff] [blame] | 354 | // If image is not in IMG_DIR (temporary storage) then exit. We don't want |
| 355 | // to copy from IMG_DIR_PERSIST or IMG_DIR_BUILTIN. |
Lei YU | e8945ea | 2019-09-29 17:25:31 +0800 | [diff] [blame] | 356 | auto src = path(); |
Shawn McCarney | ddf525f | 2024-09-27 09:27:06 -0500 | [diff] [blame] | 357 | if (!src.starts_with(IMG_DIR)) |
Lei YU | e8945ea | 2019-09-29 17:25:31 +0800 | [diff] [blame] | 358 | { |
Lei YU | e8945ea | 2019-09-29 17:25:31 +0800 | [diff] [blame] | 359 | return; |
| 360 | } |
Shawn McCarney | ddf525f | 2024-09-27 09:27:06 -0500 | [diff] [blame] | 361 | |
| 362 | // Store image in persistent dir separated by model |
| 363 | // and only store the latest one by removing old ones |
| 364 | auto dst = fs::path(IMG_DIR_PERSIST) / model; |
Lei YU | 2e0e2de | 2019-09-26 16:42:23 +0800 | [diff] [blame] | 365 | try |
| 366 | { |
| 367 | fs::remove_all(dst); |
| 368 | fs::create_directories(dst); |
| 369 | fs::copy(src, dst); |
| 370 | path(dst.string()); // Update the FilePath interface |
| 371 | } |
| 372 | catch (const fs::filesystem_error& e) |
| 373 | { |
Shawn McCarney | cdf86de | 2024-11-26 10:02:14 -0600 | [diff] [blame] | 374 | lg2::error("Error storing PSU image: src={SRC}, dst={DST}: {ERROR}", |
| 375 | "SRC", src, "DST", dst, "ERROR", e); |
Lei YU | 2e0e2de | 2019-09-26 16:42:23 +0800 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
Lei YU | e8945ea | 2019-09-29 17:25:31 +0800 | [diff] [blame] | 379 | std::string Activation::getUpdateService(const std::string& psuInventoryPath) |
| 380 | { |
| 381 | fs::path imagePath(path()); |
| 382 | |
| 383 | // The systemd unit shall be escaped |
| 384 | std::string args = psuInventoryPath; |
| 385 | args += "\\x20"; |
| 386 | args += imagePath; |
| 387 | std::replace(args.begin(), args.end(), '/', '-'); |
| 388 | |
| 389 | std::string service = PSU_UPDATE_SERVICE; |
| 390 | auto p = service.find('@'); |
Shawn McCarney | 487e2e1 | 2024-11-25 17:19:46 -0600 | [diff] [blame] | 391 | if (p == std::string::npos) |
| 392 | { |
| 393 | throw std::runtime_error{std::format( |
| 394 | "Invalid PSU update service name: {}", PSU_UPDATE_SERVICE)}; |
| 395 | } |
Lei YU | e8945ea | 2019-09-29 17:25:31 +0800 | [diff] [blame] | 396 | service.insert(p + 1, args); |
| 397 | return service; |
| 398 | } |
| 399 | |
Lei YU | 8afeee5 | 2019-10-21 15:25:35 +0800 | [diff] [blame] | 400 | void ActivationBlocksTransition::enableRebootGuard() |
| 401 | { |
Shawn McCarney | cdf86de | 2024-11-26 10:02:14 -0600 | [diff] [blame] | 402 | lg2::info("PSU image activating - BMC reboots are disabled."); |
Lei YU | 8afeee5 | 2019-10-21 15:25:35 +0800 | [diff] [blame] | 403 | |
| 404 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 405 | SYSTEMD_INTERFACE, "StartUnit"); |
| 406 | method.append("reboot-guard-enable.service", "replace"); |
| 407 | bus.call_noreply_noerror(method); |
| 408 | } |
| 409 | |
| 410 | void ActivationBlocksTransition::disableRebootGuard() |
| 411 | { |
Shawn McCarney | cdf86de | 2024-11-26 10:02:14 -0600 | [diff] [blame] | 412 | lg2::info("PSU activation has ended - BMC reboots are re-enabled."); |
Lei YU | 8afeee5 | 2019-10-21 15:25:35 +0800 | [diff] [blame] | 413 | |
| 414 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 415 | SYSTEMD_INTERFACE, "StartUnit"); |
| 416 | method.append("reboot-guard-disable.service", "replace"); |
| 417 | bus.call_noreply_noerror(method); |
| 418 | } |
| 419 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 420 | } // namespace updater |
| 421 | } // namespace software |
| 422 | } // namespace phosphor |