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