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