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 |
| 9 | #include <phosphor-logging/elog.hpp> |
| 10 | #include <phosphor-logging/elog-errors.hpp> |
| 11 | #include <xyz/openbmc_project/Common/error.hpp> |
| 12 | #include "image_verify.hpp" |
| 13 | #include "config.h" |
| 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; |
| 31 | #endif |
| 32 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 33 | constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1"; |
| 34 | constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1"; |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 35 | |
| 36 | void Activation::subscribeToSystemdSignals() |
| 37 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 38 | auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH, |
| 39 | SYSTEMD_INTERFACE, "Subscribe"); |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 40 | this->bus.call_noreply(method); |
| 41 | |
| 42 | return; |
| 43 | } |
| 44 | |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 45 | void Activation::unsubscribeFromSystemdSignals() |
| 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, "Unsubscribe"); |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 49 | this->bus.call_noreply(method); |
| 50 | |
| 51 | return; |
| 52 | } |
| 53 | |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 54 | void Activation::startActivation() |
| 55 | { |
| 56 | // Since the squashfs image has not yet been loaded to pnor and the |
| 57 | // RW volumes have not yet been created, we need to start the |
| 58 | // service files for each of those actions. |
| 59 | |
| 60 | if (!activationProgress) |
| 61 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 62 | activationProgress = std::make_unique<ActivationProgress>(bus, path); |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | if (!activationBlocksTransition) |
| 66 | { |
| 67 | activationBlocksTransition = |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 68 | std::make_unique<ActivationBlocksTransition>(bus, path); |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 69 | } |
| 70 | |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 71 | constexpr auto ubimountService = "obmc-flash-bios-ubimount@"; |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 72 | auto ubimountServiceFile = |
| 73 | std::string(ubimountService) + versionId + ".service"; |
| 74 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 75 | SYSTEMD_INTERFACE, "StartUnit"); |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 76 | method.append(ubimountServiceFile, "replace"); |
| 77 | bus.call_noreply(method); |
| 78 | |
| 79 | activationProgress->progress(10); |
| 80 | } |
| 81 | |
| 82 | void Activation::finishActivation() |
| 83 | { |
| 84 | activationProgress->progress(90); |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 85 | |
| 86 | // Set Redundancy Priority before setting to Active |
| 87 | if (!redundancyPriority) |
| 88 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 89 | redundancyPriority = |
| 90 | std::make_unique<RedundancyPriority>(bus, path, *this, 0); |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | activationProgress->progress(100); |
| 94 | |
| 95 | activationBlocksTransition.reset(nullptr); |
| 96 | activationProgress.reset(nullptr); |
| 97 | |
Saqib Khan | 1e0aa5c | 2017-08-31 11:04:17 -0500 | [diff] [blame] | 98 | ubiVolumesCreated = false; |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 99 | Activation::unsubscribeFromSystemdSignals(); |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 100 | // Remove version object from image manager |
| 101 | Activation::deleteImageManagerObject(); |
Gunnar Mills | 9741cd1 | 2017-08-28 15:09:00 -0500 | [diff] [blame] | 102 | // Create active association |
| 103 | parent.createActiveAssociation(path); |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 104 | } |
| 105 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 106 | auto Activation::activation(Activations value) -> Activations |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 107 | { |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 108 | |
| 109 | if (value != softwareServer::Activation::Activations::Active) |
| 110 | { |
| 111 | redundancyPriority.reset(nullptr); |
| 112 | } |
| 113 | |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 114 | if (value == softwareServer::Activation::Activations::Activating) |
| 115 | { |
Saqib Khan | 2cbfa03 | 2017-08-17 14:52:37 -0500 | [diff] [blame] | 116 | parent.freeSpace(); |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 117 | softwareServer::Activation::activation(value); |
| 118 | |
Saqib Khan | 1e0aa5c | 2017-08-31 11:04:17 -0500 | [diff] [blame] | 119 | if (ubiVolumesCreated == false) |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 120 | { |
Jayanth Othayoth | 4016e52 | 2018-03-20 09:39:06 -0500 | [diff] [blame^] | 121 | |
| 122 | #ifdef WANT_SIGNATURE_VERIFY |
| 123 | using Signature = openpower::software::image::Signature; |
| 124 | |
| 125 | fs::path imagePath(IMG_DIR); |
| 126 | |
| 127 | Signature signature(imagePath / versionId, SIGNED_IMAGE_CONF_PATH); |
| 128 | |
| 129 | // Validate the signed image. |
| 130 | if (!signature.verify()) |
| 131 | { |
| 132 | log<level::ERR>("Error occurred during image validation"); |
| 133 | report<InternalFailure>(); |
| 134 | |
| 135 | return softwareServer::Activation::activation( |
| 136 | softwareServer::Activation::Activations::Failed); |
| 137 | } |
| 138 | #endif |
| 139 | |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 140 | Activation::startActivation(); |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 141 | return softwareServer::Activation::activation(value); |
| 142 | } |
Saqib Khan | 1e0aa5c | 2017-08-31 11:04:17 -0500 | [diff] [blame] | 143 | else if (ubiVolumesCreated == true) |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 144 | { |
| 145 | // Only when the squashfs image is finished loading AND the RW |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 146 | // volumes have been created do we proceed with activation. To |
| 147 | // verify that this happened, we check for the mount dirs PNOR_PRSV |
| 148 | // and PNOR_RW_PREFIX_<versionid>, as well as the image dir R0. |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 149 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 150 | if ((fs::is_directory(PNOR_PRSV)) && |
| 151 | (fs::is_directory(PNOR_RW_PREFIX + versionId)) && |
| 152 | (fs::is_directory(PNOR_RO_PREFIX + versionId))) |
| 153 | { |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 154 | Activation::finishActivation(); |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 155 | return softwareServer::Activation::activation( |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 156 | softwareServer::Activation::Activations::Active); |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 157 | } |
| 158 | else |
| 159 | { |
Saqib Khan | cb9df4e | 2017-06-26 11:06:07 -0500 | [diff] [blame] | 160 | activationBlocksTransition.reset(nullptr); |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 161 | activationProgress.reset(nullptr); |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 162 | return softwareServer::Activation::activation( |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 163 | softwareServer::Activation::Activations::Failed); |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 164 | } |
Adriana Kobylak | 55f9e83 | 2017-05-14 16:13:00 -0500 | [diff] [blame] | 165 | } |
Adriana Kobylak | 692b555 | 2017-04-17 14:02:58 -0500 | [diff] [blame] | 166 | } |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 167 | else |
| 168 | { |
| 169 | activationBlocksTransition.reset(nullptr); |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 170 | activationProgress.reset(nullptr); |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 171 | } |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 172 | |
| 173 | return softwareServer::Activation::activation(value); |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 174 | } |
| 175 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 176 | auto Activation::requestedActivation(RequestedActivations value) |
| 177 | -> RequestedActivations |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 178 | { |
Saqib Khan | 1e0aa5c | 2017-08-31 11:04:17 -0500 | [diff] [blame] | 179 | ubiVolumesCreated = false; |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 180 | |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 181 | if ((value == softwareServer::Activation::RequestedActivations::Active) && |
| 182 | (softwareServer::Activation::requestedActivation() != |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 183 | softwareServer::Activation::RequestedActivations::Active)) |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 184 | { |
| 185 | if ((softwareServer::Activation::activation() == |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 186 | softwareServer::Activation::Activations::Ready) || |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 187 | (softwareServer::Activation::activation() == |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 188 | softwareServer::Activation::Activations::Failed)) |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 189 | { |
| 190 | Activation::activation( |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 191 | softwareServer::Activation::Activations::Activating); |
Adriana Kobylak | 2fdb931 | 2017-05-14 19:08:26 -0500 | [diff] [blame] | 192 | } |
| 193 | } |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 194 | return softwareServer::Activation::requestedActivation(value); |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 195 | } |
| 196 | |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 197 | void Activation::deleteImageManagerObject() |
| 198 | { |
| 199 | // Get the Delete object for <versionID> inside image_manager |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 200 | auto method = this->bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, |
| 201 | MAPPER_INTERFACE, "GetObject"); |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 202 | |
| 203 | method.append(path); |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 204 | method.append( |
| 205 | std::vector<std::string>({"xyz.openbmc_project.Object.Delete"})); |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 206 | auto mapperResponseMsg = bus.call(method); |
| 207 | if (mapperResponseMsg.is_method_error()) |
| 208 | { |
| 209 | log<level::ERR>("Error in Get Delete Object", |
| 210 | entry("VERSIONPATH=%s", path)); |
| 211 | return; |
| 212 | } |
| 213 | std::map<std::string, std::vector<std::string>> mapperResponse; |
| 214 | mapperResponseMsg.read(mapperResponse); |
| 215 | if (mapperResponse.begin() == mapperResponse.end()) |
| 216 | { |
| 217 | log<level::ERR>("ERROR in reading the mapper response", |
| 218 | entry("VERSIONPATH=%s", path)); |
| 219 | return; |
| 220 | } |
| 221 | |
| 222 | // Call the Delete object for <versionID> inside image_manager |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 223 | method = this->bus.new_method_call( |
| 224 | (mapperResponse.begin()->first).c_str(), path.c_str(), |
| 225 | "xyz.openbmc_project.Object.Delete", "Delete"); |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 226 | mapperResponseMsg = bus.call(method); |
| 227 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 228 | // Check that the bus call didn't result in an error |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 229 | if (mapperResponseMsg.is_method_error()) |
| 230 | { |
| 231 | log<level::ERR>("Error in Deleting image from image manager", |
| 232 | entry("VERSIONPATH=%s", path)); |
| 233 | return; |
| 234 | } |
| 235 | } |
| 236 | |
Saqib Khan | 2021b4c | 2017-06-07 14:37:36 -0500 | [diff] [blame] | 237 | uint8_t RedundancyPriority::priority(uint8_t value) |
| 238 | { |
Saqib Khan | b8e7f31 | 2017-08-12 10:24:10 -0500 | [diff] [blame] | 239 | parent.parent.freePriority(value, parent.versionId); |
Michael Tritz | 60bc20f | 2017-07-29 23:32:21 -0500 | [diff] [blame] | 240 | storeToFile(parent.versionId, value); |
Saqib Khan | 2021b4c | 2017-06-07 14:37:36 -0500 | [diff] [blame] | 241 | return softwareServer::RedundancyPriority::priority(value); |
| 242 | } |
| 243 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 244 | void Activation::unitStateChange(sdbusplus::message::message& msg) |
| 245 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 246 | uint32_t newStateID{}; |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 247 | sdbusplus::message::object_path newStateObjPath; |
| 248 | std::string newStateUnit{}; |
| 249 | std::string newStateResult{}; |
| 250 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 251 | // Read the msg and populate each variable |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 252 | msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult); |
| 253 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 254 | auto ubimountServiceFile = |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 255 | "obmc-flash-bios-ubimount@" + versionId + ".service"; |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 256 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 257 | if (newStateUnit == ubimountServiceFile && newStateResult == "done") |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 258 | { |
Saqib Khan | 1e0aa5c | 2017-08-31 11:04:17 -0500 | [diff] [blame] | 259 | ubiVolumesCreated = true; |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 260 | activationProgress->progress(activationProgress->progress() + 50); |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 261 | } |
| 262 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 263 | if (ubiVolumesCreated) |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 264 | { |
| 265 | Activation::activation( |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 266 | softwareServer::Activation::Activations::Activating); |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 267 | } |
| 268 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 269 | if ((newStateUnit == ubimountServiceFile) && |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 270 | (newStateResult == "failed" || newStateResult == "dependency")) |
| 271 | { |
| 272 | Activation::activation(softwareServer::Activation::Activations::Failed); |
| 273 | } |
| 274 | |
| 275 | return; |
| 276 | } |
| 277 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 278 | } // namespace updater |
| 279 | } // namespace software |
| 280 | } // namespace openpower |