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> |
| 21 | |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 22 | #include <boost/asio.hpp> |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 23 | |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 24 | namespace pfr |
| 25 | { |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 26 | // Caches the last Recovery/Panic Count to |
| 27 | // identify any new Recovery/panic actions. |
| 28 | /* TODO: When BMC Reset's, these values will be lost |
| 29 | * Persist this info using settingsd */ |
| 30 | static uint8_t lastRecoveryCount = 0; |
| 31 | static uint8_t lastPanicCount = 0; |
| 32 | static uint8_t lastMajorErr = 0; |
| 33 | static uint8_t lastMinorErr = 0; |
| 34 | |
| 35 | static bool stateTimerRunning = false; |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 36 | bool finishedSettingChkPoint = false; |
| 37 | static constexpr uint8_t bmcBootFinishedChkPoint = 0x09; |
| 38 | |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 39 | std::unique_ptr<boost::asio::steady_timer> stateTimer = nullptr; |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 40 | std::unique_ptr<boost::asio::steady_timer> initTimer = nullptr; |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 41 | |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 42 | std::vector<std::unique_ptr<PfrVersion>> pfrVersionObjects; |
| 43 | std::unique_ptr<PfrConfig> pfrConfigObject; |
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), |
Vikram Bodireddy | 3c6c8c3 | 2019-12-05 11:06:15 +0530 | [diff] [blame] | 52 | std::make_tuple("cpld_recovery", ImageType::cpldRecovery, |
| 53 | versionPurposeOther), |
| 54 | }; |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 55 | |
AppaRao Puli | e90f128 | 2019-11-05 01:07:05 +0530 | [diff] [blame] | 56 | // Recovery reason map. |
| 57 | // {<CPLD association>,{<Redfish MessageID>, <Recovery Reason>}} |
| 58 | static const boost::container::flat_map<uint8_t, |
| 59 | std::pair<std::string, std::string>> |
| 60 | recoveryReasonMap = { |
| 61 | {0x01, |
| 62 | {"BIOSFirmwareRecoveryReason", |
Chalapathi | 3fb544b | 2020-02-14 15:43:49 +0000 | [diff] [blame] | 63 | "BIOS active image authentication failure"}}, |
AppaRao Puli | e90f128 | 2019-11-05 01:07:05 +0530 | [diff] [blame] | 64 | {0x02, |
| 65 | {"BIOSFirmwareRecoveryReason", |
Chalapathi | 3fb544b | 2020-02-14 15:43:49 +0000 | [diff] [blame] | 66 | "BIOS recovery image authentication failure"}}, |
AppaRao Puli | e90f128 | 2019-11-05 01:07:05 +0530 | [diff] [blame] | 67 | {0x03, {"MEFirmwareRecoveryReason", "ME launch failure"}}, |
| 68 | {0x04, {"BIOSFirmwareRecoveryReason", "ACM launch failure"}}, |
| 69 | {0x05, {"BIOSFirmwareRecoveryReason", "IBB launch failure"}}, |
| 70 | {0x06, {"BIOSFirmwareRecoveryReason", "OBB launch failure"}}, |
| 71 | {0x07, |
| 72 | {"BMCFirmwareRecoveryReason", |
| 73 | "BMC active image authentication failure"}}, |
| 74 | {0x08, |
| 75 | {"BMCFirmwareRecoveryReason", |
| 76 | "BMC recovery image authentication failure"}}, |
| 77 | {0x09, {"BMCFirmwareRecoveryReason", "BMC launch failure"}}, |
| 78 | {0x0A, {"CPLDFirmwareRecoveryReason", "CPLD watchdog expired"}}}; |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 79 | |
AppaRao Puli | e90f128 | 2019-11-05 01:07:05 +0530 | [diff] [blame] | 80 | // Panic Reason map. |
| 81 | // {<CPLD association>, {<Redfish MessageID>, <Panic reason> }) |
| 82 | static const boost::container::flat_map<uint8_t, |
| 83 | std::pair<std::string, std::string>> |
| 84 | panicReasonMap = { |
Chalapathi | 3fb544b | 2020-02-14 15:43:49 +0000 | [diff] [blame] | 85 | {0x01, {"BIOSFirmwarePanicReason", "BIOS update intent"}}, |
| 86 | {0x02, {"BMCFirmwarePanicReason", "BMC update intent"}}, |
| 87 | {0x03, {"BMCFirmwarePanicReason", "BMC reset detected"}}, |
| 88 | {0x04, {"BMCFirmwarePanicReason", "BMC watchdog expired"}}, |
| 89 | {0x05, {"MEFirmwarePanicReason", "ME watchdog expired"}}, |
| 90 | {0x06, {"BIOSFirmwarePanicReason", "ACM watchdog expired"}}, |
| 91 | {0x07, {"BIOSFirmwarePanicReason", "IBB watchdog expired"}}, |
| 92 | {0x08, {"BIOSFirmwarePanicReason", "OBB watchdog expired"}}, |
AppaRao Puli | e90f128 | 2019-11-05 01:07:05 +0530 | [diff] [blame] | 93 | {0x09, |
| 94 | {"BIOSFirmwarePanicReason", |
Chalapathi | 3fb544b | 2020-02-14 15:43:49 +0000 | [diff] [blame] | 95 | "ACM or IBB or OBB authentication failure"}}}; |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 96 | |
AppaRao Puli | 2476694 | 2019-11-13 19:27:08 +0530 | [diff] [blame] | 97 | // Firmware resiliency major map. |
| 98 | // {<CPLD association>, {<Redfish MessageID>, <Error reason> }) |
| 99 | static const boost::container::flat_map<uint8_t, |
| 100 | std::pair<std::string, std::string>> |
| 101 | majorErrorCodeMap = { |
| 102 | {0x01, |
| 103 | {"BMCFirmwareResiliencyError", "BMC image authentication failed"}}, |
| 104 | {0x02, |
| 105 | {"BIOSFirmwareResiliencyError", "BIOS image authentication failed"}}, |
Chalapathi | 3fb544b | 2020-02-14 15:43:49 +0000 | [diff] [blame] | 106 | {0x03, {"BIOSFirmwareResiliencyError", "Update from BIOS failed"}}, |
| 107 | {0x04, {"BMCFirmwareResiliencyError", "Update from BMC failed"}}}; |
AppaRao Puli | 2476694 | 2019-11-13 19:27:08 +0530 | [diff] [blame] | 108 | |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 109 | static void updateDbusPropertiesCache() |
| 110 | { |
| 111 | for (const auto& pfrVerObj : pfrVersionObjects) |
| 112 | { |
| 113 | pfrVerObj->updateVersion(); |
| 114 | } |
| 115 | |
| 116 | // Update provisoningStatus properties |
| 117 | pfrConfigObject->updateProvisioningStatus(); |
| 118 | |
| 119 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 120 | "PFR Manager service cache data updated."); |
| 121 | } |
| 122 | |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 123 | static void logLastRecoveryEvent() |
| 124 | { |
| 125 | uint8_t reason = 0; |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 126 | if (0 != readCpldReg(ActionType::recoveryReason, reason)) |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 127 | { |
| 128 | return; |
| 129 | } |
| 130 | |
AppaRao Puli | e90f128 | 2019-11-05 01:07:05 +0530 | [diff] [blame] | 131 | auto it = recoveryReasonMap.find(reason); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 132 | if (it == recoveryReasonMap.end()) |
| 133 | { |
| 134 | // No matching found. So just return without logging event. |
| 135 | return; |
| 136 | } |
AppaRao Puli | e90f128 | 2019-11-05 01:07:05 +0530 | [diff] [blame] | 137 | std::string msgId = "OpenBMC.0.1." + it->second.first; |
| 138 | sd_journal_send("MESSAGE=%s", "Platform firmware recovery occurred.", |
| 139 | "PRIORITY=%i", LOG_WARNING, "REDFISH_MESSAGE_ID=%s", |
| 140 | msgId.c_str(), "REDFISH_MESSAGE_ARGS=%s", |
| 141 | it->second.second.c_str(), NULL); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | static void logLastPanicEvent() |
| 145 | { |
| 146 | uint8_t reason = 0; |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 147 | if (0 != readCpldReg(ActionType::panicReason, reason)) |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 148 | { |
| 149 | return; |
| 150 | } |
| 151 | |
AppaRao Puli | e90f128 | 2019-11-05 01:07:05 +0530 | [diff] [blame] | 152 | auto it = panicReasonMap.find(reason); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 153 | if (it == panicReasonMap.end()) |
| 154 | { |
| 155 | // No matching found. So just return without logging event. |
| 156 | return; |
| 157 | } |
| 158 | |
AppaRao Puli | e90f128 | 2019-11-05 01:07:05 +0530 | [diff] [blame] | 159 | std::string msgId = "OpenBMC.0.1." + it->second.first; |
| 160 | sd_journal_send("MESSAGE=%s", "Platform firmware panic occurred.", |
| 161 | "PRIORITY=%i", LOG_WARNING, "REDFISH_MESSAGE_ID=%s", |
| 162 | msgId.c_str(), "REDFISH_MESSAGE_ARGS=%s", |
| 163 | it->second.second.c_str(), NULL); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 164 | } |
| 165 | |
AppaRao Puli | 2476694 | 2019-11-13 19:27:08 +0530 | [diff] [blame] | 166 | static void logResiliencyErrorEvent(const uint8_t majorErrorCode, |
| 167 | const uint8_t minorErrorCode) |
| 168 | { |
| 169 | auto it = majorErrorCodeMap.find(majorErrorCode); |
| 170 | if (it == majorErrorCodeMap.end()) |
| 171 | { |
| 172 | // No matching found. So just return without logging event. |
| 173 | return; |
| 174 | } |
| 175 | |
| 176 | std::string errorStr = |
| 177 | it->second.second + "(MinorCode:0x" + toHexString(minorErrorCode) + ")"; |
| 178 | std::string msgId = "OpenBMC.0.1." + it->second.first; |
| 179 | sd_journal_send( |
| 180 | "MESSAGE=%s", "Platform firmware resiliency error occurred.", |
| 181 | "PRIORITY=%i", LOG_ERR, "REDFISH_MESSAGE_ID=%s", msgId.c_str(), |
| 182 | "REDFISH_MESSAGE_ARGS=%s", errorStr.c_str(), NULL); |
| 183 | } |
| 184 | |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 185 | static void checkAndLogEvents() |
| 186 | { |
| 187 | uint8_t currPanicCount = 0; |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 188 | if (0 == readCpldReg(ActionType::panicCount, currPanicCount)) |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 189 | { |
| 190 | if (lastPanicCount != currPanicCount) |
| 191 | { |
| 192 | // Update cached data and log redfish event by reading reason. |
| 193 | lastPanicCount = currPanicCount; |
| 194 | logLastPanicEvent(); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | uint8_t currRecoveryCount = 0; |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 199 | if (0 == readCpldReg(ActionType::recoveryCount, currRecoveryCount)) |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 200 | { |
| 201 | if (lastRecoveryCount != currRecoveryCount) |
| 202 | { |
| 203 | // Update cached data and log redfish event by reading reason. |
| 204 | lastRecoveryCount = currRecoveryCount; |
| 205 | logLastRecoveryEvent(); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | uint8_t majorErr = 0; |
| 210 | uint8_t minorErr = 0; |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 211 | if ((0 == readCpldReg(ActionType::majorError, majorErr)) && |
| 212 | (0 == readCpldReg(ActionType::minorError, minorErr))) |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 213 | { |
| 214 | if ((lastMajorErr != majorErr) || (lastMinorErr != minorErr)) |
| 215 | { |
| 216 | lastMajorErr = majorErr; |
| 217 | lastMinorErr = minorErr; |
| 218 | |
AppaRao Puli | 2476694 | 2019-11-13 19:27:08 +0530 | [diff] [blame] | 219 | logResiliencyErrorEvent(majorErr, minorErr); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | static void monitorPlatformStateChange( |
| 225 | sdbusplus::asio::object_server& server, |
| 226 | std::shared_ptr<sdbusplus::asio::connection>& conn) |
| 227 | { |
| 228 | constexpr size_t pollTimeout = 10; // seconds |
| 229 | stateTimer->expires_after(std::chrono::seconds(pollTimeout)); |
| 230 | stateTimer->async_wait( |
| 231 | [&server, &conn](const boost::system::error_code& ec) { |
| 232 | if (ec == boost::asio::error::operation_aborted) |
| 233 | { |
| 234 | // Timer reset. |
| 235 | return; |
| 236 | } |
| 237 | if (ec) |
| 238 | { |
| 239 | // Platform State Monitor - Timer cancelled. |
| 240 | return; |
| 241 | } |
| 242 | checkAndLogEvents(); |
| 243 | monitorPlatformStateChange(server, conn); |
| 244 | }); |
| 245 | } |
| 246 | |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 247 | void checkAndSetCheckpoint(sdbusplus::asio::object_server& server, |
| 248 | std::shared_ptr<sdbusplus::asio::connection>& conn) |
| 249 | { |
| 250 | // Check whether systemd completed all the loading. |
| 251 | conn->async_method_call( |
| 252 | [&server, &conn](boost::system::error_code ec, |
| 253 | const std::variant<uint64_t>& value) { |
AppaRao Puli | b7e172c | 2019-12-13 14:46:25 +0530 | [diff] [blame] | 254 | if (!ec) |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 255 | { |
AppaRao Puli | b7e172c | 2019-12-13 14:46:25 +0530 | [diff] [blame] | 256 | if (std::get<uint64_t>(value)) |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 257 | { |
AppaRao Puli | b7e172c | 2019-12-13 14:46:25 +0530 | [diff] [blame] | 258 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 259 | "PFR: BMC boot completed. Setting checkpoint 9."); |
| 260 | if (!finishedSettingChkPoint) |
| 261 | { |
| 262 | finishedSettingChkPoint = true; |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 263 | setBMCBootCheckpoint(bmcBootFinishedChkPoint); |
AppaRao Puli | b7e172c | 2019-12-13 14:46:25 +0530 | [diff] [blame] | 264 | } |
| 265 | return; |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | else |
| 269 | { |
AppaRao Puli | b7e172c | 2019-12-13 14:46:25 +0530 | [diff] [blame] | 270 | // Failed to get data from systemd. System might not |
| 271 | // be ready yet. Attempt again for data. |
| 272 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 273 | "PFR: aync call failed to get FinishTimestamp.", |
| 274 | phosphor::logging::entry("MSG=%s", ec.message().c_str())); |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 275 | } |
AppaRao Puli | b7e172c | 2019-12-13 14:46:25 +0530 | [diff] [blame] | 276 | // FIX-ME: Latest up-stream sync caused issue in receiving |
| 277 | // StartupFinished signal. Unable to get StartupFinished signal |
| 278 | // from systemd1 hence using poll method too, to trigger it |
| 279 | // properly. |
| 280 | constexpr size_t pollTimeout = 10; // seconds |
| 281 | initTimer->expires_after(std::chrono::seconds(pollTimeout)); |
| 282 | initTimer->async_wait([&server, |
| 283 | &conn](const boost::system::error_code& ec) { |
| 284 | if (ec == boost::asio::error::operation_aborted) |
| 285 | { |
| 286 | // Timer reset. |
| 287 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 288 | "PFR: Set boot Checkpoint - Timer aborted or stopped."); |
| 289 | return; |
| 290 | } |
| 291 | if (ec) |
| 292 | { |
| 293 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 294 | "PFR: Set boot Checkpoint - async wait error."); |
| 295 | return; |
| 296 | } |
| 297 | checkAndSetCheckpoint(server, conn); |
| 298 | }); |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 299 | }, |
| 300 | "org.freedesktop.systemd1", "/org/freedesktop/systemd1", |
| 301 | "org.freedesktop.DBus.Properties", "Get", |
| 302 | "org.freedesktop.systemd1.Manager", "FinishTimestamp"); |
| 303 | } |
| 304 | |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 305 | void monitorSignals(sdbusplus::asio::object_server& server, |
| 306 | std::shared_ptr<sdbusplus::asio::connection>& conn) |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 307 | { |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 308 | // Monitor Boot finished signal and set the checkpoint 9 to |
| 309 | // notify CPLD about BMC boot finish. |
| 310 | auto bootFinishedSignal = std::make_unique<sdbusplus::bus::match::match>( |
| 311 | static_cast<sdbusplus::bus::bus&>(*conn), |
| 312 | "type='signal'," |
| 313 | "member='StartupFinished',path='/org/freedesktop/systemd1'," |
| 314 | "interface='org.freedesktop.systemd1.Manager'", |
| 315 | [&server, &conn](sdbusplus::message::message& msg) { |
| 316 | if (!finishedSettingChkPoint) |
| 317 | { |
AppaRao Puli | b7e172c | 2019-12-13 14:46:25 +0530 | [diff] [blame] | 318 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 319 | "PFR: BMC boot completed(StartupFinished). Setting " |
| 320 | "checkpoint 9."); |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 321 | finishedSettingChkPoint = true; |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 322 | setBMCBootCheckpoint(bmcBootFinishedChkPoint); |
AppaRao Puli | 46cead9 | 2019-07-22 16:50:09 +0530 | [diff] [blame] | 323 | } |
| 324 | }); |
| 325 | checkAndSetCheckpoint(server, conn); |
| 326 | |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 327 | // Capture the Chassis state and Start the monitor timer |
| 328 | // if state changed to 'On'. Run timer until OS boot. |
| 329 | // Stop timer if state changed to 'Off'. |
| 330 | static auto matchChassisState = sdbusplus::bus::match::match( |
| 331 | static_cast<sdbusplus::bus::bus&>(*conn), |
| 332 | "type='signal',member='PropertiesChanged', " |
| 333 | "interface='org.freedesktop.DBus.Properties', " |
| 334 | "sender='xyz.openbmc_project.State.Chassis', " |
| 335 | "arg0namespace='xyz.openbmc_project.State.Chassis'", |
| 336 | [&server, &conn](sdbusplus::message::message& message) { |
| 337 | std::string intfName; |
| 338 | std::map<std::string, std::variant<std::string>> properties; |
| 339 | message.read(intfName, properties); |
| 340 | |
| 341 | const auto it = properties.find("CurrentPowerState"); |
| 342 | if (it != properties.end()) |
| 343 | { |
| 344 | const std::string* state = |
| 345 | std::get_if<std::string>(&it->second); |
| 346 | if (state != nullptr) |
| 347 | { |
| 348 | if ((*state == |
| 349 | "xyz.openbmc_project.State.Chassis.PowerState.On") && |
| 350 | (!stateTimerRunning)) |
| 351 | { |
| 352 | stateTimerRunning = true; |
| 353 | monitorPlatformStateChange(server, conn); |
| 354 | } |
| 355 | else if ((*state == "xyz.openbmc_project.State.Chassis." |
| 356 | "PowerState.Off") && |
| 357 | (stateTimerRunning)) |
| 358 | { |
| 359 | stateTimer->cancel(); |
| 360 | checkAndLogEvents(); |
| 361 | stateTimerRunning = false; |
| 362 | } |
| 363 | } |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 364 | |
| 365 | // Update the D-Bus properties when chassis state changes. |
| 366 | updateDbusPropertiesCache(); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 367 | } |
| 368 | }); |
| 369 | |
| 370 | // Capture the Host state and Start the monitor timer |
| 371 | // if state changed to 'Running'. Run timer until OS boot. |
| 372 | // Stop timer if state changed to 'Off'. |
| 373 | static auto matchHostState = sdbusplus::bus::match::match( |
| 374 | static_cast<sdbusplus::bus::bus&>(*conn), |
| 375 | "type='signal',member='PropertiesChanged', " |
| 376 | "interface='org.freedesktop.DBus.Properties', " |
| 377 | "sender='xyz.openbmc_project.State.Chassis', " |
| 378 | "arg0namespace='xyz.openbmc_project.State.Host'", |
| 379 | [&server, &conn](sdbusplus::message::message& message) { |
| 380 | std::string intfName; |
| 381 | std::map<std::string, std::variant<std::string>> properties; |
| 382 | message.read(intfName, properties); |
| 383 | |
| 384 | const auto it = properties.find("CurrentHostState"); |
| 385 | if (it != properties.end()) |
| 386 | { |
| 387 | const std::string* state = |
| 388 | std::get_if<std::string>(&it->second); |
| 389 | if (state != nullptr) |
| 390 | { |
| 391 | if ((*state == |
| 392 | "xyz.openbmc_project.State.Host.HostState.Running") && |
| 393 | (!stateTimerRunning)) |
| 394 | { |
| 395 | stateTimerRunning = true; |
| 396 | monitorPlatformStateChange(server, conn); |
| 397 | } |
| 398 | else if (((*state == "xyz.openbmc_project.State.Host." |
| 399 | "HostState.Off") || |
| 400 | (*state == "xyz.openbmc_project.State.Host." |
| 401 | "HostState.Quiesced")) && |
| 402 | (stateTimerRunning)) |
| 403 | { |
| 404 | stateTimer->cancel(); |
| 405 | checkAndLogEvents(); |
| 406 | stateTimerRunning = false; |
| 407 | } |
| 408 | } |
AppaRao Puli | e4e9565 | 2019-07-19 16:52:01 +0530 | [diff] [blame] | 409 | |
| 410 | // Update the D-Bus properties when host state changes. |
| 411 | updateDbusPropertiesCache(); |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 412 | } |
| 413 | }); |
| 414 | |
| 415 | // Capture the OS state change and stop monitor timer |
| 416 | // if OS boots completly or becomes Inactive. |
| 417 | // start timer in other cases to mnitor states. |
| 418 | static auto matchOsState = sdbusplus::bus::match::match( |
| 419 | static_cast<sdbusplus::bus::bus&>(*conn), |
| 420 | "type='signal',member='PropertiesChanged', " |
| 421 | "interface='org.freedesktop.DBus.Properties', " |
| 422 | "sender='xyz.openbmc_project.State.Chassis', " |
| 423 | "arg0namespace='xyz.openbmc_project.State.OperatingSystem.Status'", |
| 424 | [&server, &conn](sdbusplus::message::message& message) { |
| 425 | std::string intfName; |
| 426 | std::map<std::string, std::variant<std::string>> properties; |
| 427 | message.read(intfName, properties); |
| 428 | |
| 429 | const auto it = properties.find("OperatingSystemState"); |
| 430 | if (it != properties.end()) |
| 431 | { |
| 432 | const std::string* state = |
| 433 | std::get_if<std::string>(&it->second); |
| 434 | if (state != nullptr) |
| 435 | { |
| 436 | if (((*state == "BootComplete") || |
| 437 | (*state == "Inactive")) && |
| 438 | (stateTimerRunning)) |
| 439 | { |
| 440 | stateTimer->cancel(); |
| 441 | checkAndLogEvents(); |
| 442 | stateTimerRunning = false; |
| 443 | } |
| 444 | else if (!stateTimerRunning) |
| 445 | { |
| 446 | stateTimerRunning = true; |
| 447 | monitorPlatformStateChange(server, conn); |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | }); |
| 452 | |
| 453 | // First time, check and log events if any. |
| 454 | checkAndLogEvents(); |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 455 | } |
AppaRao Puli | 88aa33b | 2019-07-18 23:49:55 +0530 | [diff] [blame] | 456 | |
Chalapathi Venkataramashetty | e6fb18e | 2021-02-03 14:51:00 +0000 | [diff] [blame^] | 457 | static void updateCPLDversion(std::shared_ptr<sdbusplus::asio::connection> conn) |
| 458 | { |
| 459 | std::string cpldVersion = pfr::readCPLDVersion(); |
| 460 | conn->async_method_call( |
| 461 | [](const boost::system::error_code ec) { |
| 462 | if (ec) |
| 463 | { |
| 464 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 465 | "Unable to update cpld_active version", |
| 466 | phosphor::logging::entry("MSG=%s", ec.message().c_str())); |
| 467 | return; |
| 468 | } |
| 469 | }, |
| 470 | "xyz.openbmc_project.Settings", |
| 471 | "/xyz/openbmc_project/software/cpld_active", |
| 472 | "org.freedesktop.DBus.Properties", "Set", |
| 473 | "xyz.openbmc_project.Software.Version", "Version", |
| 474 | std::variant<std::string>(cpldVersion)); |
| 475 | return; |
| 476 | } |
| 477 | |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 478 | } // namespace pfr |
| 479 | |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 480 | int main() |
| 481 | { |
| 482 | // setup connection to dbus |
| 483 | boost::asio::io_service io; |
| 484 | auto conn = std::make_shared<sdbusplus::asio::connection>(io); |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 485 | pfr::stateTimer = std::make_unique<boost::asio::steady_timer>(io); |
| 486 | pfr::initTimer = std::make_unique<boost::asio::steady_timer>(io); |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 487 | auto server = sdbusplus::asio::object_server(conn, true); |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 488 | pfr::monitorSignals(server, conn); |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 489 | |
Chalapathi Venkataramashetty | e6fb18e | 2021-02-03 14:51:00 +0000 | [diff] [blame^] | 490 | // Update CPLD Version to cpld_active object in settings. |
| 491 | pfr::updateCPLDversion(conn); |
| 492 | |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 493 | server.add_manager("/xyz/openbmc_project/pfr"); |
| 494 | |
| 495 | // Create PFR attributes object and interface |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 496 | pfr::pfrConfigObject = std::make_unique<pfr::PfrConfig>(server, conn); |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 497 | |
| 498 | // Create Software objects using Versions interface |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 499 | for (const auto& entry : pfr::verComponentList) |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 500 | { |
AppaRao Puli | dcf1312 | 2020-05-28 01:21:39 +0530 | [diff] [blame] | 501 | pfr::pfrVersionObjects.emplace_back(std::make_unique<pfr::PfrVersion>( |
AppaRao Puli | a9bf971 | 2020-01-12 05:45:48 +0530 | [diff] [blame] | 502 | server, conn, std::get<0>(entry), std::get<1>(entry), |
| 503 | std::get<2>(entry))); |
| 504 | } |
| 505 | |
| 506 | conn->request_name("xyz.openbmc_project.PFR.Manager"); |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 507 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 508 | "Intel PFR service started successfully"); |
AppaRao Puli | e63eeda | 2019-07-05 16:25:38 +0530 | [diff] [blame] | 509 | io.run(); |
| 510 | |
| 511 | return 0; |
| 512 | } |