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 | { |
Lei YU | a2e6716 | 2019-02-22 17:35:24 +0800 | [diff] [blame] | 92 | activation(softwareServer::Activation::Activations::Activating); |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 93 | } |
| 94 | } |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 95 | return softwareServer::Activation::requestedActivation(value); |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 96 | } |
| 97 | |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 98 | void Activation::deleteImageManagerObject() |
| 99 | { |
| 100 | // Get the Delete object for <versionID> inside image_manager |
Lei YU | c9caf86 | 2019-01-24 15:40:25 +0800 | [diff] [blame] | 101 | constexpr auto versionServiceStr = "xyz.openbmc_project.Software.Version"; |
| 102 | constexpr auto deleteInterface = "xyz.openbmc_project.Object.Delete"; |
| 103 | std::string versionService; |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 104 | auto method = this->bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, |
| 105 | MAPPER_INTERFACE, "GetObject"); |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 106 | |
| 107 | method.append(path); |
Lei YU | c9caf86 | 2019-01-24 15:40:25 +0800 | [diff] [blame] | 108 | method.append(std::vector<std::string>({deleteInterface})); |
Adriana Kobylak | b8cb0cc | 2019-05-31 09:58:04 -0500 | [diff] [blame] | 109 | |
| 110 | std::map<std::string, std::vector<std::string>> mapperResponse; |
| 111 | |
| 112 | try |
| 113 | { |
| 114 | auto mapperResponseMsg = bus.call(method); |
| 115 | mapperResponseMsg.read(mapperResponse); |
| 116 | if (mapperResponse.begin() == mapperResponse.end()) |
| 117 | { |
| 118 | log<level::ERR>("ERROR in reading the mapper response", |
| 119 | entry("VERSIONPATH=%s", path.c_str())); |
| 120 | return; |
| 121 | } |
| 122 | } |
| 123 | catch (const SdBusError& e) |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 124 | { |
| 125 | log<level::ERR>("Error in Get Delete Object", |
Joseph Reynolds | afd0a45 | 2018-05-30 11:16:03 -0500 | [diff] [blame] | 126 | entry("VERSIONPATH=%s", path.c_str())); |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 127 | return; |
| 128 | } |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 129 | |
Lei YU | c9caf86 | 2019-01-24 15:40:25 +0800 | [diff] [blame] | 130 | // We need to find the phosphor-software-manager's version service |
| 131 | // to invoke the delete interface |
| 132 | for (auto resp : mapperResponse) |
| 133 | { |
| 134 | if (resp.first.find(versionServiceStr) != std::string::npos) |
| 135 | { |
| 136 | versionService = resp.first; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | if (versionService.empty()) |
| 141 | { |
| 142 | log<level::ERR>("Error finding version service"); |
| 143 | return; |
| 144 | } |
| 145 | |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 146 | // Call the Delete object for <versionID> inside image_manager |
Lei YU | c9caf86 | 2019-01-24 15:40:25 +0800 | [diff] [blame] | 147 | method = this->bus.new_method_call(versionService.c_str(), path.c_str(), |
| 148 | deleteInterface, "Delete"); |
Adriana Kobylak | ab435df | 2018-07-16 11:37:19 -0500 | [diff] [blame] | 149 | try |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 150 | { |
Adriana Kobylak | b8cb0cc | 2019-05-31 09:58:04 -0500 | [diff] [blame] | 151 | bus.call(method); |
Adriana Kobylak | ab435df | 2018-07-16 11:37:19 -0500 | [diff] [blame] | 152 | } |
| 153 | catch (const SdBusError& e) |
| 154 | { |
| 155 | if (e.name() != nullptr && strcmp("System.Error.ELOOP", e.name()) == 0) |
| 156 | { |
| 157 | // TODO: Error being tracked with openbmc/openbmc#3311 |
| 158 | } |
| 159 | else |
| 160 | { |
| 161 | log<level::ERR>("Error performing call to Delete object path", |
| 162 | entry("ERROR=%s", e.what()), |
| 163 | entry("PATH=%s", path.c_str())); |
| 164 | } |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 165 | return; |
| 166 | } |
| 167 | } |
| 168 | |
Saqib Khan | 2021b4c | 2017-06-07 14:37:36 -0500 | [diff] [blame] | 169 | uint8_t RedundancyPriority::priority(uint8_t value) |
| 170 | { |
Saqib Khan | b8e7f31 | 2017-08-12 10:24:10 -0500 | [diff] [blame] | 171 | parent.parent.freePriority(value, parent.versionId); |
Saqib Khan | 2021b4c | 2017-06-07 14:37:36 -0500 | [diff] [blame] | 172 | return softwareServer::RedundancyPriority::priority(value); |
| 173 | } |
| 174 | |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 175 | #ifdef WANT_SIGNATURE_VERIFY |
Lei YU | 2b2d229 | 2019-03-18 15:22:56 +0800 | [diff] [blame] | 176 | bool Activation::validateSignature(const std::string& pnorFileName) |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 177 | { |
| 178 | using Signature = openpower::software::image::Signature; |
| 179 | fs::path imageDir(IMG_DIR); |
| 180 | |
Lei YU | 2b2d229 | 2019-03-18 15:22:56 +0800 | [diff] [blame] | 181 | Signature signature(imageDir / versionId, pnorFileName, |
| 182 | PNOR_SIGNED_IMAGE_CONF_PATH); |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 183 | |
| 184 | // Validate the signed image. |
| 185 | if (signature.verify()) |
| 186 | { |
| 187 | return true; |
| 188 | } |
| 189 | // Log error and continue activation process, if field mode disabled. |
| 190 | log<level::ERR>("Error occurred during image validation"); |
| 191 | report<InternalFailure>(); |
| 192 | |
| 193 | try |
| 194 | { |
| 195 | if (!fieldModeEnabled()) |
| 196 | { |
| 197 | return true; |
| 198 | } |
| 199 | } |
| 200 | catch (const InternalFailure& e) |
| 201 | { |
| 202 | report<InternalFailure>(); |
| 203 | } |
| 204 | return false; |
| 205 | } |
| 206 | |
| 207 | bool Activation::fieldModeEnabled() |
| 208 | { |
Lei YU | e499446 | 2019-03-14 14:41:53 +0800 | [diff] [blame] | 209 | auto fieldModeSvc = |
| 210 | utils::getService(bus, FIELDMODE_PATH, FIELDMODE_INTERFACE); |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 211 | |
| 212 | auto method = bus.new_method_call(fieldModeSvc.c_str(), FIELDMODE_PATH, |
| 213 | "org.freedesktop.DBus.Properties", "Get"); |
| 214 | |
| 215 | method.append(FIELDMODE_INTERFACE, "FieldModeEnabled"); |
Adriana Kobylak | b8cb0cc | 2019-05-31 09:58:04 -0500 | [diff] [blame] | 216 | |
| 217 | sdbusplus::message::variant<bool> fieldMode; |
| 218 | |
| 219 | try |
| 220 | { |
| 221 | auto reply = bus.call(method); |
| 222 | reply.read(fieldMode); |
| 223 | return sdbusplus::message::variant_ns::get<bool>(fieldMode); |
| 224 | } |
| 225 | catch (const SdBusError& e) |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 226 | { |
| 227 | log<level::ERR>("Error in fieldModeEnabled getValue"); |
| 228 | elog<InternalFailure>(); |
| 229 | } |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 230 | } |
| 231 | |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 232 | #endif |
| 233 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 234 | } // namespace updater |
| 235 | } // namespace software |
| 236 | } // namespace openpower |