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