Lei YU | b53425d | 2019-02-22 11:38:40 +0800 | [diff] [blame] | 1 | #include "activation_static.hpp" |
| 2 | |
Lei YU | a2e6716 | 2019-02-22 17:35:24 +0800 | [diff] [blame] | 3 | #include "item_updater.hpp" |
| 4 | |
Lei YU | a2e6716 | 2019-02-22 17:35:24 +0800 | [diff] [blame] | 5 | #include <phosphor-logging/log.hpp> |
| 6 | |
Lei YU | b53425d | 2019-02-22 11:38:40 +0800 | [diff] [blame] | 7 | namespace openpower |
| 8 | { |
| 9 | namespace software |
| 10 | { |
| 11 | namespace updater |
| 12 | { |
| 13 | namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server; |
| 14 | |
Lei YU | a2e6716 | 2019-02-22 17:35:24 +0800 | [diff] [blame] | 15 | using namespace phosphor::logging; |
| 16 | |
| 17 | auto ActivationStatic::activation(Activations value) -> Activations |
| 18 | { |
Lei YU | 6da3dae | 2019-02-28 14:26:37 +0800 | [diff] [blame] | 19 | auto ret = value; |
Lei YU | a2e6716 | 2019-02-22 17:35:24 +0800 | [diff] [blame] | 20 | if (value != softwareServer::Activation::Activations::Active) |
| 21 | { |
| 22 | redundancyPriority.reset(nullptr); |
| 23 | } |
| 24 | |
| 25 | if (value == softwareServer::Activation::Activations::Activating) |
| 26 | { |
Lei YU | 2b2d229 | 2019-03-18 15:22:56 +0800 | [diff] [blame] | 27 | fs::path imagePath(IMG_DIR); |
| 28 | imagePath /= versionId; |
| 29 | |
| 30 | for (const auto& entry : fs::directory_iterator(imagePath)) |
| 31 | { |
| 32 | if (entry.path().extension() == ".pnor") |
| 33 | { |
| 34 | pnorFilePath = entry; |
| 35 | break; |
| 36 | } |
| 37 | } |
| 38 | if (pnorFilePath.empty()) |
| 39 | { |
| 40 | log<level::ERR>("Unable to find pnor file", |
| 41 | entry("DIR=%s", imagePath.c_str())); |
| 42 | ret = softwareServer::Activation::Activations::Failed; |
| 43 | goto out; |
| 44 | } |
| 45 | #ifdef WANT_SIGNATURE_VERIFY |
| 46 | // Validate the signed image. |
| 47 | if (!validateSignature(pnorFilePath.filename())) |
| 48 | { |
| 49 | // Cleanup |
| 50 | activationBlocksTransition.reset(nullptr); |
| 51 | activationProgress.reset(nullptr); |
| 52 | |
| 53 | ret = softwareServer::Activation::Activations::Failed; |
| 54 | goto out; |
| 55 | } |
| 56 | #endif |
Lei YU | 6da3dae | 2019-02-28 14:26:37 +0800 | [diff] [blame] | 57 | if (parent.freeSpace()) |
| 58 | { |
| 59 | startActivation(); |
| 60 | } |
| 61 | else |
| 62 | { |
| 63 | ret = softwareServer::Activation::Activations::Failed; |
| 64 | } |
Lei YU | a2e6716 | 2019-02-22 17:35:24 +0800 | [diff] [blame] | 65 | } |
| 66 | else |
| 67 | { |
| 68 | activationBlocksTransition.reset(nullptr); |
| 69 | activationProgress.reset(nullptr); |
| 70 | } |
| 71 | |
Lei YU | 2b2d229 | 2019-03-18 15:22:56 +0800 | [diff] [blame] | 72 | out: |
Lei YU | 6da3dae | 2019-02-28 14:26:37 +0800 | [diff] [blame] | 73 | return softwareServer::Activation::activation(ret); |
Lei YU | a2e6716 | 2019-02-22 17:35:24 +0800 | [diff] [blame] | 74 | } |
| 75 | |
Lei YU | b53425d | 2019-02-22 11:38:40 +0800 | [diff] [blame] | 76 | void ActivationStatic::startActivation() |
| 77 | { |
Lei YU | a2e6716 | 2019-02-22 17:35:24 +0800 | [diff] [blame] | 78 | if (!activationProgress) |
| 79 | { |
| 80 | activationProgress = std::make_unique<ActivationProgress>(bus, path); |
| 81 | } |
| 82 | |
| 83 | if (!activationBlocksTransition) |
| 84 | { |
| 85 | activationBlocksTransition = |
| 86 | std::make_unique<ActivationBlocksTransition>(bus, path); |
| 87 | } |
| 88 | |
| 89 | // TODO: check why the signal is still received without calling this |
| 90 | // function? |
| 91 | subscribeToSystemdSignals(); |
| 92 | |
| 93 | log<level::INFO>("Start programming...", |
Lei YU | 2b2d229 | 2019-03-18 15:22:56 +0800 | [diff] [blame] | 94 | entry("PNOR=%s", pnorFilePath.c_str())); |
Lei YU | a2e6716 | 2019-02-22 17:35:24 +0800 | [diff] [blame] | 95 | |
Lei YU | 2b2d229 | 2019-03-18 15:22:56 +0800 | [diff] [blame] | 96 | std::string pnorFileEscaped = pnorFilePath.string(); |
Lei YU | a2e6716 | 2019-02-22 17:35:24 +0800 | [diff] [blame] | 97 | // Escape all '/' to '-' |
| 98 | std::replace(pnorFileEscaped.begin(), pnorFileEscaped.end(), '/', '-'); |
| 99 | |
| 100 | constexpr auto updatePNORService = "openpower-pnor-update@"; |
Patrick Williams | 7fb6c34 | 2023-05-10 07:50:18 -0500 | [diff] [blame] | 101 | pnorUpdateUnit = std::string(updatePNORService) + pnorFileEscaped + |
| 102 | ".service"; |
Lei YU | a2e6716 | 2019-02-22 17:35:24 +0800 | [diff] [blame] | 103 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 104 | SYSTEMD_INTERFACE, "StartUnit"); |
| 105 | method.append(pnorUpdateUnit, "replace"); |
| 106 | bus.call_noreply(method); |
| 107 | |
| 108 | activationProgress->progress(10); |
Lei YU | b53425d | 2019-02-22 11:38:40 +0800 | [diff] [blame] | 109 | } |
| 110 | |
Patrick Williams | 0dea199 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 111 | void ActivationStatic::unitStateChange(sdbusplus::message_t& msg) |
Lei YU | b53425d | 2019-02-22 11:38:40 +0800 | [diff] [blame] | 112 | { |
Lei YU | a2e6716 | 2019-02-22 17:35:24 +0800 | [diff] [blame] | 113 | uint32_t newStateID{}; |
| 114 | sdbusplus::message::object_path newStateObjPath; |
| 115 | std::string newStateUnit{}; |
| 116 | std::string newStateResult{}; |
| 117 | |
| 118 | // Read the msg and populate each variable |
| 119 | msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult); |
| 120 | |
| 121 | if (newStateUnit == pnorUpdateUnit) |
| 122 | { |
| 123 | if (newStateResult == "done") |
| 124 | { |
| 125 | finishActivation(); |
| 126 | } |
| 127 | if (newStateResult == "failed" || newStateResult == "dependency") |
| 128 | { |
| 129 | Activation::activation( |
| 130 | softwareServer::Activation::Activations::Failed); |
| 131 | } |
| 132 | } |
Lei YU | b53425d | 2019-02-22 11:38:40 +0800 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | void ActivationStatic::finishActivation() |
| 136 | { |
Lei YU | a2e6716 | 2019-02-22 17:35:24 +0800 | [diff] [blame] | 137 | activationProgress->progress(90); |
| 138 | |
| 139 | // Set Redundancy Priority before setting to Active |
| 140 | if (!redundancyPriority) |
| 141 | { |
Patrick Williams | 7fb6c34 | 2023-05-10 07:50:18 -0500 | [diff] [blame] | 142 | redundancyPriority = std::make_unique<RedundancyPriority>(bus, path, |
| 143 | *this, 0); |
Lei YU | a2e6716 | 2019-02-22 17:35:24 +0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | activationProgress->progress(100); |
| 147 | |
| 148 | activationBlocksTransition.reset(); |
| 149 | activationProgress.reset(); |
| 150 | |
| 151 | unsubscribeFromSystemdSignals(); |
| 152 | // Remove version object from image manager |
| 153 | deleteImageManagerObject(); |
| 154 | // Create active association |
| 155 | parent.createActiveAssociation(path); |
Adriana Kobylak | 3c81037 | 2020-07-15 16:47:03 -0500 | [diff] [blame] | 156 | // Create updateable association as this |
| 157 | // can be re-programmed. |
| 158 | parent.createUpdateableAssociation(path); |
Lei YU | a2e6716 | 2019-02-22 17:35:24 +0800 | [diff] [blame] | 159 | // Create functional assocaition |
| 160 | parent.updateFunctionalAssociation(versionId); |
| 161 | |
| 162 | Activation::activation(Activation::Activations::Active); |
Lei YU | b53425d | 2019-02-22 11:38:40 +0800 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | } // namespace updater |
| 166 | } // namespace software |
| 167 | } // namespace openpower |