blob: 805eee2c44ba09cd00e6002c5b9fcac7f2f010c5 [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>
Andrew Geissler280197e2020-12-08 20:51:49 -060025#include <phosphor-logging/log.hpp>
alpana077ce68722021-07-25 13:23:59 -050026#include <regex>
Santosh Puranik253fbe92022-10-06 22:38:09 +053027#include <thread>
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
Santosh Puranik88edeb62020-03-02 12:00:09 +053043/**
Santosh Puranike9c57532022-03-15 16:51:51 +053044 * @brief Returns the BMC state
45 */
46static auto getBMCState()
47{
48 std::string bmcState;
49 try
50 {
51 auto bus = sdbusplus::bus::new_default();
52 auto properties = bus.new_method_call(
53 "xyz.openbmc_project.State.BMC", "/xyz/openbmc_project/state/bmc0",
54 "org.freedesktop.DBus.Properties", "Get");
55 properties.append("xyz.openbmc_project.State.BMC");
56 properties.append("CurrentBMCState");
57 auto result = bus.call(properties);
58 std::variant<std::string> val;
59 result.read(val);
60 if (auto pVal = std::get_if<std::string>(&val))
61 {
62 bmcState = *pVal;
63 }
64 }
65 catch (const sdbusplus::exception::SdBusError& e)
66 {
67 // Ignore any error
68 std::cerr << "Failed to get BMC state: " << e.what() << "\n";
69 }
70 return bmcState;
71}
72
73/**
74 * @brief Check if the FRU is in the cache
75 *
76 * Checks if the FRU associated with the supplied D-Bus object path is already
77 * on D-Bus. This can be used to test if a VPD collection is required for this
78 * FRU. It uses the "xyz.openbmc_project.Inventory.Item, Present" property to
79 * determine the presence of a FRU in the cache.
80 *
81 * @param objectPath - The D-Bus object path without the PIM prefix.
82 * @return true if the object exists on D-Bus, false otherwise.
83 */
84static auto isFruInVpdCache(const std::string& objectPath)
85{
86 try
87 {
88 auto bus = sdbusplus::bus::new_default();
89 auto invPath = std::string{pimPath} + objectPath;
90 auto props = bus.new_method_call(
91 "xyz.openbmc_project.Inventory.Manager", invPath.c_str(),
92 "org.freedesktop.DBus.Properties", "Get");
93 props.append("xyz.openbmc_project.Inventory.Item");
94 props.append("Present");
95 auto result = bus.call(props);
96 std::variant<bool> present;
97 result.read(present);
98 if (auto pVal = std::get_if<bool>(&present))
99 {
100 return *pVal;
101 }
102 return false;
103 }
104 catch (const sdbusplus::exception::SdBusError& e)
105 {
106 std::cout << "FRU: " << objectPath << " not in D-Bus\n";
107 // Assume not present in case of an error
108 return false;
109 }
110}
111
112/**
113 * @brief Check if VPD recollection is needed for the given EEPROM
114 *
115 * Not all FRUs can be swapped at BMC ready state. This function does the
116 * following:
117 * -- Check if the FRU is marked as "pluggableAtStandby" OR
118 * "concurrentlyMaintainable". If so, return true.
119 * -- Check if we are at BMC NotReady state. If we are, then return true.
120 * -- Else check if the FRU is not present in the VPD cache (to cover for VPD
121 * force collection). If not found in the cache, return true.
122 * -- Else return false.
123 *
124 * @param js - JSON Object.
125 * @param filePath - The EEPROM file.
126 * @return true if collection should be attempted, false otherwise.
127 */
128static auto needsRecollection(const nlohmann::json& js, const string& filePath)
129{
130 if (js["frus"][filePath].at(0).value("pluggableAtStandby", false) ||
131 js["frus"][filePath].at(0).value("concurrentlyMaintainable", false))
132 {
133 return true;
134 }
135 if (getBMCState() == "xyz.openbmc_project.State.BMC.BMCState.NotReady")
136 {
137 return true;
138 }
139 if (!isFruInVpdCache(js["frus"][filePath].at(0).value("inventoryPath", "")))
140 {
141 return true;
142 }
143 return false;
144}
145
146/**
Santosh Puranik88edeb62020-03-02 12:00:09 +0530147 * @brief Expands location codes
148 */
149static auto expandLocationCode(const string& unexpanded, const Parsed& vpdMap,
150 bool isSystemVpd)
151{
152 auto expanded{unexpanded};
153 static constexpr auto SYSTEM_OBJECT = "/system/chassis/motherboard";
154 static constexpr auto VCEN_IF = "com.ibm.ipzvpd.VCEN";
155 static constexpr auto VSYS_IF = "com.ibm.ipzvpd.VSYS";
156 size_t idx = expanded.find("fcs");
157 try
158 {
159 if (idx != string::npos)
160 {
161 string fc{};
162 string se{};
163 if (isSystemVpd)
164 {
165 const auto& fcData = vpdMap.at("VCEN").at("FC");
166 const auto& seData = vpdMap.at("VCEN").at("SE");
167 fc = string(fcData.data(), fcData.size());
168 se = string(seData.data(), seData.size());
169 }
170 else
171 {
172 fc = readBusProperty(SYSTEM_OBJECT, VCEN_IF, "FC");
173 se = readBusProperty(SYSTEM_OBJECT, VCEN_IF, "SE");
174 }
175
Alpana Kumari81671f62021-02-10 02:21:59 -0600176 // TODO: See if ND0 can be placed in the JSON
177 expanded.replace(idx, 3, fc.substr(0, 4) + ".ND0." + se);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530178 }
179 else
180 {
181 idx = expanded.find("mts");
182 if (idx != string::npos)
183 {
184 string mt{};
185 string se{};
186 if (isSystemVpd)
187 {
188 const auto& mtData = vpdMap.at("VSYS").at("TM");
189 const auto& seData = vpdMap.at("VSYS").at("SE");
190 mt = string(mtData.data(), mtData.size());
191 se = string(seData.data(), seData.size());
192 }
193 else
194 {
195 mt = readBusProperty(SYSTEM_OBJECT, VSYS_IF, "TM");
196 se = readBusProperty(SYSTEM_OBJECT, VSYS_IF, "SE");
197 }
198
199 replace(mt.begin(), mt.end(), '-', '.');
200 expanded.replace(idx, 3, mt + "." + se);
201 }
202 }
203 }
Patrick Williams8e15b932021-10-06 13:04:22 -0500204 catch (const exception& e)
Santosh Puranik88edeb62020-03-02 12:00:09 +0530205 {
Alpana Kumari58e22142020-05-05 00:22:12 -0500206 cerr << "Failed to expand location code with exception: " << e.what()
207 << "\n";
Santosh Puranik88edeb62020-03-02 12:00:09 +0530208 }
209 return expanded;
210}
Alpana Kumari2f793042020-08-18 05:51:03 -0500211
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530212/**
213 * @brief Populate FRU specific interfaces.
214 *
215 * This is a common method which handles both
216 * ipz and keyword specific interfaces thus,
217 * reducing the code redundancy.
218 * @param[in] map - Reference to the innermost keyword-value map.
219 * @param[in] preIntrStr - Reference to the interface string.
220 * @param[out] interfaces - Reference to interface map.
221 */
222template <typename T>
223static void populateFruSpecificInterfaces(const T& map,
224 const string& preIntrStr,
225 inventory::InterfaceMap& interfaces)
226{
227 inventory::PropertyMap prop;
228
229 for (const auto& kwVal : map)
230 {
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530231 auto kw = kwVal.first;
232
233 if (kw[0] == '#')
234 {
Alpana Kumari58e22142020-05-05 00:22:12 -0500235 kw = string("PD_") + kw[1];
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530236 }
Alpana Kumari8ea3f6d2020-04-02 00:26:07 -0500237 else if (isdigit(kw[0]))
238 {
Alpana Kumari58e22142020-05-05 00:22:12 -0500239 kw = string("N_") + kw;
Alpana Kumari8ea3f6d2020-04-02 00:26:07 -0500240 }
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000241 if constexpr (is_same<T, KeywordVpdMap>::value)
242 {
243 if (get_if<Binary>(&kwVal.second))
244 {
245 Binary vec(get_if<Binary>(&kwVal.second)->begin(),
246 get_if<Binary>(&kwVal.second)->end());
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000247 prop.emplace(move(kw), move(vec));
248 }
249 else
250 {
251 if (kw == "MemorySizeInKB")
252 {
253 inventory::PropertyMap memProp;
254 auto memVal = get_if<size_t>(&kwVal.second);
255 if (memVal)
256 {
257 memProp.emplace(move(kw),
258 ((*memVal) * CONVERT_MB_TO_KB));
259 interfaces.emplace(
260 "xyz.openbmc_project.Inventory.Item.Dimm",
261 move(memProp));
262 }
263 else
264 {
265 cerr << "MemorySizeInKB value not found in vpd map\n";
266 }
267 }
268 }
269 }
270 else
271 {
272 Binary vec(kwVal.second.begin(), kwVal.second.end());
273 prop.emplace(move(kw), move(vec));
274 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530275 }
276
277 interfaces.emplace(preIntrStr, move(prop));
278}
279
280/**
281 * @brief Populate Interfaces.
282 *
283 * This method populates common and extra interfaces to dbus.
284 * @param[in] js - json object
285 * @param[out] interfaces - Reference to interface map
286 * @param[in] vpdMap - Reference to the parsed vpd map.
Santosh Puranik88edeb62020-03-02 12:00:09 +0530287 * @param[in] isSystemVpd - Denotes whether we are collecting the system VPD.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530288 */
289template <typename T>
290static void populateInterfaces(const nlohmann::json& js,
291 inventory::InterfaceMap& interfaces,
Santosh Puranik88edeb62020-03-02 12:00:09 +0530292 const T& vpdMap, bool isSystemVpd)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530293{
294 for (const auto& ifs : js.items())
295 {
Santosh Puranik88edeb62020-03-02 12:00:09 +0530296 string inf = ifs.key();
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530297 inventory::PropertyMap props;
298
299 for (const auto& itr : ifs.value().items())
300 {
Santosh Puranik88edeb62020-03-02 12:00:09 +0530301 const string& busProp = itr.key();
302
Alpana Kumari31970de2020-02-17 06:49:57 -0600303 if (itr.value().is_boolean())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530304 {
Santosh Puranik88edeb62020-03-02 12:00:09 +0530305 props.emplace(busProp, itr.value().get<bool>());
306 }
307 else if (itr.value().is_string())
308 {
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600309 if (busProp == "LocationCode" && inf == IBM_LOCATION_CODE_INF)
Santosh Puranik88edeb62020-03-02 12:00:09 +0530310 {
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600311 std::string prop;
312 if constexpr (is_same<T, Parsed>::value)
Santosh Puranik88edeb62020-03-02 12:00:09 +0530313 {
Alpana Kumari414d5ae2021-03-04 21:06:35 +0000314 // TODO deprecate the com.ibm interface later
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600315 prop = expandLocationCode(itr.value().get<string>(),
316 vpdMap, isSystemVpd);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530317 }
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600318 else if constexpr (is_same<T, KeywordVpdMap>::value)
Santosh Puranik88edeb62020-03-02 12:00:09 +0530319 {
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600320 // Send empty Parsed object to expandLocationCode api.
321 prop = expandLocationCode(itr.value().get<string>(),
322 Parsed{}, false);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530323 }
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600324 props.emplace(busProp, prop);
325 interfaces.emplace(XYZ_LOCATION_CODE_INF, props);
326 interfaces.emplace(IBM_LOCATION_CODE_INF, props);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530327 }
328 else
329 {
330 props.emplace(busProp, itr.value().get<string>());
331 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530332 }
Santosh Puraniked609af2021-06-21 11:30:07 +0530333 else if (itr.value().is_array())
334 {
335 try
336 {
337 props.emplace(busProp, itr.value().get<Binary>());
338 }
Patrick Williams8e15b932021-10-06 13:04:22 -0500339 catch (const nlohmann::detail::type_error& e)
Santosh Puraniked609af2021-06-21 11:30:07 +0530340 {
341 std::cerr << "Type exception: " << e.what() << "\n";
342 // Ignore any type errors
343 }
344 }
Alpana Kumari31970de2020-02-17 06:49:57 -0600345 else if (itr.value().is_object())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530346 {
Alpana Kumari31970de2020-02-17 06:49:57 -0600347 const string& rec = itr.value().value("recordName", "");
348 const string& kw = itr.value().value("keywordName", "");
349 const string& encoding = itr.value().value("encoding", "");
350
Alpana Kumari58e22142020-05-05 00:22:12 -0500351 if constexpr (is_same<T, Parsed>::value)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530352 {
Santosh Puranik88edeb62020-03-02 12:00:09 +0530353 if (!rec.empty() && !kw.empty() && vpdMap.count(rec) &&
354 vpdMap.at(rec).count(kw))
Alpana Kumari31970de2020-02-17 06:49:57 -0600355 {
356 auto encoded =
357 encodeKeyword(vpdMap.at(rec).at(kw), encoding);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530358 props.emplace(busProp, encoded);
Alpana Kumari31970de2020-02-17 06:49:57 -0600359 }
360 }
Alpana Kumari58e22142020-05-05 00:22:12 -0500361 else if constexpr (is_same<T, KeywordVpdMap>::value)
Alpana Kumari31970de2020-02-17 06:49:57 -0600362 {
363 if (!kw.empty() && vpdMap.count(kw))
364 {
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000365 auto kwValue = get_if<Binary>(&vpdMap.at(kw));
366 auto uintValue = get_if<size_t>(&vpdMap.at(kw));
367
368 if (kwValue)
369 {
370 auto prop =
371 string((*kwValue).begin(), (*kwValue).end());
372
373 auto encoded = encodeKeyword(prop, encoding);
374
375 props.emplace(busProp, encoded);
376 }
377 else if (uintValue)
378 {
379 props.emplace(busProp, *uintValue);
380 }
Alpana Kumari31970de2020-02-17 06:49:57 -0600381 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530382 }
383 }
Matt Spinlerb1e64bb2021-09-08 09:57:48 -0500384 else if (itr.value().is_number())
385 {
386 // For now assume the value is a size_t. In the future it would
387 // be nice to come up with a way to get the type from the JSON.
388 props.emplace(busProp, itr.value().get<size_t>());
389 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530390 }
Priyanga Ramasamyaa8a8932022-01-27 09:12:41 -0600391 insertOrMerge(interfaces, inf, move(props));
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530392 }
393}
394
alpana075cb3b1f2021-12-16 11:19:36 -0600395/**
396 * @brief This API checks if this FRU is pcie_devices. If yes then it further
397 * checks whether it is PASS1 planar.
398 */
399static bool isThisPcieOnPass1planar(const nlohmann::json& js,
400 const string& file)
401{
402 auto isThisPCIeDev = false;
403 auto isPASS1 = false;
404
405 // Check if it is a PCIE device
406 if (js["frus"].find(file) != js["frus"].end())
407 {
Santosh Puranikc03f3902022-04-14 10:58:26 +0530408 if ((js["frus"][file].at(0).find("extraInterfaces") !=
409 js["frus"][file].at(0).end()))
alpana075cb3b1f2021-12-16 11:19:36 -0600410 {
Santosh Puranikc03f3902022-04-14 10:58:26 +0530411 if (js["frus"][file].at(0)["extraInterfaces"].find(
alpana075cb3b1f2021-12-16 11:19:36 -0600412 "xyz.openbmc_project.Inventory.Item.PCIeDevice") !=
Santosh Puranikc03f3902022-04-14 10:58:26 +0530413 js["frus"][file].at(0)["extraInterfaces"].end())
alpana075cb3b1f2021-12-16 11:19:36 -0600414 {
415 isThisPCIeDev = true;
416 }
417 }
418 }
419
420 if (isThisPCIeDev)
421 {
Alpana Kumaria6181e22022-05-12 05:01:53 -0500422 // Collect HW version and SystemType to know if it is PASS1 planar.
alpana075cb3b1f2021-12-16 11:19:36 -0600423 auto bus = sdbusplus::bus::new_default();
Alpana Kumaria6181e22022-05-12 05:01:53 -0500424 auto property1 = bus.new_method_call(
alpana075cb3b1f2021-12-16 11:19:36 -0600425 INVENTORY_MANAGER_SERVICE,
426 "/xyz/openbmc_project/inventory/system/chassis/motherboard",
427 "org.freedesktop.DBus.Properties", "Get");
Alpana Kumaria6181e22022-05-12 05:01:53 -0500428 property1.append("com.ibm.ipzvpd.VINI");
429 property1.append("HW");
430 auto result1 = bus.call(property1);
431 inventory::Value hwVal;
432 result1.read(hwVal);
alpana075cb3b1f2021-12-16 11:19:36 -0600433
Alpana Kumaria6181e22022-05-12 05:01:53 -0500434 // SystemType
435 auto property2 = bus.new_method_call(
436 INVENTORY_MANAGER_SERVICE,
437 "/xyz/openbmc_project/inventory/system/chassis/motherboard",
438 "org.freedesktop.DBus.Properties", "Get");
439 property2.append("com.ibm.ipzvpd.VSBP");
440 property2.append("IM");
441 auto result2 = bus.call(property2);
442 inventory::Value imVal;
443 result2.read(imVal);
444
445 auto pVal1 = get_if<Binary>(&hwVal);
446 auto pVal2 = get_if<Binary>(&imVal);
447
448 if (pVal1 && pVal2)
alpana075cb3b1f2021-12-16 11:19:36 -0600449 {
Alpana Kumaria6181e22022-05-12 05:01:53 -0500450 auto hwVersion = *pVal1;
451 auto systemType = *pVal2;
452
453 // IM kw for Everest
454 Binary everestSystem{80, 00, 48, 00};
455
456 if (systemType == everestSystem)
457 {
458 if (hwVersion[1] < 21)
459 {
460 isPASS1 = true;
461 }
462 }
463 else if (hwVersion[1] < 2)
464 {
alpana075cb3b1f2021-12-16 11:19:36 -0600465 isPASS1 = true;
Alpana Kumaria6181e22022-05-12 05:01:53 -0500466 }
alpana075cb3b1f2021-12-16 11:19:36 -0600467 }
468 }
469
470 return (isThisPCIeDev && isPASS1);
471}
472
Alpana Kumari735dee92022-03-25 01:24:40 -0500473/** Performs any pre-action needed to get the FRU setup for collection.
Alpana Kumari2f793042020-08-18 05:51:03 -0500474 *
475 * @param[in] json - json object
476 * @param[in] file - eeprom file path
477 */
478static void preAction(const nlohmann::json& json, const string& file)
479{
Alpana Kumari735dee92022-03-25 01:24:40 -0500480 if ((json["frus"][file].at(0)).find("preAction") ==
Alpana Kumari2f793042020-08-18 05:51:03 -0500481 json["frus"][file].at(0).end())
482 {
Alpana Kumari735dee92022-03-25 01:24:40 -0500483 return;
Alpana Kumari2f793042020-08-18 05:51:03 -0500484 }
485
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500486 try
Alpana Kumari2f793042020-08-18 05:51:03 -0500487 {
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500488 if (executePreAction(json, file))
Alpana Kumari2f793042020-08-18 05:51:03 -0500489 {
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500490 if (json["frus"][file].at(0).find("devAddress") !=
491 json["frus"][file].at(0).end())
Alpana Kumari40d1c192022-03-09 21:16:02 -0600492 {
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500493 // Now bind the device
494 string bind = json["frus"][file].at(0).value("devAddress", "");
495 cout << "Binding device " << bind << endl;
496 string bindCmd = string("echo \"") + bind +
497 string("\" > /sys/bus/i2c/drivers/at24/bind");
498 cout << bindCmd << endl;
499 executeCmd(bindCmd);
500
501 // Check if device showed up (test for file)
502 if (!fs::exists(file))
503 {
504 cerr << "EEPROM " << file
505 << " does not exist. Take failure action" << endl;
506 // If not, then take failure postAction
507 executePostFailAction(json, file);
508 }
509 }
510 else
511 {
512 // missing required informations
513 cerr << "VPD inventory JSON missing basic informations of "
514 "preAction "
515 "for this FRU : ["
516 << file << "]. Executing executePostFailAction." << endl;
517
518 // Take failure postAction
Alpana Kumari40d1c192022-03-09 21:16:02 -0600519 executePostFailAction(json, file);
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500520 return;
Alpana Kumari40d1c192022-03-09 21:16:02 -0600521 }
522 }
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530523 else
524 {
525 // If the FRU is not there, clear the VINI/CCIN data.
526 // Enity manager probes for this keyword to look for this
527 // FRU, now if the data is persistent on BMC and FRU is
528 // removed this can lead to ambiguity. Hence clearing this
529 // Keyword if FRU is absent.
530 const auto& invPath =
531 json["frus"][file].at(0).value("inventoryPath", "");
532
533 if (!invPath.empty())
534 {
535 inventory::ObjectMap pimObjMap{
536 {invPath, {{"com.ibm.ipzvpd.VINI", {{"CC", Binary{}}}}}}};
537
538 common::utility::callPIM(move(pimObjMap));
539 }
540 else
541 {
542 throw std::runtime_error("Path empty in Json");
543 }
544 }
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500545 }
546 catch (const GpioException& e)
547 {
548 PelAdditionalData additionalData{};
549 additionalData.emplace("DESCRIPTION", e.what());
550 createPEL(additionalData, PelSeverity::WARNING, errIntfForGpioError,
551 nullptr);
Alpana Kumari2f793042020-08-18 05:51:03 -0500552 }
Alpana Kumari2f793042020-08-18 05:51:03 -0500553}
554
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530555/**
Santosh Puranikf3e69682022-03-31 17:52:38 +0530556 * @brief Fills the Decorator.AssetTag property into the interfaces map
557 *
558 * This function should only be called in cases where we did not find a JSON
559 * symlink. A missing symlink in /var/lib will be considered as a factory reset
560 * and this function will be used to default the AssetTag property.
561 *
562 * @param interfaces A possibly pre-populated map of inetrfaces to properties.
563 * @param vpdMap A VPD map of the system VPD data.
564 */
565static void fillAssetTag(inventory::InterfaceMap& interfaces,
566 const Parsed& vpdMap)
567{
568 // Read the system serial number and MTM
569 // Default asset tag is Server-MTM-System Serial
570 inventory::Interface assetIntf{
571 "xyz.openbmc_project.Inventory.Decorator.AssetTag"};
572 inventory::PropertyMap assetTagProps;
573 std::string defaultAssetTag =
574 std::string{"Server-"} + getKwVal(vpdMap, "VSYS", "TM") +
575 std::string{"-"} + getKwVal(vpdMap, "VSYS", "SE");
576 assetTagProps.emplace("AssetTag", defaultAssetTag);
577 insertOrMerge(interfaces, assetIntf, std::move(assetTagProps));
578}
579
580/**
Santosh Puranikd3a379a2021-08-23 19:12:59 +0530581 * @brief Set certain one time properties in the inventory
582 * Use this function to insert the Functional and Enabled properties into the
583 * inventory map. This function first checks if the object in question already
584 * has these properties hosted on D-Bus, if the property is already there, it is
585 * not modified, hence the name "one time". If the property is not already
586 * present, it will be added to the map with a suitable default value (true for
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530587 * Functional and Enabled)
Santosh Puranikd3a379a2021-08-23 19:12:59 +0530588 *
589 * @param[in] object - The inventory D-Bus obejct without the inventory prefix.
590 * @param[inout] interfaces - Reference to a map of inventory interfaces to
591 * which the properties will be attached.
592 */
593static void setOneTimeProperties(const std::string& object,
594 inventory::InterfaceMap& interfaces)
595{
596 auto bus = sdbusplus::bus::new_default();
597 auto objectPath = INVENTORY_PATH + object;
598 auto prop = bus.new_method_call("xyz.openbmc_project.Inventory.Manager",
599 objectPath.c_str(),
600 "org.freedesktop.DBus.Properties", "Get");
601 prop.append("xyz.openbmc_project.State.Decorator.OperationalStatus");
602 prop.append("Functional");
603 try
604 {
605 auto result = bus.call(prop);
606 }
607 catch (const sdbusplus::exception::SdBusError& e)
608 {
609 // Treat as property unavailable
610 inventory::PropertyMap prop;
611 prop.emplace("Functional", true);
612 interfaces.emplace(
613 "xyz.openbmc_project.State.Decorator.OperationalStatus",
614 move(prop));
615 }
616 prop = bus.new_method_call("xyz.openbmc_project.Inventory.Manager",
617 objectPath.c_str(),
618 "org.freedesktop.DBus.Properties", "Get");
619 prop.append("xyz.openbmc_project.Object.Enable");
620 prop.append("Enabled");
621 try
622 {
623 auto result = bus.call(prop);
624 }
625 catch (const sdbusplus::exception::SdBusError& e)
626 {
627 // Treat as property unavailable
628 inventory::PropertyMap prop;
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530629 prop.emplace("Enabled", true);
Santosh Puranikd3a379a2021-08-23 19:12:59 +0530630 interfaces.emplace("xyz.openbmc_project.Object.Enable", move(prop));
631 }
632}
633
634/**
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530635 * @brief Prime the Inventory
636 * Prime the inventory by populating only the location code,
637 * type interface and the inventory object for the frus
638 * which are not system vpd fru.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530639 *
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530640 * @param[in] jsObject - Reference to vpd inventory json object
641 * @param[in] vpdMap - Reference to the parsed vpd map
642 *
643 * @returns Map of items in extraInterface.
644 */
645template <typename T>
646inventory::ObjectMap primeInventory(const nlohmann::json& jsObject,
647 const T& vpdMap)
648{
649 inventory::ObjectMap objects;
650
651 for (auto& itemFRUS : jsObject["frus"].items())
652 {
653 for (auto& itemEEPROM : itemFRUS.value())
654 {
Alpana Kumari2e6c6f72020-12-03 00:10:03 -0600655 // Take pre actions if needed
656 if (itemEEPROM.find("preAction") != itemEEPROM.end())
657 {
658 preAction(jsObject, itemFRUS.key());
659 }
660
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530661 inventory::InterfaceMap interfaces;
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530662 inventory::Object object(itemEEPROM.at("inventoryPath"));
663
Santosh Puranik50f60bf2021-05-26 17:55:06 +0530664 if ((itemFRUS.key() != systemVpdFilePath) &&
665 !itemEEPROM.value("noprime", false))
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530666 {
Alpana Kumaricfd7a752021-02-07 23:23:01 -0600667 inventory::PropertyMap presProp;
Priyanga Ramasamye358acb2022-03-21 14:21:50 -0500668
669 // Do not populate Present property for frus whose
670 // synthesized=true. synthesized=true says the fru is owned by
671 // some other component and not by vpd.
672 if (!itemEEPROM.value("synthesized", false))
673 {
674 presProp.emplace("Present", false);
675 interfaces.emplace("xyz.openbmc_project.Inventory.Item",
676 presProp);
677 }
Santosh Puranikd3a379a2021-08-23 19:12:59 +0530678 setOneTimeProperties(object, interfaces);
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530679 if (itemEEPROM.find("extraInterfaces") != itemEEPROM.end())
680 {
681 for (const auto& eI : itemEEPROM["extraInterfaces"].items())
682 {
683 inventory::PropertyMap props;
Alpana Kumari414d5ae2021-03-04 21:06:35 +0000684 if (eI.key() == IBM_LOCATION_CODE_INF)
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530685 {
686 if constexpr (std::is_same<T, Parsed>::value)
687 {
688 for (auto& lC : eI.value().items())
689 {
690 auto propVal = expandLocationCode(
691 lC.value().get<string>(), vpdMap, true);
692
693 props.emplace(move(lC.key()),
694 move(propVal));
Santosh Puranikb0f37492021-06-21 09:42:47 +0530695 interfaces.emplace(XYZ_LOCATION_CODE_INF,
696 props);
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530697 interfaces.emplace(move(eI.key()),
698 move(props));
699 }
700 }
701 }
702 else if (eI.key().find("Inventory.Item.") !=
703 string::npos)
704 {
705 interfaces.emplace(move(eI.key()), move(props));
706 }
Santosh Puranikd3a379a2021-08-23 19:12:59 +0530707 else if (eI.key() ==
708 "xyz.openbmc_project.Inventory.Item")
709 {
710 for (auto& val : eI.value().items())
711 {
712 if (val.key() == "PrettyName")
713 {
714 presProp.emplace(val.key(),
715 val.value().get<string>());
716 }
717 }
718 // Use insert_or_assign here as we may already have
719 // inserted the present property only earlier in
720 // this function under this same interface.
721 interfaces.insert_or_assign(eI.key(),
722 move(presProp));
723 }
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530724 }
725 }
726 objects.emplace(move(object), move(interfaces));
727 }
728 }
729 }
730 return objects;
731}
732
Alpana Kumari65b83602020-09-01 00:24:56 -0500733/**
734 * @brief This API executes command to set environment variable
735 * And then reboot the system
736 * @param[in] key -env key to set new value
737 * @param[in] value -value to set.
738 */
739void setEnvAndReboot(const string& key, const string& value)
740{
741 // set env and reboot and break.
742 executeCmd("/sbin/fw_setenv", key, value);
Andrew Geissler280197e2020-12-08 20:51:49 -0600743 log<level::INFO>("Rebooting BMC to pick up new device tree");
Alpana Kumari65b83602020-09-01 00:24:56 -0500744 // make dbus call to reboot
745 auto bus = sdbusplus::bus::new_default_system();
746 auto method = bus.new_method_call(
747 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
748 "org.freedesktop.systemd1.Manager", "Reboot");
749 bus.call_noreply(method);
750}
751
752/*
753 * @brief This API checks for env var fitconfig.
754 * If not initialised OR updated as per the current system type,
755 * update this env var and reboot the system.
756 *
757 * @param[in] systemType IM kwd in vpd tells about which system type it is.
758 * */
759void setDevTreeEnv(const string& systemType)
760{
Alpana Kumari37e72702021-11-18 11:18:04 -0600761 // Init with default dtb
762 string newDeviceTree = "conf-aspeed-bmc-ibm-rainier-p1.dtb";
Santosh Puranike5f177a2022-01-24 20:14:46 +0530763 static const deviceTreeMap deviceTreeSystemTypeMap = {
764 {RAINIER_2U, "conf-aspeed-bmc-ibm-rainier-p1.dtb"},
765 {RAINIER_2U_V2, "conf-aspeed-bmc-ibm-rainier.dtb"},
766 {RAINIER_4U, "conf-aspeed-bmc-ibm-rainier-4u-p1.dtb"},
767 {RAINIER_4U_V2, "conf-aspeed-bmc-ibm-rainier-4u.dtb"},
768 {RAINIER_1S4U, "conf-aspeed-bmc-ibm-rainier-1s4u.dtb"},
Alpana Kumari1b026112022-03-02 23:41:38 -0600769 {EVEREST, "conf-aspeed-bmc-ibm-everest.dtb"},
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530770 {EVEREST_V2, "conf-aspeed-bmc-ibm-everest.dtb"},
771 {BONNELL, "conf-aspeed-bmc-ibm-bonnell.dtb"}};
Alpana Kumari65b83602020-09-01 00:24:56 -0500772
773 if (deviceTreeSystemTypeMap.find(systemType) !=
774 deviceTreeSystemTypeMap.end())
775 {
776 newDeviceTree = deviceTreeSystemTypeMap.at(systemType);
777 }
Alpana Kumari37e72702021-11-18 11:18:04 -0600778 else
779 {
780 // System type not supported
Alpana Kumariab1e22c2021-11-24 11:03:38 -0600781 string err = "This System type not found/supported in dtb table " +
782 systemType +
783 ".Please check the HW and IM keywords in the system "
784 "VPD.Breaking...";
785
786 // map to hold additional data in case of logging pel
787 PelAdditionalData additionalData{};
788 additionalData.emplace("DESCRIPTION", err);
789 createPEL(additionalData, PelSeverity::WARNING,
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500790 errIntfForInvalidSystemType, nullptr);
Alpana Kumariab1e22c2021-11-24 11:03:38 -0600791 exit(-1);
Alpana Kumari37e72702021-11-18 11:18:04 -0600792 }
Alpana Kumari65b83602020-09-01 00:24:56 -0500793
794 string readVarValue;
795 bool envVarFound = false;
796
797 vector<string> output = executeCmd("/sbin/fw_printenv");
798 for (const auto& entry : output)
799 {
800 size_t pos = entry.find("=");
801 string key = entry.substr(0, pos);
802 if (key != "fitconfig")
803 {
804 continue;
805 }
806
807 envVarFound = true;
808 if (pos + 1 < entry.size())
809 {
810 readVarValue = entry.substr(pos + 1);
811 if (readVarValue.find(newDeviceTree) != string::npos)
812 {
813 // fitconfig is Updated. No action needed
814 break;
815 }
816 }
817 // set env and reboot and break.
818 setEnvAndReboot(key, newDeviceTree);
819 exit(0);
820 }
821
822 // check If env var Not found
823 if (!envVarFound)
824 {
825 setEnvAndReboot("fitconfig", newDeviceTree);
826 }
827}
828
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530829/**
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500830 * @brief API to check if we need to restore system VPD
831 * This functionality is only applicable for IPZ VPD data.
832 * @param[in] vpdMap - IPZ vpd map
833 * @param[in] objectPath - Object path for the FRU
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500834 */
Sunny Srivastava3c244142022-01-11 08:47:04 -0600835void restoreSystemVPD(Parsed& vpdMap, const string& objectPath)
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500836{
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500837 for (const auto& systemRecKwdPair : svpdKwdMap)
838 {
839 auto it = vpdMap.find(systemRecKwdPair.first);
840
841 // check if record is found in map we got by parser
842 if (it != vpdMap.end())
843 {
844 const auto& kwdListForRecord = systemRecKwdPair.second;
845 for (const auto& keyword : kwdListForRecord)
846 {
847 DbusPropertyMap& kwdValMap = it->second;
848 auto iterator = kwdValMap.find(keyword);
849
850 if (iterator != kwdValMap.end())
851 {
852 string& kwdValue = iterator->second;
853
854 // check bus data
855 const string& recordName = systemRecKwdPair.first;
856 const string& busValue = readBusProperty(
857 objectPath, ipzVpdInf + recordName, keyword);
858
Sunny Srivastavaa559c2d2022-05-02 11:56:45 -0500859 std::string defaultValue{' '};
860
861 // Explicit check for D0 is required as this keyword will
862 // never be blank and 0x00 should be treated as no value in
863 // this case.
864 if (recordName == "UTIL" && keyword == "D0")
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500865 {
Sunny Srivastavaa559c2d2022-05-02 11:56:45 -0500866 // default value of kwd D0 is 0x00. This kwd will never
867 // be blank.
868 defaultValue = '\0';
869 }
870
871 if (busValue.find_first_not_of(defaultValue) !=
872 string::npos)
873 {
874 if (kwdValue.find_first_not_of(defaultValue) !=
875 string::npos)
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500876 {
877 // both the data are present, check for mismatch
878 if (busValue != kwdValue)
879 {
880 string errMsg = "VPD data mismatch on cache "
881 "and hardware for record: ";
882 errMsg += (*it).first;
883 errMsg += " and keyword: ";
884 errMsg += keyword;
885
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530886 std::ostringstream busStream;
887 for (uint16_t byte : busValue)
888 {
889 busStream << std::setfill('0')
890 << std::setw(2) << std::hex
891 << "0x" << byte << " ";
892 }
893
894 std::ostringstream vpdStream;
895 for (uint16_t byte : kwdValue)
896 {
897 vpdStream << std::setfill('0')
898 << std::setw(2) << std::hex
899 << "0x" << byte << " ";
900 }
901
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500902 // data mismatch
903 PelAdditionalData additionalData;
904 additionalData.emplace("CALLOUT_INVENTORY_PATH",
Priyanga Ramasamyf6123682022-12-02 07:29:07 -0600905 INVENTORY_PATH +
906 objectPath);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500907
908 additionalData.emplace("DESCRIPTION", errMsg);
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530909 additionalData.emplace("Value on Cache: ",
910 busStream.str());
911 additionalData.emplace(
912 "Value read from EEPROM: ",
913 vpdStream.str());
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500914
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500915 createPEL(additionalData, PelSeverity::WARNING,
Priyanga Ramasamyf6123682022-12-02 07:29:07 -0600916 errIntfForSysVPDMismatch, nullptr);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500917 }
918 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500919
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530920 // If cache data is not blank, then irrespective of
921 // hardware data(blank or other than cache), copy the
922 // cache data to vpd map as we don't need to change the
923 // cache data in either case in the process of
924 // restoring system vpd.
925 Binary busData(busValue.begin(), busValue.end());
926 kwdValue = busValue;
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500927 }
Sunny Srivastavaa559c2d2022-05-02 11:56:45 -0500928 else if (kwdValue.find_first_not_of(defaultValue) ==
929 string::npos)
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500930 {
Priyanga Ramasamyda3b2d22022-10-31 05:42:22 -0500931 if (recordName == "VSYS" && keyword == "FV")
932 {
933 // Continue to the next keyword without logging +PEL
934 // for VSYS FV(stores min version of BMC firmware).
935 // Reason:There is a requirement to support blank FV
936 // so that customer can use the system without
937 // upgrading BMC to the minimum required version.
938 continue;
939 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500940 string errMsg = "VPD is blank on both cache and "
941 "hardware for record: ";
942 errMsg += (*it).first;
943 errMsg += " and keyword: ";
944 errMsg += keyword;
945 errMsg += ". SSR need to update hardware VPD.";
946
947 // both the data are blanks, log PEL
948 PelAdditionalData additionalData;
949 additionalData.emplace("CALLOUT_INVENTORY_PATH",
Priyanga Ramasamyf6123682022-12-02 07:29:07 -0600950 INVENTORY_PATH + objectPath);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500951
952 additionalData.emplace("DESCRIPTION", errMsg);
953
954 // log PEL TODO: Block IPL
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500955 createPEL(additionalData, PelSeverity::ERROR,
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500956 errIntfForBlankSystemVPD, nullptr);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500957 continue;
958 }
959 }
960 }
961 }
962 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500963}
964
965/**
alpana077ce68722021-07-25 13:23:59 -0500966 * @brief This checks for is this FRU a processor
967 * And if yes, then checks for is this primary
968 *
969 * @param[in] js- vpd json to get the information about this FRU
970 * @param[in] filePath- FRU vpd
971 *
972 * @return true/false
973 */
974bool isThisPrimaryProcessor(nlohmann::json& js, const string& filePath)
975{
976 bool isProcessor = false;
977 bool isPrimary = false;
978
979 for (const auto& item : js["frus"][filePath])
980 {
981 if (item.find("extraInterfaces") != item.end())
982 {
983 for (const auto& eI : item["extraInterfaces"].items())
984 {
985 if (eI.key().find("Inventory.Item.Cpu") != string::npos)
986 {
987 isProcessor = true;
988 }
989 }
990 }
991
992 if (isProcessor)
993 {
994 string cpuType = item.value("cpuType", "");
995 if (cpuType == "primary")
996 {
997 isPrimary = true;
998 }
999 }
1000 }
1001
1002 return (isProcessor && isPrimary);
1003}
1004
1005/**
1006 * @brief This finds DIMM vpd in vpd json and enables them by binding the device
1007 * driver
1008 * @param[in] js- vpd json to iterate through and take action if it is DIMM
1009 */
1010void doEnableAllDimms(nlohmann::json& js)
1011{
1012 // iterate over each fru
1013 for (const auto& eachFru : js["frus"].items())
1014 {
1015 // skip the driver binding if eeprom already exists
1016 if (fs::exists(eachFru.key()))
1017 {
1018 continue;
1019 }
1020
1021 for (const auto& eachInventory : eachFru.value())
1022 {
1023 if (eachInventory.find("extraInterfaces") != eachInventory.end())
1024 {
1025 for (const auto& eI : eachInventory["extraInterfaces"].items())
1026 {
1027 if (eI.key().find("Inventory.Item.Dimm") != string::npos)
1028 {
1029 string dimmVpd = eachFru.key();
1030 // fetch it from
1031 // "/sys/bus/i2c/drivers/at24/414-0050/eeprom"
1032
1033 regex matchPatern("([0-9]+-[0-9]{4})");
1034 smatch matchFound;
1035 if (regex_search(dimmVpd, matchFound, matchPatern))
1036 {
1037 vector<string> i2cReg;
1038 boost::split(i2cReg, matchFound.str(0),
1039 boost::is_any_of("-"));
1040
1041 // remove 0s from begining
1042 const regex pattern("^0+(?!$)");
1043 for (auto& i : i2cReg)
1044 {
1045 i = regex_replace(i, pattern, "");
1046 }
1047
1048 if (i2cReg.size() == 2)
1049 {
1050 // echo 24c32 0x50 >
1051 // /sys/bus/i2c/devices/i2c-16/new_device
1052 string cmnd = "echo 24c32 0x" + i2cReg[1] +
1053 " > /sys/bus/i2c/devices/i2c-" +
1054 i2cReg[0] + "/new_device";
1055
1056 executeCmd(cmnd);
1057 }
1058 }
1059 }
1060 }
1061 }
1062 }
1063 }
1064}
1065
1066/**
Priyanga Ramasamy6abdeb62022-01-09 23:15:11 -06001067 * @brief Check if the given CPU is an IO only chip.
1068 * The CPU is termed as IO, whose all of the cores are bad and can never be
1069 * used. Those CPU chips can be used for IO purpose like connecting PCIe devices
1070 * etc., The CPU whose every cores are bad, can be identified from the CP00
1071 * record's PG keyword, only if all of the 8 EQs' value equals 0xE7F9FF. (1EQ
1072 * has 4 cores grouped together by sharing its cache memory.)
1073 * @param [in] pgKeyword - PG Keyword of CPU.
1074 * @return true if the given cpu is an IO, false otherwise.
1075 */
1076static bool isCPUIOGoodOnly(const string& pgKeyword)
1077{
1078 const unsigned char io[] = {0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9,
1079 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7,
1080 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF};
1081 // EQ0 index (in PG keyword) starts at 97 (with offset starting from 0).
1082 // Each EQ carries 3 bytes of data. Totally there are 8 EQs. If all EQs'
1083 // value equals 0xE7F9FF, then the cpu has no good cores and its treated as
1084 // IO.
1085 if (memcmp(io, pgKeyword.data() + 97, 24) == 0)
1086 {
1087 return true;
1088 }
1089
1090 // The CPU is not an IO
1091 return false;
1092}
1093
1094/**
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301095 * @brief Populate Dbus.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301096 * This method invokes all the populateInterface functions
1097 * and notifies PIM about dbus object.
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301098 * @param[in] vpdMap - Either IPZ vpd map or Keyword vpd map based on the
1099 * input.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301100 * @param[in] js - Inventory json object
1101 * @param[in] filePath - Path of the vpd file
1102 * @param[in] preIntrStr - Interface string
1103 */
1104template <typename T>
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001105static void populateDbus(T& vpdMap, nlohmann::json& js, const string& filePath)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301106{
1107 inventory::InterfaceMap interfaces;
1108 inventory::ObjectMap objects;
1109 inventory::PropertyMap prop;
Shantappa Teekappanavar6aa54502021-12-09 12:59:56 -06001110 string ccinFromVpd;
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301111
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301112 bool isSystemVpd = (filePath == systemVpdFilePath);
1113 if constexpr (is_same<T, Parsed>::value)
1114 {
Shantappa Teekappanavar6aa54502021-12-09 12:59:56 -06001115 ccinFromVpd = getKwVal(vpdMap, "VINI", "CC");
1116 transform(ccinFromVpd.begin(), ccinFromVpd.end(), ccinFromVpd.begin(),
1117 ::toupper);
1118
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301119 if (isSystemVpd)
1120 {
1121 std::vector<std::string> interfaces = {motherBoardInterface};
1122 // call mapper to check for object path creation
1123 MapperResponse subTree =
1124 getObjectSubtreeForInterfaces(pimPath, 0, interfaces);
1125 string mboardPath =
1126 js["frus"][filePath].at(0).value("inventoryPath", "");
1127
1128 // Attempt system VPD restore if we have a motherboard
1129 // object in the inventory.
1130 if ((subTree.size() != 0) &&
1131 (subTree.find(pimPath + mboardPath) != subTree.end()))
1132 {
Sunny Srivastava3c244142022-01-11 08:47:04 -06001133 restoreSystemVPD(vpdMap, mboardPath);
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301134 }
1135 else
1136 {
1137 log<level::ERR>("No object path found");
1138 }
1139 }
alpana077ce68722021-07-25 13:23:59 -05001140 else
1141 {
1142 // check if it is processor vpd.
1143 auto isPrimaryCpu = isThisPrimaryProcessor(js, filePath);
1144
1145 if (isPrimaryCpu)
1146 {
1147 auto ddVersion = getKwVal(vpdMap, "CRP0", "DD");
1148
1149 auto chipVersion = atoi(ddVersion.substr(1, 2).c_str());
1150
1151 if (chipVersion >= 2)
1152 {
1153 doEnableAllDimms(js);
Santosh Puranik253fbe92022-10-06 22:38:09 +05301154 // Sleep for a few seconds to let the DIMM parses start
1155 using namespace std::chrono_literals;
1156 std::this_thread::sleep_for(5s);
alpana077ce68722021-07-25 13:23:59 -05001157 }
1158 }
1159 }
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301160 }
1161
Santosh Puranikf3e69682022-03-31 17:52:38 +05301162 auto processFactoryReset = false;
1163
Priyanga Ramasamy32c687f2022-01-04 23:14:03 -06001164 if (isSystemVpd)
1165 {
1166 string systemJsonName{};
1167 if constexpr (is_same<T, Parsed>::value)
1168 {
1169 // pick the right system json
1170 systemJsonName = getSystemsJson(vpdMap);
1171 }
1172
1173 fs::path target = systemJsonName;
1174 fs::path link = INVENTORY_JSON_SYM_LINK;
1175
Santosh Puranikf3e69682022-03-31 17:52:38 +05301176 // If the symlink does not exist, we treat that as a factory reset
1177 processFactoryReset = !fs::exists(INVENTORY_JSON_SYM_LINK);
1178
Priyanga Ramasamy32c687f2022-01-04 23:14:03 -06001179 // Create the directory for hosting the symlink
1180 fs::create_directories(VPD_FILES_PATH);
1181 // unlink the symlink previously created (if any)
1182 remove(INVENTORY_JSON_SYM_LINK);
1183 // create a new symlink based on the system
1184 fs::create_symlink(target, link);
1185
1186 // Reloading the json
1187 ifstream inventoryJson(link);
1188 js = json::parse(inventoryJson);
1189 inventoryJson.close();
1190 }
1191
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301192 for (const auto& item : js["frus"][filePath])
1193 {
1194 const auto& objectPath = item["inventoryPath"];
1195 sdbusplus::message::object_path object(objectPath);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001196
Shantappa Teekappanavar6aa54502021-12-09 12:59:56 -06001197 vector<string> ccinList;
1198 if (item.find("ccin") != item.end())
1199 {
1200 for (const auto& cc : item["ccin"])
1201 {
1202 string ccin = cc;
1203 transform(ccin.begin(), ccin.end(), ccin.begin(), ::toupper);
1204 ccinList.push_back(ccin);
1205 }
1206 }
1207
1208 if (!ccinFromVpd.empty() && !ccinList.empty() &&
1209 (find(ccinList.begin(), ccinList.end(), ccinFromVpd) ==
1210 ccinList.end()))
1211 {
1212 continue;
1213 }
1214
Priyanga Ramasamye3fed702022-01-11 01:05:32 -06001215 if ((isSystemVpd) || (item.value("noprime", false)))
Santosh Puranikd3a379a2021-08-23 19:12:59 +05301216 {
Priyanga Ramasamye3fed702022-01-11 01:05:32 -06001217
1218 // Populate one time properties for the system VPD and its sub-frus
1219 // and for other non-primeable frus.
Santosh Puranikd3a379a2021-08-23 19:12:59 +05301220 // For the remaining FRUs, this will get handled as a part of
1221 // priming the inventory.
1222 setOneTimeProperties(objectPath, interfaces);
1223 }
1224
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301225 // Populate the VPD keywords and the common interfaces only if we
1226 // are asked to inherit that data from the VPD, else only add the
1227 // extraInterfaces.
1228 if (item.value("inherit", true))
1229 {
Alpana Kumari58e22142020-05-05 00:22:12 -05001230 if constexpr (is_same<T, Parsed>::value)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301231 {
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301232 // Each record in the VPD becomes an interface and all
1233 // keyword within the record are properties under that
1234 // interface.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301235 for (const auto& record : vpdMap)
1236 {
1237 populateFruSpecificInterfaces(
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001238 record.second, ipzVpdInf + record.first, interfaces);
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301239 }
1240 }
Alpana Kumari58e22142020-05-05 00:22:12 -05001241 else if constexpr (is_same<T, KeywordVpdMap>::value)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301242 {
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001243 populateFruSpecificInterfaces(vpdMap, kwdVpdInf, interfaces);
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301244 }
Santosh Puranik88edeb62020-03-02 12:00:09 +05301245 if (js.find("commonInterfaces") != js.end())
1246 {
1247 populateInterfaces(js["commonInterfaces"], interfaces, vpdMap,
1248 isSystemVpd);
1249 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301250 }
Santosh Puranik0859eb62020-03-16 02:56:29 -05001251 else
1252 {
1253 // Check if we have been asked to inherit specific record(s)
Alpana Kumari58e22142020-05-05 00:22:12 -05001254 if constexpr (is_same<T, Parsed>::value)
Santosh Puranik0859eb62020-03-16 02:56:29 -05001255 {
1256 if (item.find("copyRecords") != item.end())
1257 {
1258 for (const auto& record : item["copyRecords"])
1259 {
1260 const string& recordName = record;
1261 if (vpdMap.find(recordName) != vpdMap.end())
1262 {
1263 populateFruSpecificInterfaces(
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001264 vpdMap.at(recordName), ipzVpdInf + recordName,
Santosh Puranik0859eb62020-03-16 02:56:29 -05001265 interfaces);
1266 }
1267 }
1268 }
1269 }
1270 }
Santosh Puranik32c46502022-02-10 08:55:07 +05301271 // Populate interfaces and properties that are common to every FRU
1272 // and additional interface that might be defined on a per-FRU
1273 // basis.
1274 if (item.find("extraInterfaces") != item.end())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301275 {
Santosh Puranik32c46502022-02-10 08:55:07 +05301276 populateInterfaces(item["extraInterfaces"], interfaces, vpdMap,
1277 isSystemVpd);
Priyanga Ramasamy6abdeb62022-01-09 23:15:11 -06001278 if constexpr (is_same<T, Parsed>::value)
1279 {
1280 if (item["extraInterfaces"].find(
1281 "xyz.openbmc_project.Inventory.Item.Cpu") !=
1282 item["extraInterfaces"].end())
1283 {
1284 if (isCPUIOGoodOnly(getKwVal(vpdMap, "CP00", "PG")))
1285 {
Priyanga Ramasamy2c607a92022-04-08 00:30:17 -05001286 interfaces[invItemIntf]["PrettyName"] = "IO Module";
Priyanga Ramasamy6abdeb62022-01-09 23:15:11 -06001287 }
1288 }
1289 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301290 }
Priyanga Ramasamye358acb2022-03-21 14:21:50 -05001291
1292 // embedded property(true or false) says whether the subfru is embedded
1293 // into the parent fru (or) not. VPD sets Present property only for
1294 // embedded frus. If the subfru is not an embedded FRU, the subfru may
1295 // or may not be physically present. Those non embedded frus will always
1296 // have Present=false irrespective of its physical presence or absence.
1297 // Eg: nvme drive in nvme slot is not an embedded FRU. So don't set
1298 // Present to true for such sub frus.
1299 // Eg: ethernet port is embedded into bmc card. So set Present to true
1300 // for such sub frus. Also donot populate present property for embedded
1301 // subfru which is synthesized. Currently there is no subfru which are
1302 // both embedded and synthesized. But still the case is handled here.
1303 if ((item.value("embedded", true)) &&
1304 (!item.value("synthesized", false)))
1305 {
1306 inventory::PropertyMap presProp;
1307 presProp.emplace("Present", true);
1308 insertOrMerge(interfaces, invItemIntf, move(presProp));
1309 }
Priyanga Ramasamyaa8a8932022-01-27 09:12:41 -06001310
Santosh Puranikf3e69682022-03-31 17:52:38 +05301311 if constexpr (is_same<T, Parsed>::value)
1312 {
1313 // Restore asset tag, if needed
1314 if (processFactoryReset && objectPath == "/system")
1315 {
1316 fillAssetTag(interfaces, vpdMap);
1317 }
1318 }
1319
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301320 objects.emplace(move(object), move(interfaces));
1321 }
1322
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301323 if (isSystemVpd)
1324 {
1325 inventory::ObjectMap primeObject = primeInventory(js, vpdMap);
1326 objects.insert(primeObject.begin(), primeObject.end());
Alpana Kumari65b83602020-09-01 00:24:56 -05001327
Alpana Kumarif05effd2021-04-07 07:32:53 -05001328 // set the U-boot environment variable for device-tree
1329 if constexpr (is_same<T, Parsed>::value)
1330 {
Santosh Puranike5f177a2022-01-24 20:14:46 +05301331 setDevTreeEnv(fs::path(getSystemsJson(vpdMap)).filename());
Alpana Kumarif05effd2021-04-07 07:32:53 -05001332 }
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301333 }
1334
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301335 // Notify PIM
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -05001336 common::utility::callPIM(move(objects));
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301337}
1338
1339int main(int argc, char** argv)
1340{
1341 int rc = 0;
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001342 json js{};
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001343 Binary vpdVector{};
1344 string file{};
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001345 // map to hold additional data in case of logging pel
1346 PelAdditionalData additionalData{};
1347
1348 // this is needed to hold base fru inventory path in case there is ECC or
1349 // vpd exception while parsing the file
1350 std::string baseFruInventoryPath = {};
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301351
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001352 // severity for PEL
1353 PelSeverity pelSeverity = PelSeverity::WARNING;
1354
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301355 try
1356 {
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301357 App app{"ibm-read-vpd - App to read IPZ format VPD, parse it and store "
1358 "in DBUS"};
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301359
1360 app.add_option("-f, --file", file, "File containing VPD (IPZ/KEYWORD)")
Alpana Kumari2f793042020-08-18 05:51:03 -05001361 ->required();
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301362
1363 CLI11_PARSE(app, argc, argv);
1364
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001365 // PEL severity should be ERROR in case of any system VPD failure
1366 if (file == systemVpdFilePath)
1367 {
1368 pelSeverity = PelSeverity::ERROR;
1369 }
1370
Santosh Puranik0246a4d2020-11-04 16:57:39 +05301371 auto jsonToParse = INVENTORY_JSON_DEFAULT;
1372
1373 // If the symlink exists, it means it has been setup for us, switch the
1374 // path
1375 if (fs::exists(INVENTORY_JSON_SYM_LINK))
1376 {
1377 jsonToParse = INVENTORY_JSON_SYM_LINK;
1378 }
1379
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301380 // Make sure that the file path we get is for a supported EEPROM
Santosh Puranik0246a4d2020-11-04 16:57:39 +05301381 ifstream inventoryJson(jsonToParse);
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001382 if (!inventoryJson)
1383 {
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001384 throw(VpdJsonException("Failed to access Json path", jsonToParse));
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001385 }
1386
1387 try
1388 {
1389 js = json::parse(inventoryJson);
1390 }
Patrick Williams8e15b932021-10-06 13:04:22 -05001391 catch (const json::parse_error& ex)
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001392 {
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001393 throw(VpdJsonException("Json parsing failed", jsonToParse));
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001394 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301395
Santosh Puranik12e24ff2021-05-11 19:33:50 +05301396 // Do we have the mandatory "frus" section?
1397 if (js.find("frus") == js.end())
1398 {
1399 throw(VpdJsonException("FRUs section not found in JSON",
1400 jsonToParse));
1401 }
1402
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301403 // Check if it's a udev path - patterned as(/ahb/ahb:apb/ahb:apb:bus@)
1404 if (file.find("/ahb:apb") != string::npos)
1405 {
1406 // Translate udev path to a generic /sys/bus/.. file path.
1407 udevToGenericPath(file);
Santosh Puranik12e24ff2021-05-11 19:33:50 +05301408
1409 if ((js["frus"].find(file) != js["frus"].end()) &&
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301410 (file == systemVpdFilePath))
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301411 {
Santosh Puranik6b2b5372022-06-02 20:49:02 +05301412 // We have already collected system VPD, skip.
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301413 return 0;
1414 }
1415 }
1416
1417 if (file.empty())
1418 {
1419 cerr << "The EEPROM path <" << file << "> is not valid.";
1420 return 0;
1421 }
Santosh Puranik12e24ff2021-05-11 19:33:50 +05301422 if (js["frus"].find(file) == js["frus"].end())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301423 {
Santosh Puranik88edeb62020-03-02 12:00:09 +05301424 return 0;
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301425 }
1426
Alpana Kumari2f793042020-08-18 05:51:03 -05001427 if (!fs::exists(file))
1428 {
1429 cout << "Device path: " << file
1430 << " does not exist. Spurious udev event? Exiting." << endl;
1431 return 0;
1432 }
1433
Santosh Puranikdedb5a62022-12-19 23:58:32 +05301434 // In case of system VPD it will already be filled, Don't have to
1435 // overwrite that.
1436 if (baseFruInventoryPath.empty())
1437 {
1438 baseFruInventoryPath = js["frus"][file][0]["inventoryPath"];
1439 }
1440
Santosh Puranik85893752020-11-10 21:31:43 +05301441 // Check if we can read the VPD file based on the power state
Santosh Puranik27a5e952021-10-07 22:08:01 -05001442 // We skip reading VPD when the power is ON in two scenarios:
Santosh Puranik31d50fa2022-04-04 12:04:37 +05301443 // 1) The eeprom we are trying to read is that of the system VPD and the
1444 // JSON symlink is already setup (the symlink's existence tells us we
1445 // are not coming out of a factory reset)
1446 // 2) The JSON tells us that the FRU EEPROM cannot be
1447 // read when we are powered ON.
Santosh Puranik27a5e952021-10-07 22:08:01 -05001448 if (js["frus"][file].at(0).value("powerOffOnly", false) ||
Santosh Puranik31d50fa2022-04-04 12:04:37 +05301449 (file == systemVpdFilePath && fs::exists(INVENTORY_JSON_SYM_LINK)))
Santosh Puranik85893752020-11-10 21:31:43 +05301450 {
1451 if ("xyz.openbmc_project.State.Chassis.PowerState.On" ==
1452 getPowerState())
1453 {
1454 cout << "This VPD cannot be read when power is ON" << endl;
1455 return 0;
1456 }
1457 }
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001458
Santosh Puranike9c57532022-03-15 16:51:51 +05301459 // Check if this VPD should be recollected at all
1460 if (!needsRecollection(js, file))
1461 {
1462 cout << "Skip VPD recollection for: " << file << endl;
1463 return 0;
1464 }
1465
Alpana Kumari2f793042020-08-18 05:51:03 -05001466 try
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301467 {
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001468 vpdVector = getVpdDataInVector(js, file);
Sunny Srivastavaf31a91b2022-06-09 08:11:29 -05001469 ParserInterface* parser = ParserFactory::getParser(
1470 vpdVector, (pimPath + baseFruInventoryPath));
Alpana Kumari2f793042020-08-18 05:51:03 -05001471 variant<KeywordVpdMap, Store> parseResult;
1472 parseResult = parser->parse();
SunnySrivastava19849a195542020-09-07 06:04:50 -05001473
Alpana Kumari2f793042020-08-18 05:51:03 -05001474 if (auto pVal = get_if<Store>(&parseResult))
1475 {
1476 populateDbus(pVal->getVpdMap(), js, file);
1477 }
1478 else if (auto pVal = get_if<KeywordVpdMap>(&parseResult))
1479 {
1480 populateDbus(*pVal, js, file);
1481 }
1482
1483 // release the parser object
1484 ParserFactory::freeParser(parser);
1485 }
Patrick Williams8e15b932021-10-06 13:04:22 -05001486 catch (const exception& e)
Alpana Kumari2f793042020-08-18 05:51:03 -05001487 {
Alpana Kumari735dee92022-03-25 01:24:40 -05001488 executePostFailAction(js, file);
PriyangaRamasamya504c3e2020-12-06 12:14:52 -06001489 throw;
Alpana Kumari2f793042020-08-18 05:51:03 -05001490 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301491 }
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001492 catch (const VpdJsonException& ex)
1493 {
1494 additionalData.emplace("JSON_PATH", ex.getJsonPath());
1495 additionalData.emplace("DESCRIPTION", ex.what());
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -05001496 createPEL(additionalData, pelSeverity, errIntfForJsonFailure, nullptr);
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001497
1498 cerr << ex.what() << "\n";
1499 rc = -1;
1500 }
1501 catch (const VpdEccException& ex)
1502 {
1503 additionalData.emplace("DESCRIPTION", "ECC check failed");
1504 additionalData.emplace("CALLOUT_INVENTORY_PATH",
1505 INVENTORY_PATH + baseFruInventoryPath);
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -05001506 createPEL(additionalData, pelSeverity, errIntfForEccCheckFail, nullptr);
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001507 dumpBadVpd(file, vpdVector);
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001508 cerr << ex.what() << "\n";
1509 rc = -1;
1510 }
1511 catch (const VpdDataException& ex)
1512 {
alpana075cb3b1f2021-12-16 11:19:36 -06001513 if (isThisPcieOnPass1planar(js, file))
1514 {
1515 cout << "Pcie_device [" << file
1516 << "]'s VPD is not valid on PASS1 planar.Ignoring.\n";
1517 rc = 0;
1518 }
Santosh Puranik53b38ed2022-04-10 23:15:22 +05301519 else if (!(isPresent(js, file).value_or(true)))
1520 {
1521 cout << "FRU at: " << file
1522 << " is not detected present. Ignore parser error.\n";
1523 rc = 0;
1524 }
alpana075cb3b1f2021-12-16 11:19:36 -06001525 else
1526 {
1527 string errorMsg =
1528 "VPD file is either empty or invalid. Parser failed for [";
1529 errorMsg += file;
1530 errorMsg += "], with error = " + std::string(ex.what());
1531
1532 additionalData.emplace("DESCRIPTION", errorMsg);
1533 additionalData.emplace("CALLOUT_INVENTORY_PATH",
1534 INVENTORY_PATH + baseFruInventoryPath);
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -05001535 createPEL(additionalData, pelSeverity, errIntfForInvalidVPD,
1536 nullptr);
alpana075cb3b1f2021-12-16 11:19:36 -06001537
1538 rc = -1;
1539 }
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001540 }
Patrick Williams8e15b932021-10-06 13:04:22 -05001541 catch (const exception& e)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301542 {
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001543 dumpBadVpd(file, vpdVector);
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301544 cerr << e.what() << "\n";
1545 rc = -1;
1546 }
1547
1548 return rc;
Alpana Kumari735dee92022-03-25 01:24:40 -05001549}