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