Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 1 | #include "activation.hpp" |
Gunnar Mills | b0ce996 | 2018-09-07 13:39:10 -0500 | [diff] [blame] | 2 | |
Lei YU | 1be8d50 | 2018-06-20 11:48:36 +0800 | [diff] [blame] | 3 | #include "images.hpp" |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 4 | #include "item_updater.hpp" |
Saqib Khan | 5d53267 | 2017-08-09 10:44:50 -0500 | [diff] [blame] | 5 | #include "serialize.hpp" |
Gunnar Mills | b0ce996 | 2018-09-07 13:39:10 -0500 | [diff] [blame] | 6 | |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 7 | #include <phosphor-logging/elog-errors.hpp> |
| 8 | #include <phosphor-logging/elog.hpp> |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 9 | #include <phosphor-logging/log.hpp> |
Adriana Kobylak | aea48f2 | 2018-07-10 10:20:56 -0500 | [diff] [blame] | 10 | #include <sdbusplus/exception.hpp> |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 11 | #include <xyz/openbmc_project/Common/error.hpp> |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 12 | |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 13 | #ifdef WANT_SIGNATURE_VERIFY |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 14 | #include "image_verify.hpp" |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 15 | #endif |
| 16 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 17 | namespace phosphor |
| 18 | { |
| 19 | namespace software |
| 20 | { |
| 21 | namespace updater |
| 22 | { |
| 23 | |
| 24 | namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server; |
| 25 | |
Saqib Khan | b9da663 | 2017-09-13 09:48:37 -0500 | [diff] [blame] | 26 | using namespace phosphor::logging; |
Adriana Kobylak | aea48f2 | 2018-07-10 10:20:56 -0500 | [diff] [blame] | 27 | using sdbusplus::exception::SdBusError; |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 28 | using InternalFailure = |
| 29 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 30 | |
| 31 | #ifdef WANT_SIGNATURE_VERIFY |
Jayanth Othayoth | 9a9d7c2 | 2018-03-28 10:05:26 -0500 | [diff] [blame] | 32 | namespace control = sdbusplus::xyz::openbmc_project::Control::server; |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 33 | #endif |
| 34 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 35 | void Activation::subscribeToSystemdSignals() |
| 36 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 37 | auto method = this->bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 38 | SYSTEMD_INTERFACE, "Subscribe"); |
Adriana Kobylak | aea48f2 | 2018-07-10 10:20:56 -0500 | [diff] [blame] | 39 | try |
| 40 | { |
| 41 | this->bus.call_noreply(method); |
| 42 | } |
| 43 | catch (const SdBusError& e) |
| 44 | { |
| 45 | if (e.name() != nullptr && |
| 46 | strcmp("org.freedesktop.systemd1.AlreadySubscribed", e.name()) == 0) |
| 47 | { |
| 48 | // If an Activation attempt fails, the Unsubscribe method is not |
| 49 | // called. This may lead to an AlreadySubscribed error if the |
| 50 | // Activation is re-attempted. |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | log<level::ERR>("Error subscribing to systemd", |
| 55 | entry("ERROR=%s", e.what())); |
| 56 | } |
| 57 | } |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 58 | |
| 59 | return; |
| 60 | } |
| 61 | |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 62 | void Activation::unsubscribeFromSystemdSignals() |
| 63 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 64 | auto method = this->bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 65 | SYSTEMD_INTERFACE, "Unsubscribe"); |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 66 | try |
| 67 | { |
| 68 | this->bus.call_noreply(method); |
| 69 | } |
| 70 | catch (const SdBusError& e) |
| 71 | { |
| 72 | log<level::ERR>("Error in unsubscribing from systemd signals", |
| 73 | entry("ERROR=%s", e.what())); |
| 74 | } |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 75 | |
| 76 | return; |
| 77 | } |
| 78 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 79 | auto Activation::activation(Activations value) -> Activations |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 80 | { |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 81 | |
Adriana Kobylak | 8bd84c8 | 2018-01-24 14:19:24 -0600 | [diff] [blame] | 82 | if ((value != softwareServer::Activation::Activations::Active) && |
| 83 | (value != softwareServer::Activation::Activations::Activating)) |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 84 | { |
| 85 | redundancyPriority.reset(nullptr); |
| 86 | } |
| 87 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 88 | if (value == softwareServer::Activation::Activations::Activating) |
| 89 | { |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 90 | #ifdef UBIFS_LAYOUT |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 91 | if (rwVolumeCreated == false && roVolumeCreated == false) |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 92 | { |
Adriana Kobylak | aea48f2 | 2018-07-10 10:20:56 -0500 | [diff] [blame] | 93 | // Enable systemd signals |
| 94 | Activation::subscribeToSystemdSignals(); |
| 95 | |
Adriana Kobylak | a696359 | 2018-09-07 14:13:29 -0500 | [diff] [blame] | 96 | parent.freeSpace(*this); |
Adriana Kobylak | 204e1e7 | 2018-01-24 16:00:05 -0600 | [diff] [blame] | 97 | |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 98 | if (!activationProgress) |
| 99 | { |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 100 | activationProgress = |
| 101 | std::make_unique<ActivationProgress>(bus, path); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 102 | } |
| 103 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 104 | if (!activationBlocksTransition) |
| 105 | { |
| 106 | activationBlocksTransition = |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 107 | std::make_unique<ActivationBlocksTransition>(bus, path); |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 108 | } |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 109 | |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 110 | #ifdef WANT_SIGNATURE_VERIFY |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 111 | fs::path uploadDir(IMG_UPLOAD_DIR); |
Lei YU | 9053225 | 2018-05-24 11:15:24 +0800 | [diff] [blame] | 112 | if (!verifySignature(uploadDir / versionId, SIGNED_IMAGE_CONF_PATH)) |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 113 | { |
Lei YU | 9053225 | 2018-05-24 11:15:24 +0800 | [diff] [blame] | 114 | onVerifyFailed(); |
Jayanth Othayoth | 9a9d7c2 | 2018-03-28 10:05:26 -0500 | [diff] [blame] | 115 | // Stop the activation process, if fieldMode is enabled. |
| 116 | if (parent.control::FieldMode::fieldModeEnabled()) |
| 117 | { |
| 118 | // Cleanup |
| 119 | activationBlocksTransition.reset(nullptr); |
| 120 | activationProgress.reset(nullptr); |
Jayanth Othayoth | 9a9d7c2 | 2018-03-28 10:05:26 -0500 | [diff] [blame] | 121 | return softwareServer::Activation::activation( |
| 122 | softwareServer::Activation::Activations::Failed); |
| 123 | } |
Jayanth Othayoth | 0e0c127 | 2018-02-21 05:46:36 -0600 | [diff] [blame] | 124 | } |
| 125 | #endif |
| 126 | |
Adriana Kobylak | 9f89e2e | 2018-05-30 13:16:20 -0500 | [diff] [blame] | 127 | flashWrite(); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 128 | |
| 129 | activationProgress->progress(10); |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 130 | } |
| 131 | else if (rwVolumeCreated == true && roVolumeCreated == true) |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 132 | { |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 133 | if (ubootEnvVarsUpdated == false) |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 134 | { |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 135 | activationProgress->progress(90); |
| 136 | |
| 137 | if (!redundancyPriority) |
| 138 | { |
| 139 | redundancyPriority = std::make_unique<RedundancyPriority>( |
| 140 | bus, path, *this, 0); |
| 141 | } |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 142 | } |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 143 | else |
| 144 | { |
| 145 | activationProgress->progress(100); |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 146 | |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 147 | activationBlocksTransition.reset(nullptr); |
| 148 | activationProgress.reset(nullptr); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 149 | |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 150 | rwVolumeCreated = false; |
| 151 | roVolumeCreated = false; |
| 152 | ubootEnvVarsUpdated = false; |
| 153 | Activation::unsubscribeFromSystemdSignals(); |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 154 | |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 155 | // Remove version object from image manager |
| 156 | Activation::deleteImageManagerObject(); |
Michael Tritz | f2b5e0d | 2017-07-25 14:39:34 -0500 | [diff] [blame] | 157 | |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 158 | // Create active association |
| 159 | parent.createActiveAssociation(path); |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 160 | |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 161 | if (Activation::checkApplyTimeImmediate() == true) |
| 162 | { |
| 163 | log<level::INFO>("Image Active. ApplyTime is immediate, " |
| 164 | "rebooting BMC."); |
| 165 | Activation::rebootBmc(); |
| 166 | } |
| 167 | |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 168 | return softwareServer::Activation::activation( |
| 169 | softwareServer::Activation::Activations::Active); |
| 170 | } |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 171 | } |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 172 | #else // !UBIFS_LAYOUT |
| 173 | |
Lei YU | 9053225 | 2018-05-24 11:15:24 +0800 | [diff] [blame] | 174 | #ifdef WANT_SIGNATURE_VERIFY |
| 175 | fs::path uploadDir(IMG_UPLOAD_DIR); |
| 176 | if (!verifySignature(uploadDir / versionId, SIGNED_IMAGE_CONF_PATH)) |
| 177 | { |
| 178 | onVerifyFailed(); |
| 179 | // Stop the activation process, if fieldMode is enabled. |
| 180 | if (parent.control::FieldMode::fieldModeEnabled()) |
| 181 | { |
| 182 | return softwareServer::Activation::activation( |
| 183 | softwareServer::Activation::Activations::Failed); |
| 184 | } |
| 185 | } |
| 186 | #endif |
Adriana Kobylak | a696359 | 2018-09-07 14:13:29 -0500 | [diff] [blame] | 187 | parent.freeSpace(*this); |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 188 | |
| 189 | flashWrite(); |
| 190 | |
| 191 | if (!redundancyPriority) |
| 192 | { |
| 193 | redundancyPriority = |
| 194 | std::make_unique<RedundancyPriority>(bus, path, *this, 0); |
| 195 | } |
| 196 | |
| 197 | // Remove version object from image manager |
| 198 | Activation::deleteImageManagerObject(); |
| 199 | |
| 200 | // Create active association |
| 201 | parent.createActiveAssociation(path); |
| 202 | |
| 203 | log<level::INFO>("BMC image ready, need reboot to get activated."); |
| 204 | return softwareServer::Activation::activation( |
| 205 | softwareServer::Activation::Activations::Active); |
| 206 | #endif |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 207 | } |
| 208 | else |
| 209 | { |
| 210 | activationBlocksTransition.reset(nullptr); |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 211 | activationProgress.reset(nullptr); |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 212 | } |
| 213 | return softwareServer::Activation::activation(value); |
| 214 | } |
| 215 | |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 216 | void Activation::deleteImageManagerObject() |
| 217 | { |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 218 | // Call the Delete object for <versionID> inside image_manager |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 219 | auto method = this->bus.new_method_call(VERSION_BUSNAME, path.c_str(), |
| 220 | "xyz.openbmc_project.Object.Delete", |
| 221 | "Delete"); |
Adriana Kobylak | 3b6a4cd | 2018-12-10 13:45:09 -0600 | [diff] [blame] | 222 | try |
| 223 | { |
| 224 | bus.call_noreply(method); |
| 225 | } |
| 226 | catch (const SdBusError& e) |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 227 | { |
| 228 | log<level::ERR>("Error in Deleting image from image manager", |
Adriana Kobylak | 596466b | 2018-02-13 14:48:53 -0600 | [diff] [blame] | 229 | entry("VERSIONPATH=%s", path.c_str())); |
Saqib Khan | ee13e83 | 2017-10-23 12:53:11 -0500 | [diff] [blame] | 230 | return; |
| 231 | } |
| 232 | } |
| 233 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 234 | auto Activation::requestedActivation(RequestedActivations value) |
| 235 | -> RequestedActivations |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 236 | { |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 237 | rwVolumeCreated = false; |
| 238 | roVolumeCreated = false; |
Adriana Kobylak | 166bdf3 | 2018-04-09 14:24:06 -0500 | [diff] [blame] | 239 | ubootEnvVarsUpdated = false; |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 240 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 241 | if ((value == softwareServer::Activation::RequestedActivations::Active) && |
| 242 | (softwareServer::Activation::requestedActivation() != |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 243 | softwareServer::Activation::RequestedActivations::Active)) |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 244 | { |
| 245 | if ((softwareServer::Activation::activation() == |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 246 | softwareServer::Activation::Activations::Ready) || |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 247 | (softwareServer::Activation::activation() == |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 248 | softwareServer::Activation::Activations::Failed)) |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 249 | { |
| 250 | Activation::activation( |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 251 | softwareServer::Activation::Activations::Activating); |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | return softwareServer::Activation::requestedActivation(value); |
| 255 | } |
| 256 | |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 257 | uint8_t RedundancyPriority::priority(uint8_t value) |
| 258 | { |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 259 | // Set the priority value so that the freePriority() function can order |
| 260 | // the versions by priority. |
| 261 | auto newPriority = softwareServer::RedundancyPriority::priority(value); |
Adriana Kobylak | bbcb7be | 2018-07-17 15:47:34 -0500 | [diff] [blame] | 262 | parent.parent.savePriority(parent.versionId, value); |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 263 | parent.parent.freePriority(value, parent.versionId); |
| 264 | return newPriority; |
Saqib Khan | 4c1aec0 | 2017-07-06 11:46:13 -0500 | [diff] [blame] | 265 | } |
| 266 | |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 267 | uint8_t RedundancyPriority::sdbusPriority(uint8_t value) |
Saqib Khan | f0382c3 | 2017-10-24 13:36:22 -0500 | [diff] [blame] | 268 | { |
Adriana Kobylak | bbcb7be | 2018-07-17 15:47:34 -0500 | [diff] [blame] | 269 | parent.parent.savePriority(parent.versionId, value); |
Adriana Kobylak | b77551c | 2017-10-27 12:46:23 -0500 | [diff] [blame] | 270 | return softwareServer::RedundancyPriority::priority(value); |
Saqib Khan | f0382c3 | 2017-10-24 13:36:22 -0500 | [diff] [blame] | 271 | } |
| 272 | |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 273 | void Activation::unitStateChange(sdbusplus::message::message& msg) |
| 274 | { |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 275 | if (softwareServer::Activation::activation() != |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 276 | softwareServer::Activation::Activations::Activating) |
Michael Tritz | 0edd4ad | 2017-07-26 14:27:42 -0500 | [diff] [blame] | 277 | { |
| 278 | return; |
| 279 | } |
| 280 | |
Adriana Kobylak | 3ce563a | 2018-06-06 16:41:15 -0500 | [diff] [blame] | 281 | onStateChanges(msg); |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 282 | |
| 283 | return; |
| 284 | } |
| 285 | |
Lei YU | 9053225 | 2018-05-24 11:15:24 +0800 | [diff] [blame] | 286 | #ifdef WANT_SIGNATURE_VERIFY |
| 287 | bool Activation::verifySignature(const fs::path& imageDir, |
| 288 | const fs::path& confDir) |
| 289 | { |
| 290 | using Signature = phosphor::software::image::Signature; |
| 291 | |
| 292 | Signature signature(imageDir, confDir); |
| 293 | |
| 294 | return signature.verify(); |
| 295 | } |
| 296 | |
| 297 | void Activation::onVerifyFailed() |
| 298 | { |
| 299 | log<level::ERR>("Error occurred during image validation"); |
| 300 | report<InternalFailure>(); |
| 301 | } |
| 302 | #endif |
| 303 | |
Saqib Khan | f37cefc | 2017-09-12 08:44:41 -0500 | [diff] [blame] | 304 | void ActivationBlocksTransition::enableRebootGuard() |
| 305 | { |
| 306 | log<level::INFO>("BMC image activating - BMC reboots are disabled."); |
| 307 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 308 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 309 | SYSTEMD_INTERFACE, "StartUnit"); |
Saqib Khan | f37cefc | 2017-09-12 08:44:41 -0500 | [diff] [blame] | 310 | method.append("reboot-guard-enable.service", "replace"); |
| 311 | bus.call_noreply(method); |
| 312 | } |
| 313 | |
| 314 | void ActivationBlocksTransition::disableRebootGuard() |
| 315 | { |
| 316 | log<level::INFO>("BMC activation has ended - BMC reboots are re-enabled."); |
| 317 | |
Adriana Kobylak | 2285fe0 | 2018-02-27 15:36:59 -0600 | [diff] [blame] | 318 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 319 | SYSTEMD_INTERFACE, "StartUnit"); |
Saqib Khan | f37cefc | 2017-09-12 08:44:41 -0500 | [diff] [blame] | 320 | method.append("reboot-guard-disable.service", "replace"); |
| 321 | bus.call_noreply(method); |
| 322 | } |
Michael Tritz | bed88af | 2017-07-19 16:00:06 -0500 | [diff] [blame] | 323 | |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 324 | bool Activation::checkApplyTimeImmediate() |
| 325 | { |
| 326 | auto service = utils::getService(bus, applyTimeObjPath, applyTimeIntf); |
| 327 | if (service.empty()) |
| 328 | { |
| 329 | log<level::INFO>("Error getting the service name for BMC image " |
| 330 | "ApplyTime. The BMC needs to be manually rebooted to " |
| 331 | "complete the image activation if needed " |
| 332 | "immediately."); |
| 333 | } |
| 334 | else |
| 335 | { |
| 336 | |
| 337 | auto method = bus.new_method_call(service.c_str(), applyTimeObjPath, |
| 338 | dbusPropIntf, "Get"); |
| 339 | method.append(applyTimeIntf, applyTimeProp); |
| 340 | |
| 341 | try |
| 342 | { |
| 343 | auto reply = bus.call(method); |
| 344 | |
| 345 | sdbusplus::message::variant<std::string> result; |
| 346 | reply.read(result); |
| 347 | auto applyTime = |
| 348 | sdbusplus::message::variant_ns::get<std::string>(result); |
| 349 | if (applyTime == applyTimeImmediate) |
| 350 | { |
| 351 | return true; |
| 352 | } |
| 353 | } |
| 354 | catch (const SdBusError& e) |
| 355 | { |
| 356 | log<level::ERR>("Error in getting ApplyTime", |
| 357 | entry("ERROR=%s", e.what())); |
| 358 | } |
| 359 | } |
| 360 | return false; |
| 361 | } |
| 362 | |
| 363 | void Activation::rebootBmc() |
| 364 | { |
| 365 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 366 | SYSTEMD_INTERFACE, "StartUnit"); |
| 367 | method.append("force-reboot.service", "replace"); |
| 368 | try |
| 369 | { |
| 370 | auto reply = bus.call(method); |
| 371 | } |
| 372 | catch (const SdBusError& e) |
| 373 | { |
| 374 | log<level::ALERT>("Error in trying to reboot the BMC. " |
| 375 | "The BMC needs to be manually rebooted to complete " |
| 376 | "the image activation."); |
| 377 | report<InternalFailure>(); |
| 378 | } |
| 379 | } |
| 380 | |
Saqib Khan | b077470 | 2017-05-23 16:02:41 -0500 | [diff] [blame] | 381 | } // namespace updater |
| 382 | } // namespace software |
| 383 | } // namespace phosphor |