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 | |
AppaRao Puli | 67d184c | 2020-05-29 00:48:33 +0530 | [diff] [blame] | 17 | #include "pfr.hpp" |
| 18 | #include "pfr_mgr.hpp" |
| 19 | |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 20 | #include <systemd/sd-journal.h> |
Chalapathi Venkataramashetty | 29b4779 | 2020-09-10 21:43:53 +0000 | [diff] [blame] | 21 | #include <unistd.h> |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 22 | |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 23 | #include <boost/asio.hpp> |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 24 | #include <sdbusplus/asio/property.hpp> |
| 25 | #include <sdbusplus/unpack_properties.hpp> |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 26 | |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 27 | namespace pfr |
| 28 | { |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 29 | |
Chalapathi Venkataramashetty | 55e7934 | 2021-03-29 10:17:48 +0000 | [diff] [blame] | 30 | static bool i2cConfigLoaded = false; |
Chalapathi Venkataramashetty | 29b4779 | 2020-09-10 21:43:53 +0000 | [diff] [blame] | 31 | static int retrCount = 10; |
Chalapathi Venkataramashetty | 55e7934 | 2021-03-29 10:17:48 +0000 | [diff] [blame] | 32 | |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 33 | static bool stateTimerRunning = false; |
sri anjaneyulu alapati | be13259 | 2023-07-17 10:16:39 +0000 | [diff] [blame] | 34 | bool bmcBootCompleteChkPointDone = false; |
| 35 | bool unProvChkPointStatus = false; |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 36 | static constexpr uint8_t bmcBootFinishedChkPoint = 0x09; |
| 37 | |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 38 | std::unique_ptr<boost::asio::steady_timer> stateTimer = nullptr; |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 39 | std::unique_ptr<boost::asio::steady_timer> initTimer = nullptr; |
Chalapathi Venkataramashetty | 29b4779 | 2020-09-10 21:43:53 +0000 | [diff] [blame] | 40 | std::unique_ptr<boost::asio::steady_timer> pfrObjTimer = nullptr; |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 41 | std::vector<std::unique_ptr<PfrVersion>> pfrVersionObjects; |
| 42 | std::unique_ptr<PfrConfig> pfrConfigObject; |
Zhikui Ren | c96f37d | 2021-12-08 15:40:51 -0800 | [diff] [blame] | 43 | std::unique_ptr<PfrPostcode> pfrPostcodeObject; |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 44 | |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 45 | // List holds <ObjPath> <ImageType> <VersionPurpose> |
| 46 | static std::vector<std::tuple<std::string, ImageType, std::string>> |
| 47 | verComponentList = { |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 48 | std::make_tuple("bmc_recovery", ImageType::bmcRecovery, |
| 49 | versionPurposeBMC), |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 50 | std::make_tuple("bios_recovery", ImageType::biosRecovery, |
| 51 | versionPurposeHost), |
ankita prasad | 56b0e66 | 2023-08-09 12:46:54 +0000 | [diff] [blame] | 52 | std::make_tuple("rot_fw_recovery", ImageType::cpldRecovery, |
Vikram Bodireddy | 3c6c8c3 | 2019-12-05 11:06:15 +0530 | [diff] [blame] | 53 | versionPurposeOther), |
Vikram Bodireddy | 8292dc6 | 2021-05-26 13:31:47 +0530 | [diff] [blame] | 54 | std::make_tuple("afm_active", ImageType::afmActive, |
| 55 | versionPurposeOther), |
| 56 | std::make_tuple("afm_recovery", ImageType::afmRecovery, |
| 57 | versionPurposeOther), |
Vikram Bodireddy | 3c6c8c3 | 2019-12-05 11:06:15 +0530 | [diff] [blame] | 58 | }; |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 59 | |
AppaRao Puli | e90f128 | 2019-11-05 01:07:05 +0530 | [diff] [blame] | 60 | // Recovery reason map. |
| 61 | // {<CPLD association>,{<Redfish MessageID>, <Recovery Reason>}} |
| 62 | static const boost::container::flat_map<uint8_t, |
| 63 | std::pair<std::string, std::string>> |
| 64 | recoveryReasonMap = { |
| 65 | {0x01, |
| 66 | {"BIOSFirmwareRecoveryReason", |
Chalapathi | 3fb544b | 2020-02-14 15:43:49 +0000 | [diff] [blame] | 67 | "BIOS active image authentication failure"}}, |
AppaRao Puli | e90f128 | 2019-11-05 01:07:05 +0530 | [diff] [blame] | 68 | {0x02, |
| 69 | {"BIOSFirmwareRecoveryReason", |
Chalapathi | 3fb544b | 2020-02-14 15:43:49 +0000 | [diff] [blame] | 70 | "BIOS recovery image authentication failure"}}, |
AppaRao Puli | e90f128 | 2019-11-05 01:07:05 +0530 | [diff] [blame] | 71 | {0x03, {"MEFirmwareRecoveryReason", "ME launch failure"}}, |
| 72 | {0x04, {"BIOSFirmwareRecoveryReason", "ACM launch failure"}}, |
| 73 | {0x05, {"BIOSFirmwareRecoveryReason", "IBB launch failure"}}, |
| 74 | {0x06, {"BIOSFirmwareRecoveryReason", "OBB launch failure"}}, |
| 75 | {0x07, |
| 76 | {"BMCFirmwareRecoveryReason", |
| 77 | "BMC active image authentication failure"}}, |
| 78 | {0x08, |
| 79 | {"BMCFirmwareRecoveryReason", |
| 80 | "BMC recovery image authentication failure"}}, |
| 81 | {0x09, {"BMCFirmwareRecoveryReason", "BMC launch failure"}}, |
sri anjaneyulu alapati | d5c4990 | 2023-06-20 11:05:40 +0000 | [diff] [blame] | 82 | {0x0A, {"CPLDFirmwareRecoveryReason", "CPLD watchdog expired"}}, |
| 83 | {0x0B, {"BMCFirmwareRecoveryReason", "BMC attestation failure"}}, |
| 84 | {0x0C, {"FirmwareResiliencyError", "CPU0 attestation failure"}}, |
| 85 | {0x0D, {"FirmwareResiliencyError", "CPU1 attestation failure"}}}; |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 86 | |
AppaRao Puli | e90f128 | 2019-11-05 01:07:05 +0530 | [diff] [blame] | 87 | // Panic Reason map. |
| 88 | // {<CPLD association>, {<Redfish MessageID>, <Panic reason> }) |
| 89 | static const boost::container::flat_map<uint8_t, |
| 90 | std::pair<std::string, std::string>> |
| 91 | panicReasonMap = { |
Chalapathi | 3fb544b | 2020-02-14 15:43:49 +0000 | [diff] [blame] | 92 | {0x01, {"BIOSFirmwarePanicReason", "BIOS update intent"}}, |
| 93 | {0x02, {"BMCFirmwarePanicReason", "BMC update intent"}}, |
| 94 | {0x03, {"BMCFirmwarePanicReason", "BMC reset detected"}}, |
| 95 | {0x04, {"BMCFirmwarePanicReason", "BMC watchdog expired"}}, |
| 96 | {0x05, {"MEFirmwarePanicReason", "ME watchdog expired"}}, |
sri anjaneyulu alapati | d5c4990 | 2023-06-20 11:05:40 +0000 | [diff] [blame] | 97 | {0x06, {"BIOSFirmwarePanicReason", "ACM/IBB/OBB WDT expired"}}, |
AppaRao Puli | e90f128 | 2019-11-05 01:07:05 +0530 | [diff] [blame] | 98 | {0x09, |
| 99 | {"BIOSFirmwarePanicReason", |
sri anjaneyulu alapati | d5c4990 | 2023-06-20 11:05:40 +0000 | [diff] [blame] | 100 | "ACM or IBB or OBB authentication failure"}}, |
| 101 | {0x0A, {"FirmwareResiliencyError", "Attestation failure"}}}; |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 102 | |
AppaRao Puli | 2476694 | 2019-11-13 19:27:08 +0530 | [diff] [blame] | 103 | // Firmware resiliency major map. |
| 104 | // {<CPLD association>, {<Redfish MessageID>, <Error reason> }) |
| 105 | static const boost::container::flat_map<uint8_t, |
| 106 | std::pair<std::string, std::string>> |
| 107 | majorErrorCodeMap = { |
| 108 | {0x01, |
| 109 | {"BMCFirmwareResiliencyError", "BMC image authentication failed"}}, |
| 110 | {0x02, |
| 111 | {"BIOSFirmwareResiliencyError", "BIOS image authentication failed"}}, |
sri anjaneyulu alapati | d5c4990 | 2023-06-20 11:05:40 +0000 | [diff] [blame] | 112 | {0x03, |
| 113 | {"BIOSFirmwareResiliencyError", "in-band and oob update failure"}}, |
| 114 | {0x04, {"BMCFirmwareResiliencyError", "Communication setup failed"}}, |
| 115 | {0x05, |
| 116 | {"FirmwareResiliencyError", |
| 117 | "Attestation measurement mismatch-Attestation failure"}}, |
| 118 | {0x06, {"FirmwareResiliencyError", "Attestation challenge timeout"}}, |
| 119 | {0x07, {"FirmwareResiliencyError", "SPDM protocol timeout"}}, |
| 120 | {0x08, {"FirmwareResiliencyError", "I2c Communication failure"}}, |
| 121 | {0x09, |
| 122 | {"CPLDFirmwareResiliencyError", |
| 123 | "Combined CPLD authentication failure"}}, |
| 124 | {0x0A, {"CPLDFirmwareResiliencyError", "Combined CPLD update failure"}}, |
| 125 | {0x0B, |
| 126 | {"CPLDFirmwareResiliencyError", "Combined CPLD recovery failure"}}, |
| 127 | {0x10, {"FirmwareResiliencyError", "Image copy Failed"}}}; |
AppaRao Puli | 2476694 | 2019-11-13 19:27:08 +0530 | [diff] [blame] | 128 | |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 129 | static void updateDbusPropertiesCache() |
| 130 | { |
| 131 | for (const auto& pfrVerObj : pfrVersionObjects) |
| 132 | { |
| 133 | pfrVerObj->updateVersion(); |
| 134 | } |
| 135 | |
| 136 | // Update provisoningStatus properties |
| 137 | pfrConfigObject->updateProvisioningStatus(); |
| 138 | |
| 139 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 140 | "PFR Manager service cache data updated."); |
| 141 | } |
| 142 | |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 143 | static void logLastRecoveryEvent() |
| 144 | { |
| 145 | uint8_t reason = 0; |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 146 | if (0 != readCpldReg(ActionType::recoveryReason, reason)) |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 147 | { |
| 148 | return; |
| 149 | } |
| 150 | |
AppaRao Puli | e90f128 | 2019-11-05 01:07:05 +0530 | [diff] [blame] | 151 | auto it = recoveryReasonMap.find(reason); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 152 | if (it == recoveryReasonMap.end()) |
| 153 | { |
| 154 | // No matching found. So just return without logging event. |
| 155 | return; |
| 156 | } |
AppaRao Puli | e90f128 | 2019-11-05 01:07:05 +0530 | [diff] [blame] | 157 | std::string msgId = "OpenBMC.0.1." + it->second.first; |
| 158 | sd_journal_send("MESSAGE=%s", "Platform firmware recovery occurred.", |
| 159 | "PRIORITY=%i", LOG_WARNING, "REDFISH_MESSAGE_ID=%s", |
| 160 | msgId.c_str(), "REDFISH_MESSAGE_ARGS=%s", |
| 161 | it->second.second.c_str(), NULL); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | static void logLastPanicEvent() |
| 165 | { |
| 166 | uint8_t reason = 0; |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 167 | if (0 != readCpldReg(ActionType::panicReason, reason)) |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 168 | { |
| 169 | return; |
| 170 | } |
| 171 | |
AppaRao Puli | e90f128 | 2019-11-05 01:07:05 +0530 | [diff] [blame] | 172 | auto it = panicReasonMap.find(reason); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 173 | if (it == panicReasonMap.end()) |
| 174 | { |
| 175 | // No matching found. So just return without logging event. |
| 176 | return; |
| 177 | } |
| 178 | |
AppaRao Puli | e90f128 | 2019-11-05 01:07:05 +0530 | [diff] [blame] | 179 | std::string msgId = "OpenBMC.0.1." + it->second.first; |
| 180 | sd_journal_send("MESSAGE=%s", "Platform firmware panic occurred.", |
| 181 | "PRIORITY=%i", LOG_WARNING, "REDFISH_MESSAGE_ID=%s", |
| 182 | msgId.c_str(), "REDFISH_MESSAGE_ARGS=%s", |
| 183 | it->second.second.c_str(), NULL); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 184 | } |
| 185 | |
AppaRao Puli | 2476694 | 2019-11-13 19:27:08 +0530 | [diff] [blame] | 186 | static void logResiliencyErrorEvent(const uint8_t majorErrorCode, |
| 187 | const uint8_t minorErrorCode) |
| 188 | { |
Chalapathi Venkataramashetty | bcc7ce1 | 2021-05-17 04:27:21 +0000 | [diff] [blame] | 189 | uint8_t cpldRoTRev = 0; |
| 190 | if (0 != readCpldReg(ActionType::readRoTRev, cpldRoTRev)) |
| 191 | { |
| 192 | return; |
| 193 | } |
| 194 | |
AppaRao Puli | 2476694 | 2019-11-13 19:27:08 +0530 | [diff] [blame] | 195 | auto it = majorErrorCodeMap.find(majorErrorCode); |
Chalapathi Venkataramashetty | bcc7ce1 | 2021-05-17 04:27:21 +0000 | [diff] [blame] | 196 | if (cpldRoTRev == 0x02) |
| 197 | { |
| 198 | auto itRev2 = majorErrorCodeMapRev2.find(majorErrorCode); |
| 199 | if (itRev2 != majorErrorCodeMapRev2.end()) |
| 200 | { |
| 201 | it = itRev2; |
| 202 | } |
| 203 | else if (it == majorErrorCodeMap.end()) |
| 204 | { |
| 205 | // No matching found. So just return without logging event. |
| 206 | return; |
| 207 | } |
| 208 | } |
| 209 | else if (it == majorErrorCodeMap.end()) |
AppaRao Puli | 2476694 | 2019-11-13 19:27:08 +0530 | [diff] [blame] | 210 | { |
| 211 | // No matching found. So just return without logging event. |
| 212 | return; |
| 213 | } |
| 214 | |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 215 | std::string errorStr = it->second.second + "(MinorCode:0x" + |
| 216 | toHexString(minorErrorCode) + ")"; |
AppaRao Puli | 2476694 | 2019-11-13 19:27:08 +0530 | [diff] [blame] | 217 | std::string msgId = "OpenBMC.0.1." + it->second.first; |
| 218 | sd_journal_send( |
| 219 | "MESSAGE=%s", "Platform firmware resiliency error occurred.", |
| 220 | "PRIORITY=%i", LOG_ERR, "REDFISH_MESSAGE_ID=%s", msgId.c_str(), |
| 221 | "REDFISH_MESSAGE_ARGS=%s", errorStr.c_str(), NULL); |
| 222 | } |
| 223 | |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 224 | static void |
| 225 | handleLastCountChange(std::shared_ptr<sdbusplus::asio::connection> conn, |
| 226 | std::string eventName, uint8_t currentCount) |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 227 | { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 228 | sdbusplus::asio::setProperty(*conn, "xyz.openbmc_project.Settings", |
| 229 | "/xyz/openbmc_project/pfr/last_events", |
| 230 | "xyz.openbmc_project.PFR.LastEvents", |
| 231 | eventName, currentCount, |
| 232 | [](boost::system::error_code ec) { |
| 233 | if (ec) |
| 234 | { |
| 235 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 236 | "PFR: Unable to update currentCount", |
| 237 | phosphor::logging::entry("MSG=%s", ec.message().c_str())); |
| 238 | return; |
| 239 | } |
| 240 | }); |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 241 | return; |
| 242 | } |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 243 | |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 244 | static void |
| 245 | checkAndLogEvents(std::shared_ptr<sdbusplus::asio::connection>& conn) |
| 246 | { |
| 247 | sdbusplus::asio::getAllProperties( |
| 248 | *conn, "xyz.openbmc_project.Settings", |
| 249 | "/xyz/openbmc_project/pfr/last_events", |
| 250 | "xyz.openbmc_project.PFR.LastEvents", |
| 251 | [conn]( |
| 252 | boost::system::error_code ec, |
Jonathan Doman | 9b7b9f7 | 2022-06-03 15:31:35 -0700 | [diff] [blame] | 253 | const std::vector< |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 254 | std::pair<std::string, std::variant<std::monostate, uint8_t>>>& |
| 255 | properties) { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 256 | if (ec) |
| 257 | { |
| 258 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 259 | "PFR: Unable get PFR last events", |
| 260 | phosphor::logging::entry("MSG=%s", ec.message().c_str())); |
| 261 | return; |
| 262 | } |
| 263 | uint8_t lastRecoveryCount = 0; |
| 264 | uint8_t lastPanicCount = 0; |
| 265 | uint8_t lastMajorErr = 0; |
| 266 | uint8_t lastMinorErr = 0; |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 267 | |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 268 | try |
| 269 | { |
| 270 | sdbusplus::unpackProperties( |
| 271 | properties, "lastRecoveryCount", lastRecoveryCount, |
| 272 | "lastPanicCount", lastPanicCount, "lastMajorErr", lastMajorErr, |
| 273 | "lastMinorErr", lastMinorErr); |
| 274 | } |
| 275 | catch (const sdbusplus::exception::UnpackPropertyError& error) |
| 276 | { |
| 277 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 278 | "PFR: Unpack error", |
| 279 | phosphor::logging::entry("MSG=%s", error.what())); |
| 280 | return; |
| 281 | } |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 282 | |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 283 | uint8_t currPanicCount = 0; |
| 284 | if (0 == readCpldReg(ActionType::panicCount, currPanicCount)) |
| 285 | { |
| 286 | if (lastPanicCount != currPanicCount) |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 287 | { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 288 | // Update cached data to dbus and log redfish |
| 289 | // event by reading reason. |
| 290 | handleLastCountChange(conn, "lastPanicCount", currPanicCount); |
| 291 | if (currPanicCount) |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 292 | { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 293 | logLastPanicEvent(); |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 294 | } |
| 295 | } |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 296 | } |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 297 | |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 298 | uint8_t currRecoveryCount = 0; |
| 299 | if (0 == readCpldReg(ActionType::recoveryCount, currRecoveryCount)) |
| 300 | { |
| 301 | if (lastRecoveryCount != currRecoveryCount) |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 302 | { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 303 | // Update cached data to dbus and log redfish |
| 304 | // event by reading reason. |
| 305 | handleLastCountChange(conn, "lastRecoveryCount", |
| 306 | currRecoveryCount); |
| 307 | if (currRecoveryCount) |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 308 | { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 309 | logLastRecoveryEvent(); |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 310 | } |
| 311 | } |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 312 | } |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 313 | |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 314 | uint8_t majorErr = 0; |
| 315 | uint8_t minorErr = 0; |
| 316 | if ((0 == readCpldReg(ActionType::majorError, majorErr)) && |
| 317 | (0 == readCpldReg(ActionType::minorError, minorErr))) |
| 318 | { |
| 319 | if ((lastMajorErr != majorErr) || (lastMinorErr != minorErr)) |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 320 | { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 321 | // Update cached data to dbus and log redfish event by |
| 322 | // reading reason. |
| 323 | handleLastCountChange(conn, "lastMajorErr", majorErr); |
| 324 | handleLastCountChange(conn, "lastMinorErr", minorErr); |
| 325 | if (majorErr && minorErr) |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 326 | { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 327 | logResiliencyErrorEvent(majorErr, minorErr); |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 328 | } |
| 329 | } |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 330 | } |
Patrick Williams | 1388f6c | 2023-10-20 11:19:41 -0500 | [diff] [blame] | 331 | }); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | static void monitorPlatformStateChange( |
| 335 | sdbusplus::asio::object_server& server, |
| 336 | std::shared_ptr<sdbusplus::asio::connection>& conn) |
| 337 | { |
| 338 | constexpr size_t pollTimeout = 10; // seconds |
| 339 | stateTimer->expires_after(std::chrono::seconds(pollTimeout)); |
| 340 | stateTimer->async_wait( |
| 341 | [&server, &conn](const boost::system::error_code& ec) { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 342 | if (ec == boost::asio::error::operation_aborted) |
| 343 | { |
| 344 | // Timer reset. |
| 345 | return; |
| 346 | } |
| 347 | if (ec) |
| 348 | { |
| 349 | // Platform State Monitor - Timer cancelled. |
| 350 | return; |
| 351 | } |
| 352 | checkAndLogEvents(conn); |
| 353 | monitorPlatformStateChange(server, conn); |
| 354 | }); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 355 | } |
| 356 | |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 357 | void checkAndSetCheckpoint(sdbusplus::asio::object_server& server, |
| 358 | std::shared_ptr<sdbusplus::asio::connection>& conn) |
| 359 | { |
| 360 | // Check whether systemd completed all the loading. |
| 361 | conn->async_method_call( |
| 362 | [&server, &conn](boost::system::error_code ec, |
| 363 | const std::variant<uint64_t>& value) { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 364 | if (!ec) |
| 365 | { |
| 366 | if (std::get<uint64_t>(value)) |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 367 | { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 368 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 369 | "BMC boot completed. Setting checkpoint 9."); |
sri anjaneyulu alapati | be13259 | 2023-07-17 10:16:39 +0000 | [diff] [blame] | 370 | if (!bmcBootCompleteChkPointDone) |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 371 | { |
sri anjaneyulu alapati | be13259 | 2023-07-17 10:16:39 +0000 | [diff] [blame] | 372 | setBMCBootCompleteChkPoint(bmcBootFinishedChkPoint); |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 373 | } |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 374 | return; |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 375 | } |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 376 | } |
| 377 | else |
| 378 | { |
| 379 | // Failed to get data from systemd. System might not |
| 380 | // be ready yet. Attempt again for data. |
| 381 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 382 | "aync call failed to get FinishTimestamp.", |
| 383 | phosphor::logging::entry("MSG=%s", ec.message().c_str())); |
| 384 | } |
| 385 | // FIX-ME: Latest up-stream sync caused issue in receiving |
| 386 | // StartupFinished signal. Unable to get StartupFinished signal |
| 387 | // from systemd1 hence using poll method too, to trigger it |
| 388 | // properly. |
| 389 | constexpr size_t pollTimeout = 10; // seconds |
| 390 | initTimer->expires_after(std::chrono::seconds(pollTimeout)); |
| 391 | initTimer->async_wait( |
| 392 | [&server, &conn](const boost::system::error_code& ec) { |
| 393 | if (ec == boost::asio::error::operation_aborted) |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 394 | { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 395 | // Timer reset. |
| 396 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 397 | "Set boot Checkpoint - Timer aborted or stopped."); |
| 398 | return; |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 399 | } |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 400 | if (ec) |
| 401 | { |
| 402 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 403 | "Set boot Checkpoint - async wait error."); |
| 404 | return; |
| 405 | } |
| 406 | checkAndSetCheckpoint(server, conn); |
| 407 | }); |
Patrick Williams | 1388f6c | 2023-10-20 11:19:41 -0500 | [diff] [blame] | 408 | }, |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 409 | "org.freedesktop.systemd1", "/org/freedesktop/systemd1", |
| 410 | "org.freedesktop.DBus.Properties", "Get", |
| 411 | "org.freedesktop.systemd1.Manager", "FinishTimestamp"); |
| 412 | } |
| 413 | |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 414 | void monitorSignals(sdbusplus::asio::object_server& server, |
| 415 | std::shared_ptr<sdbusplus::asio::connection>& conn) |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 416 | { |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 417 | // Monitor Boot finished signal and set the checkpoint 9 to |
| 418 | // notify CPLD about BMC boot finish. |
Patrick Williams | f01de22 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 419 | auto bootFinishedSignal = std::make_unique<sdbusplus::bus::match_t>( |
| 420 | static_cast<sdbusplus::bus_t&>(*conn), |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 421 | "type='signal'," |
| 422 | "member='StartupFinished',path='/org/freedesktop/systemd1'," |
| 423 | "interface='org.freedesktop.systemd1.Manager'", |
Patrick Williams | f01de22 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 424 | [&server, &conn](sdbusplus::message_t& msg) { |
sri anjaneyulu alapati | be13259 | 2023-07-17 10:16:39 +0000 | [diff] [blame] | 425 | if (!bmcBootCompleteChkPointDone) |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 426 | { |
| 427 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 428 | "BMC boot completed(StartupFinished). Setting " |
| 429 | "checkpoint 9."); |
sri anjaneyulu alapati | be13259 | 2023-07-17 10:16:39 +0000 | [diff] [blame] | 430 | setBMCBootCompleteChkPoint(bmcBootFinishedChkPoint); |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 431 | } |
Patrick Williams | 1388f6c | 2023-10-20 11:19:41 -0500 | [diff] [blame] | 432 | }); |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 433 | checkAndSetCheckpoint(server, conn); |
| 434 | |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 435 | // Capture the Chassis state and Start the monitor timer |
| 436 | // if state changed to 'On'. Run timer until OS boot. |
| 437 | // Stop timer if state changed to 'Off'. |
Patrick Williams | f01de22 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 438 | static auto matchChassisState = sdbusplus::bus::match_t( |
| 439 | static_cast<sdbusplus::bus_t&>(*conn), |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 440 | "type='signal',member='PropertiesChanged', " |
| 441 | "interface='org.freedesktop.DBus.Properties', " |
| 442 | "sender='xyz.openbmc_project.State.Chassis', " |
| 443 | "arg0namespace='xyz.openbmc_project.State.Chassis'", |
Patrick Williams | f01de22 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 444 | [&server, &conn](sdbusplus::message_t& message) { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 445 | std::string intfName; |
| 446 | std::map<std::string, std::variant<std::string>> properties; |
| 447 | message.read(intfName, properties); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 448 | |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 449 | const auto it = properties.find("CurrentPowerState"); |
| 450 | if (it != properties.end()) |
| 451 | { |
| 452 | const std::string* state = std::get_if<std::string>(&it->second); |
| 453 | if (state != nullptr) |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 454 | { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 455 | if ((*state == |
| 456 | "xyz.openbmc_project.State.Chassis.PowerState.On") && |
| 457 | (!stateTimerRunning)) |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 458 | { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 459 | stateTimerRunning = true; |
| 460 | monitorPlatformStateChange(server, conn); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 461 | } |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 462 | else if ((*state == "xyz.openbmc_project.State.Chassis." |
| 463 | "PowerState.Off") && |
| 464 | (stateTimerRunning)) |
| 465 | { |
| 466 | stateTimer->cancel(); |
| 467 | checkAndLogEvents(conn); |
| 468 | stateTimerRunning = false; |
| 469 | } |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 470 | } |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 471 | |
| 472 | // Update the D-Bus properties when chassis state changes. |
| 473 | updateDbusPropertiesCache(); |
| 474 | } |
Patrick Williams | 1388f6c | 2023-10-20 11:19:41 -0500 | [diff] [blame] | 475 | }); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 476 | |
| 477 | // Capture the Host state and Start the monitor timer |
| 478 | // if state changed to 'Running'. Run timer until OS boot. |
| 479 | // Stop timer if state changed to 'Off'. |
Patrick Williams | f01de22 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 480 | static auto matchHostState = sdbusplus::bus::match_t( |
| 481 | static_cast<sdbusplus::bus_t&>(*conn), |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 482 | "type='signal',member='PropertiesChanged', " |
| 483 | "interface='org.freedesktop.DBus.Properties', " |
| 484 | "sender='xyz.openbmc_project.State.Chassis', " |
| 485 | "arg0namespace='xyz.openbmc_project.State.Host'", |
Patrick Williams | f01de22 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 486 | [&server, &conn](sdbusplus::message_t& message) { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 487 | std::string intfName; |
| 488 | std::map<std::string, std::variant<std::string>> properties; |
| 489 | message.read(intfName, properties); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 490 | |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 491 | const auto it = properties.find("CurrentHostState"); |
| 492 | if (it != properties.end()) |
| 493 | { |
| 494 | const std::string* state = std::get_if<std::string>(&it->second); |
| 495 | if (state != nullptr) |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 496 | { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 497 | if ((*state == |
| 498 | "xyz.openbmc_project.State.Host.HostState.Running") && |
| 499 | (!stateTimerRunning)) |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 500 | { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 501 | stateTimerRunning = true; |
| 502 | monitorPlatformStateChange(server, conn); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 503 | } |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 504 | else if (((*state == "xyz.openbmc_project.State.Host." |
| 505 | "HostState.Off") || |
| 506 | (*state == "xyz.openbmc_project.State.Host." |
| 507 | "HostState.Quiesced")) && |
| 508 | (stateTimerRunning)) |
| 509 | { |
| 510 | stateTimer->cancel(); |
| 511 | checkAndLogEvents(conn); |
| 512 | stateTimerRunning = false; |
| 513 | } |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 514 | } |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 515 | |
| 516 | // Update the D-Bus properties when host state changes. |
| 517 | updateDbusPropertiesCache(); |
| 518 | } |
Patrick Williams | 1388f6c | 2023-10-20 11:19:41 -0500 | [diff] [blame] | 519 | }); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 520 | |
| 521 | // Capture the OS state change and stop monitor timer |
Manojkiran Eda | 76b85db | 2024-06-17 11:51:22 +0530 | [diff] [blame^] | 522 | // if OS boots completely or becomes Inactive. |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 523 | // start timer in other cases to mnitor states. |
Patrick Williams | f01de22 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 524 | static auto matchOsState = sdbusplus::bus::match_t( |
| 525 | static_cast<sdbusplus::bus_t&>(*conn), |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 526 | "type='signal',member='PropertiesChanged', " |
| 527 | "interface='org.freedesktop.DBus.Properties', " |
| 528 | "sender='xyz.openbmc_project.State.Chassis', " |
| 529 | "arg0namespace='xyz.openbmc_project.State.OperatingSystem.Status'", |
Patrick Williams | f01de22 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 530 | [&server, &conn](sdbusplus::message_t& message) { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 531 | std::string intfName; |
| 532 | std::map<std::string, std::variant<std::string>> properties; |
| 533 | message.read(intfName, properties); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 534 | |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 535 | const auto it = properties.find("OperatingSystemState"); |
| 536 | if (it != properties.end()) |
| 537 | { |
| 538 | const std::string* state = std::get_if<std::string>(&it->second); |
| 539 | if (state != nullptr) |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 540 | { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 541 | // The short strings "BootComplete" and "Standby" are |
| 542 | // deprecated in favor of the full enum strings |
| 543 | // Support for the short strings will be removed in the |
| 544 | // future. |
| 545 | if (((*state == "BootComplete") || |
| 546 | (*state == "xyz.openbmc_project.State.OperatingSystem." |
| 547 | "Status.OSStatus.BootComplete") || |
| 548 | (*state == "Inactive") || |
| 549 | (*state == "xyz.openbmc_project.State.OperatingSystem." |
| 550 | "Status.OSStatus.Inactive")) && |
| 551 | (stateTimerRunning)) |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 552 | { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 553 | stateTimer->cancel(); |
| 554 | checkAndLogEvents(conn); |
| 555 | stateTimerRunning = false; |
| 556 | } |
| 557 | else if (!stateTimerRunning) |
| 558 | { |
| 559 | stateTimerRunning = true; |
| 560 | monitorPlatformStateChange(server, conn); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 561 | } |
| 562 | } |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 563 | } |
Patrick Williams | 1388f6c | 2023-10-20 11:19:41 -0500 | [diff] [blame] | 564 | }); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 565 | |
| 566 | // First time, check and log events if any. |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 567 | checkAndLogEvents(conn); |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 568 | } |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 569 | |
Chalapathi Venkataramashetty | e6fb18e | 2021-02-03 14:51:00 +0000 | [diff] [blame] | 570 | static void updateCPLDversion(std::shared_ptr<sdbusplus::asio::connection> conn) |
| 571 | { |
| 572 | std::string cpldVersion = pfr::readCPLDVersion(); |
ankita prasad | 56b0e66 | 2023-08-09 12:46:54 +0000 | [diff] [blame] | 573 | lg2::info("VERSION INFO - rot_fw_active - {VER}", "VER", cpldVersion); |
Chalapathi Venkataramashetty | e6fb18e | 2021-02-03 14:51:00 +0000 | [diff] [blame] | 574 | conn->async_method_call( |
| 575 | [](const boost::system::error_code ec) { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 576 | if (ec) |
| 577 | { |
| 578 | phosphor::logging::log<phosphor::logging::level::ERR>( |
ankita prasad | 56b0e66 | 2023-08-09 12:46:54 +0000 | [diff] [blame] | 579 | "Unable to update rot_fw_active version", |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 580 | phosphor::logging::entry("MSG=%s", ec.message().c_str())); |
| 581 | return; |
| 582 | } |
Patrick Williams | 1388f6c | 2023-10-20 11:19:41 -0500 | [diff] [blame] | 583 | }, |
Chalapathi Venkataramashetty | e6fb18e | 2021-02-03 14:51:00 +0000 | [diff] [blame] | 584 | "xyz.openbmc_project.Settings", |
ankita prasad | 56b0e66 | 2023-08-09 12:46:54 +0000 | [diff] [blame] | 585 | "/xyz/openbmc_project/software/rot_fw_active", |
Chalapathi Venkataramashetty | e6fb18e | 2021-02-03 14:51:00 +0000 | [diff] [blame] | 586 | "org.freedesktop.DBus.Properties", "Set", |
| 587 | "xyz.openbmc_project.Software.Version", "Version", |
| 588 | std::variant<std::string>(cpldVersion)); |
| 589 | return; |
| 590 | } |
| 591 | |
sri anjaneyulu alapati | be13259 | 2023-07-17 10:16:39 +0000 | [diff] [blame] | 592 | void checkPfrInterface(std::shared_ptr<sdbusplus::asio::connection> conn, |
| 593 | sdbusplus::asio::object_server& server) |
Chalapathi Venkataramashetty | 29b4779 | 2020-09-10 21:43:53 +0000 | [diff] [blame] | 594 | { |
| 595 | if (!i2cConfigLoaded) |
| 596 | { |
| 597 | init(conn, i2cConfigLoaded); |
| 598 | if (retrCount > 0) |
| 599 | { |
| 600 | // pfr object not loaded yet. query again. |
| 601 | return; |
| 602 | } |
| 603 | else |
| 604 | { |
| 605 | // Platform does not contain pfr object. Stop the service. |
| 606 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 607 | "Platform does not support PFR, hence stop the " |
| 608 | "service."); |
| 609 | std::exit(EXIT_SUCCESS); |
| 610 | return; |
| 611 | } |
| 612 | } |
| 613 | else |
| 614 | { |
| 615 | retrCount = 0; |
| 616 | |
| 617 | bool locked = false; |
| 618 | bool prov = false; |
| 619 | bool support = false; |
| 620 | pfr::getProvisioningStatus(locked, prov, support); |
| 621 | if (support && prov) |
| 622 | { |
| 623 | // pfr provisioned. |
| 624 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 625 | "PFR Supported."); |
| 626 | return; |
| 627 | } |
| 628 | else |
| 629 | { |
sri anjaneyulu alapati | be13259 | 2023-07-17 10:16:39 +0000 | [diff] [blame] | 630 | unProvChkPointStatus = true; |
| 631 | pfr::monitorSignals(server, conn); |
Chalapathi Venkataramashetty | 29b4779 | 2020-09-10 21:43:53 +0000 | [diff] [blame] | 632 | } |
| 633 | } |
| 634 | } |
| 635 | void checkPFRandAddObjects(sdbusplus::asio::object_server& server, |
| 636 | std::shared_ptr<sdbusplus::asio::connection>& conn) |
| 637 | { |
sri anjaneyulu alapati | be13259 | 2023-07-17 10:16:39 +0000 | [diff] [blame] | 638 | checkPfrInterface(conn, server); |
Chalapathi Venkataramashetty | 29b4779 | 2020-09-10 21:43:53 +0000 | [diff] [blame] | 639 | |
| 640 | constexpr size_t timeout = 10; // seconds |
| 641 | pfrObjTimer->expires_after(std::chrono::seconds(timeout)); |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 642 | pfrObjTimer->async_wait( |
| 643 | [&conn, &server](const boost::system::error_code& ec) { |
Chalapathi Venkataramashetty | 29b4779 | 2020-09-10 21:43:53 +0000 | [diff] [blame] | 644 | if (ec) |
| 645 | { |
| 646 | if (ec == boost::asio::error::operation_aborted) |
| 647 | { |
| 648 | // Timer reset. |
| 649 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 650 | "pfr object found. Hence Object Timer aborted or stopped."); |
| 651 | } |
| 652 | else |
| 653 | { |
| 654 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 655 | "pfr object timer error."); |
| 656 | } |
| 657 | } |
| 658 | if (retrCount > 0) |
| 659 | { |
| 660 | checkPFRandAddObjects(server, conn); |
| 661 | } |
| 662 | else |
| 663 | { |
| 664 | pfr::monitorSignals(server, conn); |
| 665 | |
| 666 | // Update the D-Bus properties. |
| 667 | updateDbusPropertiesCache(); |
ankita prasad | 56b0e66 | 2023-08-09 12:46:54 +0000 | [diff] [blame] | 668 | // Update CPLD Version to rot_fw_active object in settings. |
Chalapathi Venkataramashetty | 29b4779 | 2020-09-10 21:43:53 +0000 | [diff] [blame] | 669 | updateCPLDversion(conn); |
| 670 | } |
| 671 | retrCount--; |
| 672 | }); |
| 673 | } |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 674 | } // namespace pfr |
| 675 | |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 676 | int main() |
| 677 | { |
| 678 | // setup connection to dbus |
| 679 | boost::asio::io_service io; |
| 680 | auto conn = std::make_shared<sdbusplus::asio::connection>(io); |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 681 | pfr::stateTimer = std::make_unique<boost::asio::steady_timer>(io); |
| 682 | pfr::initTimer = std::make_unique<boost::asio::steady_timer>(io); |
Chalapathi Venkataramashetty | 29b4779 | 2020-09-10 21:43:53 +0000 | [diff] [blame] | 683 | pfr::pfrObjTimer = std::make_unique<boost::asio::steady_timer>(io); |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 684 | auto server = sdbusplus::asio::object_server(conn, true); |
Chalapathi Venkataramashetty | 55e7934 | 2021-03-29 10:17:48 +0000 | [diff] [blame] | 685 | pfr::init(conn, pfr::i2cConfigLoaded); |
Chalapathi Venkataramashetty | 29b4779 | 2020-09-10 21:43:53 +0000 | [diff] [blame] | 686 | |
| 687 | pfr::checkPFRandAddObjects(server, conn); |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 688 | |
ankita prasad | 56b0e66 | 2023-08-09 12:46:54 +0000 | [diff] [blame] | 689 | // Update CPLD Version to rot_fw_active object in settings. |
Chalapathi Venkataramashetty | e6fb18e | 2021-02-03 14:51:00 +0000 | [diff] [blame] | 690 | pfr::updateCPLDversion(conn); |
| 691 | |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 692 | server.add_manager("/xyz/openbmc_project/pfr"); |
| 693 | |
| 694 | // Create PFR attributes object and interface |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 695 | pfr::pfrConfigObject = std::make_unique<pfr::PfrConfig>(server, conn); |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 696 | |
| 697 | // Create Software objects using Versions interface |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 698 | for (const auto& entry : pfr::verComponentList) |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 699 | { |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 700 | pfr::pfrVersionObjects.emplace_back(std::make_unique<pfr::PfrVersion>( |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 701 | server, conn, std::get<0>(entry), std::get<1>(entry), |
| 702 | std::get<2>(entry))); |
| 703 | } |
| 704 | |
Zhikui Ren | c96f37d | 2021-12-08 15:40:51 -0800 | [diff] [blame] | 705 | if (pfr::pfrConfigObject) |
| 706 | { |
| 707 | pfr::pfrConfigObject->updateProvisioningStatus(); |
| 708 | if (pfr::pfrConfigObject->getPfrProvisioned()) |
| 709 | { |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 710 | pfr::pfrPostcodeObject = std::make_unique<pfr::PfrPostcode>(server, |
| 711 | conn); |
Zhikui Ren | c96f37d | 2021-12-08 15:40:51 -0800 | [diff] [blame] | 712 | } |
| 713 | } |
| 714 | |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 715 | conn->request_name("xyz.openbmc_project.PFR.Manager"); |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 716 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 717 | "Intel PFR service started successfully"); |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 718 | io.run(); |
| 719 | |
| 720 | return 0; |
| 721 | } |