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