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