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