blob: bb0088ff6266e3c92e9c28fb9b38fd009691d4a2 [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>
Alpana Kumari65b83602020-09-01 00:24:56 -050017#include <cstdarg>
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053018#include <exception>
PriyangaRamasamy83a1d5d2020-04-30 19:15:43 +053019#include <filesystem>
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053020#include <fstream>
Alpana Kumari2f793042020-08-18 05:51:03 -050021#include <gpiod.hpp>
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053022#include <iostream>
23#include <iterator>
24#include <nlohmann/json.hpp>
Andrew Geissler280197e2020-12-08 20:51:49 -060025#include <phosphor-logging/log.hpp>
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053026
27using namespace std;
28using namespace openpower::vpd;
29using namespace CLI;
30using namespace vpd::keyword::parser;
PriyangaRamasamy83a1d5d2020-04-30 19:15:43 +053031using namespace openpower::vpd::constants;
32namespace fs = filesystem;
33using json = nlohmann::json;
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050034using namespace openpower::vpd::parser::factory;
SunnySrivastava1984945a02d2020-05-06 01:55:41 -050035using namespace openpower::vpd::inventory;
Alpana Kumaria00936f2020-04-14 07:15:46 -050036using namespace openpower::vpd::memory::parser;
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050037using namespace openpower::vpd::parser::interface;
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -050038using namespace openpower::vpd::exceptions;
Andrew Geissler280197e2020-12-08 20:51:49 -060039using namespace phosphor::logging;
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053040
Alpana Kumari65b83602020-09-01 00:24:56 -050041static const deviceTreeMap deviceTreeSystemTypeMap = {
Joel Stanley6fb0ef92021-05-26 13:14:32 +093042 {RAINIER_2U, "conf-aspeed-bmc-ibm-rainier-p1.dtb"},
43 {RAINIER_2U_V2, "conf-aspeed-bmc-ibm-rainier.dtb"},
44 {RAINIER_4U, "conf-aspeed-bmc-ibm-rainier-4u-p1.dtb"},
45 {RAINIER_4U_V2, "conf-aspeed-bmc-ibm-rainier-4u.dtb"},
Andrew Geissler2fe709f2021-03-25 10:59:07 -050046 {RAINIER_1S4U, "conf-aspeed-bmc-ibm-rainier-1s4u.dtb"},
47 {EVEREST, "conf-aspeed-bmc-ibm-everest.dtb"}};
Alpana Kumari65b83602020-09-01 00:24:56 -050048
Santosh Puranik88edeb62020-03-02 12:00:09 +053049/**
Santosh Puranik85893752020-11-10 21:31:43 +053050 * @brief Returns the power state for chassis0
51 */
52static auto getPowerState()
53{
54 // TODO: How do we handle multiple chassis?
55 string powerState{};
56 auto bus = sdbusplus::bus::new_default();
57 auto properties =
58 bus.new_method_call("xyz.openbmc_project.State.Chassis",
59 "/xyz/openbmc_project/state/chassis0",
60 "org.freedesktop.DBus.Properties", "Get");
61 properties.append("xyz.openbmc_project.State.Chassis");
62 properties.append("CurrentPowerState");
63 auto result = bus.call(properties);
64 if (!result.is_method_error())
65 {
66 variant<string> val;
67 result.read(val);
68 if (auto pVal = get_if<string>(&val))
69 {
70 powerState = *pVal;
71 }
72 }
73 cout << "Power state is: " << powerState << endl;
74 return powerState;
75}
76
77/**
Santosh Puranik88edeb62020-03-02 12:00:09 +053078 * @brief Expands location codes
79 */
80static auto expandLocationCode(const string& unexpanded, const Parsed& vpdMap,
81 bool isSystemVpd)
82{
83 auto expanded{unexpanded};
84 static constexpr auto SYSTEM_OBJECT = "/system/chassis/motherboard";
85 static constexpr auto VCEN_IF = "com.ibm.ipzvpd.VCEN";
86 static constexpr auto VSYS_IF = "com.ibm.ipzvpd.VSYS";
87 size_t idx = expanded.find("fcs");
88 try
89 {
90 if (idx != string::npos)
91 {
92 string fc{};
93 string se{};
94 if (isSystemVpd)
95 {
96 const auto& fcData = vpdMap.at("VCEN").at("FC");
97 const auto& seData = vpdMap.at("VCEN").at("SE");
98 fc = string(fcData.data(), fcData.size());
99 se = string(seData.data(), seData.size());
100 }
101 else
102 {
103 fc = readBusProperty(SYSTEM_OBJECT, VCEN_IF, "FC");
104 se = readBusProperty(SYSTEM_OBJECT, VCEN_IF, "SE");
105 }
106
Alpana Kumari81671f62021-02-10 02:21:59 -0600107 // TODO: See if ND0 can be placed in the JSON
108 expanded.replace(idx, 3, fc.substr(0, 4) + ".ND0." + se);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530109 }
110 else
111 {
112 idx = expanded.find("mts");
113 if (idx != string::npos)
114 {
115 string mt{};
116 string se{};
117 if (isSystemVpd)
118 {
119 const auto& mtData = vpdMap.at("VSYS").at("TM");
120 const auto& seData = vpdMap.at("VSYS").at("SE");
121 mt = string(mtData.data(), mtData.size());
122 se = string(seData.data(), seData.size());
123 }
124 else
125 {
126 mt = readBusProperty(SYSTEM_OBJECT, VSYS_IF, "TM");
127 se = readBusProperty(SYSTEM_OBJECT, VSYS_IF, "SE");
128 }
129
130 replace(mt.begin(), mt.end(), '-', '.');
131 expanded.replace(idx, 3, mt + "." + se);
132 }
133 }
134 }
Alpana Kumari58e22142020-05-05 00:22:12 -0500135 catch (exception& e)
Santosh Puranik88edeb62020-03-02 12:00:09 +0530136 {
Alpana Kumari58e22142020-05-05 00:22:12 -0500137 cerr << "Failed to expand location code with exception: " << e.what()
138 << "\n";
Santosh Puranik88edeb62020-03-02 12:00:09 +0530139 }
140 return expanded;
141}
Alpana Kumari2f793042020-08-18 05:51:03 -0500142
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530143/**
144 * @brief Populate FRU specific interfaces.
145 *
146 * This is a common method which handles both
147 * ipz and keyword specific interfaces thus,
148 * reducing the code redundancy.
149 * @param[in] map - Reference to the innermost keyword-value map.
150 * @param[in] preIntrStr - Reference to the interface string.
151 * @param[out] interfaces - Reference to interface map.
152 */
153template <typename T>
154static void populateFruSpecificInterfaces(const T& map,
155 const string& preIntrStr,
156 inventory::InterfaceMap& interfaces)
157{
158 inventory::PropertyMap prop;
159
160 for (const auto& kwVal : map)
161 {
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530162 auto kw = kwVal.first;
163
164 if (kw[0] == '#')
165 {
Alpana Kumari58e22142020-05-05 00:22:12 -0500166 kw = string("PD_") + kw[1];
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530167 }
Alpana Kumari8ea3f6d2020-04-02 00:26:07 -0500168 else if (isdigit(kw[0]))
169 {
Alpana Kumari58e22142020-05-05 00:22:12 -0500170 kw = string("N_") + kw;
Alpana Kumari8ea3f6d2020-04-02 00:26:07 -0500171 }
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000172 if constexpr (is_same<T, KeywordVpdMap>::value)
173 {
174 if (get_if<Binary>(&kwVal.second))
175 {
176 Binary vec(get_if<Binary>(&kwVal.second)->begin(),
177 get_if<Binary>(&kwVal.second)->end());
178
179 prop.emplace(move(kw), move(vec));
180 }
181 else
182 {
183 if (kw == "MemorySizeInKB")
184 {
185 inventory::PropertyMap memProp;
186 auto memVal = get_if<size_t>(&kwVal.second);
187 if (memVal)
188 {
189 memProp.emplace(move(kw),
190 ((*memVal) * CONVERT_MB_TO_KB));
191 interfaces.emplace(
192 "xyz.openbmc_project.Inventory.Item.Dimm",
193 move(memProp));
194 }
195 else
196 {
197 cerr << "MemorySizeInKB value not found in vpd map\n";
198 }
199 }
200 }
201 }
202 else
203 {
204 Binary vec(kwVal.second.begin(), kwVal.second.end());
205 prop.emplace(move(kw), move(vec));
206 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530207 }
208
209 interfaces.emplace(preIntrStr, move(prop));
210}
211
212/**
213 * @brief Populate Interfaces.
214 *
215 * This method populates common and extra interfaces to dbus.
216 * @param[in] js - json object
217 * @param[out] interfaces - Reference to interface map
218 * @param[in] vpdMap - Reference to the parsed vpd map.
Santosh Puranik88edeb62020-03-02 12:00:09 +0530219 * @param[in] isSystemVpd - Denotes whether we are collecting the system VPD.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530220 */
221template <typename T>
222static void populateInterfaces(const nlohmann::json& js,
223 inventory::InterfaceMap& interfaces,
Santosh Puranik88edeb62020-03-02 12:00:09 +0530224 const T& vpdMap, bool isSystemVpd)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530225{
226 for (const auto& ifs : js.items())
227 {
Santosh Puranik88edeb62020-03-02 12:00:09 +0530228 string inf = ifs.key();
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530229 inventory::PropertyMap props;
230
231 for (const auto& itr : ifs.value().items())
232 {
Santosh Puranik88edeb62020-03-02 12:00:09 +0530233 const string& busProp = itr.key();
234
Alpana Kumari31970de2020-02-17 06:49:57 -0600235 if (itr.value().is_boolean())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530236 {
Santosh Puranik88edeb62020-03-02 12:00:09 +0530237 props.emplace(busProp, itr.value().get<bool>());
238 }
239 else if (itr.value().is_string())
240 {
Alpana Kumari58e22142020-05-05 00:22:12 -0500241 if constexpr (is_same<T, Parsed>::value)
Santosh Puranik88edeb62020-03-02 12:00:09 +0530242 {
243 if (busProp == "LocationCode" &&
Alpana Kumari414d5ae2021-03-04 21:06:35 +0000244 inf == IBM_LOCATION_CODE_INF)
Santosh Puranik88edeb62020-03-02 12:00:09 +0530245 {
Alpana Kumari414d5ae2021-03-04 21:06:35 +0000246 // TODO deprecate the com.ibm interface later
Santosh Puranik88edeb62020-03-02 12:00:09 +0530247 auto prop = expandLocationCode(
248 itr.value().get<string>(), vpdMap, isSystemVpd);
249 props.emplace(busProp, prop);
Alpana Kumari414d5ae2021-03-04 21:06:35 +0000250 interfaces.emplace(XYZ_LOCATION_CODE_INF, props);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530251 }
252 else
253 {
254 props.emplace(busProp, itr.value().get<string>());
255 }
256 }
257 else
258 {
259 props.emplace(busProp, itr.value().get<string>());
260 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530261 }
Santosh Puraniked609af2021-06-21 11:30:07 +0530262 else if (itr.value().is_array())
263 {
264 try
265 {
266 props.emplace(busProp, itr.value().get<Binary>());
267 }
268 catch (nlohmann::detail::type_error& e)
269 {
270 std::cerr << "Type exception: " << e.what() << "\n";
271 // Ignore any type errors
272 }
273 }
Alpana Kumari31970de2020-02-17 06:49:57 -0600274 else if (itr.value().is_object())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530275 {
Alpana Kumari31970de2020-02-17 06:49:57 -0600276 const string& rec = itr.value().value("recordName", "");
277 const string& kw = itr.value().value("keywordName", "");
278 const string& encoding = itr.value().value("encoding", "");
279
Alpana Kumari58e22142020-05-05 00:22:12 -0500280 if constexpr (is_same<T, Parsed>::value)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530281 {
Santosh Puranik88edeb62020-03-02 12:00:09 +0530282 if (!rec.empty() && !kw.empty() && vpdMap.count(rec) &&
283 vpdMap.at(rec).count(kw))
Alpana Kumari31970de2020-02-17 06:49:57 -0600284 {
285 auto encoded =
286 encodeKeyword(vpdMap.at(rec).at(kw), encoding);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530287 props.emplace(busProp, encoded);
Alpana Kumari31970de2020-02-17 06:49:57 -0600288 }
289 }
Alpana Kumari58e22142020-05-05 00:22:12 -0500290 else if constexpr (is_same<T, KeywordVpdMap>::value)
Alpana Kumari31970de2020-02-17 06:49:57 -0600291 {
292 if (!kw.empty() && vpdMap.count(kw))
293 {
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000294 auto kwValue = get_if<Binary>(&vpdMap.at(kw));
295 auto uintValue = get_if<size_t>(&vpdMap.at(kw));
296
297 if (kwValue)
298 {
299 auto prop =
300 string((*kwValue).begin(), (*kwValue).end());
301
302 auto encoded = encodeKeyword(prop, encoding);
303
304 props.emplace(busProp, encoded);
305 }
306 else if (uintValue)
307 {
308 props.emplace(busProp, *uintValue);
309 }
Alpana Kumari31970de2020-02-17 06:49:57 -0600310 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530311 }
312 }
313 }
314 interfaces.emplace(inf, move(props));
315 }
316}
317
Alpana Kumari2f793042020-08-18 05:51:03 -0500318static Binary getVpdDataInVector(const nlohmann::json& js, const string& file)
Alpana Kumari58e22142020-05-05 00:22:12 -0500319{
320 uint32_t offset = 0;
321 // check if offset present?
322 for (const auto& item : js["frus"][file])
323 {
324 if (item.find("offset") != item.end())
325 {
326 offset = item["offset"];
327 }
328 }
329
330 // TODO: Figure out a better way to get max possible VPD size.
331 Binary vpdVector;
332 vpdVector.resize(65504);
333 ifstream vpdFile;
334 vpdFile.open(file, ios::binary);
335
336 vpdFile.seekg(offset, ios_base::cur);
337 vpdFile.read(reinterpret_cast<char*>(&vpdVector[0]), 65504);
338 vpdVector.resize(vpdFile.gcount());
339
340 return vpdVector;
341}
342
Alpana Kumari2f793042020-08-18 05:51:03 -0500343/** This API will be called at the end of VPD collection to perform any post
344 * actions.
345 *
346 * @param[in] json - json object
347 * @param[in] file - eeprom file path
348 */
349static void postFailAction(const nlohmann::json& json, const string& file)
350{
351 if ((json["frus"][file].at(0)).find("postActionFail") ==
352 json["frus"][file].at(0).end())
353 {
354 return;
355 }
356
357 uint8_t pinValue = 0;
358 string pinName;
359
360 for (const auto& postAction :
361 (json["frus"][file].at(0))["postActionFail"].items())
362 {
363 if (postAction.key() == "pin")
364 {
365 pinName = postAction.value();
366 }
367 else if (postAction.key() == "value")
368 {
369 // Get the value to set
370 pinValue = postAction.value();
371 }
372 }
373
374 cout << "Setting GPIO: " << pinName << " to " << (int)pinValue << endl;
375
376 try
377 {
378 gpiod::line outputLine = gpiod::find_line(pinName);
379
380 if (!outputLine)
381 {
382 cout << "Couldn't find output line:" << pinName
383 << " on GPIO. Skipping...\n";
384
385 return;
386 }
387 outputLine.request(
388 {"Disable line", ::gpiod::line_request::DIRECTION_OUTPUT, 0},
389 pinValue);
390 }
391 catch (system_error&)
392 {
393 cerr << "Failed to set post-action GPIO" << endl;
394 }
395}
396
397/** Performs any pre-action needed to get the FRU setup for collection.
398 *
399 * @param[in] json - json object
400 * @param[in] file - eeprom file path
401 */
402static void preAction(const nlohmann::json& json, const string& file)
403{
404 if ((json["frus"][file].at(0)).find("preAction") ==
405 json["frus"][file].at(0).end())
406 {
407 return;
408 }
409
410 uint8_t pinValue = 0;
411 string pinName;
412
413 for (const auto& postAction :
414 (json["frus"][file].at(0))["preAction"].items())
415 {
416 if (postAction.key() == "pin")
417 {
418 pinName = postAction.value();
419 }
420 else if (postAction.key() == "value")
421 {
422 // Get the value to set
423 pinValue = postAction.value();
424 }
425 }
426
427 cout << "Setting GPIO: " << pinName << " to " << (int)pinValue << endl;
428 try
429 {
430 gpiod::line outputLine = gpiod::find_line(pinName);
431
432 if (!outputLine)
433 {
434 cout << "Couldn't find output line:" << pinName
435 << " on GPIO. Skipping...\n";
436
437 return;
438 }
439 outputLine.request(
440 {"FRU pre-action", ::gpiod::line_request::DIRECTION_OUTPUT, 0},
441 pinValue);
442 }
443 catch (system_error&)
444 {
445 cerr << "Failed to set pre-action GPIO" << endl;
446 return;
447 }
448
449 // Now bind the device
450 string bind = json["frus"][file].at(0).value("bind", "");
451 cout << "Binding device " << bind << endl;
452 string bindCmd = string("echo \"") + bind +
453 string("\" > /sys/bus/i2c/drivers/at24/bind");
454 cout << bindCmd << endl;
455 executeCmd(bindCmd);
456
457 // Check if device showed up (test for file)
458 if (!fs::exists(file))
459 {
460 cout << "EEPROM " << file << " does not exist. Take failure action"
461 << endl;
462 // If not, then take failure postAction
463 postFailAction(json, file);
464 }
465}
466
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530467/**
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530468 * @brief Prime the Inventory
469 * Prime the inventory by populating only the location code,
470 * type interface and the inventory object for the frus
471 * which are not system vpd fru.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530472 *
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530473 * @param[in] jsObject - Reference to vpd inventory json object
474 * @param[in] vpdMap - Reference to the parsed vpd map
475 *
476 * @returns Map of items in extraInterface.
477 */
478template <typename T>
479inventory::ObjectMap primeInventory(const nlohmann::json& jsObject,
480 const T& vpdMap)
481{
482 inventory::ObjectMap objects;
483
484 for (auto& itemFRUS : jsObject["frus"].items())
485 {
Alpana Kumari2f793042020-08-18 05:51:03 -0500486 // Take pre actions
487 preAction(jsObject, itemFRUS.key());
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530488 for (auto& itemEEPROM : itemFRUS.value())
489 {
490 inventory::InterfaceMap interfaces;
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530491 inventory::Object object(itemEEPROM.at("inventoryPath"));
492
Santosh Puranik50f60bf2021-05-26 17:55:06 +0530493 if ((itemFRUS.key() != systemVpdFilePath) &&
494 !itemEEPROM.value("noprime", false))
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530495 {
Alpana Kumaricfd7a752021-02-07 23:23:01 -0600496 inventory::PropertyMap presProp;
497 presProp.emplace("Present", false);
498 interfaces.emplace("xyz.openbmc_project.Inventory.Item",
499 move(presProp));
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530500 if (itemEEPROM.find("extraInterfaces") != itemEEPROM.end())
501 {
502 for (const auto& eI : itemEEPROM["extraInterfaces"].items())
503 {
504 inventory::PropertyMap props;
Alpana Kumari414d5ae2021-03-04 21:06:35 +0000505 if (eI.key() == IBM_LOCATION_CODE_INF)
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530506 {
507 if constexpr (std::is_same<T, Parsed>::value)
508 {
509 for (auto& lC : eI.value().items())
510 {
511 auto propVal = expandLocationCode(
512 lC.value().get<string>(), vpdMap, true);
513
514 props.emplace(move(lC.key()),
515 move(propVal));
Santosh Puranikb0f37492021-06-21 09:42:47 +0530516 interfaces.emplace(XYZ_LOCATION_CODE_INF,
517 props);
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530518 interfaces.emplace(move(eI.key()),
519 move(props));
520 }
521 }
522 }
523 else if (eI.key().find("Inventory.Item.") !=
524 string::npos)
525 {
526 interfaces.emplace(move(eI.key()), move(props));
527 }
528 }
529 }
530 objects.emplace(move(object), move(interfaces));
531 }
532 }
533 }
534 return objects;
535}
536
Alpana Kumari65b83602020-09-01 00:24:56 -0500537/**
538 * @brief This API executes command to set environment variable
539 * And then reboot the system
540 * @param[in] key -env key to set new value
541 * @param[in] value -value to set.
542 */
543void setEnvAndReboot(const string& key, const string& value)
544{
545 // set env and reboot and break.
546 executeCmd("/sbin/fw_setenv", key, value);
Andrew Geissler280197e2020-12-08 20:51:49 -0600547 log<level::INFO>("Rebooting BMC to pick up new device tree");
Alpana Kumari65b83602020-09-01 00:24:56 -0500548 // make dbus call to reboot
549 auto bus = sdbusplus::bus::new_default_system();
550 auto method = bus.new_method_call(
551 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
552 "org.freedesktop.systemd1.Manager", "Reboot");
553 bus.call_noreply(method);
554}
555
556/*
557 * @brief This API checks for env var fitconfig.
558 * If not initialised OR updated as per the current system type,
559 * update this env var and reboot the system.
560 *
561 * @param[in] systemType IM kwd in vpd tells about which system type it is.
562 * */
563void setDevTreeEnv(const string& systemType)
564{
565 string newDeviceTree;
566
567 if (deviceTreeSystemTypeMap.find(systemType) !=
568 deviceTreeSystemTypeMap.end())
569 {
570 newDeviceTree = deviceTreeSystemTypeMap.at(systemType);
571 }
572
573 string readVarValue;
574 bool envVarFound = false;
575
576 vector<string> output = executeCmd("/sbin/fw_printenv");
577 for (const auto& entry : output)
578 {
579 size_t pos = entry.find("=");
580 string key = entry.substr(0, pos);
581 if (key != "fitconfig")
582 {
583 continue;
584 }
585
586 envVarFound = true;
587 if (pos + 1 < entry.size())
588 {
589 readVarValue = entry.substr(pos + 1);
590 if (readVarValue.find(newDeviceTree) != string::npos)
591 {
592 // fitconfig is Updated. No action needed
593 break;
594 }
595 }
596 // set env and reboot and break.
597 setEnvAndReboot(key, newDeviceTree);
598 exit(0);
599 }
600
601 // check If env var Not found
602 if (!envVarFound)
603 {
604 setEnvAndReboot("fitconfig", newDeviceTree);
605 }
606}
607
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530608/**
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500609 * @brief API to call VPD manager to write VPD to EEPROM.
610 * @param[in] Object path.
611 * @param[in] record to be updated.
612 * @param[in] keyword to be updated.
613 * @param[in] keyword data to be updated
614 */
615void updateHardware(const string& objectName, const string& recName,
616 const string& kwdName, const Binary& data)
617{
618 try
619 {
620 auto bus = sdbusplus::bus::new_default();
621 auto properties =
622 bus.new_method_call(BUSNAME, OBJPATH, IFACE, "WriteKeyword");
623 properties.append(
624 static_cast<sdbusplus::message::object_path>(objectName));
625 properties.append(recName);
626 properties.append(kwdName);
627 properties.append(data);
628 bus.call(properties);
629 }
Patrick Williams8be43342021-09-02 09:33:36 -0500630 catch (const sdbusplus::exception::exception& e)
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500631 {
632 std::string what =
633 "VPDManager WriteKeyword api failed for inventory path " +
634 objectName;
635 what += " record " + recName;
636 what += " keyword " + kwdName;
637 what += " with bus error = " + std::string(e.what());
638
639 // map to hold additional data in case of logging pel
640 PelAdditionalData additionalData{};
641 additionalData.emplace("CALLOUT_INVENTORY_PATH", objectName);
642 additionalData.emplace("DESCRIPTION", what);
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500643 createPEL(additionalData, PelSeverity::WARNING, errIntfForBusFailure);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500644 }
645}
646
647/**
648 * @brief API to check if we need to restore system VPD
649 * This functionality is only applicable for IPZ VPD data.
650 * @param[in] vpdMap - IPZ vpd map
651 * @param[in] objectPath - Object path for the FRU
652 * @return EEPROMs with records and keywords updated at standby
653 */
654std::vector<RestoredEeproms> restoreSystemVPD(Parsed& vpdMap,
655 const string& objectPath)
656{
657 // the list of keywords for VSYS record is as per the S0 system. Should be
658 // updated for another type of systems
659 static std::unordered_map<std::string, std::vector<std::string>> svpdKwdMap{
660 {"VSYS", {"BR", "TM", "SE", "SU", "RB"}},
661 {"VCEN", {"FC", "SE"}},
662 {"LXR0", {"LX"}}};
663
664 // vector to hold all the EEPROMs updated at standby
665 std::vector<RestoredEeproms> updatedEeproms = {};
666
667 for (const auto& systemRecKwdPair : svpdKwdMap)
668 {
669 auto it = vpdMap.find(systemRecKwdPair.first);
670
671 // check if record is found in map we got by parser
672 if (it != vpdMap.end())
673 {
674 const auto& kwdListForRecord = systemRecKwdPair.second;
675 for (const auto& keyword : kwdListForRecord)
676 {
677 DbusPropertyMap& kwdValMap = it->second;
678 auto iterator = kwdValMap.find(keyword);
679
680 if (iterator != kwdValMap.end())
681 {
682 string& kwdValue = iterator->second;
683
684 // check bus data
685 const string& recordName = systemRecKwdPair.first;
686 const string& busValue = readBusProperty(
687 objectPath, ipzVpdInf + recordName, keyword);
688
689 if (busValue.find_first_not_of(' ') != string::npos)
690 {
691 if (kwdValue.find_first_not_of(' ') != string::npos)
692 {
693 // both the data are present, check for mismatch
694 if (busValue != kwdValue)
695 {
696 string errMsg = "VPD data mismatch on cache "
697 "and hardware for record: ";
698 errMsg += (*it).first;
699 errMsg += " and keyword: ";
700 errMsg += keyword;
701
702 // data mismatch
703 PelAdditionalData additionalData;
704 additionalData.emplace("CALLOUT_INVENTORY_PATH",
705 objectPath);
706
707 additionalData.emplace("DESCRIPTION", errMsg);
708
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500709 createPEL(additionalData, PelSeverity::WARNING,
710 errIntfForInvalidVPD);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500711 }
712 }
713 else
714 {
715 // implies hardware data is blank
716 // update the map
717 Binary busData(busValue.begin(), busValue.end());
718
719 updatedEeproms.push_back(std::make_tuple(
720 objectPath, recordName, keyword, busData));
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500721
Sunny Srivastava90a63b92021-05-26 06:30:24 -0500722 // update the map as well, so that cache data is not
723 // updated as blank while populating VPD map on Dbus
724 // in populateDBus Api
725 kwdValue = busValue;
726 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500727 }
728 else if (kwdValue.find_first_not_of(' ') == string::npos)
729 {
730 string errMsg = "VPD is blank on both cache and "
731 "hardware for record: ";
732 errMsg += (*it).first;
733 errMsg += " and keyword: ";
734 errMsg += keyword;
735 errMsg += ". SSR need to update hardware VPD.";
736
737 // both the data are blanks, log PEL
738 PelAdditionalData additionalData;
739 additionalData.emplace("CALLOUT_INVENTORY_PATH",
740 objectPath);
741
742 additionalData.emplace("DESCRIPTION", errMsg);
743
744 // log PEL TODO: Block IPL
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500745 createPEL(additionalData, PelSeverity::ERROR,
746 errIntfForBlankSystemVPD);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500747 continue;
748 }
749 }
750 }
751 }
752 }
753
754 return updatedEeproms;
755}
756
757/**
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530758 * @brief Populate Dbus.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530759 * This method invokes all the populateInterface functions
760 * and notifies PIM about dbus object.
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530761 * @param[in] vpdMap - Either IPZ vpd map or Keyword vpd map based on the
762 * input.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530763 * @param[in] js - Inventory json object
764 * @param[in] filePath - Path of the vpd file
765 * @param[in] preIntrStr - Interface string
766 */
767template <typename T>
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500768static void populateDbus(T& vpdMap, nlohmann::json& js, const string& filePath)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530769{
770 inventory::InterfaceMap interfaces;
771 inventory::ObjectMap objects;
772 inventory::PropertyMap prop;
773
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500774 // map to hold all the keywords whose value has been changed at standby
775 vector<RestoredEeproms> updatedEeproms = {};
776
Santosh Puranik50f60bf2021-05-26 17:55:06 +0530777 bool isSystemVpd = (filePath == systemVpdFilePath);
778 if constexpr (is_same<T, Parsed>::value)
779 {
780 if (isSystemVpd)
781 {
782 std::vector<std::string> interfaces = {motherBoardInterface};
783 // call mapper to check for object path creation
784 MapperResponse subTree =
785 getObjectSubtreeForInterfaces(pimPath, 0, interfaces);
786 string mboardPath =
787 js["frus"][filePath].at(0).value("inventoryPath", "");
788
789 // Attempt system VPD restore if we have a motherboard
790 // object in the inventory.
791 if ((subTree.size() != 0) &&
792 (subTree.find(pimPath + mboardPath) != subTree.end()))
793 {
794 updatedEeproms = restoreSystemVPD(vpdMap, mboardPath);
795 }
796 else
797 {
798 log<level::ERR>("No object path found");
799 }
800 }
801 }
802
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530803 for (const auto& item : js["frus"][filePath])
804 {
805 const auto& objectPath = item["inventoryPath"];
806 sdbusplus::message::object_path object(objectPath);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500807
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530808 // Populate the VPD keywords and the common interfaces only if we
809 // are asked to inherit that data from the VPD, else only add the
810 // extraInterfaces.
811 if (item.value("inherit", true))
812 {
Alpana Kumari58e22142020-05-05 00:22:12 -0500813 if constexpr (is_same<T, Parsed>::value)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530814 {
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530815 // Each record in the VPD becomes an interface and all
816 // keyword within the record are properties under that
817 // interface.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530818 for (const auto& record : vpdMap)
819 {
820 populateFruSpecificInterfaces(
SunnySrivastava1984e12b1812020-05-26 02:23:11 -0500821 record.second, ipzVpdInf + record.first, interfaces);
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530822 }
823 }
Alpana Kumari58e22142020-05-05 00:22:12 -0500824 else if constexpr (is_same<T, KeywordVpdMap>::value)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530825 {
SunnySrivastava1984e12b1812020-05-26 02:23:11 -0500826 populateFruSpecificInterfaces(vpdMap, kwdVpdInf, interfaces);
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530827 }
Santosh Puranik88edeb62020-03-02 12:00:09 +0530828 if (js.find("commonInterfaces") != js.end())
829 {
830 populateInterfaces(js["commonInterfaces"], interfaces, vpdMap,
831 isSystemVpd);
832 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530833 }
Santosh Puranik0859eb62020-03-16 02:56:29 -0500834 else
835 {
836 // Check if we have been asked to inherit specific record(s)
Alpana Kumari58e22142020-05-05 00:22:12 -0500837 if constexpr (is_same<T, Parsed>::value)
Santosh Puranik0859eb62020-03-16 02:56:29 -0500838 {
839 if (item.find("copyRecords") != item.end())
840 {
841 for (const auto& record : item["copyRecords"])
842 {
843 const string& recordName = record;
844 if (vpdMap.find(recordName) != vpdMap.end())
845 {
846 populateFruSpecificInterfaces(
SunnySrivastava1984e12b1812020-05-26 02:23:11 -0500847 vpdMap.at(recordName), ipzVpdInf + recordName,
Santosh Puranik0859eb62020-03-16 02:56:29 -0500848 interfaces);
849 }
850 }
851 }
852 }
853 }
Alpana Kumari58e22142020-05-05 00:22:12 -0500854 if (item.value("inheritEI", true))
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530855 {
Alpana Kumari58e22142020-05-05 00:22:12 -0500856 // Populate interfaces and properties that are common to every FRU
857 // and additional interface that might be defined on a per-FRU
858 // basis.
859 if (item.find("extraInterfaces") != item.end())
860 {
861 populateInterfaces(item["extraInterfaces"], interfaces, vpdMap,
862 isSystemVpd);
863 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530864 }
865 objects.emplace(move(object), move(interfaces));
866 }
867
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530868 if (isSystemVpd)
869 {
Santosh Puranikd278df12021-05-10 15:51:42 +0530870 string systemJsonName{};
PriyangaRamasamy83a1d5d2020-04-30 19:15:43 +0530871 if constexpr (is_same<T, Parsed>::value)
872 {
Alpana Kumarif05effd2021-04-07 07:32:53 -0500873 // pick the right system json
Santosh Puranikd278df12021-05-10 15:51:42 +0530874 systemJsonName = getSystemsJson(vpdMap);
PriyangaRamasamy83a1d5d2020-04-30 19:15:43 +0530875 }
876
Santosh Puranikd278df12021-05-10 15:51:42 +0530877 fs::path target = systemJsonName;
PriyangaRamasamy83a1d5d2020-04-30 19:15:43 +0530878 fs::path link = INVENTORY_JSON_SYM_LINK;
879
Santosh Puranik0246a4d2020-11-04 16:57:39 +0530880 // Create the directory for hosting the symlink
881 fs::create_directories(VPD_FILES_PATH);
882 // unlink the symlink previously created (if any)
PriyangaRamasamy83a1d5d2020-04-30 19:15:43 +0530883 remove(INVENTORY_JSON_SYM_LINK);
884 // create a new symlink based on the system
885 fs::create_symlink(target, link);
886
887 // Reloading the json
888 ifstream inventoryJson(link);
889 auto js = json::parse(inventoryJson);
890 inventoryJson.close();
891
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530892 inventory::ObjectMap primeObject = primeInventory(js, vpdMap);
893 objects.insert(primeObject.begin(), primeObject.end());
Alpana Kumari65b83602020-09-01 00:24:56 -0500894
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500895 // if system VPD has been restored at standby, update the EEPROM
896 for (const auto& item : updatedEeproms)
897 {
898 updateHardware(get<0>(item), get<1>(item), get<2>(item),
899 get<3>(item));
900 }
Alpana Kumarif05effd2021-04-07 07:32:53 -0500901
902 // set the U-boot environment variable for device-tree
903 if constexpr (is_same<T, Parsed>::value)
904 {
905 const string imKeyword = getIM(vpdMap);
906 const string hwKeyword = getHW(vpdMap);
907 string systemType = imKeyword;
908
909 // check If system has constraint then append HW version to it.
910 ifstream sysJson(SYSTEM_JSON);
911 if (!sysJson)
912 {
913 throw((VpdJsonException("Failed to access Json path",
914 SYSTEM_JSON)));
915 }
916
917 try
918 {
919 auto systemJson = json::parse(sysJson);
Santosh Puranikd278df12021-05-10 15:51:42 +0530920 if (systemJson["system"].find(imKeyword) !=
921 systemJson["system"].end())
922 {
923 if (systemJson["system"][imKeyword].find("constraint") !=
924 systemJson["system"][imKeyword].end())
925 {
926 systemType += "_" + hwKeyword;
927 }
928 }
Alpana Kumarif05effd2021-04-07 07:32:53 -0500929 }
930 catch (json::parse_error& ex)
931 {
932 throw((VpdJsonException("System Json parsing failed",
933 SYSTEM_JSON)));
934 }
935
Alpana Kumarif05effd2021-04-07 07:32:53 -0500936 setDevTreeEnv(systemType);
937 }
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530938 }
939
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530940 // Notify PIM
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -0500941 common::utility::callPIM(move(objects));
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530942}
943
944int main(int argc, char** argv)
945{
946 int rc = 0;
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -0500947 json js{};
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -0600948 Binary vpdVector{};
949 string file{};
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -0500950 // map to hold additional data in case of logging pel
951 PelAdditionalData additionalData{};
952
953 // this is needed to hold base fru inventory path in case there is ECC or
954 // vpd exception while parsing the file
955 std::string baseFruInventoryPath = {};
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530956
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500957 // severity for PEL
958 PelSeverity pelSeverity = PelSeverity::WARNING;
959
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530960 try
961 {
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530962 App app{"ibm-read-vpd - App to read IPZ format VPD, parse it and store "
963 "in DBUS"};
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530964
965 app.add_option("-f, --file", file, "File containing VPD (IPZ/KEYWORD)")
Alpana Kumari2f793042020-08-18 05:51:03 -0500966 ->required();
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530967
968 CLI11_PARSE(app, argc, argv);
969
Santosh Puranik12e24ff2021-05-11 19:33:50 +0530970 cout << "Parser launched with file: " << file << "\n";
971
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500972 // PEL severity should be ERROR in case of any system VPD failure
973 if (file == systemVpdFilePath)
974 {
975 pelSeverity = PelSeverity::ERROR;
976 }
977
Santosh Puranik0246a4d2020-11-04 16:57:39 +0530978 auto jsonToParse = INVENTORY_JSON_DEFAULT;
979
980 // If the symlink exists, it means it has been setup for us, switch the
981 // path
982 if (fs::exists(INVENTORY_JSON_SYM_LINK))
983 {
984 jsonToParse = INVENTORY_JSON_SYM_LINK;
985 }
986
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530987 // Make sure that the file path we get is for a supported EEPROM
Santosh Puranik0246a4d2020-11-04 16:57:39 +0530988 ifstream inventoryJson(jsonToParse);
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -0500989 if (!inventoryJson)
990 {
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500991 throw(VpdJsonException("Failed to access Json path", jsonToParse));
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -0500992 }
993
994 try
995 {
996 js = json::parse(inventoryJson);
997 }
998 catch (json::parse_error& ex)
999 {
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001000 throw(VpdJsonException("Json parsing failed", jsonToParse));
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001001 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301002
Santosh Puranik12e24ff2021-05-11 19:33:50 +05301003 // Do we have the mandatory "frus" section?
1004 if (js.find("frus") == js.end())
1005 {
1006 throw(VpdJsonException("FRUs section not found in JSON",
1007 jsonToParse));
1008 }
1009
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301010 // Check if it's a udev path - patterned as(/ahb/ahb:apb/ahb:apb:bus@)
1011 if (file.find("/ahb:apb") != string::npos)
1012 {
1013 // Translate udev path to a generic /sys/bus/.. file path.
1014 udevToGenericPath(file);
Santosh Puranik12e24ff2021-05-11 19:33:50 +05301015 cout << "Path after translation: " << file << "\n";
1016
1017 if ((js["frus"].find(file) != js["frus"].end()) &&
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301018 (file == systemVpdFilePath))
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301019 {
1020 return 0;
1021 }
1022 }
1023
1024 if (file.empty())
1025 {
1026 cerr << "The EEPROM path <" << file << "> is not valid.";
1027 return 0;
1028 }
Santosh Puranik12e24ff2021-05-11 19:33:50 +05301029 if (js["frus"].find(file) == js["frus"].end())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301030 {
Alpana Kumari58e22142020-05-05 00:22:12 -05001031 cout << "Device path not in JSON, ignoring" << endl;
Santosh Puranik88edeb62020-03-02 12:00:09 +05301032 return 0;
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301033 }
1034
Alpana Kumari2f793042020-08-18 05:51:03 -05001035 if (!fs::exists(file))
1036 {
1037 cout << "Device path: " << file
1038 << " does not exist. Spurious udev event? Exiting." << endl;
1039 return 0;
1040 }
1041
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001042 baseFruInventoryPath = js["frus"][file][0]["inventoryPath"];
Santosh Puranik85893752020-11-10 21:31:43 +05301043 // Check if we can read the VPD file based on the power state
1044 if (js["frus"][file].at(0).value("powerOffOnly", false))
1045 {
1046 if ("xyz.openbmc_project.State.Chassis.PowerState.On" ==
1047 getPowerState())
1048 {
1049 cout << "This VPD cannot be read when power is ON" << endl;
1050 return 0;
1051 }
1052 }
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001053
Alpana Kumari2f793042020-08-18 05:51:03 -05001054 try
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301055 {
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001056 vpdVector = getVpdDataInVector(js, file);
PriyangaRamasamy33c61c22021-04-06 11:15:57 -05001057 ParserInterface* parser = ParserFactory::getParser(vpdVector);
Alpana Kumari2f793042020-08-18 05:51:03 -05001058 variant<KeywordVpdMap, Store> parseResult;
1059 parseResult = parser->parse();
SunnySrivastava19849a195542020-09-07 06:04:50 -05001060
Alpana Kumari2f793042020-08-18 05:51:03 -05001061 if (auto pVal = get_if<Store>(&parseResult))
1062 {
1063 populateDbus(pVal->getVpdMap(), js, file);
1064 }
1065 else if (auto pVal = get_if<KeywordVpdMap>(&parseResult))
1066 {
1067 populateDbus(*pVal, js, file);
1068 }
1069
1070 // release the parser object
1071 ParserFactory::freeParser(parser);
1072 }
1073 catch (exception& e)
1074 {
1075 postFailAction(js, file);
PriyangaRamasamya504c3e2020-12-06 12:14:52 -06001076 throw;
Alpana Kumari2f793042020-08-18 05:51:03 -05001077 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301078 }
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001079 catch (const VpdJsonException& ex)
1080 {
1081 additionalData.emplace("JSON_PATH", ex.getJsonPath());
1082 additionalData.emplace("DESCRIPTION", ex.what());
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001083 createPEL(additionalData, pelSeverity, errIntfForJsonFailure);
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001084
1085 cerr << ex.what() << "\n";
1086 rc = -1;
1087 }
1088 catch (const VpdEccException& ex)
1089 {
1090 additionalData.emplace("DESCRIPTION", "ECC check failed");
1091 additionalData.emplace("CALLOUT_INVENTORY_PATH",
1092 INVENTORY_PATH + baseFruInventoryPath);
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001093 createPEL(additionalData, pelSeverity, errIntfForEccCheckFail);
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001094 dumpBadVpd(file, vpdVector);
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001095 cerr << ex.what() << "\n";
1096 rc = -1;
1097 }
1098 catch (const VpdDataException& ex)
1099 {
1100 additionalData.emplace("DESCRIPTION", "Invalid VPD data");
1101 additionalData.emplace("CALLOUT_INVENTORY_PATH",
1102 INVENTORY_PATH + baseFruInventoryPath);
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001103 createPEL(additionalData, pelSeverity, errIntfForInvalidVPD);
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001104 dumpBadVpd(file, vpdVector);
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001105 cerr << ex.what() << "\n";
1106 rc = -1;
1107 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301108 catch (exception& e)
1109 {
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001110 dumpBadVpd(file, vpdVector);
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301111 cerr << e.what() << "\n";
1112 rc = -1;
1113 }
1114
1115 return rc;
Alpana Kumari3ab26a72021-04-05 19:09:19 +00001116}