AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2019 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "pfr_mgr.hpp" |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 18 | |
| 19 | namespace intel |
| 20 | { |
| 21 | namespace pfr |
| 22 | { |
| 23 | |
| 24 | static constexpr uint8_t activeImage = 0; |
| 25 | static constexpr uint8_t recoveryImage = 1; |
| 26 | |
| 27 | PfrVersion::PfrVersion(sdbusplus::asio::object_server &srv_, |
| 28 | std::shared_ptr<sdbusplus::asio::connection> &conn_, |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 29 | const std::string &path_, const ImageType &imgType_, |
| 30 | const std::string &purpose_) : |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 31 | server(srv_), |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 32 | conn(conn_), path(path_), imgType(imgType_), purpose(purpose_) |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 33 | { |
AppaRao Puli | 4b639a2 | 2019-10-01 18:12:59 +0530 | [diff] [blame] | 34 | version = getFirmwareVersion(imgType); |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 35 | |
| 36 | std::string objPath = "/xyz/openbmc_project/software/" + path; |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 37 | versionIface = |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 38 | server.add_interface(objPath, "xyz.openbmc_project.Software.Version"); |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 39 | versionIface->register_property("Purpose", purpose); |
| 40 | versionIface->register_property( |
| 41 | versionStr, version, |
| 42 | // Override set |
| 43 | [this](const std::string &req, std::string &propertyValue) { |
| 44 | if (internalSet) |
| 45 | { |
| 46 | if (req != propertyValue) |
| 47 | { |
| 48 | version = req; |
| 49 | propertyValue = req; |
| 50 | return 1; |
| 51 | } |
| 52 | } |
| 53 | return 0; |
| 54 | }); |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 55 | |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 56 | versionIface->initialize(); |
AppaRao Puli | d6f46c4 | 2019-07-19 22:34:04 +0530 | [diff] [blame] | 57 | |
| 58 | /* Activation interface represents activation state for an associated |
| 59 | * xyz.openbmc_project.Software.Version. since these versions are already |
| 60 | * active, so we should set "activation" to Active and |
| 61 | * "RequestedActivation" to None. */ |
| 62 | std::string activation = |
Vikram Bodireddy | 336196d | 2019-12-05 10:58:37 +0530 | [diff] [blame] | 63 | (imgType == ImageType::bmcRecovery || |
Vikram Bodireddy | 3c6c8c3 | 2019-12-05 11:06:15 +0530 | [diff] [blame^] | 64 | imgType == ImageType::biosRecovery || |
| 65 | imgType == ImageType::cpldRecovery) |
Vikram Bodireddy | 336196d | 2019-12-05 10:58:37 +0530 | [diff] [blame] | 66 | ? "xyz.openbmc_project.Software.Activation.Activations.StandbySpare" |
| 67 | : "xyz.openbmc_project.Software.Activation.Activations.Active"; |
AppaRao Puli | d6f46c4 | 2019-07-19 22:34:04 +0530 | [diff] [blame] | 68 | std::string reqActNone = |
| 69 | "xyz.openbmc_project.Software.Activation.RequestedActivations.None"; |
| 70 | auto activationIface = server.add_interface( |
| 71 | objPath, "xyz.openbmc_project.Software.Activation"); |
| 72 | activationIface->register_property("Activation", activation); |
| 73 | activationIface->register_property("RequestedActivation", reqActNone); |
| 74 | |
| 75 | activationIface->initialize(); |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 76 | } |
| 77 | |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 78 | void PfrVersion::updateVersion() |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 79 | { |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 80 | if (versionIface && versionIface->is_initialized()) |
| 81 | { |
AppaRao Puli | 4b639a2 | 2019-10-01 18:12:59 +0530 | [diff] [blame] | 82 | std::string ver = getFirmwareVersion(imgType); |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 83 | internalSet = true; |
| 84 | versionIface->set_property(versionStr, ver); |
| 85 | internalSet = false; |
| 86 | } |
| 87 | return; |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | PfrConfig::PfrConfig(sdbusplus::asio::object_server &srv_, |
| 91 | std::shared_ptr<sdbusplus::asio::connection> &conn_) : |
| 92 | server(srv_), |
| 93 | conn(conn_) |
| 94 | { |
AppaRao Puli | cc1ed68 | 2019-10-01 12:29:40 +0530 | [diff] [blame] | 95 | pfrCfgIface = server.add_interface("/xyz/openbmc_project/pfr", |
| 96 | "xyz.openbmc_project.PFR.Attributes"); |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 97 | |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 98 | getProvisioningStatus(ufmLocked, ufmProvisioned); |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 99 | |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 100 | pfrCfgIface->register_property(ufmProvisionedStr, ufmProvisioned, |
| 101 | // Override set |
| 102 | [this](const bool req, bool propertyValue) { |
| 103 | if (internalSet) |
| 104 | { |
| 105 | if (req != propertyValue) |
| 106 | { |
| 107 | ufmProvisioned = req; |
| 108 | propertyValue = req; |
| 109 | return 1; |
| 110 | } |
| 111 | } |
| 112 | return 0; |
| 113 | }); |
| 114 | |
| 115 | pfrCfgIface->register_property(ufmLockedStr, ufmLocked, |
| 116 | // Override set |
| 117 | [this](const bool req, bool propertyValue) { |
| 118 | if (internalSet) |
| 119 | { |
| 120 | if (req != propertyValue) |
| 121 | { |
| 122 | ufmLocked = req; |
| 123 | propertyValue = req; |
| 124 | return 1; |
| 125 | } |
| 126 | } |
| 127 | return 0; |
| 128 | }); |
| 129 | |
| 130 | pfrCfgIface->initialize(); |
| 131 | } |
| 132 | |
| 133 | void PfrConfig::updateProvisioningStatus() |
| 134 | { |
| 135 | if (pfrCfgIface && pfrCfgIface->is_initialized()) |
| 136 | { |
| 137 | bool lockVal = false; |
| 138 | bool provVal = false; |
| 139 | getProvisioningStatus(lockVal, provVal); |
| 140 | internalSet = true; |
| 141 | pfrCfgIface->set_property(ufmProvisionedStr, provVal); |
| 142 | pfrCfgIface->set_property(ufmLockedStr, lockVal); |
| 143 | internalSet = false; |
| 144 | } |
| 145 | return; |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | } // namespace pfr |
| 149 | } // namespace intel |