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