blob: c530c61305715df0be1eeeac93752ceb229adb7f [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;
Priyanga Ramasamy952d6c52022-11-07 07:20:24 -0600845 for (const auto& keywordInfo : kwdListForRecord)
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500846 {
Priyanga Ramasamy952d6c52022-11-07 07:20:24 -0600847 const auto keyword = get<0>(keywordInfo);
848
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500849 DbusPropertyMap& kwdValMap = it->second;
850 auto iterator = kwdValMap.find(keyword);
851
852 if (iterator != kwdValMap.end())
853 {
854 string& kwdValue = iterator->second;
855
856 // check bus data
857 const string& recordName = systemRecKwdPair.first;
858 const string& busValue = readBusProperty(
859 objectPath, ipzVpdInf + recordName, keyword);
860
Priyanga Ramasamy952d6c52022-11-07 07:20:24 -0600861 const auto& defaultValue = get<1>(keywordInfo);
862 Binary busDataInBinary(busValue.begin(), busValue.end());
863 Binary kwdDataInBinary(kwdValue.begin(), kwdValue.end());
Sunny Srivastavaa559c2d2022-05-02 11:56:45 -0500864
Priyanga Ramasamy952d6c52022-11-07 07:20:24 -0600865 if (busDataInBinary != defaultValue)
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500866 {
Priyanga Ramasamy952d6c52022-11-07 07:20:24 -0600867 if (kwdDataInBinary != defaultValue)
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500868 {
869 // both the data are present, check for mismatch
870 if (busValue != kwdValue)
871 {
Priyanga Ramasamy24942232023-01-05 04:54:59 -0600872 string errMsg = "Mismatch found between backup "
873 "and primary VPD for record: ";
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500874 errMsg += (*it).first;
875 errMsg += " and keyword: ";
876 errMsg += keyword;
877
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530878 std::ostringstream busStream;
879 for (uint16_t byte : busValue)
880 {
881 busStream << std::setfill('0')
882 << std::setw(2) << std::hex
883 << "0x" << byte << " ";
884 }
885
886 std::ostringstream vpdStream;
887 for (uint16_t byte : kwdValue)
888 {
889 vpdStream << std::setfill('0')
890 << std::setw(2) << std::hex
891 << "0x" << byte << " ";
892 }
893
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500894 // data mismatch
895 PelAdditionalData additionalData;
896 additionalData.emplace("CALLOUT_INVENTORY_PATH",
Priyanga Ramasamyf6123682022-12-02 07:29:07 -0600897 INVENTORY_PATH +
898 objectPath);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500899
900 additionalData.emplace("DESCRIPTION", errMsg);
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530901 additionalData.emplace(
Priyanga Ramasamy24942232023-01-05 04:54:59 -0600902 "Value read from Backup: ",
903 busStream.str());
904 additionalData.emplace(
905 "Value read from Primary: ",
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530906 vpdStream.str());
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500907
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500908 createPEL(additionalData, PelSeverity::WARNING,
Priyanga Ramasamy24942232023-01-05 04:54:59 -0600909 errIntfForVPDMismatch, nullptr);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500910 }
911 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500912
Priyanga Ramasamy24942232023-01-05 04:54:59 -0600913 // If backup data is not default, then irrespective of
914 // primary data(default or other than backup), copy the
915 // backup data to vpd map as we don't need to change the
916 // backup data in either case in the process of
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530917 // restoring system vpd.
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530918 kwdValue = busValue;
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500919 }
Priyanga Ramasamy952d6c52022-11-07 07:20:24 -0600920 else if (kwdDataInBinary == defaultValue &&
921 get<2>(keywordInfo)) // Check isPELRequired is true
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500922 {
Priyanga Ramasamy24942232023-01-05 04:54:59 -0600923 string errMsg = "Found default value on both backup "
924 "and primary VPD for record: ";
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500925 errMsg += (*it).first;
926 errMsg += " and keyword: ";
927 errMsg += keyword;
Priyanga Ramasamy24942232023-01-05 04:54:59 -0600928 errMsg += ". SSR need to update primary VPD.";
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500929
Priyanga Ramasamy24942232023-01-05 04:54:59 -0600930 // mfg default on both backup and primary, log PEL
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500931 PelAdditionalData additionalData;
932 additionalData.emplace("CALLOUT_INVENTORY_PATH",
Priyanga Ramasamyf6123682022-12-02 07:29:07 -0600933 INVENTORY_PATH + objectPath);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500934
935 additionalData.emplace("DESCRIPTION", errMsg);
936
937 // log PEL TODO: Block IPL
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500938 createPEL(additionalData, PelSeverity::ERROR,
Priyanga Ramasamy24942232023-01-05 04:54:59 -0600939 errIntfForVPDDefault, nullptr);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500940 continue;
941 }
942 }
943 }
944 }
945 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500946}
947
948/**
alpana077ce68722021-07-25 13:23:59 -0500949 * @brief This checks for is this FRU a processor
950 * And if yes, then checks for is this primary
951 *
952 * @param[in] js- vpd json to get the information about this FRU
953 * @param[in] filePath- FRU vpd
954 *
955 * @return true/false
956 */
957bool isThisPrimaryProcessor(nlohmann::json& js, const string& filePath)
958{
959 bool isProcessor = false;
960 bool isPrimary = false;
961
962 for (const auto& item : js["frus"][filePath])
963 {
964 if (item.find("extraInterfaces") != item.end())
965 {
966 for (const auto& eI : item["extraInterfaces"].items())
967 {
968 if (eI.key().find("Inventory.Item.Cpu") != string::npos)
969 {
970 isProcessor = true;
971 }
972 }
973 }
974
975 if (isProcessor)
976 {
977 string cpuType = item.value("cpuType", "");
978 if (cpuType == "primary")
979 {
980 isPrimary = true;
981 }
982 }
983 }
984
985 return (isProcessor && isPrimary);
986}
987
988/**
989 * @brief This finds DIMM vpd in vpd json and enables them by binding the device
990 * driver
991 * @param[in] js- vpd json to iterate through and take action if it is DIMM
992 */
993void doEnableAllDimms(nlohmann::json& js)
994{
995 // iterate over each fru
996 for (const auto& eachFru : js["frus"].items())
997 {
998 // skip the driver binding if eeprom already exists
999 if (fs::exists(eachFru.key()))
1000 {
1001 continue;
1002 }
1003
1004 for (const auto& eachInventory : eachFru.value())
1005 {
1006 if (eachInventory.find("extraInterfaces") != eachInventory.end())
1007 {
1008 for (const auto& eI : eachInventory["extraInterfaces"].items())
1009 {
1010 if (eI.key().find("Inventory.Item.Dimm") != string::npos)
1011 {
1012 string dimmVpd = eachFru.key();
1013 // fetch it from
1014 // "/sys/bus/i2c/drivers/at24/414-0050/eeprom"
1015
1016 regex matchPatern("([0-9]+-[0-9]{4})");
1017 smatch matchFound;
1018 if (regex_search(dimmVpd, matchFound, matchPatern))
1019 {
1020 vector<string> i2cReg;
1021 boost::split(i2cReg, matchFound.str(0),
1022 boost::is_any_of("-"));
1023
1024 // remove 0s from begining
1025 const regex pattern("^0+(?!$)");
1026 for (auto& i : i2cReg)
1027 {
1028 i = regex_replace(i, pattern, "");
1029 }
1030
1031 if (i2cReg.size() == 2)
1032 {
1033 // echo 24c32 0x50 >
1034 // /sys/bus/i2c/devices/i2c-16/new_device
1035 string cmnd = "echo 24c32 0x" + i2cReg[1] +
1036 " > /sys/bus/i2c/devices/i2c-" +
1037 i2cReg[0] + "/new_device";
1038
1039 executeCmd(cmnd);
1040 }
1041 }
1042 }
1043 }
1044 }
1045 }
1046 }
1047}
1048
1049/**
Priyanga Ramasamy6abdeb62022-01-09 23:15:11 -06001050 * @brief Check if the given CPU is an IO only chip.
1051 * The CPU is termed as IO, whose all of the cores are bad and can never be
1052 * used. Those CPU chips can be used for IO purpose like connecting PCIe devices
1053 * etc., The CPU whose every cores are bad, can be identified from the CP00
1054 * record's PG keyword, only if all of the 8 EQs' value equals 0xE7F9FF. (1EQ
1055 * has 4 cores grouped together by sharing its cache memory.)
1056 * @param [in] pgKeyword - PG Keyword of CPU.
1057 * @return true if the given cpu is an IO, false otherwise.
1058 */
1059static bool isCPUIOGoodOnly(const string& pgKeyword)
1060{
1061 const unsigned char io[] = {0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9,
1062 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7,
1063 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF};
1064 // EQ0 index (in PG keyword) starts at 97 (with offset starting from 0).
1065 // Each EQ carries 3 bytes of data. Totally there are 8 EQs. If all EQs'
1066 // value equals 0xE7F9FF, then the cpu has no good cores and its treated as
1067 // IO.
1068 if (memcmp(io, pgKeyword.data() + 97, 24) == 0)
1069 {
1070 return true;
1071 }
1072
1073 // The CPU is not an IO
1074 return false;
1075}
1076
1077/**
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301078 * @brief Populate Dbus.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301079 * This method invokes all the populateInterface functions
1080 * and notifies PIM about dbus object.
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301081 * @param[in] vpdMap - Either IPZ vpd map or Keyword vpd map based on the
1082 * input.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301083 * @param[in] js - Inventory json object
1084 * @param[in] filePath - Path of the vpd file
1085 * @param[in] preIntrStr - Interface string
1086 */
1087template <typename T>
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001088static void populateDbus(T& vpdMap, nlohmann::json& js, const string& filePath)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301089{
1090 inventory::InterfaceMap interfaces;
1091 inventory::ObjectMap objects;
1092 inventory::PropertyMap prop;
Shantappa Teekappanavar6aa54502021-12-09 12:59:56 -06001093 string ccinFromVpd;
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301094
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301095 bool isSystemVpd = (filePath == systemVpdFilePath);
1096 if constexpr (is_same<T, Parsed>::value)
1097 {
Shantappa Teekappanavar6aa54502021-12-09 12:59:56 -06001098 ccinFromVpd = getKwVal(vpdMap, "VINI", "CC");
1099 transform(ccinFromVpd.begin(), ccinFromVpd.end(), ccinFromVpd.begin(),
1100 ::toupper);
1101
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301102 if (isSystemVpd)
1103 {
1104 std::vector<std::string> interfaces = {motherBoardInterface};
1105 // call mapper to check for object path creation
1106 MapperResponse subTree =
1107 getObjectSubtreeForInterfaces(pimPath, 0, interfaces);
1108 string mboardPath =
1109 js["frus"][filePath].at(0).value("inventoryPath", "");
1110
1111 // Attempt system VPD restore if we have a motherboard
1112 // object in the inventory.
1113 if ((subTree.size() != 0) &&
1114 (subTree.find(pimPath + mboardPath) != subTree.end()))
1115 {
Sunny Srivastava3c244142022-01-11 08:47:04 -06001116 restoreSystemVPD(vpdMap, mboardPath);
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301117 }
1118 else
1119 {
1120 log<level::ERR>("No object path found");
1121 }
1122 }
alpana077ce68722021-07-25 13:23:59 -05001123 else
1124 {
1125 // check if it is processor vpd.
1126 auto isPrimaryCpu = isThisPrimaryProcessor(js, filePath);
1127
1128 if (isPrimaryCpu)
1129 {
1130 auto ddVersion = getKwVal(vpdMap, "CRP0", "DD");
1131
1132 auto chipVersion = atoi(ddVersion.substr(1, 2).c_str());
1133
1134 if (chipVersion >= 2)
1135 {
1136 doEnableAllDimms(js);
Santosh Puranik253fbe92022-10-06 22:38:09 +05301137 // Sleep for a few seconds to let the DIMM parses start
1138 using namespace std::chrono_literals;
1139 std::this_thread::sleep_for(5s);
alpana077ce68722021-07-25 13:23:59 -05001140 }
1141 }
1142 }
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301143 }
1144
Santosh Puranikf3e69682022-03-31 17:52:38 +05301145 auto processFactoryReset = false;
1146
Priyanga Ramasamy32c687f2022-01-04 23:14:03 -06001147 if (isSystemVpd)
1148 {
1149 string systemJsonName{};
1150 if constexpr (is_same<T, Parsed>::value)
1151 {
1152 // pick the right system json
1153 systemJsonName = getSystemsJson(vpdMap);
1154 }
1155
1156 fs::path target = systemJsonName;
1157 fs::path link = INVENTORY_JSON_SYM_LINK;
1158
Santosh Puranikf3e69682022-03-31 17:52:38 +05301159 // If the symlink does not exist, we treat that as a factory reset
1160 processFactoryReset = !fs::exists(INVENTORY_JSON_SYM_LINK);
1161
Priyanga Ramasamy32c687f2022-01-04 23:14:03 -06001162 // Create the directory for hosting the symlink
1163 fs::create_directories(VPD_FILES_PATH);
1164 // unlink the symlink previously created (if any)
1165 remove(INVENTORY_JSON_SYM_LINK);
1166 // create a new symlink based on the system
1167 fs::create_symlink(target, link);
1168
1169 // Reloading the json
1170 ifstream inventoryJson(link);
1171 js = json::parse(inventoryJson);
1172 inventoryJson.close();
1173 }
1174
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301175 for (const auto& item : js["frus"][filePath])
1176 {
1177 const auto& objectPath = item["inventoryPath"];
1178 sdbusplus::message::object_path object(objectPath);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001179
Shantappa Teekappanavar6aa54502021-12-09 12:59:56 -06001180 vector<string> ccinList;
1181 if (item.find("ccin") != item.end())
1182 {
1183 for (const auto& cc : item["ccin"])
1184 {
1185 string ccin = cc;
1186 transform(ccin.begin(), ccin.end(), ccin.begin(), ::toupper);
1187 ccinList.push_back(ccin);
1188 }
1189 }
1190
1191 if (!ccinFromVpd.empty() && !ccinList.empty() &&
1192 (find(ccinList.begin(), ccinList.end(), ccinFromVpd) ==
1193 ccinList.end()))
1194 {
1195 continue;
1196 }
1197
Priyanga Ramasamye3fed702022-01-11 01:05:32 -06001198 if ((isSystemVpd) || (item.value("noprime", false)))
Santosh Puranikd3a379a2021-08-23 19:12:59 +05301199 {
Priyanga Ramasamye3fed702022-01-11 01:05:32 -06001200
1201 // Populate one time properties for the system VPD and its sub-frus
1202 // and for other non-primeable frus.
Santosh Puranikd3a379a2021-08-23 19:12:59 +05301203 // For the remaining FRUs, this will get handled as a part of
1204 // priming the inventory.
1205 setOneTimeProperties(objectPath, interfaces);
1206 }
1207
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301208 // Populate the VPD keywords and the common interfaces only if we
1209 // are asked to inherit that data from the VPD, else only add the
1210 // extraInterfaces.
1211 if (item.value("inherit", true))
1212 {
Alpana Kumari58e22142020-05-05 00:22:12 -05001213 if constexpr (is_same<T, Parsed>::value)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301214 {
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301215 // Each record in the VPD becomes an interface and all
1216 // keyword within the record are properties under that
1217 // interface.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301218 for (const auto& record : vpdMap)
1219 {
1220 populateFruSpecificInterfaces(
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001221 record.second, ipzVpdInf + record.first, interfaces);
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301222 }
1223 }
Alpana Kumari58e22142020-05-05 00:22:12 -05001224 else if constexpr (is_same<T, KeywordVpdMap>::value)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301225 {
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001226 populateFruSpecificInterfaces(vpdMap, kwdVpdInf, interfaces);
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301227 }
Santosh Puranik88edeb62020-03-02 12:00:09 +05301228 if (js.find("commonInterfaces") != js.end())
1229 {
1230 populateInterfaces(js["commonInterfaces"], interfaces, vpdMap,
1231 isSystemVpd);
1232 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301233 }
Santosh Puranik0859eb62020-03-16 02:56:29 -05001234 else
1235 {
1236 // Check if we have been asked to inherit specific record(s)
Alpana Kumari58e22142020-05-05 00:22:12 -05001237 if constexpr (is_same<T, Parsed>::value)
Santosh Puranik0859eb62020-03-16 02:56:29 -05001238 {
1239 if (item.find("copyRecords") != item.end())
1240 {
1241 for (const auto& record : item["copyRecords"])
1242 {
1243 const string& recordName = record;
1244 if (vpdMap.find(recordName) != vpdMap.end())
1245 {
1246 populateFruSpecificInterfaces(
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001247 vpdMap.at(recordName), ipzVpdInf + recordName,
Santosh Puranik0859eb62020-03-16 02:56:29 -05001248 interfaces);
1249 }
1250 }
1251 }
1252 }
1253 }
Santosh Puranik32c46502022-02-10 08:55:07 +05301254 // Populate interfaces and properties that are common to every FRU
1255 // and additional interface that might be defined on a per-FRU
1256 // basis.
1257 if (item.find("extraInterfaces") != item.end())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301258 {
Santosh Puranik32c46502022-02-10 08:55:07 +05301259 populateInterfaces(item["extraInterfaces"], interfaces, vpdMap,
1260 isSystemVpd);
Priyanga Ramasamy6abdeb62022-01-09 23:15:11 -06001261 if constexpr (is_same<T, Parsed>::value)
1262 {
1263 if (item["extraInterfaces"].find(
1264 "xyz.openbmc_project.Inventory.Item.Cpu") !=
1265 item["extraInterfaces"].end())
1266 {
1267 if (isCPUIOGoodOnly(getKwVal(vpdMap, "CP00", "PG")))
1268 {
Priyanga Ramasamy2c607a92022-04-08 00:30:17 -05001269 interfaces[invItemIntf]["PrettyName"] = "IO Module";
Priyanga Ramasamy6abdeb62022-01-09 23:15:11 -06001270 }
1271 }
1272 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301273 }
Priyanga Ramasamye358acb2022-03-21 14:21:50 -05001274
1275 // embedded property(true or false) says whether the subfru is embedded
1276 // into the parent fru (or) not. VPD sets Present property only for
1277 // embedded frus. If the subfru is not an embedded FRU, the subfru may
1278 // or may not be physically present. Those non embedded frus will always
1279 // have Present=false irrespective of its physical presence or absence.
1280 // Eg: nvme drive in nvme slot is not an embedded FRU. So don't set
1281 // Present to true for such sub frus.
1282 // Eg: ethernet port is embedded into bmc card. So set Present to true
1283 // for such sub frus. Also donot populate present property for embedded
1284 // subfru which is synthesized. Currently there is no subfru which are
1285 // both embedded and synthesized. But still the case is handled here.
1286 if ((item.value("embedded", true)) &&
1287 (!item.value("synthesized", false)))
1288 {
1289 inventory::PropertyMap presProp;
1290 presProp.emplace("Present", true);
1291 insertOrMerge(interfaces, invItemIntf, move(presProp));
1292 }
Priyanga Ramasamyaa8a8932022-01-27 09:12:41 -06001293
Santosh Puranikf3e69682022-03-31 17:52:38 +05301294 if constexpr (is_same<T, Parsed>::value)
1295 {
1296 // Restore asset tag, if needed
1297 if (processFactoryReset && objectPath == "/system")
1298 {
1299 fillAssetTag(interfaces, vpdMap);
1300 }
1301 }
1302
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301303 objects.emplace(move(object), move(interfaces));
1304 }
1305
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301306 if (isSystemVpd)
1307 {
1308 inventory::ObjectMap primeObject = primeInventory(js, vpdMap);
1309 objects.insert(primeObject.begin(), primeObject.end());
Alpana Kumari65b83602020-09-01 00:24:56 -05001310
Alpana Kumarif05effd2021-04-07 07:32:53 -05001311 // set the U-boot environment variable for device-tree
1312 if constexpr (is_same<T, Parsed>::value)
1313 {
Santosh Puranike5f177a2022-01-24 20:14:46 +05301314 setDevTreeEnv(fs::path(getSystemsJson(vpdMap)).filename());
Alpana Kumarif05effd2021-04-07 07:32:53 -05001315 }
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301316 }
1317
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301318 // Notify PIM
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -05001319 common::utility::callPIM(move(objects));
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301320}
1321
1322int main(int argc, char** argv)
1323{
1324 int rc = 0;
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001325 json js{};
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001326 Binary vpdVector{};
1327 string file{};
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001328 // map to hold additional data in case of logging pel
1329 PelAdditionalData additionalData{};
1330
1331 // this is needed to hold base fru inventory path in case there is ECC or
1332 // vpd exception while parsing the file
1333 std::string baseFruInventoryPath = {};
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301334
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001335 // severity for PEL
1336 PelSeverity pelSeverity = PelSeverity::WARNING;
1337
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301338 try
1339 {
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301340 App app{"ibm-read-vpd - App to read IPZ format VPD, parse it and store "
1341 "in DBUS"};
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301342
1343 app.add_option("-f, --file", file, "File containing VPD (IPZ/KEYWORD)")
Alpana Kumari2f793042020-08-18 05:51:03 -05001344 ->required();
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301345
1346 CLI11_PARSE(app, argc, argv);
1347
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001348 // PEL severity should be ERROR in case of any system VPD failure
1349 if (file == systemVpdFilePath)
1350 {
1351 pelSeverity = PelSeverity::ERROR;
1352 }
1353
Santosh Puranik0246a4d2020-11-04 16:57:39 +05301354 auto jsonToParse = INVENTORY_JSON_DEFAULT;
1355
1356 // If the symlink exists, it means it has been setup for us, switch the
1357 // path
1358 if (fs::exists(INVENTORY_JSON_SYM_LINK))
1359 {
1360 jsonToParse = INVENTORY_JSON_SYM_LINK;
1361 }
1362
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301363 // Make sure that the file path we get is for a supported EEPROM
Santosh Puranik0246a4d2020-11-04 16:57:39 +05301364 ifstream inventoryJson(jsonToParse);
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001365 if (!inventoryJson)
1366 {
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001367 throw(VpdJsonException("Failed to access Json path", jsonToParse));
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001368 }
1369
1370 try
1371 {
1372 js = json::parse(inventoryJson);
1373 }
Patrick Williams8e15b932021-10-06 13:04:22 -05001374 catch (const json::parse_error& ex)
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001375 {
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001376 throw(VpdJsonException("Json parsing failed", jsonToParse));
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001377 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301378
Santosh Puranik12e24ff2021-05-11 19:33:50 +05301379 // Do we have the mandatory "frus" section?
1380 if (js.find("frus") == js.end())
1381 {
1382 throw(VpdJsonException("FRUs section not found in JSON",
1383 jsonToParse));
1384 }
1385
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301386 // Check if it's a udev path - patterned as(/ahb/ahb:apb/ahb:apb:bus@)
1387 if (file.find("/ahb:apb") != string::npos)
1388 {
1389 // Translate udev path to a generic /sys/bus/.. file path.
1390 udevToGenericPath(file);
Santosh Puranik12e24ff2021-05-11 19:33:50 +05301391
1392 if ((js["frus"].find(file) != js["frus"].end()) &&
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301393 (file == systemVpdFilePath))
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301394 {
Santosh Puranik6b2b5372022-06-02 20:49:02 +05301395 // We have already collected system VPD, skip.
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301396 return 0;
1397 }
1398 }
1399
1400 if (file.empty())
1401 {
1402 cerr << "The EEPROM path <" << file << "> is not valid.";
1403 return 0;
1404 }
Santosh Puranik12e24ff2021-05-11 19:33:50 +05301405 if (js["frus"].find(file) == js["frus"].end())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301406 {
Santosh Puranik88edeb62020-03-02 12:00:09 +05301407 return 0;
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301408 }
1409
Alpana Kumari2f793042020-08-18 05:51:03 -05001410 if (!fs::exists(file))
1411 {
1412 cout << "Device path: " << file
1413 << " does not exist. Spurious udev event? Exiting." << endl;
1414 return 0;
1415 }
1416
Santosh Puranikdedb5a62022-12-19 23:58:32 +05301417 // In case of system VPD it will already be filled, Don't have to
1418 // overwrite that.
1419 if (baseFruInventoryPath.empty())
1420 {
1421 baseFruInventoryPath = js["frus"][file][0]["inventoryPath"];
1422 }
1423
Santosh Puranik85893752020-11-10 21:31:43 +05301424 // Check if we can read the VPD file based on the power state
Santosh Puranik27a5e952021-10-07 22:08:01 -05001425 // We skip reading VPD when the power is ON in two scenarios:
Santosh Puranik31d50fa2022-04-04 12:04:37 +05301426 // 1) The eeprom we are trying to read is that of the system VPD and the
1427 // JSON symlink is already setup (the symlink's existence tells us we
1428 // are not coming out of a factory reset)
1429 // 2) The JSON tells us that the FRU EEPROM cannot be
1430 // read when we are powered ON.
Santosh Puranik27a5e952021-10-07 22:08:01 -05001431 if (js["frus"][file].at(0).value("powerOffOnly", false) ||
Santosh Puranik31d50fa2022-04-04 12:04:37 +05301432 (file == systemVpdFilePath && fs::exists(INVENTORY_JSON_SYM_LINK)))
Santosh Puranik85893752020-11-10 21:31:43 +05301433 {
1434 if ("xyz.openbmc_project.State.Chassis.PowerState.On" ==
1435 getPowerState())
1436 {
1437 cout << "This VPD cannot be read when power is ON" << endl;
1438 return 0;
1439 }
1440 }
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001441
Santosh Puranike9c57532022-03-15 16:51:51 +05301442 // Check if this VPD should be recollected at all
1443 if (!needsRecollection(js, file))
1444 {
1445 cout << "Skip VPD recollection for: " << file << endl;
1446 return 0;
1447 }
1448
Alpana Kumari2f793042020-08-18 05:51:03 -05001449 try
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301450 {
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001451 vpdVector = getVpdDataInVector(js, file);
Sunny Srivastavaf31a91b2022-06-09 08:11:29 -05001452 ParserInterface* parser = ParserFactory::getParser(
1453 vpdVector, (pimPath + baseFruInventoryPath));
Alpana Kumari2f793042020-08-18 05:51:03 -05001454 variant<KeywordVpdMap, Store> parseResult;
1455 parseResult = parser->parse();
SunnySrivastava19849a195542020-09-07 06:04:50 -05001456
Alpana Kumari2f793042020-08-18 05:51:03 -05001457 if (auto pVal = get_if<Store>(&parseResult))
1458 {
1459 populateDbus(pVal->getVpdMap(), js, file);
1460 }
1461 else if (auto pVal = get_if<KeywordVpdMap>(&parseResult))
1462 {
1463 populateDbus(*pVal, js, file);
1464 }
1465
1466 // release the parser object
1467 ParserFactory::freeParser(parser);
1468 }
Patrick Williams8e15b932021-10-06 13:04:22 -05001469 catch (const exception& e)
Alpana Kumari2f793042020-08-18 05:51:03 -05001470 {
Alpana Kumari735dee92022-03-25 01:24:40 -05001471 executePostFailAction(js, file);
PriyangaRamasamya504c3e2020-12-06 12:14:52 -06001472 throw;
Alpana Kumari2f793042020-08-18 05:51:03 -05001473 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301474 }
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001475 catch (const VpdJsonException& ex)
1476 {
1477 additionalData.emplace("JSON_PATH", ex.getJsonPath());
1478 additionalData.emplace("DESCRIPTION", ex.what());
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -05001479 createPEL(additionalData, pelSeverity, errIntfForJsonFailure, nullptr);
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001480
1481 cerr << ex.what() << "\n";
1482 rc = -1;
1483 }
1484 catch (const VpdEccException& ex)
1485 {
1486 additionalData.emplace("DESCRIPTION", "ECC check failed");
1487 additionalData.emplace("CALLOUT_INVENTORY_PATH",
1488 INVENTORY_PATH + baseFruInventoryPath);
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -05001489 createPEL(additionalData, pelSeverity, errIntfForEccCheckFail, nullptr);
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001490 dumpBadVpd(file, vpdVector);
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001491 cerr << ex.what() << "\n";
1492 rc = -1;
1493 }
1494 catch (const VpdDataException& ex)
1495 {
alpana075cb3b1f2021-12-16 11:19:36 -06001496 if (isThisPcieOnPass1planar(js, file))
1497 {
1498 cout << "Pcie_device [" << file
1499 << "]'s VPD is not valid on PASS1 planar.Ignoring.\n";
1500 rc = 0;
1501 }
Santosh Puranik53b38ed2022-04-10 23:15:22 +05301502 else if (!(isPresent(js, file).value_or(true)))
1503 {
1504 cout << "FRU at: " << file
1505 << " is not detected present. Ignore parser error.\n";
1506 rc = 0;
1507 }
alpana075cb3b1f2021-12-16 11:19:36 -06001508 else
1509 {
1510 string errorMsg =
1511 "VPD file is either empty or invalid. Parser failed for [";
1512 errorMsg += file;
1513 errorMsg += "], with error = " + std::string(ex.what());
1514
1515 additionalData.emplace("DESCRIPTION", errorMsg);
1516 additionalData.emplace("CALLOUT_INVENTORY_PATH",
1517 INVENTORY_PATH + baseFruInventoryPath);
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -05001518 createPEL(additionalData, pelSeverity, errIntfForInvalidVPD,
1519 nullptr);
alpana075cb3b1f2021-12-16 11:19:36 -06001520
1521 rc = -1;
1522 }
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001523 }
Patrick Williams8e15b932021-10-06 13:04:22 -05001524 catch (const exception& e)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301525 {
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001526 dumpBadVpd(file, vpdVector);
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301527 cerr << e.what() << "\n";
1528 rc = -1;
1529 }
1530
1531 return rc;
Alpana Kumari735dee92022-03-25 01:24:40 -05001532}