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 | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 215 | std::string errorStr = |
| 216 | it->second.second + "(MinorCode:0x" + 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 | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 228 | sdbusplus::asio::setProperty( |
| 229 | *conn, "xyz.openbmc_project.Settings", |
| 230 | "/xyz/openbmc_project/pfr/last_events", |
| 231 | "xyz.openbmc_project.PFR.LastEvents", 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 | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 256 | if (ec) |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 257 | { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 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; |
| 267 | |
| 268 | try |
| 269 | { |
| 270 | sdbusplus::unpackProperties( |
| 271 | properties, "lastRecoveryCount", lastRecoveryCount, |
| 272 | "lastPanicCount", lastPanicCount, "lastMajorErr", |
| 273 | lastMajorErr, "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 | } |
| 282 | |
| 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 | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 288 | // Update cached data to dbus and log redfish |
| 289 | // event by reading reason. |
| 290 | handleLastCountChange(conn, "lastPanicCount", |
| 291 | currPanicCount); |
| 292 | if (currPanicCount) |
| 293 | { |
| 294 | logLastPanicEvent(); |
| 295 | } |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 299 | uint8_t currRecoveryCount = 0; |
| 300 | if (0 == readCpldReg(ActionType::recoveryCount, currRecoveryCount)) |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 301 | { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 302 | if (lastRecoveryCount != currRecoveryCount) |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 303 | { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 304 | // Update cached data to dbus and log redfish |
| 305 | // event by reading reason. |
| 306 | handleLastCountChange(conn, "lastRecoveryCount", |
| 307 | currRecoveryCount); |
| 308 | if (currRecoveryCount) |
| 309 | { |
| 310 | logLastRecoveryEvent(); |
| 311 | } |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 315 | uint8_t majorErr = 0; |
| 316 | uint8_t minorErr = 0; |
| 317 | if ((0 == readCpldReg(ActionType::majorError, majorErr)) && |
| 318 | (0 == readCpldReg(ActionType::minorError, minorErr))) |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 319 | { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 320 | if ((lastMajorErr != majorErr) || (lastMinorErr != minorErr)) |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 321 | { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 322 | // Update cached data to dbus and log redfish event by |
| 323 | // reading reason. |
| 324 | handleLastCountChange(conn, "lastMajorErr", majorErr); |
| 325 | handleLastCountChange(conn, "lastMinorErr", minorErr); |
| 326 | if (majorErr && minorErr) |
| 327 | { |
| 328 | logResiliencyErrorEvent(majorErr, minorErr); |
| 329 | } |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 330 | } |
| 331 | } |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 332 | }); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | static void monitorPlatformStateChange( |
| 336 | sdbusplus::asio::object_server& server, |
| 337 | std::shared_ptr<sdbusplus::asio::connection>& conn) |
| 338 | { |
| 339 | constexpr size_t pollTimeout = 10; // seconds |
| 340 | stateTimer->expires_after(std::chrono::seconds(pollTimeout)); |
| 341 | stateTimer->async_wait( |
| 342 | [&server, &conn](const boost::system::error_code& ec) { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 343 | if (ec == boost::asio::error::operation_aborted) |
| 344 | { |
| 345 | // Timer reset. |
| 346 | return; |
| 347 | } |
| 348 | if (ec) |
| 349 | { |
| 350 | // Platform State Monitor - Timer cancelled. |
| 351 | return; |
| 352 | } |
| 353 | checkAndLogEvents(conn); |
| 354 | monitorPlatformStateChange(server, conn); |
| 355 | }); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 356 | } |
| 357 | |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 358 | void checkAndSetCheckpoint(sdbusplus::asio::object_server& server, |
| 359 | std::shared_ptr<sdbusplus::asio::connection>& conn) |
| 360 | { |
| 361 | // Check whether systemd completed all the loading. |
| 362 | conn->async_method_call( |
| 363 | [&server, &conn](boost::system::error_code ec, |
| 364 | const std::variant<uint64_t>& value) { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 365 | if (!ec) |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 366 | { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 367 | if (std::get<uint64_t>(value)) |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 368 | { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 369 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 370 | "BMC boot completed. Setting checkpoint 9."); |
| 371 | if (!bmcBootCompleteChkPointDone) |
| 372 | { |
| 373 | setBMCBootCompleteChkPoint(bmcBootFinishedChkPoint); |
| 374 | } |
| 375 | return; |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 376 | } |
| 377 | } |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 378 | else |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 379 | { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 380 | // Failed to get data from systemd. System might not |
| 381 | // be ready yet. Attempt again for data. |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 382 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 383 | "aync call failed to get FinishTimestamp.", |
| 384 | phosphor::logging::entry("MSG=%s", ec.message().c_str())); |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 385 | } |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 386 | // FIX-ME: Latest up-stream sync caused issue in receiving |
| 387 | // StartupFinished signal. Unable to get StartupFinished signal |
| 388 | // from systemd1 hence using poll method too, to trigger it |
| 389 | // properly. |
| 390 | constexpr size_t pollTimeout = 10; // seconds |
| 391 | initTimer->expires_after(std::chrono::seconds(pollTimeout)); |
| 392 | initTimer->async_wait( |
| 393 | [&server, &conn](const boost::system::error_code& ec) { |
| 394 | if (ec == boost::asio::error::operation_aborted) |
| 395 | { |
| 396 | // Timer reset. |
| 397 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 398 | "Set boot Checkpoint - Timer aborted or stopped."); |
| 399 | return; |
| 400 | } |
| 401 | if (ec) |
| 402 | { |
| 403 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 404 | "Set boot Checkpoint - async wait error."); |
| 405 | return; |
| 406 | } |
| 407 | checkAndSetCheckpoint(server, conn); |
| 408 | }); |
| 409 | }, |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 410 | "org.freedesktop.systemd1", "/org/freedesktop/systemd1", |
| 411 | "org.freedesktop.DBus.Properties", "Get", |
| 412 | "org.freedesktop.systemd1.Manager", "FinishTimestamp"); |
| 413 | } |
| 414 | |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 415 | void monitorSignals(sdbusplus::asio::object_server& server, |
| 416 | std::shared_ptr<sdbusplus::asio::connection>& conn) |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 417 | { |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 418 | // Monitor Boot finished signal and set the checkpoint 9 to |
| 419 | // notify CPLD about BMC boot finish. |
Patrick Williams | f01de22 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 420 | auto bootFinishedSignal = std::make_unique<sdbusplus::bus::match_t>( |
| 421 | static_cast<sdbusplus::bus_t&>(*conn), |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 422 | "type='signal'," |
| 423 | "member='StartupFinished',path='/org/freedesktop/systemd1'," |
| 424 | "interface='org.freedesktop.systemd1.Manager'", |
Patrick Williams | f01de22 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 425 | [&server, &conn](sdbusplus::message_t& msg) { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 426 | if (!bmcBootCompleteChkPointDone) |
| 427 | { |
| 428 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 429 | "BMC boot completed(StartupFinished). Setting " |
| 430 | "checkpoint 9."); |
| 431 | setBMCBootCompleteChkPoint(bmcBootFinishedChkPoint); |
| 432 | } |
| 433 | }); |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 434 | checkAndSetCheckpoint(server, conn); |
| 435 | |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 436 | // Capture the Chassis state and Start the monitor timer |
| 437 | // if state changed to 'On'. Run timer until OS boot. |
| 438 | // Stop timer if state changed to 'Off'. |
Patrick Williams | f01de22 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 439 | static auto matchChassisState = sdbusplus::bus::match_t( |
| 440 | static_cast<sdbusplus::bus_t&>(*conn), |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 441 | "type='signal',member='PropertiesChanged', " |
| 442 | "interface='org.freedesktop.DBus.Properties', " |
| 443 | "sender='xyz.openbmc_project.State.Chassis', " |
| 444 | "arg0namespace='xyz.openbmc_project.State.Chassis'", |
Patrick Williams | f01de22 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 445 | [&server, &conn](sdbusplus::message_t& message) { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 446 | std::string intfName; |
| 447 | std::map<std::string, std::variant<std::string>> properties; |
| 448 | message.read(intfName, properties); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 449 | |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 450 | const auto it = properties.find("CurrentPowerState"); |
| 451 | if (it != properties.end()) |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 452 | { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 453 | const std::string* state = |
| 454 | std::get_if<std::string>(&it->second); |
| 455 | if (state != nullptr) |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 456 | { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 457 | if ((*state == |
| 458 | "xyz.openbmc_project.State.Chassis.PowerState.On") && |
| 459 | (!stateTimerRunning)) |
| 460 | { |
| 461 | stateTimerRunning = true; |
| 462 | monitorPlatformStateChange(server, conn); |
| 463 | } |
| 464 | else if ((*state == "xyz.openbmc_project.State.Chassis." |
| 465 | "PowerState.Off") && |
| 466 | (stateTimerRunning)) |
| 467 | { |
| 468 | stateTimer->cancel(); |
| 469 | checkAndLogEvents(conn); |
| 470 | stateTimerRunning = false; |
| 471 | } |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 472 | } |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 473 | |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 474 | // Update the D-Bus properties when chassis state changes. |
| 475 | updateDbusPropertiesCache(); |
| 476 | } |
| 477 | }); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 478 | |
| 479 | // Capture the Host state and Start the monitor timer |
| 480 | // if state changed to 'Running'. Run timer until OS boot. |
| 481 | // Stop timer if state changed to 'Off'. |
Patrick Williams | f01de22 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 482 | static auto matchHostState = sdbusplus::bus::match_t( |
| 483 | static_cast<sdbusplus::bus_t&>(*conn), |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 484 | "type='signal',member='PropertiesChanged', " |
| 485 | "interface='org.freedesktop.DBus.Properties', " |
| 486 | "sender='xyz.openbmc_project.State.Chassis', " |
| 487 | "arg0namespace='xyz.openbmc_project.State.Host'", |
Patrick Williams | f01de22 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 488 | [&server, &conn](sdbusplus::message_t& message) { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 489 | std::string intfName; |
| 490 | std::map<std::string, std::variant<std::string>> properties; |
| 491 | message.read(intfName, properties); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 492 | |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 493 | const auto it = properties.find("CurrentHostState"); |
| 494 | if (it != properties.end()) |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 495 | { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 496 | const std::string* state = |
| 497 | std::get_if<std::string>(&it->second); |
| 498 | if (state != nullptr) |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 499 | { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 500 | if ((*state == |
| 501 | "xyz.openbmc_project.State.Host.HostState.Running") && |
| 502 | (!stateTimerRunning)) |
| 503 | { |
| 504 | stateTimerRunning = true; |
| 505 | monitorPlatformStateChange(server, conn); |
| 506 | } |
| 507 | else if (((*state == "xyz.openbmc_project.State.Host." |
| 508 | "HostState.Off") || |
| 509 | (*state == "xyz.openbmc_project.State.Host." |
| 510 | "HostState.Quiesced")) && |
| 511 | (stateTimerRunning)) |
| 512 | { |
| 513 | stateTimer->cancel(); |
| 514 | checkAndLogEvents(conn); |
| 515 | stateTimerRunning = false; |
| 516 | } |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 517 | } |
Patrick Williams | 304e82e | 2023-05-10 07:51:13 -0500 | [diff] [blame] | 518 | |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 519 | // Update the D-Bus properties when host state changes. |
| 520 | updateDbusPropertiesCache(); |
| 521 | } |
| 522 | }); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 523 | |
| 524 | // Capture the OS state change and stop monitor timer |
Manojkiran Eda | 76b85db | 2024-06-17 11:51:22 +0530 | [diff] [blame] | 525 | // if OS boots completely or becomes Inactive. |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 526 | // start timer in other cases to mnitor states. |
Patrick Williams | f01de22 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 527 | static auto matchOsState = sdbusplus::bus::match_t( |
| 528 | static_cast<sdbusplus::bus_t&>(*conn), |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 529 | "type='signal',member='PropertiesChanged', " |
| 530 | "interface='org.freedesktop.DBus.Properties', " |
| 531 | "sender='xyz.openbmc_project.State.Chassis', " |
| 532 | "arg0namespace='xyz.openbmc_project.State.OperatingSystem.Status'", |
Patrick Williams | f01de22 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 533 | [&server, &conn](sdbusplus::message_t& message) { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 534 | std::string intfName; |
| 535 | std::map<std::string, std::variant<std::string>> properties; |
| 536 | message.read(intfName, properties); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 537 | |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 538 | const auto it = properties.find("OperatingSystemState"); |
| 539 | if (it != properties.end()) |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 540 | { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 541 | const std::string* state = |
| 542 | std::get_if<std::string>(&it->second); |
| 543 | if (state != nullptr) |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 544 | { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 545 | // The short strings "BootComplete" and "Standby" are |
| 546 | // deprecated in favor of the full enum strings |
| 547 | // Support for the short strings will be removed in the |
| 548 | // future. |
| 549 | if (((*state == "BootComplete") || |
| 550 | (*state == "xyz.openbmc_project.State.OperatingSystem." |
| 551 | "Status.OSStatus.BootComplete") || |
| 552 | (*state == "Inactive") || |
| 553 | (*state == "xyz.openbmc_project.State.OperatingSystem." |
| 554 | "Status.OSStatus.Inactive")) && |
| 555 | (stateTimerRunning)) |
| 556 | { |
| 557 | stateTimer->cancel(); |
| 558 | checkAndLogEvents(conn); |
| 559 | stateTimerRunning = false; |
| 560 | } |
| 561 | else if (!stateTimerRunning) |
| 562 | { |
| 563 | stateTimerRunning = true; |
| 564 | monitorPlatformStateChange(server, conn); |
| 565 | } |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 566 | } |
| 567 | } |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 568 | }); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 569 | |
| 570 | // First time, check and log events if any. |
Chalapathi Venkataramashetty | b213487 | 2020-10-02 21:45:36 +0000 | [diff] [blame] | 571 | checkAndLogEvents(conn); |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 572 | } |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 573 | |
Chalapathi Venkataramashetty | e6fb18e | 2021-02-03 14:51:00 +0000 | [diff] [blame] | 574 | static void updateCPLDversion(std::shared_ptr<sdbusplus::asio::connection> conn) |
| 575 | { |
| 576 | std::string cpldVersion = pfr::readCPLDVersion(); |
ankita prasad | 56b0e66 | 2023-08-09 12:46:54 +0000 | [diff] [blame] | 577 | lg2::info("VERSION INFO - rot_fw_active - {VER}", "VER", cpldVersion); |
Chalapathi Venkataramashetty | e6fb18e | 2021-02-03 14:51:00 +0000 | [diff] [blame] | 578 | conn->async_method_call( |
| 579 | [](const boost::system::error_code ec) { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 580 | if (ec) |
| 581 | { |
| 582 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 583 | "Unable to update rot_fw_active version", |
| 584 | phosphor::logging::entry("MSG=%s", ec.message().c_str())); |
| 585 | return; |
| 586 | } |
| 587 | }, |
Chalapathi Venkataramashetty | e6fb18e | 2021-02-03 14:51:00 +0000 | [diff] [blame] | 588 | "xyz.openbmc_project.Settings", |
ankita prasad | 56b0e66 | 2023-08-09 12:46:54 +0000 | [diff] [blame] | 589 | "/xyz/openbmc_project/software/rot_fw_active", |
Chalapathi Venkataramashetty | e6fb18e | 2021-02-03 14:51:00 +0000 | [diff] [blame] | 590 | "org.freedesktop.DBus.Properties", "Set", |
| 591 | "xyz.openbmc_project.Software.Version", "Version", |
| 592 | std::variant<std::string>(cpldVersion)); |
| 593 | return; |
| 594 | } |
| 595 | |
sri anjaneyulu alapati | be13259 | 2023-07-17 10:16:39 +0000 | [diff] [blame] | 596 | void checkPfrInterface(std::shared_ptr<sdbusplus::asio::connection> conn, |
| 597 | sdbusplus::asio::object_server& server) |
Chalapathi Venkataramashetty | 29b4779 | 2020-09-10 21:43:53 +0000 | [diff] [blame] | 598 | { |
| 599 | if (!i2cConfigLoaded) |
| 600 | { |
| 601 | init(conn, i2cConfigLoaded); |
| 602 | if (retrCount > 0) |
| 603 | { |
| 604 | // pfr object not loaded yet. query again. |
| 605 | return; |
| 606 | } |
| 607 | else |
| 608 | { |
| 609 | // Platform does not contain pfr object. Stop the service. |
| 610 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 611 | "Platform does not support PFR, hence stop the " |
| 612 | "service."); |
| 613 | std::exit(EXIT_SUCCESS); |
| 614 | return; |
| 615 | } |
| 616 | } |
| 617 | else |
| 618 | { |
| 619 | retrCount = 0; |
| 620 | |
| 621 | bool locked = false; |
| 622 | bool prov = false; |
| 623 | bool support = false; |
| 624 | pfr::getProvisioningStatus(locked, prov, support); |
| 625 | if (support && prov) |
| 626 | { |
| 627 | // pfr provisioned. |
| 628 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 629 | "PFR Supported."); |
| 630 | return; |
| 631 | } |
| 632 | else |
| 633 | { |
sri anjaneyulu alapati | be13259 | 2023-07-17 10:16:39 +0000 | [diff] [blame] | 634 | unProvChkPointStatus = true; |
| 635 | pfr::monitorSignals(server, conn); |
Chalapathi Venkataramashetty | 29b4779 | 2020-09-10 21:43:53 +0000 | [diff] [blame] | 636 | } |
| 637 | } |
| 638 | } |
| 639 | void checkPFRandAddObjects(sdbusplus::asio::object_server& server, |
| 640 | std::shared_ptr<sdbusplus::asio::connection>& conn) |
| 641 | { |
sri anjaneyulu alapati | be13259 | 2023-07-17 10:16:39 +0000 | [diff] [blame] | 642 | checkPfrInterface(conn, server); |
Chalapathi Venkataramashetty | 29b4779 | 2020-09-10 21:43:53 +0000 | [diff] [blame] | 643 | |
| 644 | constexpr size_t timeout = 10; // seconds |
| 645 | pfrObjTimer->expires_after(std::chrono::seconds(timeout)); |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 646 | pfrObjTimer->async_wait([&conn, |
| 647 | &server](const boost::system::error_code& ec) { |
Chalapathi Venkataramashetty | 29b4779 | 2020-09-10 21:43:53 +0000 | [diff] [blame] | 648 | if (ec) |
| 649 | { |
| 650 | if (ec == boost::asio::error::operation_aborted) |
| 651 | { |
| 652 | // Timer reset. |
| 653 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 654 | "pfr object found. Hence Object Timer aborted or stopped."); |
| 655 | } |
| 656 | else |
| 657 | { |
| 658 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 659 | "pfr object timer error."); |
| 660 | } |
| 661 | } |
| 662 | if (retrCount > 0) |
| 663 | { |
| 664 | checkPFRandAddObjects(server, conn); |
| 665 | } |
| 666 | else |
| 667 | { |
| 668 | pfr::monitorSignals(server, conn); |
| 669 | |
| 670 | // Update the D-Bus properties. |
| 671 | updateDbusPropertiesCache(); |
ankita prasad | 56b0e66 | 2023-08-09 12:46:54 +0000 | [diff] [blame] | 672 | // Update CPLD Version to rot_fw_active object in settings. |
Chalapathi Venkataramashetty | 29b4779 | 2020-09-10 21:43:53 +0000 | [diff] [blame] | 673 | updateCPLDversion(conn); |
| 674 | } |
| 675 | retrCount--; |
| 676 | }); |
| 677 | } |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 678 | } // namespace pfr |
| 679 | |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 680 | int main() |
| 681 | { |
| 682 | // setup connection to dbus |
| 683 | boost::asio::io_service io; |
| 684 | auto conn = std::make_shared<sdbusplus::asio::connection>(io); |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 685 | pfr::stateTimer = std::make_unique<boost::asio::steady_timer>(io); |
| 686 | pfr::initTimer = std::make_unique<boost::asio::steady_timer>(io); |
Chalapathi Venkataramashetty | 29b4779 | 2020-09-10 21:43:53 +0000 | [diff] [blame] | 687 | pfr::pfrObjTimer = std::make_unique<boost::asio::steady_timer>(io); |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 688 | auto server = sdbusplus::asio::object_server(conn, true); |
Chalapathi Venkataramashetty | 55e7934 | 2021-03-29 10:17:48 +0000 | [diff] [blame] | 689 | pfr::init(conn, pfr::i2cConfigLoaded); |
Chalapathi Venkataramashetty | 29b4779 | 2020-09-10 21:43:53 +0000 | [diff] [blame] | 690 | |
| 691 | pfr::checkPFRandAddObjects(server, conn); |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 692 | |
ankita prasad | 56b0e66 | 2023-08-09 12:46:54 +0000 | [diff] [blame] | 693 | // Update CPLD Version to rot_fw_active object in settings. |
Chalapathi Venkataramashetty | e6fb18e | 2021-02-03 14:51:00 +0000 | [diff] [blame] | 694 | pfr::updateCPLDversion(conn); |
| 695 | |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 696 | server.add_manager("/xyz/openbmc_project/pfr"); |
| 697 | |
| 698 | // Create PFR attributes object and interface |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 699 | pfr::pfrConfigObject = std::make_unique<pfr::PfrConfig>(server, conn); |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 700 | |
| 701 | // Create Software objects using Versions interface |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 702 | for (const auto& entry : pfr::verComponentList) |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 703 | { |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 704 | pfr::pfrVersionObjects.emplace_back(std::make_unique<pfr::PfrVersion>( |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 705 | server, conn, std::get<0>(entry), std::get<1>(entry), |
| 706 | std::get<2>(entry))); |
| 707 | } |
| 708 | |
Zhikui Ren | c96f37d | 2021-12-08 15:40:51 -0800 | [diff] [blame] | 709 | if (pfr::pfrConfigObject) |
| 710 | { |
| 711 | pfr::pfrConfigObject->updateProvisioningStatus(); |
| 712 | if (pfr::pfrConfigObject->getPfrProvisioned()) |
| 713 | { |
Patrick Williams | 1695ee3 | 2024-08-16 15:21:41 -0400 | [diff] [blame^] | 714 | pfr::pfrPostcodeObject = |
| 715 | std::make_unique<pfr::PfrPostcode>(server, conn); |
Zhikui Ren | c96f37d | 2021-12-08 15:40:51 -0800 | [diff] [blame] | 716 | } |
| 717 | } |
| 718 | |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 719 | conn->request_name("xyz.openbmc_project.PFR.Manager"); |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 720 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 721 | "Intel PFR service started successfully"); |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 722 | io.run(); |
| 723 | |
| 724 | return 0; |
| 725 | } |