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" |
Michael Tritz | 60bc20f | 2017-07-29 23:32:21 -0500 | [diff] [blame] | 6 | #include "serialize.hpp" |
Gunnar Mills | f6ed589 | 2018-09-07 17:08:02 -0500 | [diff] [blame] | 7 | |
| 8 | #include <experimental/filesystem> |
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> |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 11 | |
Jayanth Othayoth | 4016e52 | 2018-03-20 09:39:06 -0500 | [diff] [blame] | 12 | #ifdef WANT_SIGNATURE_VERIFY |
Jayanth Othayoth | 4016e52 | 2018-03-20 09:39:06 -0500 | [diff] [blame] | 13 | #include "image_verify.hpp" |
Gunnar Mills | f6ed589 | 2018-09-07 17:08:02 -0500 | [diff] [blame] | 14 | |
| 15 | #include <phosphor-logging/elog-errors.hpp> |
| 16 | #include <phosphor-logging/elog.hpp> |
| 17 | #include <sdbusplus/server.hpp> |
| 18 | #include <xyz/openbmc_project/Common/error.hpp> |
Jayanth Othayoth | 4016e52 | 2018-03-20 09:39:06 -0500 | [diff] [blame] | 19 | #endif |
| 20 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 21 | namespace openpower |
| 22 | { |
| 23 | namespace software |
| 24 | { |
| 25 | namespace updater |
| 26 | { |
| 27 | |
Adriana Kobylak | 55f9e83 | 2017-05-14 16:13:00 -0500 | [diff] [blame] | 28 | namespace fs = std::experimental::filesystem; |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 29 | namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server; |
| 30 | |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 31 | using namespace phosphor::logging; |
Gunnar Mills | 74b657e | 2018-07-13 09:27:31 -0500 | [diff] [blame] | 32 | using sdbusplus::exception::SdBusError; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 33 | |
Jayanth Othayoth | 4016e52 | 2018-03-20 09:39:06 -0500 | [diff] [blame] | 34 | #ifdef WANT_SIGNATURE_VERIFY |
| 35 | using InternalFailure = |
| 36 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 37 | |
| 38 | // Field mode path and interface. |
| 39 | constexpr auto FIELDMODE_PATH("/xyz/openbmc_project/software"); |
| 40 | constexpr auto FIELDMODE_INTERFACE("xyz.openbmc_project.Control.FieldMode"); |
Jayanth Othayoth | 4016e52 | 2018-03-20 09:39:06 -0500 | [diff] [blame] | 41 | #endif |
| 42 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 43 | constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1"; |
| 44 | constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1"; |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 45 | |
| 46 | void Activation::subscribeToSystemdSignals() |
| 47 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 48 | auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH, |
| 49 | SYSTEMD_INTERFACE, "Subscribe"); |
Gunnar Mills | 74b657e | 2018-07-13 09:27:31 -0500 | [diff] [blame] | 50 | try |
| 51 | { |
| 52 | this->bus.call_noreply(method); |
| 53 | } |
| 54 | catch (const SdBusError& e) |
| 55 | { |
| 56 | if (e.name() != nullptr && |
| 57 | strcmp("org.freedesktop.systemd1.AlreadySubscribed", e.name()) == 0) |
| 58 | { |
| 59 | // If an Activation attempt fails, the Unsubscribe method is not |
| 60 | // called. This may lead to an AlreadySubscribed error if the |
| 61 | // Activation is re-attempted. |
| 62 | } |
| 63 | else |
| 64 | { |
| 65 | log<level::ERR>("Error subscribing to systemd", |
| 66 | entry("ERROR=%s", e.what())); |
| 67 | } |
| 68 | } |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 69 | return; |
| 70 | } |
| 71 | |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 72 | void Activation::unsubscribeFromSystemdSignals() |
| 73 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 74 | auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH, |
| 75 | SYSTEMD_INTERFACE, "Unsubscribe"); |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 76 | this->bus.call_noreply(method); |
| 77 | |
| 78 | return; |
| 79 | } |
| 80 | |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 81 | void Activation::startActivation() |
| 82 | { |
| 83 | // Since the squashfs image has not yet been loaded to pnor and the |
| 84 | // RW volumes have not yet been created, we need to start the |
| 85 | // service files for each of those actions. |
| 86 | |
| 87 | if (!activationProgress) |
| 88 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 89 | activationProgress = std::make_unique<ActivationProgress>(bus, path); |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | if (!activationBlocksTransition) |
| 93 | { |
| 94 | activationBlocksTransition = |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 95 | std::make_unique<ActivationBlocksTransition>(bus, path); |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 96 | } |
| 97 | |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 98 | constexpr auto ubimountService = "obmc-flash-bios-ubimount@"; |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 99 | auto ubimountServiceFile = |
| 100 | std::string(ubimountService) + versionId + ".service"; |
| 101 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 102 | SYSTEMD_INTERFACE, "StartUnit"); |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 103 | method.append(ubimountServiceFile, "replace"); |
| 104 | bus.call_noreply(method); |
| 105 | |
| 106 | activationProgress->progress(10); |
| 107 | } |
| 108 | |
| 109 | void Activation::finishActivation() |
| 110 | { |
| 111 | activationProgress->progress(90); |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 112 | |
| 113 | // Set Redundancy Priority before setting to Active |
| 114 | if (!redundancyPriority) |
| 115 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 116 | redundancyPriority = |
| 117 | std::make_unique<RedundancyPriority>(bus, path, *this, 0); |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | activationProgress->progress(100); |
| 121 | |
| 122 | activationBlocksTransition.reset(nullptr); |
| 123 | activationProgress.reset(nullptr); |
| 124 | |
Saqib Khan | 1e0aa5c | 2017-08-31 11:04:17 -0500 | [diff] [blame] | 125 | ubiVolumesCreated = false; |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 126 | Activation::unsubscribeFromSystemdSignals(); |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 127 | // Remove version object from image manager |
| 128 | Activation::deleteImageManagerObject(); |
Gunnar Mills | 9741cd1 | 2017-08-28 15:09:00 -0500 | [diff] [blame] | 129 | // Create active association |
| 130 | parent.createActiveAssociation(path); |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 131 | } |
| 132 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 133 | auto Activation::activation(Activations value) -> Activations |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 134 | { |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 135 | |
| 136 | if (value != softwareServer::Activation::Activations::Active) |
| 137 | { |
| 138 | redundancyPriority.reset(nullptr); |
| 139 | } |
| 140 | |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 141 | if (value == softwareServer::Activation::Activations::Activating) |
| 142 | { |
Saqib Khan | 2cbfa03 | 2017-08-17 14:52:37 -0500 | [diff] [blame] | 143 | parent.freeSpace(); |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 144 | softwareServer::Activation::activation(value); |
| 145 | |
Saqib Khan | 1e0aa5c | 2017-08-31 11:04:17 -0500 | [diff] [blame] | 146 | if (ubiVolumesCreated == false) |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 147 | { |
Gunnar Mills | 74b657e | 2018-07-13 09:27:31 -0500 | [diff] [blame] | 148 | // Enable systemd signals |
| 149 | Activation::subscribeToSystemdSignals(); |
Jayanth Othayoth | 4016e52 | 2018-03-20 09:39:06 -0500 | [diff] [blame] | 150 | |
| 151 | #ifdef WANT_SIGNATURE_VERIFY |
Jayanth Othayoth | 4016e52 | 2018-03-20 09:39:06 -0500 | [diff] [blame] | 152 | // Validate the signed image. |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 153 | if (!validateSignature()) |
Jayanth Othayoth | 4016e52 | 2018-03-20 09:39:06 -0500 | [diff] [blame] | 154 | { |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 155 | // Cleanup |
| 156 | activationBlocksTransition.reset(nullptr); |
| 157 | activationProgress.reset(nullptr); |
Jayanth Othayoth | 4016e52 | 2018-03-20 09:39:06 -0500 | [diff] [blame] | 158 | |
| 159 | return softwareServer::Activation::activation( |
| 160 | softwareServer::Activation::Activations::Failed); |
| 161 | } |
| 162 | #endif |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 163 | Activation::startActivation(); |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 164 | return softwareServer::Activation::activation(value); |
| 165 | } |
Saqib Khan | 1e0aa5c | 2017-08-31 11:04:17 -0500 | [diff] [blame] | 166 | else if (ubiVolumesCreated == true) |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 167 | { |
| 168 | // Only when the squashfs image is finished loading AND the RW |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 169 | // volumes have been created do we proceed with activation. To |
| 170 | // verify that this happened, we check for the mount dirs PNOR_PRSV |
| 171 | // and PNOR_RW_PREFIX_<versionid>, as well as the image dir R0. |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 172 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 173 | if ((fs::is_directory(PNOR_PRSV)) && |
| 174 | (fs::is_directory(PNOR_RW_PREFIX + versionId)) && |
| 175 | (fs::is_directory(PNOR_RO_PREFIX + versionId))) |
| 176 | { |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 177 | Activation::finishActivation(); |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 178 | return softwareServer::Activation::activation( |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 179 | softwareServer::Activation::Activations::Active); |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 180 | } |
| 181 | else |
| 182 | { |
Saqib Khan | cb9df4e | 2017-06-26 11:06:07 -0500 | [diff] [blame] | 183 | activationBlocksTransition.reset(nullptr); |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 184 | activationProgress.reset(nullptr); |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 185 | return softwareServer::Activation::activation( |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 186 | softwareServer::Activation::Activations::Failed); |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 187 | } |
Adriana Kobylak | 55f9e83 | 2017-05-14 16:13:00 -0500 | [diff] [blame] | 188 | } |
Adriana Kobylak | 692b555 | 2017-04-17 14:02:58 -0500 | [diff] [blame] | 189 | } |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 190 | else |
| 191 | { |
| 192 | activationBlocksTransition.reset(nullptr); |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 193 | activationProgress.reset(nullptr); |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 194 | } |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 195 | |
| 196 | return softwareServer::Activation::activation(value); |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 197 | } |
| 198 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 199 | auto Activation::requestedActivation(RequestedActivations value) |
| 200 | -> RequestedActivations |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 201 | { |
Saqib Khan | 1e0aa5c | 2017-08-31 11:04:17 -0500 | [diff] [blame] | 202 | ubiVolumesCreated = false; |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 203 | |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 204 | if ((value == softwareServer::Activation::RequestedActivations::Active) && |
| 205 | (softwareServer::Activation::requestedActivation() != |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 206 | softwareServer::Activation::RequestedActivations::Active)) |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 207 | { |
| 208 | if ((softwareServer::Activation::activation() == |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 209 | softwareServer::Activation::Activations::Ready) || |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 210 | (softwareServer::Activation::activation() == |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 211 | softwareServer::Activation::Activations::Failed)) |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 212 | { |
| 213 | Activation::activation( |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 214 | softwareServer::Activation::Activations::Activating); |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 215 | } |
| 216 | } |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 217 | return softwareServer::Activation::requestedActivation(value); |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 218 | } |
| 219 | |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 220 | void Activation::deleteImageManagerObject() |
| 221 | { |
| 222 | // Get the Delete object for <versionID> inside image_manager |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 223 | auto method = this->bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, |
| 224 | MAPPER_INTERFACE, "GetObject"); |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 225 | |
| 226 | method.append(path); |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 227 | method.append( |
| 228 | std::vector<std::string>({"xyz.openbmc_project.Object.Delete"})); |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 229 | auto mapperResponseMsg = bus.call(method); |
| 230 | if (mapperResponseMsg.is_method_error()) |
| 231 | { |
| 232 | log<level::ERR>("Error in Get Delete Object", |
Joseph Reynolds | afd0a45 | 2018-05-30 11:16:03 -0500 | [diff] [blame] | 233 | entry("VERSIONPATH=%s", path.c_str())); |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 234 | return; |
| 235 | } |
| 236 | std::map<std::string, std::vector<std::string>> mapperResponse; |
| 237 | mapperResponseMsg.read(mapperResponse); |
| 238 | if (mapperResponse.begin() == mapperResponse.end()) |
| 239 | { |
| 240 | log<level::ERR>("ERROR in reading the mapper response", |
Joseph Reynolds | afd0a45 | 2018-05-30 11:16:03 -0500 | [diff] [blame] | 241 | entry("VERSIONPATH=%s", path.c_str())); |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 242 | return; |
| 243 | } |
| 244 | |
| 245 | // Call the Delete object for <versionID> inside image_manager |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 246 | method = this->bus.new_method_call( |
| 247 | (mapperResponse.begin()->first).c_str(), path.c_str(), |
| 248 | "xyz.openbmc_project.Object.Delete", "Delete"); |
Adriana Kobylak | ab435df | 2018-07-16 11:37:19 -0500 | [diff] [blame] | 249 | try |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 250 | { |
Adriana Kobylak | ab435df | 2018-07-16 11:37:19 -0500 | [diff] [blame] | 251 | auto mapperResponseMsg = bus.call(method); |
| 252 | |
| 253 | // Check that the bus call didn't result in an error |
| 254 | if (mapperResponseMsg.is_method_error()) |
| 255 | { |
| 256 | log<level::ERR>("Error in Deleting image from image manager", |
| 257 | entry("VERSIONPATH=%s", path.c_str())); |
| 258 | return; |
| 259 | } |
| 260 | } |
| 261 | catch (const SdBusError& e) |
| 262 | { |
| 263 | if (e.name() != nullptr && strcmp("System.Error.ELOOP", e.name()) == 0) |
| 264 | { |
| 265 | // TODO: Error being tracked with openbmc/openbmc#3311 |
| 266 | } |
| 267 | else |
| 268 | { |
| 269 | log<level::ERR>("Error performing call to Delete object path", |
| 270 | entry("ERROR=%s", e.what()), |
| 271 | entry("PATH=%s", path.c_str())); |
| 272 | } |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 273 | return; |
| 274 | } |
| 275 | } |
| 276 | |
Saqib Khan | 2021b4c | 2017-06-07 14:37:36 -0500 | [diff] [blame] | 277 | uint8_t RedundancyPriority::priority(uint8_t value) |
| 278 | { |
Saqib Khan | b8e7f31 | 2017-08-12 10:24:10 -0500 | [diff] [blame] | 279 | parent.parent.freePriority(value, parent.versionId); |
Michael Tritz | 60bc20f | 2017-07-29 23:32:21 -0500 | [diff] [blame] | 280 | storeToFile(parent.versionId, value); |
Saqib Khan | 2021b4c | 2017-06-07 14:37:36 -0500 | [diff] [blame] | 281 | return softwareServer::RedundancyPriority::priority(value); |
| 282 | } |
| 283 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 284 | void Activation::unitStateChange(sdbusplus::message::message& msg) |
| 285 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 286 | uint32_t newStateID{}; |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 287 | sdbusplus::message::object_path newStateObjPath; |
| 288 | std::string newStateUnit{}; |
| 289 | std::string newStateResult{}; |
| 290 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 291 | // Read the msg and populate each variable |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 292 | msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult); |
| 293 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 294 | auto ubimountServiceFile = |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 295 | "obmc-flash-bios-ubimount@" + versionId + ".service"; |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 296 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 297 | if (newStateUnit == ubimountServiceFile && newStateResult == "done") |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 298 | { |
Saqib Khan | 1e0aa5c | 2017-08-31 11:04:17 -0500 | [diff] [blame] | 299 | ubiVolumesCreated = true; |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 300 | activationProgress->progress(activationProgress->progress() + 50); |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 301 | } |
| 302 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 303 | if (ubiVolumesCreated) |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 304 | { |
| 305 | Activation::activation( |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 306 | softwareServer::Activation::Activations::Activating); |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 307 | } |
| 308 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 309 | if ((newStateUnit == ubimountServiceFile) && |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 310 | (newStateResult == "failed" || newStateResult == "dependency")) |
| 311 | { |
| 312 | Activation::activation(softwareServer::Activation::Activations::Failed); |
| 313 | } |
| 314 | |
| 315 | return; |
| 316 | } |
| 317 | |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 318 | #ifdef WANT_SIGNATURE_VERIFY |
| 319 | inline bool Activation::validateSignature() |
| 320 | { |
| 321 | using Signature = openpower::software::image::Signature; |
| 322 | fs::path imageDir(IMG_DIR); |
| 323 | |
| 324 | Signature signature(imageDir / versionId, PNOR_SIGNED_IMAGE_CONF_PATH); |
| 325 | |
| 326 | // Validate the signed image. |
| 327 | if (signature.verify()) |
| 328 | { |
| 329 | return true; |
| 330 | } |
| 331 | // Log error and continue activation process, if field mode disabled. |
| 332 | log<level::ERR>("Error occurred during image validation"); |
| 333 | report<InternalFailure>(); |
| 334 | |
| 335 | try |
| 336 | { |
| 337 | if (!fieldModeEnabled()) |
| 338 | { |
| 339 | return true; |
| 340 | } |
| 341 | } |
| 342 | catch (const InternalFailure& e) |
| 343 | { |
| 344 | report<InternalFailure>(); |
| 345 | } |
| 346 | return false; |
| 347 | } |
| 348 | |
| 349 | bool Activation::fieldModeEnabled() |
| 350 | { |
| 351 | auto fieldModeSvc = getService(bus, FIELDMODE_PATH, FIELDMODE_INTERFACE); |
| 352 | |
| 353 | auto method = bus.new_method_call(fieldModeSvc.c_str(), FIELDMODE_PATH, |
| 354 | "org.freedesktop.DBus.Properties", "Get"); |
| 355 | |
| 356 | method.append(FIELDMODE_INTERFACE, "FieldModeEnabled"); |
| 357 | auto reply = bus.call(method); |
| 358 | if (reply.is_method_error()) |
| 359 | { |
| 360 | log<level::ERR>("Error in fieldModeEnabled getValue"); |
| 361 | elog<InternalFailure>(); |
| 362 | } |
| 363 | sdbusplus::message::variant<bool> fieldMode; |
| 364 | reply.read(fieldMode); |
| 365 | |
William A. Kennington III | 17f55a8 | 2018-11-27 15:22:05 -0800 | [diff] [blame] | 366 | return sdbusplus::message::variant_ns::get<bool>(fieldMode); |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | std::string Activation::getService(sdbusplus::bus::bus& bus, |
| 370 | const std::string& path, |
| 371 | const std::string& intf) |
| 372 | { |
| 373 | auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, |
| 374 | MAPPER_INTERFACE, "GetObject"); |
| 375 | |
| 376 | mapperCall.append(path); |
| 377 | mapperCall.append(std::vector<std::string>({intf})); |
| 378 | |
| 379 | auto mapperResponseMsg = bus.call(mapperCall); |
| 380 | |
| 381 | if (mapperResponseMsg.is_method_error()) |
| 382 | { |
| 383 | log<level::ERR>("ERROR in getting service", |
| 384 | entry("PATH=%s", path.c_str()), |
| 385 | entry("INTERFACE=%s", intf.c_str())); |
| 386 | |
| 387 | elog<InternalFailure>(); |
| 388 | } |
| 389 | |
| 390 | std::map<std::string, std::vector<std::string>> mapperResponse; |
| 391 | mapperResponseMsg.read(mapperResponse); |
| 392 | |
| 393 | if (mapperResponse.begin() == mapperResponse.end()) |
| 394 | { |
| 395 | log<level::ERR>("ERROR reading mapper response", |
| 396 | entry("PATH=%s", path.c_str()), |
| 397 | entry("INTERFACE=%s", intf.c_str())); |
| 398 | |
| 399 | elog<InternalFailure>(); |
| 400 | } |
| 401 | return mapperResponse.begin()->first; |
| 402 | } |
| 403 | #endif |
| 404 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 405 | } // namespace updater |
| 406 | } // namespace software |
| 407 | } // namespace openpower |