blob: ba033189d05f1ef156c273de9afa7ca7f1475f13 [file] [log] [blame]
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301#include "config.h"
2
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -05003#include "common_utility.hpp"
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05304#include "defines.hpp"
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -05005#include "ibm_vpd_utils.hpp"
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05006#include "ipz_parser.hpp"
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05307#include "keyword_vpd_parser.hpp"
Alpana Kumaria00936f2020-04-14 07:15:46 -05008#include "memory_vpd_parser.hpp"
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05009#include "parser_factory.hpp"
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -050010#include "vpd_exceptions.hpp"
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053011
SunnySrivastava19849094d4f2020-08-05 09:32:29 -050012#include <assert.h>
Alpana Kumari8ea3f6d2020-04-02 00:26:07 -050013#include <ctype.h>
14
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053015#include <CLI/CLI.hpp>
Santosh Puranik88edeb62020-03-02 12:00:09 +053016#include <algorithm>
alpana077ce68722021-07-25 13:23:59 -050017#include <boost/algorithm/string.hpp>
Alpana Kumari65b83602020-09-01 00:24:56 -050018#include <cstdarg>
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053019#include <exception>
PriyangaRamasamy83a1d5d2020-04-30 19:15:43 +053020#include <filesystem>
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053021#include <fstream>
Alpana Kumari2f793042020-08-18 05:51:03 -050022#include <gpiod.hpp>
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053023#include <iostream>
24#include <iterator>
25#include <nlohmann/json.hpp>
Andrew Geissler280197e2020-12-08 20:51:49 -060026#include <phosphor-logging/log.hpp>
alpana077ce68722021-07-25 13:23:59 -050027#include <regex>
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053028
29using namespace std;
30using namespace openpower::vpd;
31using namespace CLI;
32using namespace vpd::keyword::parser;
PriyangaRamasamy83a1d5d2020-04-30 19:15:43 +053033using namespace openpower::vpd::constants;
34namespace fs = filesystem;
35using json = nlohmann::json;
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050036using namespace openpower::vpd::parser::factory;
SunnySrivastava1984945a02d2020-05-06 01:55:41 -050037using namespace openpower::vpd::inventory;
Alpana Kumaria00936f2020-04-14 07:15:46 -050038using namespace openpower::vpd::memory::parser;
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050039using namespace openpower::vpd::parser::interface;
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -050040using namespace openpower::vpd::exceptions;
Andrew Geissler280197e2020-12-08 20:51:49 -060041using namespace phosphor::logging;
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053042
Sunny Srivastava3c244142022-01-11 08:47:04 -060043// Map to hold record, kwd pair which can be re-stored at standby.
44// The list of keywords for VSYS record is as per the S0 system. Should
45// be updated for another type of systems
46static const std::unordered_map<std::string, std::vector<std::string>>
Sunny Srivastava01e6c632022-02-28 03:38:46 -060047 svpdKwdMap{{"VSYS", {"BR", "TM", "SE", "SU", "RB", "WN"}},
Sunny Srivastava3c244142022-01-11 08:47:04 -060048 {"VCEN", {"FC", "SE"}},
49 {"LXR0", {"LX"}}};
50
Santosh Puranik88edeb62020-03-02 12:00:09 +053051/**
Santosh Puranik85893752020-11-10 21:31:43 +053052 * @brief Returns the power state for chassis0
53 */
54static auto getPowerState()
55{
56 // TODO: How do we handle multiple chassis?
57 string powerState{};
58 auto bus = sdbusplus::bus::new_default();
59 auto properties =
60 bus.new_method_call("xyz.openbmc_project.State.Chassis",
61 "/xyz/openbmc_project/state/chassis0",
62 "org.freedesktop.DBus.Properties", "Get");
63 properties.append("xyz.openbmc_project.State.Chassis");
64 properties.append("CurrentPowerState");
65 auto result = bus.call(properties);
66 if (!result.is_method_error())
67 {
68 variant<string> val;
69 result.read(val);
70 if (auto pVal = get_if<string>(&val))
71 {
72 powerState = *pVal;
73 }
74 }
75 cout << "Power state is: " << powerState << endl;
76 return powerState;
77}
78
79/**
Santosh Puranike9c57532022-03-15 16:51:51 +053080 * @brief Returns the BMC state
81 */
82static auto getBMCState()
83{
84 std::string bmcState;
85 try
86 {
87 auto bus = sdbusplus::bus::new_default();
88 auto properties = bus.new_method_call(
89 "xyz.openbmc_project.State.BMC", "/xyz/openbmc_project/state/bmc0",
90 "org.freedesktop.DBus.Properties", "Get");
91 properties.append("xyz.openbmc_project.State.BMC");
92 properties.append("CurrentBMCState");
93 auto result = bus.call(properties);
94 std::variant<std::string> val;
95 result.read(val);
96 if (auto pVal = std::get_if<std::string>(&val))
97 {
98 bmcState = *pVal;
99 }
100 }
101 catch (const sdbusplus::exception::SdBusError& e)
102 {
103 // Ignore any error
104 std::cerr << "Failed to get BMC state: " << e.what() << "\n";
105 }
106 return bmcState;
107}
108
109/**
110 * @brief Check if the FRU is in the cache
111 *
112 * Checks if the FRU associated with the supplied D-Bus object path is already
113 * on D-Bus. This can be used to test if a VPD collection is required for this
114 * FRU. It uses the "xyz.openbmc_project.Inventory.Item, Present" property to
115 * determine the presence of a FRU in the cache.
116 *
117 * @param objectPath - The D-Bus object path without the PIM prefix.
118 * @return true if the object exists on D-Bus, false otherwise.
119 */
120static auto isFruInVpdCache(const std::string& objectPath)
121{
122 try
123 {
124 auto bus = sdbusplus::bus::new_default();
125 auto invPath = std::string{pimPath} + objectPath;
126 auto props = bus.new_method_call(
127 "xyz.openbmc_project.Inventory.Manager", invPath.c_str(),
128 "org.freedesktop.DBus.Properties", "Get");
129 props.append("xyz.openbmc_project.Inventory.Item");
130 props.append("Present");
131 auto result = bus.call(props);
132 std::variant<bool> present;
133 result.read(present);
134 if (auto pVal = std::get_if<bool>(&present))
135 {
136 return *pVal;
137 }
138 return false;
139 }
140 catch (const sdbusplus::exception::SdBusError& e)
141 {
142 std::cout << "FRU: " << objectPath << " not in D-Bus\n";
143 // Assume not present in case of an error
144 return false;
145 }
146}
147
148/**
149 * @brief Check if VPD recollection is needed for the given EEPROM
150 *
151 * Not all FRUs can be swapped at BMC ready state. This function does the
152 * following:
153 * -- Check if the FRU is marked as "pluggableAtStandby" OR
154 * "concurrentlyMaintainable". If so, return true.
155 * -- Check if we are at BMC NotReady state. If we are, then return true.
156 * -- Else check if the FRU is not present in the VPD cache (to cover for VPD
157 * force collection). If not found in the cache, return true.
158 * -- Else return false.
159 *
160 * @param js - JSON Object.
161 * @param filePath - The EEPROM file.
162 * @return true if collection should be attempted, false otherwise.
163 */
164static auto needsRecollection(const nlohmann::json& js, const string& filePath)
165{
166 if (js["frus"][filePath].at(0).value("pluggableAtStandby", false) ||
167 js["frus"][filePath].at(0).value("concurrentlyMaintainable", false))
168 {
169 return true;
170 }
171 if (getBMCState() == "xyz.openbmc_project.State.BMC.BMCState.NotReady")
172 {
173 return true;
174 }
175 if (!isFruInVpdCache(js["frus"][filePath].at(0).value("inventoryPath", "")))
176 {
177 return true;
178 }
179 return false;
180}
181
182/**
Santosh Puranik88edeb62020-03-02 12:00:09 +0530183 * @brief Expands location codes
184 */
185static auto expandLocationCode(const string& unexpanded, const Parsed& vpdMap,
186 bool isSystemVpd)
187{
188 auto expanded{unexpanded};
189 static constexpr auto SYSTEM_OBJECT = "/system/chassis/motherboard";
190 static constexpr auto VCEN_IF = "com.ibm.ipzvpd.VCEN";
191 static constexpr auto VSYS_IF = "com.ibm.ipzvpd.VSYS";
192 size_t idx = expanded.find("fcs");
193 try
194 {
195 if (idx != string::npos)
196 {
197 string fc{};
198 string se{};
199 if (isSystemVpd)
200 {
201 const auto& fcData = vpdMap.at("VCEN").at("FC");
202 const auto& seData = vpdMap.at("VCEN").at("SE");
203 fc = string(fcData.data(), fcData.size());
204 se = string(seData.data(), seData.size());
205 }
206 else
207 {
208 fc = readBusProperty(SYSTEM_OBJECT, VCEN_IF, "FC");
209 se = readBusProperty(SYSTEM_OBJECT, VCEN_IF, "SE");
210 }
211
Alpana Kumari81671f62021-02-10 02:21:59 -0600212 // TODO: See if ND0 can be placed in the JSON
213 expanded.replace(idx, 3, fc.substr(0, 4) + ".ND0." + se);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530214 }
215 else
216 {
217 idx = expanded.find("mts");
218 if (idx != string::npos)
219 {
220 string mt{};
221 string se{};
222 if (isSystemVpd)
223 {
224 const auto& mtData = vpdMap.at("VSYS").at("TM");
225 const auto& seData = vpdMap.at("VSYS").at("SE");
226 mt = string(mtData.data(), mtData.size());
227 se = string(seData.data(), seData.size());
228 }
229 else
230 {
231 mt = readBusProperty(SYSTEM_OBJECT, VSYS_IF, "TM");
232 se = readBusProperty(SYSTEM_OBJECT, VSYS_IF, "SE");
233 }
234
235 replace(mt.begin(), mt.end(), '-', '.');
236 expanded.replace(idx, 3, mt + "." + se);
237 }
238 }
239 }
Patrick Williams8e15b932021-10-06 13:04:22 -0500240 catch (const exception& e)
Santosh Puranik88edeb62020-03-02 12:00:09 +0530241 {
Alpana Kumari58e22142020-05-05 00:22:12 -0500242 cerr << "Failed to expand location code with exception: " << e.what()
243 << "\n";
Santosh Puranik88edeb62020-03-02 12:00:09 +0530244 }
245 return expanded;
246}
Alpana Kumari2f793042020-08-18 05:51:03 -0500247
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530248/**
249 * @brief Populate FRU specific interfaces.
250 *
251 * This is a common method which handles both
252 * ipz and keyword specific interfaces thus,
253 * reducing the code redundancy.
254 * @param[in] map - Reference to the innermost keyword-value map.
255 * @param[in] preIntrStr - Reference to the interface string.
256 * @param[out] interfaces - Reference to interface map.
257 */
258template <typename T>
259static void populateFruSpecificInterfaces(const T& map,
260 const string& preIntrStr,
261 inventory::InterfaceMap& interfaces)
262{
263 inventory::PropertyMap prop;
264
265 for (const auto& kwVal : map)
266 {
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530267 auto kw = kwVal.first;
268
269 if (kw[0] == '#')
270 {
Alpana Kumari58e22142020-05-05 00:22:12 -0500271 kw = string("PD_") + kw[1];
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530272 }
Alpana Kumari8ea3f6d2020-04-02 00:26:07 -0500273 else if (isdigit(kw[0]))
274 {
Alpana Kumari58e22142020-05-05 00:22:12 -0500275 kw = string("N_") + kw;
Alpana Kumari8ea3f6d2020-04-02 00:26:07 -0500276 }
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000277 if constexpr (is_same<T, KeywordVpdMap>::value)
278 {
279 if (get_if<Binary>(&kwVal.second))
280 {
281 Binary vec(get_if<Binary>(&kwVal.second)->begin(),
282 get_if<Binary>(&kwVal.second)->end());
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000283 prop.emplace(move(kw), move(vec));
284 }
285 else
286 {
287 if (kw == "MemorySizeInKB")
288 {
289 inventory::PropertyMap memProp;
290 auto memVal = get_if<size_t>(&kwVal.second);
291 if (memVal)
292 {
293 memProp.emplace(move(kw),
294 ((*memVal) * CONVERT_MB_TO_KB));
295 interfaces.emplace(
296 "xyz.openbmc_project.Inventory.Item.Dimm",
297 move(memProp));
298 }
299 else
300 {
301 cerr << "MemorySizeInKB value not found in vpd map\n";
302 }
303 }
304 }
305 }
306 else
307 {
308 Binary vec(kwVal.second.begin(), kwVal.second.end());
309 prop.emplace(move(kw), move(vec));
310 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530311 }
312
313 interfaces.emplace(preIntrStr, move(prop));
314}
315
316/**
317 * @brief Populate Interfaces.
318 *
319 * This method populates common and extra interfaces to dbus.
320 * @param[in] js - json object
321 * @param[out] interfaces - Reference to interface map
322 * @param[in] vpdMap - Reference to the parsed vpd map.
Santosh Puranik88edeb62020-03-02 12:00:09 +0530323 * @param[in] isSystemVpd - Denotes whether we are collecting the system VPD.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530324 */
325template <typename T>
326static void populateInterfaces(const nlohmann::json& js,
327 inventory::InterfaceMap& interfaces,
Santosh Puranik88edeb62020-03-02 12:00:09 +0530328 const T& vpdMap, bool isSystemVpd)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530329{
330 for (const auto& ifs : js.items())
331 {
Santosh Puranik88edeb62020-03-02 12:00:09 +0530332 string inf = ifs.key();
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530333 inventory::PropertyMap props;
334
335 for (const auto& itr : ifs.value().items())
336 {
Santosh Puranik88edeb62020-03-02 12:00:09 +0530337 const string& busProp = itr.key();
338
Alpana Kumari31970de2020-02-17 06:49:57 -0600339 if (itr.value().is_boolean())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530340 {
Santosh Puranik88edeb62020-03-02 12:00:09 +0530341 props.emplace(busProp, itr.value().get<bool>());
342 }
343 else if (itr.value().is_string())
344 {
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600345 if (busProp == "LocationCode" && inf == IBM_LOCATION_CODE_INF)
Santosh Puranik88edeb62020-03-02 12:00:09 +0530346 {
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600347 std::string prop;
348 if constexpr (is_same<T, Parsed>::value)
Santosh Puranik88edeb62020-03-02 12:00:09 +0530349 {
Alpana Kumari414d5ae2021-03-04 21:06:35 +0000350 // TODO deprecate the com.ibm interface later
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600351 prop = expandLocationCode(itr.value().get<string>(),
352 vpdMap, isSystemVpd);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530353 }
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600354 else if constexpr (is_same<T, KeywordVpdMap>::value)
Santosh Puranik88edeb62020-03-02 12:00:09 +0530355 {
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600356 // Send empty Parsed object to expandLocationCode api.
357 prop = expandLocationCode(itr.value().get<string>(),
358 Parsed{}, false);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530359 }
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600360 props.emplace(busProp, prop);
361 interfaces.emplace(XYZ_LOCATION_CODE_INF, props);
362 interfaces.emplace(IBM_LOCATION_CODE_INF, props);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530363 }
364 else
365 {
366 props.emplace(busProp, itr.value().get<string>());
367 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530368 }
Santosh Puraniked609af2021-06-21 11:30:07 +0530369 else if (itr.value().is_array())
370 {
371 try
372 {
373 props.emplace(busProp, itr.value().get<Binary>());
374 }
Patrick Williams8e15b932021-10-06 13:04:22 -0500375 catch (const nlohmann::detail::type_error& e)
Santosh Puraniked609af2021-06-21 11:30:07 +0530376 {
377 std::cerr << "Type exception: " << e.what() << "\n";
378 // Ignore any type errors
379 }
380 }
Alpana Kumari31970de2020-02-17 06:49:57 -0600381 else if (itr.value().is_object())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530382 {
Alpana Kumari31970de2020-02-17 06:49:57 -0600383 const string& rec = itr.value().value("recordName", "");
384 const string& kw = itr.value().value("keywordName", "");
385 const string& encoding = itr.value().value("encoding", "");
386
Alpana Kumari58e22142020-05-05 00:22:12 -0500387 if constexpr (is_same<T, Parsed>::value)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530388 {
Santosh Puranik88edeb62020-03-02 12:00:09 +0530389 if (!rec.empty() && !kw.empty() && vpdMap.count(rec) &&
390 vpdMap.at(rec).count(kw))
Alpana Kumari31970de2020-02-17 06:49:57 -0600391 {
392 auto encoded =
393 encodeKeyword(vpdMap.at(rec).at(kw), encoding);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530394 props.emplace(busProp, encoded);
Alpana Kumari31970de2020-02-17 06:49:57 -0600395 }
396 }
Alpana Kumari58e22142020-05-05 00:22:12 -0500397 else if constexpr (is_same<T, KeywordVpdMap>::value)
Alpana Kumari31970de2020-02-17 06:49:57 -0600398 {
399 if (!kw.empty() && vpdMap.count(kw))
400 {
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000401 auto kwValue = get_if<Binary>(&vpdMap.at(kw));
402 auto uintValue = get_if<size_t>(&vpdMap.at(kw));
403
404 if (kwValue)
405 {
406 auto prop =
407 string((*kwValue).begin(), (*kwValue).end());
408
409 auto encoded = encodeKeyword(prop, encoding);
410
411 props.emplace(busProp, encoded);
412 }
413 else if (uintValue)
414 {
415 props.emplace(busProp, *uintValue);
416 }
Alpana Kumari31970de2020-02-17 06:49:57 -0600417 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530418 }
419 }
Matt Spinlerb1e64bb2021-09-08 09:57:48 -0500420 else if (itr.value().is_number())
421 {
422 // For now assume the value is a size_t. In the future it would
423 // be nice to come up with a way to get the type from the JSON.
424 props.emplace(busProp, itr.value().get<size_t>());
425 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530426 }
Priyanga Ramasamyaa8a8932022-01-27 09:12:41 -0600427 insertOrMerge(interfaces, inf, move(props));
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530428 }
429}
430
Priyanga Ramasamy37233782021-12-09 03:14:02 -0600431/*API to reset EEPROM pointer to a safe position to avoid VPD corruption.
432 * Currently do reset only for DIMM VPD.*/
433static void resetEEPROMPointer(const nlohmann::json& js, const string& file,
434 ifstream& vpdFile)
435{
436 for (const auto& item : js["frus"][file])
437 {
438 if (item.find("extraInterfaces") != item.end())
439 {
440 if (item["extraInterfaces"].find(
441 "xyz.openbmc_project.Inventory.Item.Dimm") !=
442 item["extraInterfaces"].end())
443 {
444 // moves the EEPROM pointer to 2048 'th byte.
445 vpdFile.seekg(2047, std::ios::beg);
446 // Read that byte and discard - to affirm the move
447 // operation.
448 char ch;
449 vpdFile.read(&ch, sizeof(ch));
450 }
451 return;
452 }
453 }
454}
455
alpana075cb3b1f2021-12-16 11:19:36 -0600456/**
457 * @brief This API checks if this FRU is pcie_devices. If yes then it further
458 * checks whether it is PASS1 planar.
459 */
460static bool isThisPcieOnPass1planar(const nlohmann::json& js,
461 const string& file)
462{
463 auto isThisPCIeDev = false;
464 auto isPASS1 = false;
465
466 // Check if it is a PCIE device
467 if (js["frus"].find(file) != js["frus"].end())
468 {
Santosh Puranikc03f3902022-04-14 10:58:26 +0530469 if ((js["frus"][file].at(0).find("extraInterfaces") !=
470 js["frus"][file].at(0).end()))
alpana075cb3b1f2021-12-16 11:19:36 -0600471 {
Santosh Puranikc03f3902022-04-14 10:58:26 +0530472 if (js["frus"][file].at(0)["extraInterfaces"].find(
alpana075cb3b1f2021-12-16 11:19:36 -0600473 "xyz.openbmc_project.Inventory.Item.PCIeDevice") !=
Santosh Puranikc03f3902022-04-14 10:58:26 +0530474 js["frus"][file].at(0)["extraInterfaces"].end())
alpana075cb3b1f2021-12-16 11:19:36 -0600475 {
476 isThisPCIeDev = true;
477 }
478 }
479 }
480
481 if (isThisPCIeDev)
482 {
483 // Collect SystemType to know if it is PASS1 planar.
484 auto bus = sdbusplus::bus::new_default();
485 auto properties = bus.new_method_call(
486 INVENTORY_MANAGER_SERVICE,
487 "/xyz/openbmc_project/inventory/system/chassis/motherboard",
488 "org.freedesktop.DBus.Properties", "Get");
489 properties.append("com.ibm.ipzvpd.VINI");
490 properties.append("HW");
491 auto result = bus.call(properties);
492
493 inventory::Value val;
494 result.read(val);
495 if (auto pVal = get_if<Binary>(&val))
496 {
497 auto hwVersion = *pVal;
498 if (hwVersion[1] < 2)
499 isPASS1 = true;
500 }
501 }
502
503 return (isThisPCIeDev && isPASS1);
504}
505
Alpana Kumari2f793042020-08-18 05:51:03 -0500506static Binary getVpdDataInVector(const nlohmann::json& js, const string& file)
Alpana Kumari58e22142020-05-05 00:22:12 -0500507{
508 uint32_t offset = 0;
509 // check if offset present?
510 for (const auto& item : js["frus"][file])
511 {
512 if (item.find("offset") != item.end())
513 {
514 offset = item["offset"];
515 }
516 }
517
518 // TODO: Figure out a better way to get max possible VPD size.
Priyanga Ramasamy3c2a2b92021-12-22 00:09:38 -0600519 auto maxVPDSize = std::min(std::filesystem::file_size(file),
520 static_cast<uintmax_t>(65504));
521
Alpana Kumari58e22142020-05-05 00:22:12 -0500522 Binary vpdVector;
Priyanga Ramasamy3c2a2b92021-12-22 00:09:38 -0600523 vpdVector.resize(maxVPDSize);
Alpana Kumari58e22142020-05-05 00:22:12 -0500524 ifstream vpdFile;
525 vpdFile.open(file, ios::binary);
526
527 vpdFile.seekg(offset, ios_base::cur);
Priyanga Ramasamy3c2a2b92021-12-22 00:09:38 -0600528 vpdFile.read(reinterpret_cast<char*>(&vpdVector[0]), maxVPDSize);
Alpana Kumari58e22142020-05-05 00:22:12 -0500529 vpdVector.resize(vpdFile.gcount());
530
Priyanga Ramasamy37233782021-12-09 03:14:02 -0600531 resetEEPROMPointer(js, file, vpdFile);
532
Alpana Kumari58e22142020-05-05 00:22:12 -0500533 return vpdVector;
534}
535
Alpana Kumari735dee92022-03-25 01:24:40 -0500536/** Performs any pre-action needed to get the FRU setup for collection.
Alpana Kumari2f793042020-08-18 05:51:03 -0500537 *
538 * @param[in] json - json object
539 * @param[in] file - eeprom file path
540 */
541static void preAction(const nlohmann::json& json, const string& file)
542{
Alpana Kumari735dee92022-03-25 01:24:40 -0500543 if ((json["frus"][file].at(0)).find("preAction") ==
Alpana Kumari2f793042020-08-18 05:51:03 -0500544 json["frus"][file].at(0).end())
545 {
Alpana Kumari735dee92022-03-25 01:24:40 -0500546 return;
Alpana Kumari2f793042020-08-18 05:51:03 -0500547 }
548
Alpana Kumari735dee92022-03-25 01:24:40 -0500549 if (executePreAction(json, file))
Alpana Kumari2f793042020-08-18 05:51:03 -0500550 {
Alpana Kumari735dee92022-03-25 01:24:40 -0500551 if (json["frus"][file].at(0).find("devAddress") !=
552 json["frus"][file].at(0).end())
Alpana Kumari2f793042020-08-18 05:51:03 -0500553 {
Alpana Kumari735dee92022-03-25 01:24:40 -0500554 // Now bind the device
555 string bind = json["frus"][file].at(0).value("devAddress", "");
556 cout << "Binding device " << bind << endl;
557 string bindCmd = string("echo \"") + bind +
558 string("\" > /sys/bus/i2c/drivers/at24/bind");
559 cout << bindCmd << endl;
560 executeCmd(bindCmd);
561 }
Alpana Kumari2e6c6f72020-12-03 00:10:03 -0600562
Alpana Kumari735dee92022-03-25 01:24:40 -0500563 // Check if device showed up (test for file)
564 if (!fs::exists(file))
565 {
566 cout << "EEPROM " << file << " does not exist. Take failure action"
Alpana Kumari2e6c6f72020-12-03 00:10:03 -0600567 << endl;
Alpana Kumari735dee92022-03-25 01:24:40 -0500568 // If not, then take failure postAction
569 executePostFailAction(json, file);
Alpana Kumari2f793042020-08-18 05:51:03 -0500570 }
571 }
Alpana Kumari2f793042020-08-18 05:51:03 -0500572}
573
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530574/**
Santosh Puranikd3a379a2021-08-23 19:12:59 +0530575 * @brief Set certain one time properties in the inventory
576 * Use this function to insert the Functional and Enabled properties into the
577 * inventory map. This function first checks if the object in question already
578 * has these properties hosted on D-Bus, if the property is already there, it is
579 * not modified, hence the name "one time". If the property is not already
580 * present, it will be added to the map with a suitable default value (true for
581 * Functional and false for Enabled)
582 *
583 * @param[in] object - The inventory D-Bus obejct without the inventory prefix.
584 * @param[inout] interfaces - Reference to a map of inventory interfaces to
585 * which the properties will be attached.
586 */
587static void setOneTimeProperties(const std::string& object,
588 inventory::InterfaceMap& interfaces)
589{
590 auto bus = sdbusplus::bus::new_default();
591 auto objectPath = INVENTORY_PATH + object;
592 auto prop = bus.new_method_call("xyz.openbmc_project.Inventory.Manager",
593 objectPath.c_str(),
594 "org.freedesktop.DBus.Properties", "Get");
595 prop.append("xyz.openbmc_project.State.Decorator.OperationalStatus");
596 prop.append("Functional");
597 try
598 {
599 auto result = bus.call(prop);
600 }
601 catch (const sdbusplus::exception::SdBusError& e)
602 {
603 // Treat as property unavailable
604 inventory::PropertyMap prop;
605 prop.emplace("Functional", true);
606 interfaces.emplace(
607 "xyz.openbmc_project.State.Decorator.OperationalStatus",
608 move(prop));
609 }
610 prop = bus.new_method_call("xyz.openbmc_project.Inventory.Manager",
611 objectPath.c_str(),
612 "org.freedesktop.DBus.Properties", "Get");
613 prop.append("xyz.openbmc_project.Object.Enable");
614 prop.append("Enabled");
615 try
616 {
617 auto result = bus.call(prop);
618 }
619 catch (const sdbusplus::exception::SdBusError& e)
620 {
621 // Treat as property unavailable
622 inventory::PropertyMap prop;
623 prop.emplace("Enabled", false);
624 interfaces.emplace("xyz.openbmc_project.Object.Enable", move(prop));
625 }
626}
627
628/**
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530629 * @brief Prime the Inventory
630 * Prime the inventory by populating only the location code,
631 * type interface and the inventory object for the frus
632 * which are not system vpd fru.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530633 *
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530634 * @param[in] jsObject - Reference to vpd inventory json object
635 * @param[in] vpdMap - Reference to the parsed vpd map
636 *
637 * @returns Map of items in extraInterface.
638 */
639template <typename T>
640inventory::ObjectMap primeInventory(const nlohmann::json& jsObject,
641 const T& vpdMap)
642{
643 inventory::ObjectMap objects;
644
645 for (auto& itemFRUS : jsObject["frus"].items())
646 {
647 for (auto& itemEEPROM : itemFRUS.value())
648 {
Alpana Kumari2e6c6f72020-12-03 00:10:03 -0600649 // Take pre actions if needed
650 if (itemEEPROM.find("preAction") != itemEEPROM.end())
651 {
652 preAction(jsObject, itemFRUS.key());
653 }
654
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530655 inventory::InterfaceMap interfaces;
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530656 inventory::Object object(itemEEPROM.at("inventoryPath"));
657
Santosh Puranik50f60bf2021-05-26 17:55:06 +0530658 if ((itemFRUS.key() != systemVpdFilePath) &&
659 !itemEEPROM.value("noprime", false))
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530660 {
Alpana Kumaricfd7a752021-02-07 23:23:01 -0600661 inventory::PropertyMap presProp;
Priyanga Ramasamye358acb2022-03-21 14:21:50 -0500662
663 // Do not populate Present property for frus whose
664 // synthesized=true. synthesized=true says the fru is owned by
665 // some other component and not by vpd.
666 if (!itemEEPROM.value("synthesized", false))
667 {
668 presProp.emplace("Present", false);
669 interfaces.emplace("xyz.openbmc_project.Inventory.Item",
670 presProp);
671 }
Santosh Puranikd3a379a2021-08-23 19:12:59 +0530672 setOneTimeProperties(object, interfaces);
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530673 if (itemEEPROM.find("extraInterfaces") != itemEEPROM.end())
674 {
675 for (const auto& eI : itemEEPROM["extraInterfaces"].items())
676 {
677 inventory::PropertyMap props;
Alpana Kumari414d5ae2021-03-04 21:06:35 +0000678 if (eI.key() == IBM_LOCATION_CODE_INF)
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530679 {
680 if constexpr (std::is_same<T, Parsed>::value)
681 {
682 for (auto& lC : eI.value().items())
683 {
684 auto propVal = expandLocationCode(
685 lC.value().get<string>(), vpdMap, true);
686
687 props.emplace(move(lC.key()),
688 move(propVal));
Santosh Puranikb0f37492021-06-21 09:42:47 +0530689 interfaces.emplace(XYZ_LOCATION_CODE_INF,
690 props);
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530691 interfaces.emplace(move(eI.key()),
692 move(props));
693 }
694 }
695 }
696 else if (eI.key().find("Inventory.Item.") !=
697 string::npos)
698 {
699 interfaces.emplace(move(eI.key()), move(props));
700 }
Santosh Puranikd3a379a2021-08-23 19:12:59 +0530701 else if (eI.key() ==
702 "xyz.openbmc_project.Inventory.Item")
703 {
704 for (auto& val : eI.value().items())
705 {
706 if (val.key() == "PrettyName")
707 {
708 presProp.emplace(val.key(),
709 val.value().get<string>());
710 }
711 }
712 // Use insert_or_assign here as we may already have
713 // inserted the present property only earlier in
714 // this function under this same interface.
715 interfaces.insert_or_assign(eI.key(),
716 move(presProp));
717 }
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530718 }
719 }
720 objects.emplace(move(object), move(interfaces));
721 }
722 }
723 }
724 return objects;
725}
726
Alpana Kumari65b83602020-09-01 00:24:56 -0500727/**
728 * @brief This API executes command to set environment variable
729 * And then reboot the system
730 * @param[in] key -env key to set new value
731 * @param[in] value -value to set.
732 */
733void setEnvAndReboot(const string& key, const string& value)
734{
735 // set env and reboot and break.
736 executeCmd("/sbin/fw_setenv", key, value);
Andrew Geissler280197e2020-12-08 20:51:49 -0600737 log<level::INFO>("Rebooting BMC to pick up new device tree");
Alpana Kumari65b83602020-09-01 00:24:56 -0500738 // make dbus call to reboot
739 auto bus = sdbusplus::bus::new_default_system();
740 auto method = bus.new_method_call(
741 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
742 "org.freedesktop.systemd1.Manager", "Reboot");
743 bus.call_noreply(method);
744}
745
746/*
747 * @brief This API checks for env var fitconfig.
748 * If not initialised OR updated as per the current system type,
749 * update this env var and reboot the system.
750 *
751 * @param[in] systemType IM kwd in vpd tells about which system type it is.
752 * */
753void setDevTreeEnv(const string& systemType)
754{
Alpana Kumari37e72702021-11-18 11:18:04 -0600755 // Init with default dtb
756 string newDeviceTree = "conf-aspeed-bmc-ibm-rainier-p1.dtb";
Santosh Puranike5f177a2022-01-24 20:14:46 +0530757 static const deviceTreeMap deviceTreeSystemTypeMap = {
758 {RAINIER_2U, "conf-aspeed-bmc-ibm-rainier-p1.dtb"},
759 {RAINIER_2U_V2, "conf-aspeed-bmc-ibm-rainier.dtb"},
760 {RAINIER_4U, "conf-aspeed-bmc-ibm-rainier-4u-p1.dtb"},
761 {RAINIER_4U_V2, "conf-aspeed-bmc-ibm-rainier-4u.dtb"},
762 {RAINIER_1S4U, "conf-aspeed-bmc-ibm-rainier-1s4u.dtb"},
763 {EVEREST, "conf-aspeed-bmc-ibm-everest.dtb"}};
Alpana Kumari65b83602020-09-01 00:24:56 -0500764
765 if (deviceTreeSystemTypeMap.find(systemType) !=
766 deviceTreeSystemTypeMap.end())
767 {
768 newDeviceTree = deviceTreeSystemTypeMap.at(systemType);
769 }
Alpana Kumari37e72702021-11-18 11:18:04 -0600770 else
771 {
772 // System type not supported
Alpana Kumariab1e22c2021-11-24 11:03:38 -0600773 string err = "This System type not found/supported in dtb table " +
774 systemType +
775 ".Please check the HW and IM keywords in the system "
776 "VPD.Breaking...";
777
778 // map to hold additional data in case of logging pel
779 PelAdditionalData additionalData{};
780 additionalData.emplace("DESCRIPTION", err);
781 createPEL(additionalData, PelSeverity::WARNING,
782 errIntfForInvalidSystemType);
783 exit(-1);
Alpana Kumari37e72702021-11-18 11:18:04 -0600784 }
Alpana Kumari65b83602020-09-01 00:24:56 -0500785
786 string readVarValue;
787 bool envVarFound = false;
788
789 vector<string> output = executeCmd("/sbin/fw_printenv");
790 for (const auto& entry : output)
791 {
792 size_t pos = entry.find("=");
793 string key = entry.substr(0, pos);
794 if (key != "fitconfig")
795 {
796 continue;
797 }
798
799 envVarFound = true;
800 if (pos + 1 < entry.size())
801 {
802 readVarValue = entry.substr(pos + 1);
803 if (readVarValue.find(newDeviceTree) != string::npos)
804 {
805 // fitconfig is Updated. No action needed
806 break;
807 }
808 }
809 // set env and reboot and break.
810 setEnvAndReboot(key, newDeviceTree);
811 exit(0);
812 }
813
814 // check If env var Not found
815 if (!envVarFound)
816 {
817 setEnvAndReboot("fitconfig", newDeviceTree);
818 }
819}
820
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530821/**
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500822 * @brief API to call VPD manager to write VPD to EEPROM.
823 * @param[in] Object path.
824 * @param[in] record to be updated.
825 * @param[in] keyword to be updated.
826 * @param[in] keyword data to be updated
827 */
828void updateHardware(const string& objectName, const string& recName,
829 const string& kwdName, const Binary& data)
830{
831 try
832 {
833 auto bus = sdbusplus::bus::new_default();
834 auto properties =
835 bus.new_method_call(BUSNAME, OBJPATH, IFACE, "WriteKeyword");
836 properties.append(
837 static_cast<sdbusplus::message::object_path>(objectName));
838 properties.append(recName);
839 properties.append(kwdName);
840 properties.append(data);
841 bus.call(properties);
842 }
Patrick Williams8be43342021-09-02 09:33:36 -0500843 catch (const sdbusplus::exception::exception& e)
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500844 {
845 std::string what =
846 "VPDManager WriteKeyword api failed for inventory path " +
847 objectName;
848 what += " record " + recName;
849 what += " keyword " + kwdName;
850 what += " with bus error = " + std::string(e.what());
851
852 // map to hold additional data in case of logging pel
853 PelAdditionalData additionalData{};
854 additionalData.emplace("CALLOUT_INVENTORY_PATH", objectName);
855 additionalData.emplace("DESCRIPTION", what);
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500856 createPEL(additionalData, PelSeverity::WARNING, errIntfForBusFailure);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500857 }
858}
859
860/**
Sunny Srivastava3c244142022-01-11 08:47:04 -0600861 * @brief An api to get list of blank system VPD properties.
862 * @param[in] vpdMap - IPZ vpd map.
863 * @param[in] objectPath - Object path for the FRU.
864 * @param[out] blankPropertyList - Properties which are blank in System VPD and
865 * needs to be updated as standby.
866 */
867void getListOfBlankSystemVpd(Parsed& vpdMap, const string& objectPath,
868 std::vector<RestoredEeproms>& blankPropertyList)
869{
870 for (const auto& systemRecKwdPair : svpdKwdMap)
871 {
872 auto it = vpdMap.find(systemRecKwdPair.first);
873
874 // check if record is found in map we got by parser
875 if (it != vpdMap.end())
876 {
877 const auto& kwdListForRecord = systemRecKwdPair.second;
878 for (const auto& keyword : kwdListForRecord)
879 {
880 DbusPropertyMap& kwdValMap = it->second;
881 auto iterator = kwdValMap.find(keyword);
882
883 if (iterator != kwdValMap.end())
884 {
885 string& kwdValue = iterator->second;
886
887 // check bus data
888 const string& recordName = systemRecKwdPair.first;
889 const string& busValue = readBusProperty(
890 objectPath, ipzVpdInf + recordName, keyword);
891
892 if (busValue.find_first_not_of(' ') != string::npos)
893 {
894 if (kwdValue.find_first_not_of(' ') == string::npos)
895 {
896 // implies data is blank on EEPROM but not on cache.
897 // So EEPROM vpd update is required.
898 Binary busData(busValue.begin(), busValue.end());
899
900 blankPropertyList.push_back(std::make_tuple(
901 objectPath, recordName, keyword, busData));
902 }
903 }
904 }
905 }
906 }
907 }
908}
909
910/**
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500911 * @brief API to check if we need to restore system VPD
912 * This functionality is only applicable for IPZ VPD data.
913 * @param[in] vpdMap - IPZ vpd map
914 * @param[in] objectPath - Object path for the FRU
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500915 */
Sunny Srivastava3c244142022-01-11 08:47:04 -0600916void restoreSystemVPD(Parsed& vpdMap, const string& objectPath)
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500917{
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500918 for (const auto& systemRecKwdPair : svpdKwdMap)
919 {
920 auto it = vpdMap.find(systemRecKwdPair.first);
921
922 // check if record is found in map we got by parser
923 if (it != vpdMap.end())
924 {
925 const auto& kwdListForRecord = systemRecKwdPair.second;
926 for (const auto& keyword : kwdListForRecord)
927 {
928 DbusPropertyMap& kwdValMap = it->second;
929 auto iterator = kwdValMap.find(keyword);
930
931 if (iterator != kwdValMap.end())
932 {
933 string& kwdValue = iterator->second;
934
935 // check bus data
936 const string& recordName = systemRecKwdPair.first;
937 const string& busValue = readBusProperty(
938 objectPath, ipzVpdInf + recordName, keyword);
939
940 if (busValue.find_first_not_of(' ') != string::npos)
941 {
942 if (kwdValue.find_first_not_of(' ') != string::npos)
943 {
944 // both the data are present, check for mismatch
945 if (busValue != kwdValue)
946 {
947 string errMsg = "VPD data mismatch on cache "
948 "and hardware for record: ";
949 errMsg += (*it).first;
950 errMsg += " and keyword: ";
951 errMsg += keyword;
952
953 // data mismatch
954 PelAdditionalData additionalData;
955 additionalData.emplace("CALLOUT_INVENTORY_PATH",
956 objectPath);
957
958 additionalData.emplace("DESCRIPTION", errMsg);
959
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500960 createPEL(additionalData, PelSeverity::WARNING,
961 errIntfForInvalidVPD);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500962 }
963 }
964 else
965 {
966 // implies hardware data is blank
967 // update the map
968 Binary busData(busValue.begin(), busValue.end());
969
Sunny Srivastava90a63b92021-05-26 06:30:24 -0500970 // update the map as well, so that cache data is not
971 // updated as blank while populating VPD map on Dbus
972 // in populateDBus Api
973 kwdValue = busValue;
974 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500975 }
976 else if (kwdValue.find_first_not_of(' ') == string::npos)
977 {
978 string errMsg = "VPD is blank on both cache and "
979 "hardware for record: ";
980 errMsg += (*it).first;
981 errMsg += " and keyword: ";
982 errMsg += keyword;
983 errMsg += ". SSR need to update hardware VPD.";
984
985 // both the data are blanks, log PEL
986 PelAdditionalData additionalData;
987 additionalData.emplace("CALLOUT_INVENTORY_PATH",
988 objectPath);
989
990 additionalData.emplace("DESCRIPTION", errMsg);
991
992 // log PEL TODO: Block IPL
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500993 createPEL(additionalData, PelSeverity::ERROR,
994 errIntfForBlankSystemVPD);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500995 continue;
996 }
997 }
998 }
999 }
1000 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001001}
1002
1003/**
alpana077ce68722021-07-25 13:23:59 -05001004 * @brief This checks for is this FRU a processor
1005 * And if yes, then checks for is this primary
1006 *
1007 * @param[in] js- vpd json to get the information about this FRU
1008 * @param[in] filePath- FRU vpd
1009 *
1010 * @return true/false
1011 */
1012bool isThisPrimaryProcessor(nlohmann::json& js, const string& filePath)
1013{
1014 bool isProcessor = false;
1015 bool isPrimary = false;
1016
1017 for (const auto& item : js["frus"][filePath])
1018 {
1019 if (item.find("extraInterfaces") != item.end())
1020 {
1021 for (const auto& eI : item["extraInterfaces"].items())
1022 {
1023 if (eI.key().find("Inventory.Item.Cpu") != string::npos)
1024 {
1025 isProcessor = true;
1026 }
1027 }
1028 }
1029
1030 if (isProcessor)
1031 {
1032 string cpuType = item.value("cpuType", "");
1033 if (cpuType == "primary")
1034 {
1035 isPrimary = true;
1036 }
1037 }
1038 }
1039
1040 return (isProcessor && isPrimary);
1041}
1042
1043/**
1044 * @brief This finds DIMM vpd in vpd json and enables them by binding the device
1045 * driver
1046 * @param[in] js- vpd json to iterate through and take action if it is DIMM
1047 */
1048void doEnableAllDimms(nlohmann::json& js)
1049{
1050 // iterate over each fru
1051 for (const auto& eachFru : js["frus"].items())
1052 {
1053 // skip the driver binding if eeprom already exists
1054 if (fs::exists(eachFru.key()))
1055 {
1056 continue;
1057 }
1058
1059 for (const auto& eachInventory : eachFru.value())
1060 {
1061 if (eachInventory.find("extraInterfaces") != eachInventory.end())
1062 {
1063 for (const auto& eI : eachInventory["extraInterfaces"].items())
1064 {
1065 if (eI.key().find("Inventory.Item.Dimm") != string::npos)
1066 {
1067 string dimmVpd = eachFru.key();
1068 // fetch it from
1069 // "/sys/bus/i2c/drivers/at24/414-0050/eeprom"
1070
1071 regex matchPatern("([0-9]+-[0-9]{4})");
1072 smatch matchFound;
1073 if (regex_search(dimmVpd, matchFound, matchPatern))
1074 {
1075 vector<string> i2cReg;
1076 boost::split(i2cReg, matchFound.str(0),
1077 boost::is_any_of("-"));
1078
1079 // remove 0s from begining
1080 const regex pattern("^0+(?!$)");
1081 for (auto& i : i2cReg)
1082 {
1083 i = regex_replace(i, pattern, "");
1084 }
1085
1086 if (i2cReg.size() == 2)
1087 {
1088 // echo 24c32 0x50 >
1089 // /sys/bus/i2c/devices/i2c-16/new_device
1090 string cmnd = "echo 24c32 0x" + i2cReg[1] +
1091 " > /sys/bus/i2c/devices/i2c-" +
1092 i2cReg[0] + "/new_device";
1093
1094 executeCmd(cmnd);
1095 }
1096 }
1097 }
1098 }
1099 }
1100 }
1101 }
1102}
1103
1104/**
Priyanga Ramasamy6abdeb62022-01-09 23:15:11 -06001105 * @brief Check if the given CPU is an IO only chip.
1106 * The CPU is termed as IO, whose all of the cores are bad and can never be
1107 * used. Those CPU chips can be used for IO purpose like connecting PCIe devices
1108 * etc., The CPU whose every cores are bad, can be identified from the CP00
1109 * record's PG keyword, only if all of the 8 EQs' value equals 0xE7F9FF. (1EQ
1110 * has 4 cores grouped together by sharing its cache memory.)
1111 * @param [in] pgKeyword - PG Keyword of CPU.
1112 * @return true if the given cpu is an IO, false otherwise.
1113 */
1114static bool isCPUIOGoodOnly(const string& pgKeyword)
1115{
1116 const unsigned char io[] = {0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9,
1117 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7,
1118 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF};
1119 // EQ0 index (in PG keyword) starts at 97 (with offset starting from 0).
1120 // Each EQ carries 3 bytes of data. Totally there are 8 EQs. If all EQs'
1121 // value equals 0xE7F9FF, then the cpu has no good cores and its treated as
1122 // IO.
1123 if (memcmp(io, pgKeyword.data() + 97, 24) == 0)
1124 {
1125 return true;
1126 }
1127
1128 // The CPU is not an IO
1129 return false;
1130}
1131
1132/**
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301133 * @brief Populate Dbus.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301134 * This method invokes all the populateInterface functions
1135 * and notifies PIM about dbus object.
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301136 * @param[in] vpdMap - Either IPZ vpd map or Keyword vpd map based on the
1137 * input.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301138 * @param[in] js - Inventory json object
1139 * @param[in] filePath - Path of the vpd file
1140 * @param[in] preIntrStr - Interface string
1141 */
1142template <typename T>
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001143static void populateDbus(T& vpdMap, nlohmann::json& js, const string& filePath)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301144{
1145 inventory::InterfaceMap interfaces;
1146 inventory::ObjectMap objects;
1147 inventory::PropertyMap prop;
Shantappa Teekappanavar6aa54502021-12-09 12:59:56 -06001148 string ccinFromVpd;
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301149
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301150 bool isSystemVpd = (filePath == systemVpdFilePath);
1151 if constexpr (is_same<T, Parsed>::value)
1152 {
Shantappa Teekappanavar6aa54502021-12-09 12:59:56 -06001153 ccinFromVpd = getKwVal(vpdMap, "VINI", "CC");
1154 transform(ccinFromVpd.begin(), ccinFromVpd.end(), ccinFromVpd.begin(),
1155 ::toupper);
1156
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301157 if (isSystemVpd)
1158 {
1159 std::vector<std::string> interfaces = {motherBoardInterface};
1160 // call mapper to check for object path creation
1161 MapperResponse subTree =
1162 getObjectSubtreeForInterfaces(pimPath, 0, interfaces);
1163 string mboardPath =
1164 js["frus"][filePath].at(0).value("inventoryPath", "");
1165
1166 // Attempt system VPD restore if we have a motherboard
1167 // object in the inventory.
1168 if ((subTree.size() != 0) &&
1169 (subTree.find(pimPath + mboardPath) != subTree.end()))
1170 {
Sunny Srivastava3c244142022-01-11 08:47:04 -06001171 restoreSystemVPD(vpdMap, mboardPath);
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301172 }
1173 else
1174 {
1175 log<level::ERR>("No object path found");
1176 }
1177 }
alpana077ce68722021-07-25 13:23:59 -05001178 else
1179 {
1180 // check if it is processor vpd.
1181 auto isPrimaryCpu = isThisPrimaryProcessor(js, filePath);
1182
1183 if (isPrimaryCpu)
1184 {
1185 auto ddVersion = getKwVal(vpdMap, "CRP0", "DD");
1186
1187 auto chipVersion = atoi(ddVersion.substr(1, 2).c_str());
1188
1189 if (chipVersion >= 2)
1190 {
1191 doEnableAllDimms(js);
1192 }
1193 }
1194 }
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301195 }
1196
Priyanga Ramasamy32c687f2022-01-04 23:14:03 -06001197 if (isSystemVpd)
1198 {
1199 string systemJsonName{};
1200 if constexpr (is_same<T, Parsed>::value)
1201 {
1202 // pick the right system json
1203 systemJsonName = getSystemsJson(vpdMap);
1204 }
1205
1206 fs::path target = systemJsonName;
1207 fs::path link = INVENTORY_JSON_SYM_LINK;
1208
1209 // Create the directory for hosting the symlink
1210 fs::create_directories(VPD_FILES_PATH);
1211 // unlink the symlink previously created (if any)
1212 remove(INVENTORY_JSON_SYM_LINK);
1213 // create a new symlink based on the system
1214 fs::create_symlink(target, link);
1215
1216 // Reloading the json
1217 ifstream inventoryJson(link);
1218 js = json::parse(inventoryJson);
1219 inventoryJson.close();
1220 }
1221
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301222 for (const auto& item : js["frus"][filePath])
1223 {
1224 const auto& objectPath = item["inventoryPath"];
1225 sdbusplus::message::object_path object(objectPath);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001226
Shantappa Teekappanavar6aa54502021-12-09 12:59:56 -06001227 vector<string> ccinList;
1228 if (item.find("ccin") != item.end())
1229 {
1230 for (const auto& cc : item["ccin"])
1231 {
1232 string ccin = cc;
1233 transform(ccin.begin(), ccin.end(), ccin.begin(), ::toupper);
1234 ccinList.push_back(ccin);
1235 }
1236 }
1237
1238 if (!ccinFromVpd.empty() && !ccinList.empty() &&
1239 (find(ccinList.begin(), ccinList.end(), ccinFromVpd) ==
1240 ccinList.end()))
1241 {
1242 continue;
1243 }
1244
Priyanga Ramasamye3fed702022-01-11 01:05:32 -06001245 if ((isSystemVpd) || (item.value("noprime", false)))
Santosh Puranikd3a379a2021-08-23 19:12:59 +05301246 {
Priyanga Ramasamye3fed702022-01-11 01:05:32 -06001247
1248 // Populate one time properties for the system VPD and its sub-frus
1249 // and for other non-primeable frus.
Santosh Puranikd3a379a2021-08-23 19:12:59 +05301250 // For the remaining FRUs, this will get handled as a part of
1251 // priming the inventory.
1252 setOneTimeProperties(objectPath, interfaces);
1253 }
1254
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301255 // Populate the VPD keywords and the common interfaces only if we
1256 // are asked to inherit that data from the VPD, else only add the
1257 // extraInterfaces.
1258 if (item.value("inherit", true))
1259 {
Alpana Kumari58e22142020-05-05 00:22:12 -05001260 if constexpr (is_same<T, Parsed>::value)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301261 {
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301262 // Each record in the VPD becomes an interface and all
1263 // keyword within the record are properties under that
1264 // interface.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301265 for (const auto& record : vpdMap)
1266 {
1267 populateFruSpecificInterfaces(
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001268 record.second, ipzVpdInf + record.first, interfaces);
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301269 }
1270 }
Alpana Kumari58e22142020-05-05 00:22:12 -05001271 else if constexpr (is_same<T, KeywordVpdMap>::value)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301272 {
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001273 populateFruSpecificInterfaces(vpdMap, kwdVpdInf, interfaces);
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301274 }
Santosh Puranik88edeb62020-03-02 12:00:09 +05301275 if (js.find("commonInterfaces") != js.end())
1276 {
1277 populateInterfaces(js["commonInterfaces"], interfaces, vpdMap,
1278 isSystemVpd);
1279 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301280 }
Santosh Puranik0859eb62020-03-16 02:56:29 -05001281 else
1282 {
1283 // Check if we have been asked to inherit specific record(s)
Alpana Kumari58e22142020-05-05 00:22:12 -05001284 if constexpr (is_same<T, Parsed>::value)
Santosh Puranik0859eb62020-03-16 02:56:29 -05001285 {
1286 if (item.find("copyRecords") != item.end())
1287 {
1288 for (const auto& record : item["copyRecords"])
1289 {
1290 const string& recordName = record;
1291 if (vpdMap.find(recordName) != vpdMap.end())
1292 {
1293 populateFruSpecificInterfaces(
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001294 vpdMap.at(recordName), ipzVpdInf + recordName,
Santosh Puranik0859eb62020-03-16 02:56:29 -05001295 interfaces);
1296 }
1297 }
1298 }
1299 }
1300 }
Santosh Puranik32c46502022-02-10 08:55:07 +05301301 // Populate interfaces and properties that are common to every FRU
1302 // and additional interface that might be defined on a per-FRU
1303 // basis.
1304 if (item.find("extraInterfaces") != item.end())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301305 {
Santosh Puranik32c46502022-02-10 08:55:07 +05301306 populateInterfaces(item["extraInterfaces"], interfaces, vpdMap,
1307 isSystemVpd);
Priyanga Ramasamy6abdeb62022-01-09 23:15:11 -06001308 if constexpr (is_same<T, Parsed>::value)
1309 {
1310 if (item["extraInterfaces"].find(
1311 "xyz.openbmc_project.Inventory.Item.Cpu") !=
1312 item["extraInterfaces"].end())
1313 {
1314 if (isCPUIOGoodOnly(getKwVal(vpdMap, "CP00", "PG")))
1315 {
Priyanga Ramasamy2c607a92022-04-08 00:30:17 -05001316 interfaces[invItemIntf]["PrettyName"] = "IO Module";
Priyanga Ramasamy6abdeb62022-01-09 23:15:11 -06001317 }
1318 }
1319 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301320 }
Priyanga Ramasamye358acb2022-03-21 14:21:50 -05001321
1322 // embedded property(true or false) says whether the subfru is embedded
1323 // into the parent fru (or) not. VPD sets Present property only for
1324 // embedded frus. If the subfru is not an embedded FRU, the subfru may
1325 // or may not be physically present. Those non embedded frus will always
1326 // have Present=false irrespective of its physical presence or absence.
1327 // Eg: nvme drive in nvme slot is not an embedded FRU. So don't set
1328 // Present to true for such sub frus.
1329 // Eg: ethernet port is embedded into bmc card. So set Present to true
1330 // for such sub frus. Also donot populate present property for embedded
1331 // subfru which is synthesized. Currently there is no subfru which are
1332 // both embedded and synthesized. But still the case is handled here.
1333 if ((item.value("embedded", true)) &&
1334 (!item.value("synthesized", false)))
1335 {
1336 inventory::PropertyMap presProp;
1337 presProp.emplace("Present", true);
1338 insertOrMerge(interfaces, invItemIntf, move(presProp));
1339 }
Priyanga Ramasamyaa8a8932022-01-27 09:12:41 -06001340
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301341 objects.emplace(move(object), move(interfaces));
1342 }
1343
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301344 if (isSystemVpd)
1345 {
1346 inventory::ObjectMap primeObject = primeInventory(js, vpdMap);
1347 objects.insert(primeObject.begin(), primeObject.end());
Alpana Kumari65b83602020-09-01 00:24:56 -05001348
Alpana Kumarif05effd2021-04-07 07:32:53 -05001349 // set the U-boot environment variable for device-tree
1350 if constexpr (is_same<T, Parsed>::value)
1351 {
Santosh Puranike5f177a2022-01-24 20:14:46 +05301352 setDevTreeEnv(fs::path(getSystemsJson(vpdMap)).filename());
Alpana Kumarif05effd2021-04-07 07:32:53 -05001353 }
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301354 }
1355
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301356 // Notify PIM
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -05001357 common::utility::callPIM(move(objects));
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301358}
1359
1360int main(int argc, char** argv)
1361{
1362 int rc = 0;
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001363 json js{};
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001364 Binary vpdVector{};
1365 string file{};
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001366 // map to hold additional data in case of logging pel
1367 PelAdditionalData additionalData{};
1368
1369 // this is needed to hold base fru inventory path in case there is ECC or
1370 // vpd exception while parsing the file
1371 std::string baseFruInventoryPath = {};
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301372
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001373 // severity for PEL
1374 PelSeverity pelSeverity = PelSeverity::WARNING;
1375
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301376 try
1377 {
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301378 App app{"ibm-read-vpd - App to read IPZ format VPD, parse it and store "
1379 "in DBUS"};
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301380
1381 app.add_option("-f, --file", file, "File containing VPD (IPZ/KEYWORD)")
Alpana Kumari2f793042020-08-18 05:51:03 -05001382 ->required();
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301383
1384 CLI11_PARSE(app, argc, argv);
1385
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001386 // PEL severity should be ERROR in case of any system VPD failure
1387 if (file == systemVpdFilePath)
1388 {
1389 pelSeverity = PelSeverity::ERROR;
1390 }
1391
Santosh Puranik0246a4d2020-11-04 16:57:39 +05301392 auto jsonToParse = INVENTORY_JSON_DEFAULT;
1393
1394 // If the symlink exists, it means it has been setup for us, switch the
1395 // path
1396 if (fs::exists(INVENTORY_JSON_SYM_LINK))
1397 {
1398 jsonToParse = INVENTORY_JSON_SYM_LINK;
1399 }
1400
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301401 // Make sure that the file path we get is for a supported EEPROM
Santosh Puranik0246a4d2020-11-04 16:57:39 +05301402 ifstream inventoryJson(jsonToParse);
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001403 if (!inventoryJson)
1404 {
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001405 throw(VpdJsonException("Failed to access Json path", jsonToParse));
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001406 }
1407
1408 try
1409 {
1410 js = json::parse(inventoryJson);
1411 }
Patrick Williams8e15b932021-10-06 13:04:22 -05001412 catch (const json::parse_error& ex)
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001413 {
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001414 throw(VpdJsonException("Json parsing failed", jsonToParse));
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001415 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301416
Santosh Puranik12e24ff2021-05-11 19:33:50 +05301417 // Do we have the mandatory "frus" section?
1418 if (js.find("frus") == js.end())
1419 {
1420 throw(VpdJsonException("FRUs section not found in JSON",
1421 jsonToParse));
1422 }
1423
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301424 // Check if it's a udev path - patterned as(/ahb/ahb:apb/ahb:apb:bus@)
1425 if (file.find("/ahb:apb") != string::npos)
1426 {
1427 // Translate udev path to a generic /sys/bus/.. file path.
1428 udevToGenericPath(file);
Santosh Puranik12e24ff2021-05-11 19:33:50 +05301429
1430 if ((js["frus"].find(file) != js["frus"].end()) &&
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301431 (file == systemVpdFilePath))
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301432 {
Sunny Srivastava3c244142022-01-11 08:47:04 -06001433 // We need manager service active to process restoring of
1434 // system VPD on hardware. So in case any system restore is
1435 // required, update hardware in the second trigger of parser
1436 // code for system vpd file path.
1437
1438 std::vector<std::string> interfaces{motherBoardInterface};
1439
1440 // call mapper to check for object path creation
1441 MapperResponse subTree =
1442 getObjectSubtreeForInterfaces(pimPath, 0, interfaces);
1443 string mboardPath =
1444 js["frus"][file].at(0).value("inventoryPath", "");
1445
1446 // Attempt system VPD restore if we have a motherboard
1447 // object in the inventory.
1448 if ((subTree.size() != 0) &&
1449 (subTree.find(pimPath + mboardPath) != subTree.end()))
1450 {
1451 vpdVector = getVpdDataInVector(js, file);
1452 ParserInterface* parser =
1453 ParserFactory::getParser(vpdVector);
1454 variant<KeywordVpdMap, Store> parseResult;
1455 parseResult = parser->parse();
1456
1457 if (auto pVal = get_if<Store>(&parseResult))
1458 {
1459 // map to hold all the keywords whose value is blank and
1460 // needs to be updated at standby.
1461 vector<RestoredEeproms> blankSystemVpdProperties{};
1462 getListOfBlankSystemVpd(pVal->getVpdMap(), mboardPath,
1463 blankSystemVpdProperties);
1464
1465 // if system VPD restore is required, update the
1466 // EEPROM
1467 for (const auto& item : blankSystemVpdProperties)
1468 {
1469 updateHardware(get<0>(item), get<1>(item),
1470 get<2>(item), get<3>(item));
1471 }
1472 }
1473 else
1474 {
1475 std::cout << "Not a valid format to restore system VPD"
1476 << std::endl;
1477 }
1478 // release the parser object
1479 ParserFactory::freeParser(parser);
1480 }
1481 else
1482 {
1483 log<level::ERR>("No object path found");
1484 }
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301485 return 0;
1486 }
1487 }
1488
1489 if (file.empty())
1490 {
1491 cerr << "The EEPROM path <" << file << "> is not valid.";
1492 return 0;
1493 }
Santosh Puranik12e24ff2021-05-11 19:33:50 +05301494 if (js["frus"].find(file) == js["frus"].end())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301495 {
Santosh Puranik88edeb62020-03-02 12:00:09 +05301496 return 0;
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301497 }
1498
Alpana Kumari2f793042020-08-18 05:51:03 -05001499 if (!fs::exists(file))
1500 {
1501 cout << "Device path: " << file
1502 << " does not exist. Spurious udev event? Exiting." << endl;
1503 return 0;
1504 }
1505
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001506 baseFruInventoryPath = js["frus"][file][0]["inventoryPath"];
Santosh Puranik85893752020-11-10 21:31:43 +05301507 // Check if we can read the VPD file based on the power state
Santosh Puranik27a5e952021-10-07 22:08:01 -05001508 // We skip reading VPD when the power is ON in two scenarios:
Santosh Puranik31d50fa2022-04-04 12:04:37 +05301509 // 1) The eeprom we are trying to read is that of the system VPD and the
1510 // JSON symlink is already setup (the symlink's existence tells us we
1511 // are not coming out of a factory reset)
1512 // 2) The JSON tells us that the FRU EEPROM cannot be
1513 // read when we are powered ON.
Santosh Puranik27a5e952021-10-07 22:08:01 -05001514 if (js["frus"][file].at(0).value("powerOffOnly", false) ||
Santosh Puranik31d50fa2022-04-04 12:04:37 +05301515 (file == systemVpdFilePath && fs::exists(INVENTORY_JSON_SYM_LINK)))
Santosh Puranik85893752020-11-10 21:31:43 +05301516 {
1517 if ("xyz.openbmc_project.State.Chassis.PowerState.On" ==
1518 getPowerState())
1519 {
1520 cout << "This VPD cannot be read when power is ON" << endl;
1521 return 0;
1522 }
1523 }
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001524
Santosh Puranike9c57532022-03-15 16:51:51 +05301525 // Check if this VPD should be recollected at all
1526 if (!needsRecollection(js, file))
1527 {
1528 cout << "Skip VPD recollection for: " << file << endl;
1529 return 0;
1530 }
1531
Alpana Kumari2f793042020-08-18 05:51:03 -05001532 try
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301533 {
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001534 vpdVector = getVpdDataInVector(js, file);
PriyangaRamasamy33c61c22021-04-06 11:15:57 -05001535 ParserInterface* parser = ParserFactory::getParser(vpdVector);
Alpana Kumari2f793042020-08-18 05:51:03 -05001536 variant<KeywordVpdMap, Store> parseResult;
1537 parseResult = parser->parse();
SunnySrivastava19849a195542020-09-07 06:04:50 -05001538
Alpana Kumari2f793042020-08-18 05:51:03 -05001539 if (auto pVal = get_if<Store>(&parseResult))
1540 {
1541 populateDbus(pVal->getVpdMap(), js, file);
1542 }
1543 else if (auto pVal = get_if<KeywordVpdMap>(&parseResult))
1544 {
1545 populateDbus(*pVal, js, file);
1546 }
1547
1548 // release the parser object
1549 ParserFactory::freeParser(parser);
1550 }
Patrick Williams8e15b932021-10-06 13:04:22 -05001551 catch (const exception& e)
Alpana Kumari2f793042020-08-18 05:51:03 -05001552 {
Alpana Kumari735dee92022-03-25 01:24:40 -05001553 executePostFailAction(js, file);
PriyangaRamasamya504c3e2020-12-06 12:14:52 -06001554 throw;
Alpana Kumari2f793042020-08-18 05:51:03 -05001555 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301556 }
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001557 catch (const VpdJsonException& ex)
1558 {
1559 additionalData.emplace("JSON_PATH", ex.getJsonPath());
1560 additionalData.emplace("DESCRIPTION", ex.what());
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001561 createPEL(additionalData, pelSeverity, errIntfForJsonFailure);
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001562
1563 cerr << ex.what() << "\n";
1564 rc = -1;
1565 }
1566 catch (const VpdEccException& ex)
1567 {
1568 additionalData.emplace("DESCRIPTION", "ECC check failed");
1569 additionalData.emplace("CALLOUT_INVENTORY_PATH",
1570 INVENTORY_PATH + baseFruInventoryPath);
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001571 createPEL(additionalData, pelSeverity, errIntfForEccCheckFail);
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001572 dumpBadVpd(file, vpdVector);
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001573 cerr << ex.what() << "\n";
1574 rc = -1;
1575 }
1576 catch (const VpdDataException& ex)
1577 {
alpana075cb3b1f2021-12-16 11:19:36 -06001578 if (isThisPcieOnPass1planar(js, file))
1579 {
1580 cout << "Pcie_device [" << file
1581 << "]'s VPD is not valid on PASS1 planar.Ignoring.\n";
1582 rc = 0;
1583 }
Santosh Puranik53b38ed2022-04-10 23:15:22 +05301584 else if (!(isPresent(js, file).value_or(true)))
1585 {
1586 cout << "FRU at: " << file
1587 << " is not detected present. Ignore parser error.\n";
1588 rc = 0;
1589 }
alpana075cb3b1f2021-12-16 11:19:36 -06001590 else
1591 {
1592 string errorMsg =
1593 "VPD file is either empty or invalid. Parser failed for [";
1594 errorMsg += file;
1595 errorMsg += "], with error = " + std::string(ex.what());
1596
1597 additionalData.emplace("DESCRIPTION", errorMsg);
1598 additionalData.emplace("CALLOUT_INVENTORY_PATH",
1599 INVENTORY_PATH + baseFruInventoryPath);
1600 createPEL(additionalData, pelSeverity, errIntfForInvalidVPD);
1601
1602 rc = -1;
1603 }
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001604 }
Patrick Williams8e15b932021-10-06 13:04:22 -05001605 catch (const exception& e)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301606 {
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001607 dumpBadVpd(file, vpdVector);
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301608 cerr << e.what() << "\n";
1609 rc = -1;
1610 }
1611
1612 return rc;
Alpana Kumari735dee92022-03-25 01:24:40 -05001613}