Adriana Kobylak | 692b555 | 2017-04-17 14:02:58 -0500 | [diff] [blame] | 1 | #include "config.h" |
Gunnar Mills | f6ed589 | 2018-09-07 17:08:02 -0500 | [diff] [blame] | 2 | |
| 3 | #include "activation.hpp" |
| 4 | |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 5 | #include "item_updater.hpp" |
Gunnar Mills | f6ed589 | 2018-09-07 17:08:02 -0500 | [diff] [blame] | 6 | |
Jayashankar Padath | 4d3d912 | 2019-07-24 16:46:22 +0530 | [diff] [blame] | 7 | #include <phosphor-logging/elog-errors.hpp> |
| 8 | #include <phosphor-logging/elog.hpp> |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 9 | #include <phosphor-logging/log.hpp> |
Gunnar Mills | 74b657e | 2018-07-13 09:27:31 -0500 | [diff] [blame] | 10 | #include <sdbusplus/exception.hpp> |
Jayashankar Padath | 4d3d912 | 2019-07-24 16:46:22 +0530 | [diff] [blame] | 11 | #include <sdbusplus/server.hpp> |
| 12 | #include <xyz/openbmc_project/Common/error.hpp> |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 13 | |
Brad Bishop | 9f44c99 | 2020-11-06 14:48:46 -0500 | [diff] [blame] | 14 | #include <filesystem> |
Brad Bishop | 8facccf | 2020-11-04 09:44:58 -0500 | [diff] [blame] | 15 | |
Jayanth Othayoth | 4016e52 | 2018-03-20 09:39:06 -0500 | [diff] [blame] | 16 | #ifdef WANT_SIGNATURE_VERIFY |
Jayanth Othayoth | 4016e52 | 2018-03-20 09:39:06 -0500 | [diff] [blame] | 17 | #include "image_verify.hpp" |
Jayanth Othayoth | 4016e52 | 2018-03-20 09:39:06 -0500 | [diff] [blame] | 18 | #endif |
| 19 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 20 | namespace openpower |
| 21 | { |
| 22 | namespace software |
| 23 | { |
| 24 | namespace updater |
| 25 | { |
| 26 | |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 27 | namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server; |
| 28 | |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 29 | using namespace phosphor::logging; |
Jayanth Othayoth | 4016e52 | 2018-03-20 09:39:06 -0500 | [diff] [blame] | 30 | using InternalFailure = |
| 31 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 32 | |
Jayashankar Padath | 4d3d912 | 2019-07-24 16:46:22 +0530 | [diff] [blame] | 33 | #ifdef WANT_SIGNATURE_VERIFY |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 34 | // Field mode path and interface. |
| 35 | constexpr auto FIELDMODE_PATH("/xyz/openbmc_project/software"); |
| 36 | constexpr auto FIELDMODE_INTERFACE("xyz.openbmc_project.Control.FieldMode"); |
Jayanth Othayoth | 4016e52 | 2018-03-20 09:39:06 -0500 | [diff] [blame] | 37 | #endif |
| 38 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 39 | constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1"; |
| 40 | constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1"; |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 41 | |
| 42 | void Activation::subscribeToSystemdSignals() |
| 43 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 44 | auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH, |
| 45 | SYSTEMD_INTERFACE, "Subscribe"); |
Gunnar Mills | 74b657e | 2018-07-13 09:27:31 -0500 | [diff] [blame] | 46 | try |
| 47 | { |
| 48 | this->bus.call_noreply(method); |
| 49 | } |
Patrick Williams | 0dea199 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 50 | catch (const sdbusplus::exception_t& e) |
Gunnar Mills | 74b657e | 2018-07-13 09:27:31 -0500 | [diff] [blame] | 51 | { |
| 52 | if (e.name() != nullptr && |
| 53 | strcmp("org.freedesktop.systemd1.AlreadySubscribed", e.name()) == 0) |
| 54 | { |
| 55 | // If an Activation attempt fails, the Unsubscribe method is not |
| 56 | // called. This may lead to an AlreadySubscribed error if the |
| 57 | // Activation is re-attempted. |
| 58 | } |
| 59 | else |
| 60 | { |
| 61 | log<level::ERR>("Error subscribing to systemd", |
| 62 | entry("ERROR=%s", e.what())); |
| 63 | } |
| 64 | } |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 65 | return; |
| 66 | } |
| 67 | |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 68 | void Activation::unsubscribeFromSystemdSignals() |
| 69 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 70 | auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH, |
| 71 | SYSTEMD_INTERFACE, "Unsubscribe"); |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 72 | this->bus.call_noreply(method); |
| 73 | |
| 74 | return; |
| 75 | } |
| 76 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 77 | auto Activation::requestedActivation(RequestedActivations value) |
| 78 | -> RequestedActivations |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 79 | { |
| 80 | if ((value == softwareServer::Activation::RequestedActivations::Active) && |
| 81 | (softwareServer::Activation::requestedActivation() != |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 82 | softwareServer::Activation::RequestedActivations::Active)) |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 83 | { |
| 84 | if ((softwareServer::Activation::activation() == |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 85 | softwareServer::Activation::Activations::Ready) || |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 86 | (softwareServer::Activation::activation() == |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 87 | softwareServer::Activation::Activations::Failed)) |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 88 | { |
Lei YU | a2e6716 | 2019-02-22 17:35:24 +0800 | [diff] [blame] | 89 | activation(softwareServer::Activation::Activations::Activating); |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 90 | } |
| 91 | } |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 92 | return softwareServer::Activation::requestedActivation(value); |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 93 | } |
| 94 | |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 95 | void Activation::deleteImageManagerObject() |
| 96 | { |
| 97 | // Get the Delete object for <versionID> inside image_manager |
Lei YU | c9caf86 | 2019-01-24 15:40:25 +0800 | [diff] [blame] | 98 | constexpr auto versionServiceStr = "xyz.openbmc_project.Software.Version"; |
| 99 | constexpr auto deleteInterface = "xyz.openbmc_project.Object.Delete"; |
| 100 | std::string versionService; |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 101 | auto method = this->bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, |
| 102 | MAPPER_INTERFACE, "GetObject"); |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 103 | |
| 104 | method.append(path); |
Lei YU | c9caf86 | 2019-01-24 15:40:25 +0800 | [diff] [blame] | 105 | method.append(std::vector<std::string>({deleteInterface})); |
Adriana Kobylak | b8cb0cc | 2019-05-31 09:58:04 -0500 | [diff] [blame] | 106 | |
| 107 | std::map<std::string, std::vector<std::string>> mapperResponse; |
| 108 | |
| 109 | try |
| 110 | { |
| 111 | auto mapperResponseMsg = bus.call(method); |
| 112 | mapperResponseMsg.read(mapperResponse); |
| 113 | if (mapperResponse.begin() == mapperResponse.end()) |
| 114 | { |
| 115 | log<level::ERR>("ERROR in reading the mapper response", |
| 116 | entry("VERSIONPATH=%s", path.c_str())); |
| 117 | return; |
| 118 | } |
| 119 | } |
Patrick Williams | 0dea199 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 120 | catch (const sdbusplus::exception_t& e) |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 121 | { |
| 122 | log<level::ERR>("Error in Get Delete Object", |
Joseph Reynolds | afd0a45 | 2018-05-30 11:16:03 -0500 | [diff] [blame] | 123 | entry("VERSIONPATH=%s", path.c_str())); |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 124 | return; |
| 125 | } |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 126 | |
Lei YU | c9caf86 | 2019-01-24 15:40:25 +0800 | [diff] [blame] | 127 | // We need to find the phosphor-software-manager's version service |
| 128 | // to invoke the delete interface |
| 129 | for (auto resp : mapperResponse) |
| 130 | { |
| 131 | if (resp.first.find(versionServiceStr) != std::string::npos) |
| 132 | { |
| 133 | versionService = resp.first; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | if (versionService.empty()) |
| 138 | { |
| 139 | log<level::ERR>("Error finding version service"); |
| 140 | return; |
| 141 | } |
| 142 | |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 143 | // Call the Delete object for <versionID> inside image_manager |
Lei YU | c9caf86 | 2019-01-24 15:40:25 +0800 | [diff] [blame] | 144 | method = this->bus.new_method_call(versionService.c_str(), path.c_str(), |
| 145 | deleteInterface, "Delete"); |
Adriana Kobylak | ab435df | 2018-07-16 11:37:19 -0500 | [diff] [blame] | 146 | try |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 147 | { |
Adriana Kobylak | b8cb0cc | 2019-05-31 09:58:04 -0500 | [diff] [blame] | 148 | bus.call(method); |
Adriana Kobylak | ab435df | 2018-07-16 11:37:19 -0500 | [diff] [blame] | 149 | } |
Patrick Williams | 0dea199 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 150 | catch (const sdbusplus::exception_t& e) |
Adriana Kobylak | ab435df | 2018-07-16 11:37:19 -0500 | [diff] [blame] | 151 | { |
| 152 | if (e.name() != nullptr && strcmp("System.Error.ELOOP", e.name()) == 0) |
| 153 | { |
| 154 | // TODO: Error being tracked with openbmc/openbmc#3311 |
| 155 | } |
| 156 | else |
| 157 | { |
| 158 | log<level::ERR>("Error performing call to Delete object path", |
| 159 | entry("ERROR=%s", e.what()), |
| 160 | entry("PATH=%s", path.c_str())); |
| 161 | } |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 162 | return; |
| 163 | } |
| 164 | } |
| 165 | |
Jayashankar Padath | 4d3d912 | 2019-07-24 16:46:22 +0530 | [diff] [blame] | 166 | bool Activation::checkApplyTimeImmediate() |
| 167 | { |
| 168 | auto service = utils::getService(bus, applyTimeObjPath, applyTimeIntf); |
| 169 | if (service.empty()) |
| 170 | { |
| 171 | log<level::INFO>("Error getting the service name for Host image " |
| 172 | "ApplyTime. The Host needs to be manually rebooted to " |
| 173 | "complete the image activation if needed " |
| 174 | "immediately."); |
| 175 | } |
| 176 | else |
| 177 | { |
Jayashankar Padath | 4d3d912 | 2019-07-24 16:46:22 +0530 | [diff] [blame] | 178 | auto method = bus.new_method_call(service.c_str(), applyTimeObjPath, |
| 179 | dbusPropIntf, "Get"); |
| 180 | method.append(applyTimeIntf, applyTimeProp); |
| 181 | |
| 182 | try |
| 183 | { |
| 184 | auto reply = bus.call(method); |
| 185 | |
Patrick Williams | 212102e | 2020-05-13 17:50:50 -0500 | [diff] [blame] | 186 | std::variant<std::string> result; |
Jayashankar Padath | 4d3d912 | 2019-07-24 16:46:22 +0530 | [diff] [blame] | 187 | reply.read(result); |
Patrick Williams | 550f31b | 2020-05-13 11:15:24 -0500 | [diff] [blame] | 188 | auto applyTime = std::get<std::string>(result); |
Jayashankar Padath | 4d3d912 | 2019-07-24 16:46:22 +0530 | [diff] [blame] | 189 | if (applyTime == applyTimeImmediate) |
| 190 | { |
| 191 | return true; |
| 192 | } |
| 193 | } |
Patrick Williams | 0dea199 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 194 | catch (const sdbusplus::exception_t& e) |
Jayashankar Padath | 4d3d912 | 2019-07-24 16:46:22 +0530 | [diff] [blame] | 195 | { |
| 196 | log<level::ERR>("Error in getting ApplyTime", |
| 197 | entry("ERROR=%s", e.what())); |
| 198 | } |
| 199 | } |
| 200 | return false; |
| 201 | } |
| 202 | |
| 203 | void Activation::rebootHost() |
| 204 | { |
| 205 | auto service = utils::getService(bus, hostStateObjPath, hostStateIntf); |
| 206 | if (service.empty()) |
| 207 | { |
| 208 | log<level::ALERT>("Error in getting the service name to reboot the " |
| 209 | "Host. The Host needs to be manually rebooted to " |
| 210 | "complete the image activation."); |
| 211 | } |
| 212 | |
| 213 | auto method = bus.new_method_call(service.c_str(), hostStateObjPath, |
| 214 | dbusPropIntf, "Set"); |
Patrick Williams | 212102e | 2020-05-13 17:50:50 -0500 | [diff] [blame] | 215 | std::variant<std::string> hostReboot = hostStateRebootVal; |
Jayashankar Padath | 4d3d912 | 2019-07-24 16:46:22 +0530 | [diff] [blame] | 216 | method.append(hostStateIntf, hostStateRebootProp, hostReboot); |
| 217 | |
| 218 | try |
| 219 | { |
| 220 | auto reply = bus.call(method); |
| 221 | } |
Patrick Williams | 0dea199 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 222 | catch (const sdbusplus::exception_t& e) |
Jayashankar Padath | 4d3d912 | 2019-07-24 16:46:22 +0530 | [diff] [blame] | 223 | { |
| 224 | log<level::ALERT>("Error in trying to reboot the Host. " |
| 225 | "The Host needs to be manually rebooted to complete " |
| 226 | "the image activation.", |
| 227 | entry("ERROR=%s", e.what())); |
| 228 | report<InternalFailure>(); |
| 229 | } |
| 230 | } |
| 231 | |
Saqib Khan | 2021b4c | 2017-06-07 14:37:36 -0500 | [diff] [blame] | 232 | uint8_t RedundancyPriority::priority(uint8_t value) |
| 233 | { |
Saqib Khan | b8e7f31 | 2017-08-12 10:24:10 -0500 | [diff] [blame] | 234 | parent.parent.freePriority(value, parent.versionId); |
Saqib Khan | 2021b4c | 2017-06-07 14:37:36 -0500 | [diff] [blame] | 235 | return softwareServer::RedundancyPriority::priority(value); |
| 236 | } |
| 237 | |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 238 | #ifdef WANT_SIGNATURE_VERIFY |
Lei YU | 2b2d229 | 2019-03-18 15:22:56 +0800 | [diff] [blame] | 239 | bool Activation::validateSignature(const std::string& pnorFileName) |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 240 | { |
| 241 | using Signature = openpower::software::image::Signature; |
Brad Bishop | 9f44c99 | 2020-11-06 14:48:46 -0500 | [diff] [blame] | 242 | std::filesystem::path imageDir(IMG_DIR); |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 243 | |
Lei YU | 2b2d229 | 2019-03-18 15:22:56 +0800 | [diff] [blame] | 244 | Signature signature(imageDir / versionId, pnorFileName, |
| 245 | PNOR_SIGNED_IMAGE_CONF_PATH); |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 246 | |
| 247 | // Validate the signed image. |
| 248 | if (signature.verify()) |
| 249 | { |
| 250 | return true; |
| 251 | } |
| 252 | // Log error and continue activation process, if field mode disabled. |
| 253 | log<level::ERR>("Error occurred during image validation"); |
| 254 | report<InternalFailure>(); |
| 255 | |
| 256 | try |
| 257 | { |
| 258 | if (!fieldModeEnabled()) |
| 259 | { |
| 260 | return true; |
| 261 | } |
| 262 | } |
| 263 | catch (const InternalFailure& e) |
| 264 | { |
| 265 | report<InternalFailure>(); |
| 266 | } |
| 267 | return false; |
| 268 | } |
| 269 | |
| 270 | bool Activation::fieldModeEnabled() |
| 271 | { |
Patrick Williams | 7fb6c34 | 2023-05-10 07:50:18 -0500 | [diff] [blame] | 272 | auto fieldModeSvc = utils::getService(bus, FIELDMODE_PATH, |
| 273 | FIELDMODE_INTERFACE); |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 274 | |
| 275 | auto method = bus.new_method_call(fieldModeSvc.c_str(), FIELDMODE_PATH, |
| 276 | "org.freedesktop.DBus.Properties", "Get"); |
| 277 | |
| 278 | method.append(FIELDMODE_INTERFACE, "FieldModeEnabled"); |
Adriana Kobylak | b8cb0cc | 2019-05-31 09:58:04 -0500 | [diff] [blame] | 279 | |
Patrick Williams | 212102e | 2020-05-13 17:50:50 -0500 | [diff] [blame] | 280 | std::variant<bool> fieldMode; |
Adriana Kobylak | b8cb0cc | 2019-05-31 09:58:04 -0500 | [diff] [blame] | 281 | |
| 282 | try |
| 283 | { |
| 284 | auto reply = bus.call(method); |
| 285 | reply.read(fieldMode); |
Patrick Williams | 550f31b | 2020-05-13 11:15:24 -0500 | [diff] [blame] | 286 | return std::get<bool>(fieldMode); |
Adriana Kobylak | b8cb0cc | 2019-05-31 09:58:04 -0500 | [diff] [blame] | 287 | } |
Patrick Williams | 0dea199 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 288 | catch (const sdbusplus::exception_t& e) |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 289 | { |
| 290 | log<level::ERR>("Error in fieldModeEnabled getValue"); |
| 291 | elog<InternalFailure>(); |
| 292 | } |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 293 | } |
| 294 | |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 295 | #endif |
| 296 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 297 | } // namespace updater |
| 298 | } // namespace software |
| 299 | } // namespace openpower |