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 | |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 19 | namespace pfr |
| 20 | { |
| 21 | |
Alex Schendel | 5cf320c | 2021-12-09 12:11:04 -0800 | [diff] [blame] | 22 | inline void printVersion(const std::string& path, const std::string& version) |
| 23 | { |
| 24 | lg2::info("VERSION INFO - {TYPE} - {VER}", "TYPE", path, "VER", version); |
| 25 | } |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 26 | static constexpr uint8_t activeImage = 0; |
| 27 | static constexpr uint8_t recoveryImage = 1; |
| 28 | |
AppaRao Puli | 0e75891 | 2020-01-29 03:07:54 +0530 | [diff] [blame] | 29 | std::shared_ptr<sdbusplus::asio::dbus_interface> associationIface; |
| 30 | std::set<std::tuple<std::string, std::string, std::string>> associations; |
| 31 | |
AppaRao Puli | 67d184c | 2020-05-29 00:48:33 +0530 | [diff] [blame] | 32 | PfrVersion::PfrVersion(sdbusplus::asio::object_server& srv_, |
| 33 | std::shared_ptr<sdbusplus::asio::connection>& conn_, |
| 34 | const std::string& path_, const ImageType& imgType_, |
| 35 | const std::string& purpose_) : |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 36 | server(srv_), |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 37 | conn(conn_), path(path_), imgType(imgType_), purpose(purpose_) |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 38 | { |
AppaRao Puli | 4b639a2 | 2019-10-01 18:12:59 +0530 | [diff] [blame] | 39 | version = getFirmwareVersion(imgType); |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 40 | |
Alex Schendel | 5cf320c | 2021-12-09 12:11:04 -0800 | [diff] [blame] | 41 | if (!(version == "0.0" || version.empty())) |
| 42 | { |
| 43 | printVersion(path, version); |
| 44 | } |
| 45 | |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 46 | std::string objPath = "/xyz/openbmc_project/software/" + path; |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 47 | versionIface = |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 48 | server.add_interface(objPath, "xyz.openbmc_project.Software.Version"); |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 49 | |
Vikram Bodireddy | 1c06ae4 | 2021-07-08 15:26:51 +0530 | [diff] [blame] | 50 | if (versionIface != nullptr) |
| 51 | { |
| 52 | |
| 53 | versionIface->register_property("Purpose", purpose); |
| 54 | versionIface->register_property( |
| 55 | versionStr, version, |
| 56 | // Override set |
| 57 | [this](const std::string& req, std::string& propertyValue) { |
| 58 | if (internalSet) |
| 59 | { |
| 60 | if (req != propertyValue) |
| 61 | { |
| 62 | version = req; |
| 63 | propertyValue = req; |
| 64 | return 1; |
| 65 | } |
| 66 | } |
| 67 | return 0; |
| 68 | }); |
| 69 | |
| 70 | versionIface->initialize(); |
| 71 | } |
AppaRao Puli | d6f46c4 | 2019-07-19 22:34:04 +0530 | [diff] [blame] | 72 | |
AppaRao Puli | 916d600 | 2019-12-18 01:37:02 +0530 | [diff] [blame] | 73 | std::string activation = |
| 74 | "xyz.openbmc_project.Software.Activation.Activations.StandbySpare"; |
| 75 | |
| 76 | if ((imgType == ImageType::bmcActive) || |
| 77 | (imgType == ImageType::biosActive) || |
Vikram Bodireddy | 8292dc6 | 2021-05-26 13:31:47 +0530 | [diff] [blame] | 78 | (imgType == ImageType::cpldActive) || (imgType == ImageType::afmActive)) |
Vikram Bodireddy | 0fd4dde | 2019-12-06 15:48:00 +0530 | [diff] [blame] | 79 | { |
AppaRao Puli | 916d600 | 2019-12-18 01:37:02 +0530 | [diff] [blame] | 80 | // Running images so set Activations to "Active" |
Vikram Bodireddy | 0fd4dde | 2019-12-06 15:48:00 +0530 | [diff] [blame] | 81 | activation = |
| 82 | "xyz.openbmc_project.Software.Activation.Activations.Active"; |
AppaRao Puli | 916d600 | 2019-12-18 01:37:02 +0530 | [diff] [blame] | 83 | |
AppaRao Puli | 0e75891 | 2020-01-29 03:07:54 +0530 | [diff] [blame] | 84 | // For all Active images, functional endpoints must be added. This is |
| 85 | // used in bmcweb & ipmi for fetching active component versions. |
| 86 | |
| 87 | // TODO: We have redundant active firmware version objects for BMC |
| 88 | // and BIOS active images. BMC version is read from /etc/os-release |
| 89 | // BIOS version is read from SMBIOS. Since it provides more |
| 90 | // version information, Lets expose those as functional. |
| 91 | // Down the line, Redundant inventory objects need to be addressed. |
Vikram Bodireddy | 8292dc6 | 2021-05-26 13:31:47 +0530 | [diff] [blame] | 92 | if ((imgType == ImageType::cpldActive) || |
| 93 | (imgType == ImageType::afmActive)) |
AppaRao Puli | 0e75891 | 2020-01-29 03:07:54 +0530 | [diff] [blame] | 94 | { |
| 95 | associations.emplace("functional", "software_version", objPath); |
| 96 | } |
Vikram Bodireddy | 0fd4dde | 2019-12-06 15:48:00 +0530 | [diff] [blame] | 97 | } |
| 98 | |
AppaRao Puli | d6f46c4 | 2019-07-19 22:34:04 +0530 | [diff] [blame] | 99 | std::string reqActNone = |
| 100 | "xyz.openbmc_project.Software.Activation.RequestedActivations.None"; |
| 101 | auto activationIface = server.add_interface( |
| 102 | objPath, "xyz.openbmc_project.Software.Activation"); |
AppaRao Puli | d6f46c4 | 2019-07-19 22:34:04 +0530 | [diff] [blame] | 103 | |
Vikram Bodireddy | 1c06ae4 | 2021-07-08 15:26:51 +0530 | [diff] [blame] | 104 | if (activationIface != nullptr) |
| 105 | { |
| 106 | |
| 107 | activationIface->register_property("Activation", activation); |
| 108 | activationIface->register_property("RequestedActivation", reqActNone); |
| 109 | |
| 110 | activationIface->initialize(); |
| 111 | } |
AppaRao Puli | 0e75891 | 2020-01-29 03:07:54 +0530 | [diff] [blame] | 112 | |
| 113 | // All the components exposed under PFR.Manager are updateable. |
| 114 | // Lets add objPath endpoints to 'updatable' association |
| 115 | associations.emplace("updateable", "software_version", objPath); |
| 116 | associationIface->set_property("Associations", associations); |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 117 | } |
| 118 | |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 119 | void PfrVersion::updateVersion() |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 120 | { |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 121 | if (versionIface && versionIface->is_initialized()) |
| 122 | { |
AppaRao Puli | 4b639a2 | 2019-10-01 18:12:59 +0530 | [diff] [blame] | 123 | std::string ver = getFirmwareVersion(imgType); |
Alex Schendel | 5cf320c | 2021-12-09 12:11:04 -0800 | [diff] [blame] | 124 | printVersion(path, ver); |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 125 | internalSet = true; |
| 126 | versionIface->set_property(versionStr, ver); |
| 127 | internalSet = false; |
| 128 | } |
| 129 | return; |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 130 | } |
| 131 | |
AppaRao Puli | 67d184c | 2020-05-29 00:48:33 +0530 | [diff] [blame] | 132 | PfrConfig::PfrConfig(sdbusplus::asio::object_server& srv_, |
| 133 | std::shared_ptr<sdbusplus::asio::connection>& conn_) : |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 134 | server(srv_), |
| 135 | conn(conn_) |
| 136 | { |
AppaRao Puli | cc1ed68 | 2019-10-01 12:29:40 +0530 | [diff] [blame] | 137 | pfrCfgIface = server.add_interface("/xyz/openbmc_project/pfr", |
| 138 | "xyz.openbmc_project.PFR.Attributes"); |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 139 | |
Chalapathi Venkataramashetty | f881970 | 2021-02-03 09:43:46 +0000 | [diff] [blame] | 140 | ufmLocked = false; |
| 141 | ufmProvisioned = false; |
| 142 | ufmSupport = false; |
| 143 | getProvisioningStatus(ufmLocked, ufmProvisioned, ufmSupport); |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 144 | |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 145 | pfrCfgIface->register_property(ufmProvisionedStr, ufmProvisioned, |
| 146 | // Override set |
| 147 | [this](const bool req, bool propertyValue) { |
| 148 | if (internalSet) |
| 149 | { |
| 150 | if (req != propertyValue) |
| 151 | { |
| 152 | ufmProvisioned = req; |
| 153 | propertyValue = req; |
| 154 | return 1; |
| 155 | } |
| 156 | } |
| 157 | return 0; |
| 158 | }); |
| 159 | |
| 160 | pfrCfgIface->register_property(ufmLockedStr, ufmLocked, |
| 161 | // Override set |
| 162 | [this](const bool req, bool propertyValue) { |
| 163 | if (internalSet) |
| 164 | { |
| 165 | if (req != propertyValue) |
| 166 | { |
| 167 | ufmLocked = req; |
| 168 | propertyValue = req; |
| 169 | return 1; |
| 170 | } |
| 171 | } |
| 172 | return 0; |
| 173 | }); |
| 174 | |
Chalapathi Venkataramashetty | f881970 | 2021-02-03 09:43:46 +0000 | [diff] [blame] | 175 | pfrCfgIface->register_property(ufmSupportStr, ufmSupport, |
| 176 | // Override set |
| 177 | [this](const bool req, bool propertyValue) { |
| 178 | if (internalSet) |
| 179 | { |
| 180 | if (req != propertyValue) |
| 181 | { |
| 182 | ufmSupport = req; |
| 183 | propertyValue = req; |
| 184 | return 1; |
| 185 | } |
| 186 | } |
| 187 | return 0; |
| 188 | }); |
| 189 | |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 190 | pfrCfgIface->initialize(); |
AppaRao Puli | 0e75891 | 2020-01-29 03:07:54 +0530 | [diff] [blame] | 191 | |
| 192 | associationIface = |
| 193 | server.add_interface("/xyz/openbmc_project/software", |
| 194 | "xyz.openbmc_project.Association.Definitions"); |
| 195 | associationIface->register_property("Associations", associations); |
| 196 | associationIface->initialize(); |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | void PfrConfig::updateProvisioningStatus() |
| 200 | { |
| 201 | if (pfrCfgIface && pfrCfgIface->is_initialized()) |
| 202 | { |
| 203 | bool lockVal = false; |
| 204 | bool provVal = false; |
Chalapathi Venkataramashetty | f881970 | 2021-02-03 09:43:46 +0000 | [diff] [blame] | 205 | bool supportVal = false; |
| 206 | getProvisioningStatus(lockVal, provVal, supportVal); |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 207 | internalSet = true; |
| 208 | pfrCfgIface->set_property(ufmProvisionedStr, provVal); |
| 209 | pfrCfgIface->set_property(ufmLockedStr, lockVal); |
Chalapathi Venkataramashetty | f881970 | 2021-02-03 09:43:46 +0000 | [diff] [blame] | 210 | pfrCfgIface->set_property(ufmSupportStr, supportVal); |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 211 | internalSet = false; |
| 212 | } |
| 213 | return; |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 214 | } |
| 215 | |
Zhikui Ren | c96f37d | 2021-12-08 15:40:51 -0800 | [diff] [blame] | 216 | static constexpr const char* postcodeStrProp = "PlatformState"; |
| 217 | static constexpr const char* postcodeStrDefault = "Unknown"; |
| 218 | static constexpr const char* postcodeDataProp = "Data"; |
| 219 | static constexpr const char* postcodeIface = |
| 220 | "xyz.openbmc_project.State.Boot.Platform"; |
| 221 | |
| 222 | PfrPostcode::PfrPostcode(sdbusplus::asio::object_server& srv_, |
| 223 | std::shared_ptr<sdbusplus::asio::connection>& conn_) : |
| 224 | server(srv_), |
| 225 | conn(conn_) |
| 226 | { |
| 227 | if (getPlatformState(postcode) < 0) |
| 228 | { |
| 229 | postcode = 0; |
| 230 | } |
| 231 | |
| 232 | pfrPostcodeIface = |
| 233 | server.add_interface("/xyz/openbmc_project/pfr", postcodeIface); |
| 234 | |
| 235 | if (pfrPostcodeIface != nullptr) |
| 236 | { |
| 237 | pfrPostcodeIface->register_property( |
| 238 | postcodeDataProp, postcode, |
| 239 | // Override set |
| 240 | [this](const uint8_t req, uint8_t& propertyValue) { |
| 241 | if (internalSet) |
| 242 | { |
| 243 | if (req != propertyValue) |
| 244 | { |
| 245 | postcode = req; |
| 246 | propertyValue = req; |
| 247 | return 1; |
| 248 | } |
| 249 | } |
| 250 | return 0; |
| 251 | }, |
| 252 | [this](uint8_t& propertyValue) { |
| 253 | updatePostcode(); |
| 254 | propertyValue = postcode; |
| 255 | return propertyValue; |
| 256 | }); |
| 257 | |
| 258 | pfrPostcodeIface->register_property(postcodeStrProp, |
| 259 | std::string(postcodeStrDefault)); |
| 260 | |
| 261 | pfrPostcodeIface->initialize(); |
| 262 | auto it = postcodeMap.find(postcode); |
| 263 | if (it != postcodeMap.end()) |
| 264 | { |
| 265 | pfrPostcodeIface->set_property(postcodeStrProp, it->second); |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | void PfrPostcode::updatePostcode() |
| 271 | { |
| 272 | if (pfrPostcodeIface && pfrPostcodeIface->is_initialized()) |
| 273 | { |
| 274 | if (getPlatformState(postcode) < 0) |
| 275 | { |
| 276 | postcode = 0; |
| 277 | } |
| 278 | |
| 279 | internalSet = true; |
| 280 | pfrPostcodeIface->set_property(postcodeDataProp, postcode); |
| 281 | auto it = postcodeMap.find(postcode); |
| 282 | if (it == postcodeMap.end()) |
| 283 | { |
| 284 | pfrPostcodeIface->set_property(postcodeStrProp, postcodeStrDefault); |
| 285 | } |
| 286 | else |
| 287 | { |
| 288 | pfrPostcodeIface->set_property(postcodeStrProp, it->second); |
| 289 | } |
| 290 | internalSet = false; |
| 291 | } |
| 292 | return; |
| 293 | } |
| 294 | |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 295 | } // namespace pfr |