blob: 5cbe32c7ee9bef5f7a32a6c66f66bd760149eae5 [file] [log] [blame]
AppaRao Pulie63eeda2019-07-05 16:25:38 +05301/*
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 Puli67d184c2020-05-29 00:48:33 +053017#include "pfr.hpp"
18#include "pfr_mgr.hpp"
19
AppaRao Puli88aa33b2019-07-18 23:49:55 +053020#include <systemd/sd-journal.h>
21
AppaRao Puli46cead92019-07-22 16:50:09 +053022#include <boost/asio.hpp>
AppaRao Pulie63eeda2019-07-05 16:25:38 +053023
AppaRao Pulidcf13122020-05-28 01:21:39 +053024namespace pfr
25{
AppaRao Puli88aa33b2019-07-18 23:49:55 +053026// 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 */
30static uint8_t lastRecoveryCount = 0;
31static uint8_t lastPanicCount = 0;
32static uint8_t lastMajorErr = 0;
33static uint8_t lastMinorErr = 0;
34
Chalapathi Venkataramashetty55e79342021-03-29 10:17:48 +000035static bool i2cConfigLoaded = false;
36
AppaRao Puli88aa33b2019-07-18 23:49:55 +053037static bool stateTimerRunning = false;
AppaRao Puli46cead92019-07-22 16:50:09 +053038bool finishedSettingChkPoint = false;
39static constexpr uint8_t bmcBootFinishedChkPoint = 0x09;
40
AppaRao Puli88aa33b2019-07-18 23:49:55 +053041std::unique_ptr<boost::asio::steady_timer> stateTimer = nullptr;
AppaRao Puli46cead92019-07-22 16:50:09 +053042std::unique_ptr<boost::asio::steady_timer> initTimer = nullptr;
AppaRao Puli88aa33b2019-07-18 23:49:55 +053043
AppaRao Pulidcf13122020-05-28 01:21:39 +053044std::vector<std::unique_ptr<PfrVersion>> pfrVersionObjects;
45std::unique_ptr<PfrConfig> pfrConfigObject;
AppaRao Pulie4e95652019-07-19 16:52:01 +053046
AppaRao Pulie4e95652019-07-19 16:52:01 +053047// List holds <ObjPath> <ImageType> <VersionPurpose>
48static std::vector<std::tuple<std::string, ImageType, std::string>>
49 verComponentList = {
AppaRao Pulie4e95652019-07-19 16:52:01 +053050 std::make_tuple("bmc_recovery", ImageType::bmcRecovery,
51 versionPurposeBMC),
AppaRao Pulie4e95652019-07-19 16:52:01 +053052 std::make_tuple("bios_recovery", ImageType::biosRecovery,
53 versionPurposeHost),
Vikram Bodireddy3c6c8c32019-12-05 11:06:15 +053054 std::make_tuple("cpld_recovery", ImageType::cpldRecovery,
55 versionPurposeOther),
Vikram Bodireddy8292dc62021-05-26 13:31:47 +053056 std::make_tuple("afm_active", ImageType::afmActive,
57 versionPurposeOther),
58 std::make_tuple("afm_recovery", ImageType::afmRecovery,
59 versionPurposeOther),
Vikram Bodireddy3c6c8c32019-12-05 11:06:15 +053060};
AppaRao Pulie4e95652019-07-19 16:52:01 +053061
AppaRao Pulie90f1282019-11-05 01:07:05 +053062// Recovery reason map.
63// {<CPLD association>,{<Redfish MessageID>, <Recovery Reason>}}
64static const boost::container::flat_map<uint8_t,
65 std::pair<std::string, std::string>>
66 recoveryReasonMap = {
67 {0x01,
68 {"BIOSFirmwareRecoveryReason",
Chalapathi3fb544b2020-02-14 15:43:49 +000069 "BIOS active image authentication failure"}},
AppaRao Pulie90f1282019-11-05 01:07:05 +053070 {0x02,
71 {"BIOSFirmwareRecoveryReason",
Chalapathi3fb544b2020-02-14 15:43:49 +000072 "BIOS recovery image authentication failure"}},
AppaRao Pulie90f1282019-11-05 01:07:05 +053073 {0x03, {"MEFirmwareRecoveryReason", "ME launch failure"}},
74 {0x04, {"BIOSFirmwareRecoveryReason", "ACM launch failure"}},
75 {0x05, {"BIOSFirmwareRecoveryReason", "IBB launch failure"}},
76 {0x06, {"BIOSFirmwareRecoveryReason", "OBB launch failure"}},
77 {0x07,
78 {"BMCFirmwareRecoveryReason",
79 "BMC active image authentication failure"}},
80 {0x08,
81 {"BMCFirmwareRecoveryReason",
82 "BMC recovery image authentication failure"}},
83 {0x09, {"BMCFirmwareRecoveryReason", "BMC launch failure"}},
84 {0x0A, {"CPLDFirmwareRecoveryReason", "CPLD watchdog expired"}}};
AppaRao Puli88aa33b2019-07-18 23:49:55 +053085
AppaRao Pulie90f1282019-11-05 01:07:05 +053086// Panic Reason map.
87// {<CPLD association>, {<Redfish MessageID>, <Panic reason> })
88static const boost::container::flat_map<uint8_t,
89 std::pair<std::string, std::string>>
90 panicReasonMap = {
Chalapathi3fb544b2020-02-14 15:43:49 +000091 {0x01, {"BIOSFirmwarePanicReason", "BIOS update intent"}},
92 {0x02, {"BMCFirmwarePanicReason", "BMC update intent"}},
93 {0x03, {"BMCFirmwarePanicReason", "BMC reset detected"}},
94 {0x04, {"BMCFirmwarePanicReason", "BMC watchdog expired"}},
95 {0x05, {"MEFirmwarePanicReason", "ME watchdog expired"}},
96 {0x06, {"BIOSFirmwarePanicReason", "ACM watchdog expired"}},
97 {0x07, {"BIOSFirmwarePanicReason", "IBB watchdog expired"}},
98 {0x08, {"BIOSFirmwarePanicReason", "OBB watchdog expired"}},
AppaRao Pulie90f1282019-11-05 01:07:05 +053099 {0x09,
100 {"BIOSFirmwarePanicReason",
Chalapathi3fb544b2020-02-14 15:43:49 +0000101 "ACM or IBB or OBB authentication failure"}}};
AppaRao Puli88aa33b2019-07-18 23:49:55 +0530102
AppaRao Puli24766942019-11-13 19:27:08 +0530103// Firmware resiliency major map.
104// {<CPLD association>, {<Redfish MessageID>, <Error reason> })
105static 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"}},
Chalapathi3fb544b2020-02-14 15:43:49 +0000112 {0x03, {"BIOSFirmwareResiliencyError", "Update from BIOS failed"}},
113 {0x04, {"BMCFirmwareResiliencyError", "Update from BMC failed"}}};
AppaRao Puli24766942019-11-13 19:27:08 +0530114
AppaRao Pulie4e95652019-07-19 16:52:01 +0530115static void updateDbusPropertiesCache()
116{
117 for (const auto& pfrVerObj : pfrVersionObjects)
118 {
119 pfrVerObj->updateVersion();
120 }
121
122 // Update provisoningStatus properties
123 pfrConfigObject->updateProvisioningStatus();
124
125 phosphor::logging::log<phosphor::logging::level::INFO>(
126 "PFR Manager service cache data updated.");
127}
128
AppaRao Puli88aa33b2019-07-18 23:49:55 +0530129static void logLastRecoveryEvent()
130{
131 uint8_t reason = 0;
AppaRao Pulidcf13122020-05-28 01:21:39 +0530132 if (0 != readCpldReg(ActionType::recoveryReason, reason))
AppaRao Puli88aa33b2019-07-18 23:49:55 +0530133 {
134 return;
135 }
136
AppaRao Pulie90f1282019-11-05 01:07:05 +0530137 auto it = recoveryReasonMap.find(reason);
AppaRao Puli88aa33b2019-07-18 23:49:55 +0530138 if (it == recoveryReasonMap.end())
139 {
140 // No matching found. So just return without logging event.
141 return;
142 }
AppaRao Pulie90f1282019-11-05 01:07:05 +0530143 std::string msgId = "OpenBMC.0.1." + it->second.first;
144 sd_journal_send("MESSAGE=%s", "Platform firmware recovery occurred.",
145 "PRIORITY=%i", LOG_WARNING, "REDFISH_MESSAGE_ID=%s",
146 msgId.c_str(), "REDFISH_MESSAGE_ARGS=%s",
147 it->second.second.c_str(), NULL);
AppaRao Puli88aa33b2019-07-18 23:49:55 +0530148}
149
150static void logLastPanicEvent()
151{
152 uint8_t reason = 0;
AppaRao Pulidcf13122020-05-28 01:21:39 +0530153 if (0 != readCpldReg(ActionType::panicReason, reason))
AppaRao Puli88aa33b2019-07-18 23:49:55 +0530154 {
155 return;
156 }
157
AppaRao Pulie90f1282019-11-05 01:07:05 +0530158 auto it = panicReasonMap.find(reason);
AppaRao Puli88aa33b2019-07-18 23:49:55 +0530159 if (it == panicReasonMap.end())
160 {
161 // No matching found. So just return without logging event.
162 return;
163 }
164
AppaRao Pulie90f1282019-11-05 01:07:05 +0530165 std::string msgId = "OpenBMC.0.1." + it->second.first;
166 sd_journal_send("MESSAGE=%s", "Platform firmware panic occurred.",
167 "PRIORITY=%i", LOG_WARNING, "REDFISH_MESSAGE_ID=%s",
168 msgId.c_str(), "REDFISH_MESSAGE_ARGS=%s",
169 it->second.second.c_str(), NULL);
AppaRao Puli88aa33b2019-07-18 23:49:55 +0530170}
171
AppaRao Puli24766942019-11-13 19:27:08 +0530172static void logResiliencyErrorEvent(const uint8_t majorErrorCode,
173 const uint8_t minorErrorCode)
174{
175 auto it = majorErrorCodeMap.find(majorErrorCode);
176 if (it == majorErrorCodeMap.end())
177 {
178 // No matching found. So just return without logging event.
179 return;
180 }
181
182 std::string errorStr =
183 it->second.second + "(MinorCode:0x" + toHexString(minorErrorCode) + ")";
184 std::string msgId = "OpenBMC.0.1." + it->second.first;
185 sd_journal_send(
186 "MESSAGE=%s", "Platform firmware resiliency error occurred.",
187 "PRIORITY=%i", LOG_ERR, "REDFISH_MESSAGE_ID=%s", msgId.c_str(),
188 "REDFISH_MESSAGE_ARGS=%s", errorStr.c_str(), NULL);
189}
190
AppaRao Puli88aa33b2019-07-18 23:49:55 +0530191static void checkAndLogEvents()
192{
193 uint8_t currPanicCount = 0;
AppaRao Pulidcf13122020-05-28 01:21:39 +0530194 if (0 == readCpldReg(ActionType::panicCount, currPanicCount))
AppaRao Puli88aa33b2019-07-18 23:49:55 +0530195 {
196 if (lastPanicCount != currPanicCount)
197 {
198 // Update cached data and log redfish event by reading reason.
199 lastPanicCount = currPanicCount;
200 logLastPanicEvent();
201 }
202 }
203
204 uint8_t currRecoveryCount = 0;
AppaRao Pulidcf13122020-05-28 01:21:39 +0530205 if (0 == readCpldReg(ActionType::recoveryCount, currRecoveryCount))
AppaRao Puli88aa33b2019-07-18 23:49:55 +0530206 {
207 if (lastRecoveryCount != currRecoveryCount)
208 {
209 // Update cached data and log redfish event by reading reason.
210 lastRecoveryCount = currRecoveryCount;
211 logLastRecoveryEvent();
212 }
213 }
214
215 uint8_t majorErr = 0;
216 uint8_t minorErr = 0;
AppaRao Pulidcf13122020-05-28 01:21:39 +0530217 if ((0 == readCpldReg(ActionType::majorError, majorErr)) &&
218 (0 == readCpldReg(ActionType::minorError, minorErr)))
AppaRao Puli88aa33b2019-07-18 23:49:55 +0530219 {
220 if ((lastMajorErr != majorErr) || (lastMinorErr != minorErr))
221 {
222 lastMajorErr = majorErr;
223 lastMinorErr = minorErr;
224
AppaRao Puli24766942019-11-13 19:27:08 +0530225 logResiliencyErrorEvent(majorErr, minorErr);
AppaRao Puli88aa33b2019-07-18 23:49:55 +0530226 }
227 }
228}
229
230static void monitorPlatformStateChange(
231 sdbusplus::asio::object_server& server,
232 std::shared_ptr<sdbusplus::asio::connection>& conn)
233{
234 constexpr size_t pollTimeout = 10; // seconds
235 stateTimer->expires_after(std::chrono::seconds(pollTimeout));
236 stateTimer->async_wait(
237 [&server, &conn](const boost::system::error_code& ec) {
238 if (ec == boost::asio::error::operation_aborted)
239 {
240 // Timer reset.
241 return;
242 }
243 if (ec)
244 {
245 // Platform State Monitor - Timer cancelled.
246 return;
247 }
248 checkAndLogEvents();
249 monitorPlatformStateChange(server, conn);
250 });
251}
252
AppaRao Puli46cead92019-07-22 16:50:09 +0530253void checkAndSetCheckpoint(sdbusplus::asio::object_server& server,
254 std::shared_ptr<sdbusplus::asio::connection>& conn)
255{
256 // Check whether systemd completed all the loading.
257 conn->async_method_call(
258 [&server, &conn](boost::system::error_code ec,
259 const std::variant<uint64_t>& value) {
AppaRao Pulib7e172c2019-12-13 14:46:25 +0530260 if (!ec)
AppaRao Puli46cead92019-07-22 16:50:09 +0530261 {
AppaRao Pulib7e172c2019-12-13 14:46:25 +0530262 if (std::get<uint64_t>(value))
AppaRao Puli46cead92019-07-22 16:50:09 +0530263 {
AppaRao Pulib7e172c2019-12-13 14:46:25 +0530264 phosphor::logging::log<phosphor::logging::level::INFO>(
265 "PFR: BMC boot completed. Setting checkpoint 9.");
266 if (!finishedSettingChkPoint)
267 {
268 finishedSettingChkPoint = true;
AppaRao Pulidcf13122020-05-28 01:21:39 +0530269 setBMCBootCheckpoint(bmcBootFinishedChkPoint);
AppaRao Pulib7e172c2019-12-13 14:46:25 +0530270 }
271 return;
AppaRao Puli46cead92019-07-22 16:50:09 +0530272 }
273 }
274 else
275 {
AppaRao Pulib7e172c2019-12-13 14:46:25 +0530276 // Failed to get data from systemd. System might not
277 // be ready yet. Attempt again for data.
278 phosphor::logging::log<phosphor::logging::level::ERR>(
279 "PFR: aync call failed to get FinishTimestamp.",
280 phosphor::logging::entry("MSG=%s", ec.message().c_str()));
AppaRao Puli46cead92019-07-22 16:50:09 +0530281 }
AppaRao Pulib7e172c2019-12-13 14:46:25 +0530282 // FIX-ME: Latest up-stream sync caused issue in receiving
283 // StartupFinished signal. Unable to get StartupFinished signal
284 // from systemd1 hence using poll method too, to trigger it
285 // properly.
286 constexpr size_t pollTimeout = 10; // seconds
287 initTimer->expires_after(std::chrono::seconds(pollTimeout));
288 initTimer->async_wait([&server,
289 &conn](const boost::system::error_code& ec) {
290 if (ec == boost::asio::error::operation_aborted)
291 {
292 // Timer reset.
293 phosphor::logging::log<phosphor::logging::level::INFO>(
294 "PFR: Set boot Checkpoint - Timer aborted or stopped.");
295 return;
296 }
297 if (ec)
298 {
299 phosphor::logging::log<phosphor::logging::level::ERR>(
300 "PFR: Set boot Checkpoint - async wait error.");
301 return;
302 }
303 checkAndSetCheckpoint(server, conn);
304 });
AppaRao Puli46cead92019-07-22 16:50:09 +0530305 },
306 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
307 "org.freedesktop.DBus.Properties", "Get",
308 "org.freedesktop.systemd1.Manager", "FinishTimestamp");
309}
310
AppaRao Pulia9bf9712020-01-12 05:45:48 +0530311void monitorSignals(sdbusplus::asio::object_server& server,
312 std::shared_ptr<sdbusplus::asio::connection>& conn)
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530313{
AppaRao Puli46cead92019-07-22 16:50:09 +0530314 // Monitor Boot finished signal and set the checkpoint 9 to
315 // notify CPLD about BMC boot finish.
316 auto bootFinishedSignal = std::make_unique<sdbusplus::bus::match::match>(
317 static_cast<sdbusplus::bus::bus&>(*conn),
318 "type='signal',"
319 "member='StartupFinished',path='/org/freedesktop/systemd1',"
320 "interface='org.freedesktop.systemd1.Manager'",
321 [&server, &conn](sdbusplus::message::message& msg) {
322 if (!finishedSettingChkPoint)
323 {
AppaRao Pulib7e172c2019-12-13 14:46:25 +0530324 phosphor::logging::log<phosphor::logging::level::INFO>(
325 "PFR: BMC boot completed(StartupFinished). Setting "
326 "checkpoint 9.");
AppaRao Puli46cead92019-07-22 16:50:09 +0530327 finishedSettingChkPoint = true;
AppaRao Pulidcf13122020-05-28 01:21:39 +0530328 setBMCBootCheckpoint(bmcBootFinishedChkPoint);
AppaRao Puli46cead92019-07-22 16:50:09 +0530329 }
330 });
331 checkAndSetCheckpoint(server, conn);
332
AppaRao Puli88aa33b2019-07-18 23:49:55 +0530333 // Capture the Chassis state and Start the monitor timer
334 // if state changed to 'On'. Run timer until OS boot.
335 // Stop timer if state changed to 'Off'.
336 static auto matchChassisState = sdbusplus::bus::match::match(
337 static_cast<sdbusplus::bus::bus&>(*conn),
338 "type='signal',member='PropertiesChanged', "
339 "interface='org.freedesktop.DBus.Properties', "
340 "sender='xyz.openbmc_project.State.Chassis', "
341 "arg0namespace='xyz.openbmc_project.State.Chassis'",
342 [&server, &conn](sdbusplus::message::message& message) {
343 std::string intfName;
344 std::map<std::string, std::variant<std::string>> properties;
345 message.read(intfName, properties);
346
347 const auto it = properties.find("CurrentPowerState");
348 if (it != properties.end())
349 {
350 const std::string* state =
351 std::get_if<std::string>(&it->second);
352 if (state != nullptr)
353 {
354 if ((*state ==
355 "xyz.openbmc_project.State.Chassis.PowerState.On") &&
356 (!stateTimerRunning))
357 {
358 stateTimerRunning = true;
359 monitorPlatformStateChange(server, conn);
360 }
361 else if ((*state == "xyz.openbmc_project.State.Chassis."
362 "PowerState.Off") &&
363 (stateTimerRunning))
364 {
365 stateTimer->cancel();
366 checkAndLogEvents();
367 stateTimerRunning = false;
368 }
369 }
AppaRao Pulie4e95652019-07-19 16:52:01 +0530370
371 // Update the D-Bus properties when chassis state changes.
372 updateDbusPropertiesCache();
AppaRao Puli88aa33b2019-07-18 23:49:55 +0530373 }
374 });
375
376 // Capture the Host state and Start the monitor timer
377 // if state changed to 'Running'. Run timer until OS boot.
378 // Stop timer if state changed to 'Off'.
379 static auto matchHostState = sdbusplus::bus::match::match(
380 static_cast<sdbusplus::bus::bus&>(*conn),
381 "type='signal',member='PropertiesChanged', "
382 "interface='org.freedesktop.DBus.Properties', "
383 "sender='xyz.openbmc_project.State.Chassis', "
384 "arg0namespace='xyz.openbmc_project.State.Host'",
385 [&server, &conn](sdbusplus::message::message& message) {
386 std::string intfName;
387 std::map<std::string, std::variant<std::string>> properties;
388 message.read(intfName, properties);
389
390 const auto it = properties.find("CurrentHostState");
391 if (it != properties.end())
392 {
393 const std::string* state =
394 std::get_if<std::string>(&it->second);
395 if (state != nullptr)
396 {
397 if ((*state ==
398 "xyz.openbmc_project.State.Host.HostState.Running") &&
399 (!stateTimerRunning))
400 {
401 stateTimerRunning = true;
402 monitorPlatformStateChange(server, conn);
403 }
404 else if (((*state == "xyz.openbmc_project.State.Host."
405 "HostState.Off") ||
406 (*state == "xyz.openbmc_project.State.Host."
407 "HostState.Quiesced")) &&
408 (stateTimerRunning))
409 {
410 stateTimer->cancel();
411 checkAndLogEvents();
412 stateTimerRunning = false;
413 }
414 }
AppaRao Pulie4e95652019-07-19 16:52:01 +0530415
416 // Update the D-Bus properties when host state changes.
417 updateDbusPropertiesCache();
AppaRao Puli88aa33b2019-07-18 23:49:55 +0530418 }
419 });
420
421 // Capture the OS state change and stop monitor timer
422 // if OS boots completly or becomes Inactive.
423 // start timer in other cases to mnitor states.
424 static auto matchOsState = sdbusplus::bus::match::match(
425 static_cast<sdbusplus::bus::bus&>(*conn),
426 "type='signal',member='PropertiesChanged', "
427 "interface='org.freedesktop.DBus.Properties', "
428 "sender='xyz.openbmc_project.State.Chassis', "
429 "arg0namespace='xyz.openbmc_project.State.OperatingSystem.Status'",
430 [&server, &conn](sdbusplus::message::message& message) {
431 std::string intfName;
432 std::map<std::string, std::variant<std::string>> properties;
433 message.read(intfName, properties);
434
435 const auto it = properties.find("OperatingSystemState");
436 if (it != properties.end())
437 {
438 const std::string* state =
439 std::get_if<std::string>(&it->second);
440 if (state != nullptr)
441 {
442 if (((*state == "BootComplete") ||
443 (*state == "Inactive")) &&
444 (stateTimerRunning))
445 {
446 stateTimer->cancel();
447 checkAndLogEvents();
448 stateTimerRunning = false;
449 }
450 else if (!stateTimerRunning)
451 {
452 stateTimerRunning = true;
453 monitorPlatformStateChange(server, conn);
454 }
455 }
456 }
457 });
458
459 // First time, check and log events if any.
460 checkAndLogEvents();
AppaRao Pulia9bf9712020-01-12 05:45:48 +0530461}
AppaRao Puli88aa33b2019-07-18 23:49:55 +0530462
Chalapathi Venkataramashettye6fb18e2021-02-03 14:51:00 +0000463static void updateCPLDversion(std::shared_ptr<sdbusplus::asio::connection> conn)
464{
465 std::string cpldVersion = pfr::readCPLDVersion();
466 conn->async_method_call(
467 [](const boost::system::error_code ec) {
468 if (ec)
469 {
470 phosphor::logging::log<phosphor::logging::level::ERR>(
471 "Unable to update cpld_active version",
472 phosphor::logging::entry("MSG=%s", ec.message().c_str()));
473 return;
474 }
475 },
476 "xyz.openbmc_project.Settings",
477 "/xyz/openbmc_project/software/cpld_active",
478 "org.freedesktop.DBus.Properties", "Set",
479 "xyz.openbmc_project.Software.Version", "Version",
480 std::variant<std::string>(cpldVersion));
481 return;
482}
483
AppaRao Pulidcf13122020-05-28 01:21:39 +0530484} // namespace pfr
485
AppaRao Pulia9bf9712020-01-12 05:45:48 +0530486int main()
487{
488 // setup connection to dbus
489 boost::asio::io_service io;
490 auto conn = std::make_shared<sdbusplus::asio::connection>(io);
AppaRao Pulidcf13122020-05-28 01:21:39 +0530491 pfr::stateTimer = std::make_unique<boost::asio::steady_timer>(io);
492 pfr::initTimer = std::make_unique<boost::asio::steady_timer>(io);
AppaRao Pulia9bf9712020-01-12 05:45:48 +0530493 auto server = sdbusplus::asio::object_server(conn, true);
Chalapathi Venkataramashetty55e79342021-03-29 10:17:48 +0000494 pfr::init(conn, pfr::i2cConfigLoaded);
AppaRao Pulidcf13122020-05-28 01:21:39 +0530495 pfr::monitorSignals(server, conn);
AppaRao Pulia9bf9712020-01-12 05:45:48 +0530496
Chalapathi Venkataramashettye6fb18e2021-02-03 14:51:00 +0000497 // Update CPLD Version to cpld_active object in settings.
498 pfr::updateCPLDversion(conn);
499
AppaRao Pulia9bf9712020-01-12 05:45:48 +0530500 server.add_manager("/xyz/openbmc_project/pfr");
501
502 // Create PFR attributes object and interface
AppaRao Pulidcf13122020-05-28 01:21:39 +0530503 pfr::pfrConfigObject = std::make_unique<pfr::PfrConfig>(server, conn);
AppaRao Pulia9bf9712020-01-12 05:45:48 +0530504
505 // Create Software objects using Versions interface
AppaRao Pulidcf13122020-05-28 01:21:39 +0530506 for (const auto& entry : pfr::verComponentList)
AppaRao Pulia9bf9712020-01-12 05:45:48 +0530507 {
AppaRao Pulidcf13122020-05-28 01:21:39 +0530508 pfr::pfrVersionObjects.emplace_back(std::make_unique<pfr::PfrVersion>(
AppaRao Pulia9bf9712020-01-12 05:45:48 +0530509 server, conn, std::get<0>(entry), std::get<1>(entry),
510 std::get<2>(entry)));
511 }
512
513 conn->request_name("xyz.openbmc_project.PFR.Manager");
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530514 phosphor::logging::log<phosphor::logging::level::INFO>(
515 "Intel PFR service started successfully");
AppaRao Pulie63eeda2019-07-05 16:25:38 +0530516 io.run();
517
518 return 0;
519}