blob: cc46aa2096e08d0a0ad2cd80806de110e9081957 [file] [log] [blame]
SunnySrivastava198443306542020-04-01 02:50:20 -05001#include "config.h"
2
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -05003#include "ibm_vpd_utils.hpp"
Patrick Venturec83c4dc2018-11-01 16:29:18 -07004
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -05005#include "common_utility.hpp"
SunnySrivastava1984d076da82020-03-05 05:33:35 -06006#include "defines.hpp"
PriyangaRamasamyc0a534f2020-08-24 21:29:18 +05307#include "vpd_exceptions.hpp"
SunnySrivastava1984d076da82020-03-05 05:33:35 -06008
Alpana Kumari6bd095f2022-02-23 10:20:20 -06009#include <boost/algorithm/string.hpp>
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -060010#include <filesystem>
PriyangaRamasamyc0a534f2020-08-24 21:29:18 +053011#include <fstream>
Alpana Kumari735dee92022-03-25 01:24:40 -050012#include <gpiod.hpp>
PriyangaRamasamyc0a534f2020-08-24 21:29:18 +053013#include <iomanip>
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -050014#include <nlohmann/json.hpp>
SunnySrivastava19849094d4f2020-08-05 09:32:29 -050015#include <phosphor-logging/elog-errors.hpp>
Patrick Venturec83c4dc2018-11-01 16:29:18 -070016#include <phosphor-logging/log.hpp>
PriyangaRamasamy647868e2020-09-08 17:03:19 +053017#include <regex>
Patrick Venturec83c4dc2018-11-01 16:29:18 -070018#include <sdbusplus/server.hpp>
PriyangaRamasamyc0a534f2020-08-24 21:29:18 +053019#include <sstream>
20#include <vector>
SunnySrivastava19849094d4f2020-08-05 09:32:29 -050021#include <xyz/openbmc_project/Common/error.hpp>
Deepak Kodihalli76794492017-02-16 23:48:18 -060022
PriyangaRamasamyc0a534f2020-08-24 21:29:18 +053023using json = nlohmann::json;
24
Deepak Kodihalli76794492017-02-16 23:48:18 -060025namespace openpower
26{
27namespace vpd
28{
SunnySrivastava1984945a02d2020-05-06 01:55:41 -050029using namespace openpower::vpd::constants;
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -050030using namespace inventory;
31using namespace phosphor::logging;
SunnySrivastava19849094d4f2020-08-05 09:32:29 -050032using namespace sdbusplus::xyz::openbmc_project::Common::Error;
PriyangaRamasamyc0a534f2020-08-24 21:29:18 +053033using namespace record;
34using namespace openpower::vpd::exceptions;
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -050035using namespace common::utility;
Sunny Srivastava0746eee2021-03-22 13:36:54 -050036using Severity = openpower::vpd::constants::PelSeverity;
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -060037namespace fs = std::filesystem;
Sunny Srivastava0746eee2021-03-22 13:36:54 -050038
39// mapping of severity enum to severity interface
40static std::unordered_map<Severity, std::string> sevMap = {
41 {Severity::INFORMATIONAL,
42 "xyz.openbmc_project.Logging.Entry.Level.Informational"},
43 {Severity::DEBUG, "xyz.openbmc_project.Logging.Entry.Level.Debug"},
44 {Severity::NOTICE, "xyz.openbmc_project.Logging.Entry.Level.Notice"},
45 {Severity::WARNING, "xyz.openbmc_project.Logging.Entry.Level.Warning"},
46 {Severity::CRITICAL, "xyz.openbmc_project.Logging.Entry.Level.Critical"},
47 {Severity::EMERGENCY, "xyz.openbmc_project.Logging.Entry.Level.Emergency"},
48 {Severity::ERROR, "xyz.openbmc_project.Logging.Entry.Level.Error"},
49 {Severity::ALERT, "xyz.openbmc_project.Logging.Entry.Level.Alert"}};
50
Deepak Kodihalli76794492017-02-16 23:48:18 -060051namespace inventory
52{
53
SunnySrivastava19849094d4f2020-08-05 09:32:29 -050054MapperResponse
55 getObjectSubtreeForInterfaces(const std::string& root, const int32_t depth,
56 const std::vector<std::string>& interfaces)
57{
58 auto bus = sdbusplus::bus::new_default();
59 auto mapperCall = bus.new_method_call(mapperDestination, mapperObjectPath,
60 mapperInterface, "GetSubTree");
61 mapperCall.append(root);
62 mapperCall.append(depth);
63 mapperCall.append(interfaces);
64
65 MapperResponse result = {};
66
67 try
68 {
69 auto response = bus.call(mapperCall);
70
71 response.read(result);
72 }
Patrick Williams2eb01762022-07-22 19:26:56 -050073 catch (const sdbusplus::exception_t& e)
SunnySrivastava19849094d4f2020-08-05 09:32:29 -050074 {
75 log<level::ERR>("Error in mapper GetSubTree",
76 entry("ERROR=%s", e.what()));
77 }
78
79 return result;
80}
81
Deepak Kodihalli76794492017-02-16 23:48:18 -060082} // namespace inventory
83
SunnySrivastava1984f6d541e2020-02-04 12:50:40 -060084LE2ByteData readUInt16LE(Binary::const_iterator iterator)
85{
86 LE2ByteData lowByte = *iterator;
87 LE2ByteData highByte = *(iterator + 1);
88 lowByte |= (highByte << 8);
89 return lowByte;
90}
91
SunnySrivastava1984d076da82020-03-05 05:33:35 -060092/** @brief Encodes a keyword for D-Bus.
93 */
Priyanga Ramasamye0084322022-09-27 06:28:33 -050094std::string encodeKeyword(const std::string& kw, const std::string& encoding)
SunnySrivastava1984d076da82020-03-05 05:33:35 -060095{
96 if (encoding == "MAC")
97 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -050098 std::string res{};
SunnySrivastava1984d076da82020-03-05 05:33:35 -060099 size_t first = kw[0];
100 res += toHex(first >> 4);
101 res += toHex(first & 0x0f);
102 for (size_t i = 1; i < kw.size(); ++i)
103 {
104 res += ":";
105 res += toHex(kw[i] >> 4);
106 res += toHex(kw[i] & 0x0f);
107 }
108 return res;
109 }
110 else if (encoding == "DATE")
111 {
112 // Date, represent as
113 // <year>-<month>-<day> <hour>:<min>
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500114 std::string res{};
SunnySrivastava1984d076da82020-03-05 05:33:35 -0600115 static constexpr uint8_t skipPrefix = 3;
116
117 auto strItr = kw.begin();
118 advance(strItr, skipPrefix);
119 for_each(strItr, kw.end(), [&res](size_t c) { res += c; });
120
121 res.insert(BD_YEAR_END, 1, '-');
122 res.insert(BD_MONTH_END, 1, '-');
123 res.insert(BD_DAY_END, 1, ' ');
124 res.insert(BD_HOUR_END, 1, ':');
125
126 return res;
127 }
128 else // default to string encoding
129 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500130 return std::string(kw.begin(), kw.end());
SunnySrivastava1984d076da82020-03-05 05:33:35 -0600131 }
132}
SunnySrivastava198443306542020-04-01 02:50:20 -0500133
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500134std::string readBusProperty(const std::string& obj, const std::string& inf,
135 const std::string& prop)
SunnySrivastava198443306542020-04-01 02:50:20 -0500136{
137 std::string propVal{};
138 std::string object = INVENTORY_PATH + obj;
139 auto bus = sdbusplus::bus::new_default();
140 auto properties = bus.new_method_call(
141 "xyz.openbmc_project.Inventory.Manager", object.c_str(),
142 "org.freedesktop.DBus.Properties", "Get");
143 properties.append(inf);
144 properties.append(prop);
145 auto result = bus.call(properties);
146 if (!result.is_method_error())
147 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500148 std::variant<Binary, std::string> val;
SunnySrivastava198443306542020-04-01 02:50:20 -0500149 result.read(val);
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500150 if (auto pVal = std::get_if<Binary>(&val))
SunnySrivastava198443306542020-04-01 02:50:20 -0500151 {
152 propVal.assign(reinterpret_cast<const char*>(pVal->data()),
153 pVal->size());
154 }
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500155 else if (auto pVal = std::get_if<std::string>(&val))
SunnySrivastava1984bca5aaa2020-04-21 05:31:04 -0500156 {
157 propVal.assign(pVal->data(), pVal->size());
158 }
SunnySrivastava198443306542020-04-01 02:50:20 -0500159 }
160 return propVal;
161}
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -0500162
163void createPEL(const std::map<std::string, std::string>& additionalData,
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500164 const Severity& sev, const std::string& errIntf)
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -0500165{
166 try
167 {
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500168 std::string pelSeverity =
169 "xyz.openbmc_project.Logging.Entry.Level.Error";
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -0500170 auto bus = sdbusplus::bus::new_default();
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -0500171 auto service = getService(bus, loggerObjectPath, loggerCreateInterface);
172 auto method = bus.new_method_call(service.c_str(), loggerObjectPath,
173 loggerCreateInterface, "Create");
174
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500175 auto itr = sevMap.find(sev);
176 if (itr != sevMap.end())
177 {
178 pelSeverity = itr->second;
179 }
180
181 method.append(errIntf, pelSeverity, additionalData);
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -0500182 auto resp = bus.call(method);
183 }
Patrick Williams2eb01762022-07-22 19:26:56 -0500184 catch (const sdbusplus::exception_t& e)
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -0500185 {
186 throw std::runtime_error(
187 "Error in invoking D-Bus logging create interface to register PEL");
188 }
189}
PriyangaRamasamyc0a534f2020-08-24 21:29:18 +0530190
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500191inventory::VPDfilepath getVpdFilePath(const std::string& jsonFile,
PriyangaRamasamyc0a534f2020-08-24 21:29:18 +0530192 const std::string& ObjPath)
193{
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500194 std::ifstream inventoryJson(jsonFile);
PriyangaRamasamyc0a534f2020-08-24 21:29:18 +0530195 const auto& jsonObject = json::parse(inventoryJson);
196 inventory::VPDfilepath filePath{};
197
198 if (jsonObject.find("frus") == jsonObject.end())
199 {
200 throw(VpdJsonException(
201 "Invalid JSON structure - frus{} object not found in ", jsonFile));
202 }
203
204 const nlohmann::json& groupFRUS =
205 jsonObject["frus"].get_ref<const nlohmann::json::object_t&>();
206 for (const auto& itemFRUS : groupFRUS.items())
207 {
208 const std::vector<nlohmann::json>& groupEEPROM =
209 itemFRUS.value().get_ref<const nlohmann::json::array_t&>();
210 for (const auto& itemEEPROM : groupEEPROM)
211 {
212 if (itemEEPROM["inventoryPath"]
213 .get_ref<const nlohmann::json::string_t&>() == ObjPath)
214 {
215 filePath = itemFRUS.key();
216 return filePath;
217 }
218 }
219 }
220
221 return filePath;
222}
223
224bool isPathInJson(const std::string& eepromPath)
225{
226 bool present = false;
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500227 std::ifstream inventoryJson(INVENTORY_JSON_SYM_LINK);
PriyangaRamasamyc0a534f2020-08-24 21:29:18 +0530228
229 try
230 {
231 auto js = json::parse(inventoryJson);
232 if (js.find("frus") == js.end())
233 {
234 throw(VpdJsonException(
235 "Invalid JSON structure - frus{} object not found in ",
236 INVENTORY_JSON_SYM_LINK));
237 }
238 json fruJson = js["frus"];
239
240 if (fruJson.find(eepromPath) != fruJson.end())
241 {
242 present = true;
243 }
244 }
Patrick Williams8e15b932021-10-06 13:04:22 -0500245 catch (const json::parse_error& ex)
PriyangaRamasamyc0a534f2020-08-24 21:29:18 +0530246 {
247 throw(VpdJsonException("Json Parsing failed", INVENTORY_JSON_SYM_LINK));
248 }
249 return present;
250}
251
252bool isRecKwInDbusJson(const std::string& recordName,
253 const std::string& keyword)
254{
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500255 std::ifstream propertyJson(DBUS_PROP_JSON);
PriyangaRamasamyc0a534f2020-08-24 21:29:18 +0530256 json dbusProperty;
257 bool present = false;
258
259 if (propertyJson.is_open())
260 {
261 try
262 {
263 auto dbusPropertyJson = json::parse(propertyJson);
264 if (dbusPropertyJson.find("dbusProperties") ==
265 dbusPropertyJson.end())
266 {
267 throw(VpdJsonException("dbusProperties{} object not found in "
268 "DbusProperties json : ",
269 DBUS_PROP_JSON));
270 }
271
272 dbusProperty = dbusPropertyJson["dbusProperties"];
273 if (dbusProperty.contains(recordName))
274 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500275 const std::vector<std::string>& kwdsToPublish =
276 dbusProperty[recordName];
PriyangaRamasamyc0a534f2020-08-24 21:29:18 +0530277 if (find(kwdsToPublish.begin(), kwdsToPublish.end(), keyword) !=
278 kwdsToPublish.end()) // present
279 {
280 present = true;
281 }
282 }
283 }
Patrick Williams8e15b932021-10-06 13:04:22 -0500284 catch (const json::parse_error& ex)
PriyangaRamasamyc0a534f2020-08-24 21:29:18 +0530285 {
286 throw(VpdJsonException("Json Parsing failed", DBUS_PROP_JSON));
287 }
288 }
289 else
290 {
291 // If dbus properties json is not available, we assume the given
292 // record-keyword is part of dbus-properties json. So setting the bool
293 // variable to true.
294 present = true;
295 }
296 return present;
297}
298
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -0500299vpdType vpdTypeCheck(const Binary& vpdVector)
300{
301 // Read first 3 Bytes to check the 11S bar code format
302 std::string is11SFormat = "";
303 for (uint8_t i = 0; i < FORMAT_11S_LEN; i++)
304 {
305 is11SFormat += vpdVector[MEMORY_VPD_DATA_START + i];
306 }
307
308 if (vpdVector[IPZ_DATA_START] == KW_VAL_PAIR_START_TAG)
309 {
310 // IPZ VPD FORMAT
311 return vpdType::IPZ_VPD;
312 }
313 else if (vpdVector[KW_VPD_DATA_START] == KW_VPD_START_TAG)
314 {
315 // KEYWORD VPD FORMAT
316 return vpdType::KEYWORD_VPD;
317 }
318 else if (is11SFormat.compare(MEMORY_VPD_START_TAG) == 0)
319 {
320 // Memory VPD format
321 return vpdType::MEMORY_VPD;
322 }
323
324 // INVALID VPD FORMAT
325 return vpdType::INVALID_VPD_FORMAT;
326}
327
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500328const std::string getIM(const Parsed& vpdMap)
Alpana Kumarif05effd2021-04-07 07:32:53 -0500329{
330 Binary imVal;
331 auto property = vpdMap.find("VSBP");
332 if (property != vpdMap.end())
333 {
334 auto kw = (property->second).find("IM");
335 if (kw != (property->second).end())
336 {
337 copy(kw->second.begin(), kw->second.end(), back_inserter(imVal));
338 }
339 }
340
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500341 std::ostringstream oss;
Alpana Kumarif05effd2021-04-07 07:32:53 -0500342 for (auto& i : imVal)
343 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500344 oss << std::setw(2) << std::setfill('0') << std::hex
345 << static_cast<int>(i);
Alpana Kumarif05effd2021-04-07 07:32:53 -0500346 }
347
348 return oss.str();
349}
350
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500351const std::string getHW(const Parsed& vpdMap)
Alpana Kumarif05effd2021-04-07 07:32:53 -0500352{
353 Binary hwVal;
354 auto prop = vpdMap.find("VINI");
355 if (prop != vpdMap.end())
356 {
357 auto kw = (prop->second).find("HW");
358 if (kw != (prop->second).end())
359 {
360 copy(kw->second.begin(), kw->second.end(), back_inserter(hwVal));
361 }
362 }
363
Alpana Kumari88d2ae82021-11-10 03:23:31 -0600364 // The planar pass only comes from the LSB of the HW keyword,
365 // where as the MSB is used for other purposes such as signifying clock
366 // termination.
367 hwVal[0] = 0x00;
368
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500369 std::ostringstream hwString;
Alpana Kumarif05effd2021-04-07 07:32:53 -0500370 for (auto& i : hwVal)
371 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500372 hwString << std::setw(2) << std::setfill('0') << std::hex
373 << static_cast<int>(i);
Alpana Kumarif05effd2021-04-07 07:32:53 -0500374 }
375
376 return hwString.str();
377}
378
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500379std::string getSystemsJson(const Parsed& vpdMap)
Alpana Kumarif05effd2021-04-07 07:32:53 -0500380{
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500381 std::string jsonPath = "/usr/share/vpd/";
382 std::string jsonName{};
Alpana Kumarif05effd2021-04-07 07:32:53 -0500383
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500384 std::ifstream systemJson(SYSTEM_JSON);
Alpana Kumarif05effd2021-04-07 07:32:53 -0500385 if (!systemJson)
386 {
387 throw((VpdJsonException("Failed to access Json path", SYSTEM_JSON)));
388 }
389
390 try
391 {
392 auto js = json::parse(systemJson);
393
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500394 std::string hwKeyword = getHW(vpdMap);
395 const std::string imKeyword = getIM(vpdMap);
Alpana Kumarif05effd2021-04-07 07:32:53 -0500396
Alpana Kumari1b026112022-03-02 23:41:38 -0600397 transform(hwKeyword.begin(), hwKeyword.end(), hwKeyword.begin(),
398 ::toupper);
399
Alpana Kumarif05effd2021-04-07 07:32:53 -0500400 if (js.find("system") == js.end())
401 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500402 throw std::runtime_error("Invalid systems Json");
Alpana Kumarif05effd2021-04-07 07:32:53 -0500403 }
404
405 if (js["system"].find(imKeyword) == js["system"].end())
406 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500407 throw std::runtime_error(
Alpana Kumarif05effd2021-04-07 07:32:53 -0500408 "Invalid system. This system type is not present "
409 "in the systemsJson. IM: " +
410 imKeyword);
411 }
412
413 if ((js["system"][imKeyword].find("constraint") !=
414 js["system"][imKeyword].end()) &&
Alpana Kumari1b026112022-03-02 23:41:38 -0600415 js["system"][imKeyword]["constraint"].find("HW") !=
416 js["system"][imKeyword]["constraint"].end())
Alpana Kumarif05effd2021-04-07 07:32:53 -0500417 {
Alpana Kumari1b026112022-03-02 23:41:38 -0600418 // collect hw versions from json, and check hwKeyword is part of it
419 // if hwKeyword is found there then load respective json
420 // otherwise load default one.
421 for (const auto& hwVersion :
422 js["system"][imKeyword]["constraint"]["HW"])
423 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500424 std::string hw = hwVersion;
Alpana Kumari1b026112022-03-02 23:41:38 -0600425 transform(hw.begin(), hw.end(), hw.begin(), ::toupper);
426
427 if (hw == hwKeyword)
428 {
429 jsonName = js["system"][imKeyword]["constraint"]["json"];
430 break;
431 }
432 }
433
434 if (jsonName.empty() && js["system"][imKeyword].find("default") !=
435 js["system"][imKeyword].end())
436 {
437 jsonName = js["system"][imKeyword]["default"];
438 }
Alpana Kumarif05effd2021-04-07 07:32:53 -0500439 }
440 else if (js["system"][imKeyword].find("default") !=
441 js["system"][imKeyword].end())
442 {
443 jsonName = js["system"][imKeyword]["default"];
444 }
445 else
446 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500447 throw std::runtime_error(
Alpana Kumarif05effd2021-04-07 07:32:53 -0500448 "Bad System json. Neither constraint nor default found");
449 }
450
451 jsonPath += jsonName;
452 }
453
Patrick Williams8e15b932021-10-06 13:04:22 -0500454 catch (const json::parse_error& ex)
Alpana Kumarif05effd2021-04-07 07:32:53 -0500455 {
456 throw(VpdJsonException("Json Parsing failed", SYSTEM_JSON));
457 }
458 return jsonPath;
459}
460
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500461void udevToGenericPath(std::string& file)
PriyangaRamasamy647868e2020-09-08 17:03:19 +0530462{
463 // Sample udevEvent i2c path :
464 // "/sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/1e78a480.i2c-bus/i2c-8/8-0051/8-00510/nvmem"
465 // find if the path contains the word i2c in it.
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500466 if (file.find("i2c") != std::string::npos)
PriyangaRamasamy647868e2020-09-08 17:03:19 +0530467 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500468 std::string i2cBusAddr{};
PriyangaRamasamy647868e2020-09-08 17:03:19 +0530469
470 // Every udev i2c path should have the common pattern
471 // "i2c-bus_number/bus_number-vpd_address". Search for
472 // "bus_number-vpd_address".
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500473 std::regex i2cPattern("((i2c)-[0-9]+\\/)([0-9]+-[0-9]{4})");
474 std::smatch match;
475 if (std::regex_search(file, match, i2cPattern))
PriyangaRamasamy647868e2020-09-08 17:03:19 +0530476 {
477 i2cBusAddr = match.str(3);
478 }
479 else
480 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500481 std::cerr << "The given udev path < " << file
482 << " > doesn't match the required pattern. Skipping VPD "
483 "collection."
484 << std::endl;
PriyangaRamasamy647868e2020-09-08 17:03:19 +0530485 exit(EXIT_SUCCESS);
486 }
487 // Forming the generic file path
488 file = i2cPathPrefix + i2cBusAddr + "/eeprom";
489 }
490 // Sample udevEvent spi path :
491 // "/sys/devices/platform/ahb/ahb:apb/1e79b000.fsi/fsi-master/fsi0/slave@00:00/00:00:00:04/spi_master/spi2/spi2.0/spi2.00/nvmem"
492 // find if the path contains the word spi in it.
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500493 else if (file.find("spi") != std::string::npos)
PriyangaRamasamy647868e2020-09-08 17:03:19 +0530494 {
495 // Every udev spi path will have common pattern "spi<Digit>/", which
496 // describes the spi bus number at which the fru is connected; Followed
497 // by a slash following the vpd address of the fru. Taking the above
498 // input as a common key, we try to search for the pattern "spi<Digit>/"
499 // using regular expression.
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500500 std::regex spiPattern("((spi)[0-9]+)(\\/)");
501 std::string spiBus{};
502 std::smatch match;
503 if (std::regex_search(file, match, spiPattern))
PriyangaRamasamy647868e2020-09-08 17:03:19 +0530504 {
505 spiBus = match.str(1);
506 }
507 else
508 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500509 std::cerr << "The given udev path < " << file
510 << " > doesn't match the required pattern. Skipping VPD "
511 "collection."
512 << std::endl;
PriyangaRamasamy647868e2020-09-08 17:03:19 +0530513 exit(EXIT_SUCCESS);
514 }
515 // Forming the generic path
516 file = spiPathPrefix + spiBus + ".0/eeprom";
517 }
518 else
519 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500520 std::cerr << "\n The given EEPROM path < " << file
521 << " > is not valid. It's neither I2C nor "
522 "SPI path. Skipping VPD collection.."
523 << std::endl;
PriyangaRamasamy647868e2020-09-08 17:03:19 +0530524 exit(EXIT_SUCCESS);
525 }
526}
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500527std::string getBadVpdName(const std::string& file)
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -0600528{
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500529 std::string badVpd = BAD_VPD_DIR;
530 if (file.find("i2c") != std::string::npos)
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -0600531 {
532 badVpd += "i2c-";
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500533 std::regex i2cPattern("(at24/)([0-9]+-[0-9]+)\\/");
534 std::smatch match;
535 if (std::regex_search(file, match, i2cPattern))
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -0600536 {
537 badVpd += match.str(2);
538 }
539 }
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500540 else if (file.find("spi") != std::string::npos)
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -0600541 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500542 std::regex spiPattern("((spi)[0-9]+)(.0)");
543 std::smatch match;
544 if (std::regex_search(file, match, spiPattern))
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -0600545 {
546 badVpd += match.str(1);
547 }
548 }
549 return badVpd;
550}
551
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500552void dumpBadVpd(const std::string& file, const Binary& vpdVector)
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -0600553{
554 fs::path badVpdDir = BAD_VPD_DIR;
555 fs::create_directory(badVpdDir);
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500556 std::string badVpdPath = getBadVpdName(file);
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -0600557 if (fs::exists(badVpdPath))
558 {
559 std::error_code ec;
560 fs::remove(badVpdPath, ec);
561 if (ec) // error code
562 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500563 std::string error = "Error removing the existing broken vpd in ";
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -0600564 error += badVpdPath;
565 error += ". Error code : ";
566 error += ec.value();
567 error += ". Error message : ";
568 error += ec.message();
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500569 throw std::runtime_error(error);
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -0600570 }
571 }
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500572 std::ofstream badVpdFileStream(badVpdPath, std::ofstream::binary);
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -0600573 if (!badVpdFileStream)
574 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500575 throw std::runtime_error(
576 "Failed to open bad vpd file path in /tmp/bad-vpd. "
577 "Unable to dump the broken/bad vpd file.");
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -0600578 }
579 badVpdFileStream.write(reinterpret_cast<const char*>(vpdVector.data()),
580 vpdVector.size());
581}
alpana077ce68722021-07-25 13:23:59 -0500582
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500583const std::string getKwVal(const Parsed& vpdMap, const std::string& rec,
584 const std::string& kwd)
alpana077ce68722021-07-25 13:23:59 -0500585{
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500586 std::string kwVal{};
alpana077ce68722021-07-25 13:23:59 -0500587
588 auto findRec = vpdMap.find(rec);
589
590 // check if record is found in map we got by parser
591 if (findRec != vpdMap.end())
592 {
593 auto findKwd = findRec->second.find(kwd);
594
595 if (findKwd != findRec->second.end())
596 {
597 kwVal = findKwd->second;
598 }
599 }
600
601 return kwVal;
602}
603
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500604std::string byteArrayToHexString(const Binary& vec)
Priyanga Ramasamyc9ecf8e2021-10-08 02:28:52 -0500605{
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500606 std::stringstream ss;
607 std::string hexRep = "0x";
Priyanga Ramasamyc9ecf8e2021-10-08 02:28:52 -0500608 ss << hexRep;
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500609 std::string str = ss.str();
Priyanga Ramasamyc9ecf8e2021-10-08 02:28:52 -0500610
611 // convert Decimal to Hex string
612 for (auto& v : vec)
613 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500614 ss << std::setfill('0') << std::setw(2) << std::hex << (int)v;
Priyanga Ramasamyc9ecf8e2021-10-08 02:28:52 -0500615 str = ss.str();
616 }
617 return str;
618}
619
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500620std::string getPrintableValue(const Binary& vec)
Priyanga Ramasamy02434932021-10-07 16:26:05 -0500621{
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500622 std::string str{};
Priyanga Ramasamy02434932021-10-07 16:26:05 -0500623
Priyanga Ramasamyc9ecf8e2021-10-08 02:28:52 -0500624 // find for a non printable value in the vector
625 const auto it = std::find_if(vec.begin(), vec.end(),
626 [](const auto& ele) { return !isprint(ele); });
Priyanga Ramasamy02434932021-10-07 16:26:05 -0500627
Priyanga Ramasamyc9ecf8e2021-10-08 02:28:52 -0500628 if (it != vec.end()) // if the given vector has any non printable value
629 {
630 for (auto itr = it; itr != vec.end(); itr++)
Priyanga Ramasamy02434932021-10-07 16:26:05 -0500631 {
Priyanga Ramasamyc9ecf8e2021-10-08 02:28:52 -0500632 if (*itr != 0x00)
633 {
634 str = byteArrayToHexString(vec);
635 return str;
636 }
Priyanga Ramasamy02434932021-10-07 16:26:05 -0500637 }
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500638 str = std::string(vec.begin(), it);
Priyanga Ramasamy02434932021-10-07 16:26:05 -0500639 }
640 else
641 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500642 str = std::string(vec.begin(), vec.end());
Priyanga Ramasamy02434932021-10-07 16:26:05 -0500643 }
644 return str;
645}
646
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500647void executePostFailAction(const nlohmann::json& json, const std::string& file)
Alpana Kumari735dee92022-03-25 01:24:40 -0500648{
649 if ((json["frus"][file].at(0)).find("postActionFail") ==
650 json["frus"][file].at(0).end())
651 {
652 return;
653 }
654
655 uint8_t pinValue = 0;
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500656 std::string pinName;
Alpana Kumari735dee92022-03-25 01:24:40 -0500657
658 for (const auto& postAction :
659 (json["frus"][file].at(0))["postActionFail"].items())
660 {
661 if (postAction.key() == "pin")
662 {
663 pinName = postAction.value();
664 }
665 else if (postAction.key() == "value")
666 {
667 // Get the value to set
668 pinValue = postAction.value();
669 }
670 }
671
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500672 std::cout << "Setting GPIO: " << pinName << " to " << (int)pinValue
673 << std::endl;
Alpana Kumari735dee92022-03-25 01:24:40 -0500674
675 try
676 {
677 gpiod::line outputLine = gpiod::find_line(pinName);
678
679 if (!outputLine)
680 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500681 throw std::runtime_error(
Alpana Kumari6bd095f2022-02-23 10:20:20 -0600682 "Couldn't find output line for the GPIO. Skipping "
683 "this GPIO action.");
Alpana Kumari735dee92022-03-25 01:24:40 -0500684 }
685 outputLine.request(
686 {"Disable line", ::gpiod::line_request::DIRECTION_OUTPUT, 0},
687 pinValue);
688 }
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500689 catch (const std::exception& e)
Alpana Kumari735dee92022-03-25 01:24:40 -0500690 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500691 std::string i2cBusAddr;
692 std::string errMsg = e.what();
Alpana Kumari6bd095f2022-02-23 10:20:20 -0600693 errMsg += "\nGPIO: " + pinName;
694
695 if ((json["frus"][file].at(0)["postActionFail"].find(
696 "gpioI2CAddress")) !=
697 json["frus"][file].at(0)["postActionFail"].end())
698 {
699 i2cBusAddr =
700 json["frus"][file].at(0)["postActionFail"]["gpioI2CAddress"];
Sunny Srivastavafdf9ff22022-06-15 11:15:54 -0500701 errMsg += " i2cBusAddress: " + i2cBusAddr;
Alpana Kumari6bd095f2022-02-23 10:20:20 -0600702 }
703
Sunny Srivastavafdf9ff22022-06-15 11:15:54 -0500704 PelAdditionalData additionalData{};
705 additionalData.emplace("DESCRIPTION", errMsg);
706 createPEL(additionalData, PelSeverity::WARNING, errIntfForGpioError);
Alpana Kumari735dee92022-03-25 01:24:40 -0500707 }
Alpana Kumari6bd095f2022-02-23 10:20:20 -0600708
709 return;
Alpana Kumari735dee92022-03-25 01:24:40 -0500710}
711
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500712std::optional<bool> isPresent(const nlohmann::json& json,
713 const std::string& file)
Santosh Puranik53b38ed2022-04-10 23:15:22 +0530714
Alpana Kumari735dee92022-03-25 01:24:40 -0500715{
716 if ((json["frus"][file].at(0)).find("presence") !=
717 json["frus"][file].at(0).end())
718 {
719 if (((json["frus"][file].at(0)["presence"]).find("pin") !=
720 json["frus"][file].at(0)["presence"].end()) &&
721 ((json["frus"][file].at(0)["presence"]).find("value") !=
722 json["frus"][file].at(0)["presence"].end()))
723 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500724 std::string presPinName =
725 json["frus"][file].at(0)["presence"]["pin"];
Alpana Kumari735dee92022-03-25 01:24:40 -0500726 Byte presPinValue = json["frus"][file].at(0)["presence"]["value"];
727
728 try
729 {
730 gpiod::line presenceLine = gpiod::find_line(presPinName);
731
732 if (!presenceLine)
733 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500734 std::cerr << "Couldn't find the presence line for - "
735 << presPinName << std::endl;
Alpana Kumari40d1c192022-03-09 21:16:02 -0600736
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500737 throw std::runtime_error(
Alpana Kumari6bd095f2022-02-23 10:20:20 -0600738 "Couldn't find the presence line for the "
739 "GPIO. Skipping this GPIO action.");
Alpana Kumari735dee92022-03-25 01:24:40 -0500740 }
741
742 presenceLine.request({"Read the presence line",
743 gpiod::line_request::DIRECTION_INPUT, 0});
744
745 Byte gpioData = presenceLine.get_value();
746
Santosh Puranik53b38ed2022-04-10 23:15:22 +0530747 return (gpioData == presPinValue);
Alpana Kumari735dee92022-03-25 01:24:40 -0500748 }
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500749 catch (const std::exception& e)
Alpana Kumari735dee92022-03-25 01:24:40 -0500750 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500751 std::string i2cBusAddr;
752 std::string errMsg = e.what();
Alpana Kumari6bd095f2022-02-23 10:20:20 -0600753 errMsg += " GPIO : " + presPinName;
754
755 if ((json["frus"][file].at(0)["presence"])
756 .find("gpioI2CAddress") !=
757 json["frus"][file].at(0)["presence"].end())
758 {
759 i2cBusAddr =
760 json["frus"][file].at(0)["presence"]["gpioI2CAddress"];
Sunny Srivastavafdf9ff22022-06-15 11:15:54 -0500761 errMsg += " i2cBusAddress: " + i2cBusAddr;
Alpana Kumari6bd095f2022-02-23 10:20:20 -0600762 }
763
Sunny Srivastavafdf9ff22022-06-15 11:15:54 -0500764 PelAdditionalData additionalData{};
765 additionalData.emplace("DESCRIPTION", errMsg);
766 createPEL(additionalData, PelSeverity::WARNING,
767 errIntfForGpioError);
768
Alpana Kumari40d1c192022-03-09 21:16:02 -0600769 // Take failure postAction
770 executePostFailAction(json, file);
Alpana Kumari735dee92022-03-25 01:24:40 -0500771 return false;
772 }
773 }
Alpana Kumari40d1c192022-03-09 21:16:02 -0600774 else
775 {
776 // missing required informations
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500777 std::cerr
778 << "VPD inventory JSON missing basic informations of presence "
779 "for this FRU : ["
780 << file << "]. Executing executePostFailAction." << std::endl;
Alpana Kumari40d1c192022-03-09 21:16:02 -0600781
782 // Take failure postAction
783 executePostFailAction(json, file);
784
785 return false;
786 }
Alpana Kumari735dee92022-03-25 01:24:40 -0500787 }
Santosh Puranik53b38ed2022-04-10 23:15:22 +0530788 return std::optional<bool>{};
789}
790
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500791bool executePreAction(const nlohmann::json& json, const std::string& file)
Santosh Puranik53b38ed2022-04-10 23:15:22 +0530792{
793 auto present = isPresent(json, file);
794 if (present && !present.value())
795 {
796 executePostFailAction(json, file);
797 return false;
798 }
Alpana Kumari735dee92022-03-25 01:24:40 -0500799
800 if ((json["frus"][file].at(0)).find("preAction") !=
801 json["frus"][file].at(0).end())
802 {
803 if (((json["frus"][file].at(0)["preAction"]).find("pin") !=
804 json["frus"][file].at(0)["preAction"].end()) &&
805 ((json["frus"][file].at(0)["preAction"]).find("value") !=
806 json["frus"][file].at(0)["preAction"].end()))
807 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500808 std::string pinName = json["frus"][file].at(0)["preAction"]["pin"];
Alpana Kumari735dee92022-03-25 01:24:40 -0500809 // Get the value to set
810 Byte pinValue = json["frus"][file].at(0)["preAction"]["value"];
811
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500812 std::cout << "Setting GPIO: " << pinName << " to " << (int)pinValue
813 << std::endl;
Alpana Kumari735dee92022-03-25 01:24:40 -0500814 try
815 {
816 gpiod::line outputLine = gpiod::find_line(pinName);
817
818 if (!outputLine)
819 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500820 std::cerr << "Couldn't find the line for output pin - "
821 << pinName << std::endl;
822 throw std::runtime_error(
Alpana Kumari6bd095f2022-02-23 10:20:20 -0600823 "Couldn't find output line for the GPIO. "
824 "Skipping this GPIO action.");
Alpana Kumari735dee92022-03-25 01:24:40 -0500825 }
826 outputLine.request({"FRU pre-action",
827 ::gpiod::line_request::DIRECTION_OUTPUT, 0},
828 pinValue);
829 }
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500830 catch (const std::exception& e)
Alpana Kumari735dee92022-03-25 01:24:40 -0500831 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500832 std::string i2cBusAddr;
833 std::string errMsg = e.what();
Alpana Kumari6bd095f2022-02-23 10:20:20 -0600834 errMsg += " GPIO : " + pinName;
835
836 if ((json["frus"][file].at(0)["preAction"])
837 .find("gpioI2CAddress") !=
838 json["frus"][file].at(0)["preAction"].end())
839 {
840 i2cBusAddr =
841 json["frus"][file].at(0)["preAction"]["gpioI2CAddress"];
Sunny Srivastavafdf9ff22022-06-15 11:15:54 -0500842 errMsg += " i2cBusAddress: " + i2cBusAddr;
Alpana Kumari6bd095f2022-02-23 10:20:20 -0600843 }
844
Sunny Srivastavafdf9ff22022-06-15 11:15:54 -0500845 PelAdditionalData additionalData{};
846 additionalData.emplace("DESCRIPTION", errMsg);
847 createPEL(additionalData, PelSeverity::WARNING,
848 errIntfForGpioError);
Alpana Kumari40d1c192022-03-09 21:16:02 -0600849
850 // Take failure postAction
851 executePostFailAction(json, file);
852
Alpana Kumari735dee92022-03-25 01:24:40 -0500853 return false;
854 }
855 }
Alpana Kumari40d1c192022-03-09 21:16:02 -0600856 else
857 {
858 // missing required informations
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500859 std::cerr
Alpana Kumari40d1c192022-03-09 21:16:02 -0600860 << "VPD inventory JSON missing basic informations of preAction "
861 "for this FRU : ["
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500862 << file << "]. Executing executePostFailAction." << std::endl;
Alpana Kumari40d1c192022-03-09 21:16:02 -0600863
864 // Take failure postAction
865 executePostFailAction(json, file);
866
867 return false;
868 }
Alpana Kumari735dee92022-03-25 01:24:40 -0500869 }
870 return true;
871}
872
Priyanga Ramasamyaa8a8932022-01-27 09:12:41 -0600873void insertOrMerge(inventory::InterfaceMap& map,
874 const inventory::Interface& interface,
875 inventory::PropertyMap&& property)
876{
877 if (map.find(interface) != map.end())
878 {
879 auto& prop = map.at(interface);
880 prop.insert(property.begin(), property.end());
881 }
882 else
883 {
884 map.emplace(interface, property);
885 }
886}
Santosh Puranikf2d3b532022-04-19 06:44:07 -0500887
888BIOSAttrValueType readBIOSAttribute(const std::string& attrName)
889{
890 std::tuple<std::string, BIOSAttrValueType, BIOSAttrValueType> attrVal;
891 auto bus = sdbusplus::bus::new_default();
892 auto method = bus.new_method_call(
893 "xyz.openbmc_project.BIOSConfigManager",
894 "/xyz/openbmc_project/bios_config/manager",
895 "xyz.openbmc_project.BIOSConfig.Manager", "GetAttribute");
896 method.append(attrName);
897 try
898 {
899 auto result = bus.call(method);
900 result.read(std::get<0>(attrVal), std::get<1>(attrVal),
901 std::get<2>(attrVal));
902 }
903 catch (const sdbusplus::exception::SdBusError& e)
904 {
905 std::cerr << "Failed to read BIOS Attribute: " << attrName << std::endl;
906 std::cerr << e.what() << std::endl;
907 }
908 return std::get<1>(attrVal);
909}
Priyanga Ramasamy335873f2022-05-18 01:31:54 -0500910
911std::string getPowerState()
912{
913 // TODO: How do we handle multiple chassis?
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500914 std::string powerState{};
Priyanga Ramasamy335873f2022-05-18 01:31:54 -0500915 auto bus = sdbusplus::bus::new_default();
916 auto properties =
917 bus.new_method_call("xyz.openbmc_project.State.Chassis",
918 "/xyz/openbmc_project/state/chassis0",
919 "org.freedesktop.DBus.Properties", "Get");
920 properties.append("xyz.openbmc_project.State.Chassis");
921 properties.append("CurrentPowerState");
922 auto result = bus.call(properties);
923 if (!result.is_method_error())
924 {
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500925 std::variant<std::string> val;
Priyanga Ramasamy335873f2022-05-18 01:31:54 -0500926 result.read(val);
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500927 if (auto pVal = std::get_if<std::string>(&val))
Priyanga Ramasamy335873f2022-05-18 01:31:54 -0500928 {
929 powerState = *pVal;
930 }
931 }
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500932 std::cout << "Power state is: " << powerState << std::endl;
Priyanga Ramasamy335873f2022-05-18 01:31:54 -0500933 return powerState;
934}
Santosh Puranik6b2b5372022-06-02 20:49:02 +0530935
936Binary getVpdDataInVector(const nlohmann::json& js, const std::string& file)
937{
938 uint32_t offset = 0;
939 // check if offset present?
940 for (const auto& item : js["frus"][file])
941 {
942 if (item.find("offset") != item.end())
943 {
944 offset = item["offset"];
945 }
946 }
947
948 // TODO: Figure out a better way to get max possible VPD size.
949 auto maxVPDSize = std::min(std::filesystem::file_size(file),
950 static_cast<uintmax_t>(65504));
951
952 Binary vpdVector;
953 vpdVector.resize(maxVPDSize);
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500954 std::ifstream vpdFile;
955 vpdFile.open(file, std::ios::binary);
Santosh Puranik6b2b5372022-06-02 20:49:02 +0530956
Priyanga Ramasamye0084322022-09-27 06:28:33 -0500957 vpdFile.seekg(offset, std::ios_base::cur);
Santosh Puranik6b2b5372022-06-02 20:49:02 +0530958 vpdFile.read(reinterpret_cast<char*>(&vpdVector[0]), maxVPDSize);
959 vpdVector.resize(vpdFile.gcount());
960
961 // Make sure we reset the EEPROM pointer to a "safe" location if it was DIMM
962 // SPD that we just read.
963 for (const auto& item : js["frus"][file])
964 {
965 if (item.find("extraInterfaces") != item.end())
966 {
967 if (item["extraInterfaces"].find(
968 "xyz.openbmc_project.Inventory.Item.Dimm") !=
969 item["extraInterfaces"].end())
970 {
971 // moves the EEPROM pointer to 2048 'th byte.
972 vpdFile.seekg(2047, std::ios::beg);
973 // Read that byte and discard - to affirm the move
974 // operation.
975 char ch;
976 vpdFile.read(&ch, sizeof(ch));
977 break;
978 }
979 }
980 }
981
982 return vpdVector;
983}
Patrick Venturec83c4dc2018-11-01 16:29:18 -0700984} // namespace vpd
Alpana Kumari735dee92022-03-25 01:24:40 -0500985} // namespace openpower