blob: 5993982e00e0808e2baa3bf3998cf6b6abf87afc [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",
905 objectPath);
906
907 additionalData.emplace("DESCRIPTION", errMsg);
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530908 additionalData.emplace("Value on Cache: ",
909 busStream.str());
910 additionalData.emplace(
911 "Value read from EEPROM: ",
912 vpdStream.str());
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500913
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500914 createPEL(additionalData, PelSeverity::WARNING,
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500915 errIntfForInvalidVPD, nullptr);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500916 }
917 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500918
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530919 // If cache data is not blank, then irrespective of
920 // hardware data(blank or other than cache), copy the
921 // cache data to vpd map as we don't need to change the
922 // cache data in either case in the process of
923 // restoring system vpd.
924 Binary busData(busValue.begin(), busValue.end());
925 kwdValue = busValue;
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500926 }
Sunny Srivastavaa559c2d2022-05-02 11:56:45 -0500927 else if (kwdValue.find_first_not_of(defaultValue) ==
928 string::npos)
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500929 {
Priyanga Ramasamyda3b2d22022-10-31 05:42:22 -0500930 if (recordName == "VSYS" && keyword == "FV")
931 {
932 // Continue to the next keyword without logging +PEL
933 // for VSYS FV(stores min version of BMC firmware).
934 // Reason:There is a requirement to support blank FV
935 // so that customer can use the system without
936 // upgrading BMC to the minimum required version.
937 continue;
938 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500939 string errMsg = "VPD is blank on both cache and "
940 "hardware for record: ";
941 errMsg += (*it).first;
942 errMsg += " and keyword: ";
943 errMsg += keyword;
944 errMsg += ". SSR need to update hardware VPD.";
945
946 // both the data are blanks, log PEL
947 PelAdditionalData additionalData;
948 additionalData.emplace("CALLOUT_INVENTORY_PATH",
949 objectPath);
950
951 additionalData.emplace("DESCRIPTION", errMsg);
952
953 // log PEL TODO: Block IPL
Sunny Srivastava0746eee2021-03-22 13:36:54 -0500954 createPEL(additionalData, PelSeverity::ERROR,
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500955 errIntfForBlankSystemVPD, nullptr);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500956 continue;
957 }
958 }
959 }
960 }
961 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500962}
963
964/**
alpana077ce68722021-07-25 13:23:59 -0500965 * @brief This checks for is this FRU a processor
966 * And if yes, then checks for is this primary
967 *
968 * @param[in] js- vpd json to get the information about this FRU
969 * @param[in] filePath- FRU vpd
970 *
971 * @return true/false
972 */
973bool isThisPrimaryProcessor(nlohmann::json& js, const string& filePath)
974{
975 bool isProcessor = false;
976 bool isPrimary = false;
977
978 for (const auto& item : js["frus"][filePath])
979 {
980 if (item.find("extraInterfaces") != item.end())
981 {
982 for (const auto& eI : item["extraInterfaces"].items())
983 {
984 if (eI.key().find("Inventory.Item.Cpu") != string::npos)
985 {
986 isProcessor = true;
987 }
988 }
989 }
990
991 if (isProcessor)
992 {
993 string cpuType = item.value("cpuType", "");
994 if (cpuType == "primary")
995 {
996 isPrimary = true;
997 }
998 }
999 }
1000
1001 return (isProcessor && isPrimary);
1002}
1003
1004/**
1005 * @brief This finds DIMM vpd in vpd json and enables them by binding the device
1006 * driver
1007 * @param[in] js- vpd json to iterate through and take action if it is DIMM
1008 */
1009void doEnableAllDimms(nlohmann::json& js)
1010{
1011 // iterate over each fru
1012 for (const auto& eachFru : js["frus"].items())
1013 {
1014 // skip the driver binding if eeprom already exists
1015 if (fs::exists(eachFru.key()))
1016 {
1017 continue;
1018 }
1019
1020 for (const auto& eachInventory : eachFru.value())
1021 {
1022 if (eachInventory.find("extraInterfaces") != eachInventory.end())
1023 {
1024 for (const auto& eI : eachInventory["extraInterfaces"].items())
1025 {
1026 if (eI.key().find("Inventory.Item.Dimm") != string::npos)
1027 {
1028 string dimmVpd = eachFru.key();
1029 // fetch it from
1030 // "/sys/bus/i2c/drivers/at24/414-0050/eeprom"
1031
1032 regex matchPatern("([0-9]+-[0-9]{4})");
1033 smatch matchFound;
1034 if (regex_search(dimmVpd, matchFound, matchPatern))
1035 {
1036 vector<string> i2cReg;
1037 boost::split(i2cReg, matchFound.str(0),
1038 boost::is_any_of("-"));
1039
1040 // remove 0s from begining
1041 const regex pattern("^0+(?!$)");
1042 for (auto& i : i2cReg)
1043 {
1044 i = regex_replace(i, pattern, "");
1045 }
1046
1047 if (i2cReg.size() == 2)
1048 {
1049 // echo 24c32 0x50 >
1050 // /sys/bus/i2c/devices/i2c-16/new_device
1051 string cmnd = "echo 24c32 0x" + i2cReg[1] +
1052 " > /sys/bus/i2c/devices/i2c-" +
1053 i2cReg[0] + "/new_device";
1054
1055 executeCmd(cmnd);
1056 }
1057 }
1058 }
1059 }
1060 }
1061 }
1062 }
1063}
1064
1065/**
Priyanga Ramasamy6abdeb62022-01-09 23:15:11 -06001066 * @brief Check if the given CPU is an IO only chip.
1067 * The CPU is termed as IO, whose all of the cores are bad and can never be
1068 * used. Those CPU chips can be used for IO purpose like connecting PCIe devices
1069 * etc., The CPU whose every cores are bad, can be identified from the CP00
1070 * record's PG keyword, only if all of the 8 EQs' value equals 0xE7F9FF. (1EQ
1071 * has 4 cores grouped together by sharing its cache memory.)
1072 * @param [in] pgKeyword - PG Keyword of CPU.
1073 * @return true if the given cpu is an IO, false otherwise.
1074 */
1075static bool isCPUIOGoodOnly(const string& pgKeyword)
1076{
1077 const unsigned char io[] = {0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9,
1078 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7,
1079 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF};
1080 // EQ0 index (in PG keyword) starts at 97 (with offset starting from 0).
1081 // Each EQ carries 3 bytes of data. Totally there are 8 EQs. If all EQs'
1082 // value equals 0xE7F9FF, then the cpu has no good cores and its treated as
1083 // IO.
1084 if (memcmp(io, pgKeyword.data() + 97, 24) == 0)
1085 {
1086 return true;
1087 }
1088
1089 // The CPU is not an IO
1090 return false;
1091}
1092
1093/**
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301094 * @brief Populate Dbus.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301095 * This method invokes all the populateInterface functions
1096 * and notifies PIM about dbus object.
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301097 * @param[in] vpdMap - Either IPZ vpd map or Keyword vpd map based on the
1098 * input.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301099 * @param[in] js - Inventory json object
1100 * @param[in] filePath - Path of the vpd file
1101 * @param[in] preIntrStr - Interface string
1102 */
1103template <typename T>
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001104static void populateDbus(T& vpdMap, nlohmann::json& js, const string& filePath)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301105{
1106 inventory::InterfaceMap interfaces;
1107 inventory::ObjectMap objects;
1108 inventory::PropertyMap prop;
Shantappa Teekappanavar6aa54502021-12-09 12:59:56 -06001109 string ccinFromVpd;
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301110
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301111 bool isSystemVpd = (filePath == systemVpdFilePath);
1112 if constexpr (is_same<T, Parsed>::value)
1113 {
Shantappa Teekappanavar6aa54502021-12-09 12:59:56 -06001114 ccinFromVpd = getKwVal(vpdMap, "VINI", "CC");
1115 transform(ccinFromVpd.begin(), ccinFromVpd.end(), ccinFromVpd.begin(),
1116 ::toupper);
1117
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301118 if (isSystemVpd)
1119 {
1120 std::vector<std::string> interfaces = {motherBoardInterface};
1121 // call mapper to check for object path creation
1122 MapperResponse subTree =
1123 getObjectSubtreeForInterfaces(pimPath, 0, interfaces);
1124 string mboardPath =
1125 js["frus"][filePath].at(0).value("inventoryPath", "");
1126
1127 // Attempt system VPD restore if we have a motherboard
1128 // object in the inventory.
1129 if ((subTree.size() != 0) &&
1130 (subTree.find(pimPath + mboardPath) != subTree.end()))
1131 {
Sunny Srivastava3c244142022-01-11 08:47:04 -06001132 restoreSystemVPD(vpdMap, mboardPath);
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301133 }
1134 else
1135 {
1136 log<level::ERR>("No object path found");
1137 }
1138 }
alpana077ce68722021-07-25 13:23:59 -05001139 else
1140 {
1141 // check if it is processor vpd.
1142 auto isPrimaryCpu = isThisPrimaryProcessor(js, filePath);
1143
1144 if (isPrimaryCpu)
1145 {
1146 auto ddVersion = getKwVal(vpdMap, "CRP0", "DD");
1147
1148 auto chipVersion = atoi(ddVersion.substr(1, 2).c_str());
1149
1150 if (chipVersion >= 2)
1151 {
1152 doEnableAllDimms(js);
Santosh Puranik253fbe92022-10-06 22:38:09 +05301153 // Sleep for a few seconds to let the DIMM parses start
1154 using namespace std::chrono_literals;
1155 std::this_thread::sleep_for(5s);
alpana077ce68722021-07-25 13:23:59 -05001156 }
1157 }
1158 }
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301159 }
1160
Santosh Puranikf3e69682022-03-31 17:52:38 +05301161 auto processFactoryReset = false;
1162
Priyanga Ramasamy32c687f2022-01-04 23:14:03 -06001163 if (isSystemVpd)
1164 {
1165 string systemJsonName{};
1166 if constexpr (is_same<T, Parsed>::value)
1167 {
1168 // pick the right system json
1169 systemJsonName = getSystemsJson(vpdMap);
1170 }
1171
1172 fs::path target = systemJsonName;
1173 fs::path link = INVENTORY_JSON_SYM_LINK;
1174
Santosh Puranikf3e69682022-03-31 17:52:38 +05301175 // If the symlink does not exist, we treat that as a factory reset
1176 processFactoryReset = !fs::exists(INVENTORY_JSON_SYM_LINK);
1177
Priyanga Ramasamy32c687f2022-01-04 23:14:03 -06001178 // Create the directory for hosting the symlink
1179 fs::create_directories(VPD_FILES_PATH);
1180 // unlink the symlink previously created (if any)
1181 remove(INVENTORY_JSON_SYM_LINK);
1182 // create a new symlink based on the system
1183 fs::create_symlink(target, link);
1184
1185 // Reloading the json
1186 ifstream inventoryJson(link);
1187 js = json::parse(inventoryJson);
1188 inventoryJson.close();
1189 }
1190
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301191 for (const auto& item : js["frus"][filePath])
1192 {
1193 const auto& objectPath = item["inventoryPath"];
1194 sdbusplus::message::object_path object(objectPath);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001195
Shantappa Teekappanavar6aa54502021-12-09 12:59:56 -06001196 vector<string> ccinList;
1197 if (item.find("ccin") != item.end())
1198 {
1199 for (const auto& cc : item["ccin"])
1200 {
1201 string ccin = cc;
1202 transform(ccin.begin(), ccin.end(), ccin.begin(), ::toupper);
1203 ccinList.push_back(ccin);
1204 }
1205 }
1206
1207 if (!ccinFromVpd.empty() && !ccinList.empty() &&
1208 (find(ccinList.begin(), ccinList.end(), ccinFromVpd) ==
1209 ccinList.end()))
1210 {
1211 continue;
1212 }
1213
Priyanga Ramasamye3fed702022-01-11 01:05:32 -06001214 if ((isSystemVpd) || (item.value("noprime", false)))
Santosh Puranikd3a379a2021-08-23 19:12:59 +05301215 {
Priyanga Ramasamye3fed702022-01-11 01:05:32 -06001216
1217 // Populate one time properties for the system VPD and its sub-frus
1218 // and for other non-primeable frus.
Santosh Puranikd3a379a2021-08-23 19:12:59 +05301219 // For the remaining FRUs, this will get handled as a part of
1220 // priming the inventory.
1221 setOneTimeProperties(objectPath, interfaces);
1222 }
1223
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301224 // Populate the VPD keywords and the common interfaces only if we
1225 // are asked to inherit that data from the VPD, else only add the
1226 // extraInterfaces.
1227 if (item.value("inherit", true))
1228 {
Alpana Kumari58e22142020-05-05 00:22:12 -05001229 if constexpr (is_same<T, Parsed>::value)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301230 {
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301231 // Each record in the VPD becomes an interface and all
1232 // keyword within the record are properties under that
1233 // interface.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301234 for (const auto& record : vpdMap)
1235 {
1236 populateFruSpecificInterfaces(
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001237 record.second, ipzVpdInf + record.first, interfaces);
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301238 }
1239 }
Alpana Kumari58e22142020-05-05 00:22:12 -05001240 else if constexpr (is_same<T, KeywordVpdMap>::value)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301241 {
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001242 populateFruSpecificInterfaces(vpdMap, kwdVpdInf, interfaces);
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301243 }
Santosh Puranik88edeb62020-03-02 12:00:09 +05301244 if (js.find("commonInterfaces") != js.end())
1245 {
1246 populateInterfaces(js["commonInterfaces"], interfaces, vpdMap,
1247 isSystemVpd);
1248 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301249 }
Santosh Puranik0859eb62020-03-16 02:56:29 -05001250 else
1251 {
1252 // Check if we have been asked to inherit specific record(s)
Alpana Kumari58e22142020-05-05 00:22:12 -05001253 if constexpr (is_same<T, Parsed>::value)
Santosh Puranik0859eb62020-03-16 02:56:29 -05001254 {
1255 if (item.find("copyRecords") != item.end())
1256 {
1257 for (const auto& record : item["copyRecords"])
1258 {
1259 const string& recordName = record;
1260 if (vpdMap.find(recordName) != vpdMap.end())
1261 {
1262 populateFruSpecificInterfaces(
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001263 vpdMap.at(recordName), ipzVpdInf + recordName,
Santosh Puranik0859eb62020-03-16 02:56:29 -05001264 interfaces);
1265 }
1266 }
1267 }
1268 }
1269 }
Santosh Puranik32c46502022-02-10 08:55:07 +05301270 // Populate interfaces and properties that are common to every FRU
1271 // and additional interface that might be defined on a per-FRU
1272 // basis.
1273 if (item.find("extraInterfaces") != item.end())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301274 {
Santosh Puranik32c46502022-02-10 08:55:07 +05301275 populateInterfaces(item["extraInterfaces"], interfaces, vpdMap,
1276 isSystemVpd);
Priyanga Ramasamy6abdeb62022-01-09 23:15:11 -06001277 if constexpr (is_same<T, Parsed>::value)
1278 {
1279 if (item["extraInterfaces"].find(
1280 "xyz.openbmc_project.Inventory.Item.Cpu") !=
1281 item["extraInterfaces"].end())
1282 {
1283 if (isCPUIOGoodOnly(getKwVal(vpdMap, "CP00", "PG")))
1284 {
Priyanga Ramasamy2c607a92022-04-08 00:30:17 -05001285 interfaces[invItemIntf]["PrettyName"] = "IO Module";
Priyanga Ramasamy6abdeb62022-01-09 23:15:11 -06001286 }
1287 }
1288 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301289 }
Priyanga Ramasamye358acb2022-03-21 14:21:50 -05001290
1291 // embedded property(true or false) says whether the subfru is embedded
1292 // into the parent fru (or) not. VPD sets Present property only for
1293 // embedded frus. If the subfru is not an embedded FRU, the subfru may
1294 // or may not be physically present. Those non embedded frus will always
1295 // have Present=false irrespective of its physical presence or absence.
1296 // Eg: nvme drive in nvme slot is not an embedded FRU. So don't set
1297 // Present to true for such sub frus.
1298 // Eg: ethernet port is embedded into bmc card. So set Present to true
1299 // for such sub frus. Also donot populate present property for embedded
1300 // subfru which is synthesized. Currently there is no subfru which are
1301 // both embedded and synthesized. But still the case is handled here.
1302 if ((item.value("embedded", true)) &&
1303 (!item.value("synthesized", false)))
1304 {
1305 inventory::PropertyMap presProp;
1306 presProp.emplace("Present", true);
1307 insertOrMerge(interfaces, invItemIntf, move(presProp));
1308 }
Priyanga Ramasamyaa8a8932022-01-27 09:12:41 -06001309
Santosh Puranikf3e69682022-03-31 17:52:38 +05301310 if constexpr (is_same<T, Parsed>::value)
1311 {
1312 // Restore asset tag, if needed
1313 if (processFactoryReset && objectPath == "/system")
1314 {
1315 fillAssetTag(interfaces, vpdMap);
1316 }
1317 }
1318
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301319 objects.emplace(move(object), move(interfaces));
1320 }
1321
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301322 if (isSystemVpd)
1323 {
1324 inventory::ObjectMap primeObject = primeInventory(js, vpdMap);
1325 objects.insert(primeObject.begin(), primeObject.end());
Alpana Kumari65b83602020-09-01 00:24:56 -05001326
Alpana Kumarif05effd2021-04-07 07:32:53 -05001327 // set the U-boot environment variable for device-tree
1328 if constexpr (is_same<T, Parsed>::value)
1329 {
Santosh Puranike5f177a2022-01-24 20:14:46 +05301330 setDevTreeEnv(fs::path(getSystemsJson(vpdMap)).filename());
Alpana Kumarif05effd2021-04-07 07:32:53 -05001331 }
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301332 }
1333
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301334 // Notify PIM
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -05001335 common::utility::callPIM(move(objects));
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301336}
1337
1338int main(int argc, char** argv)
1339{
1340 int rc = 0;
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001341 json js{};
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001342 Binary vpdVector{};
1343 string file{};
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001344 // map to hold additional data in case of logging pel
1345 PelAdditionalData additionalData{};
1346
1347 // this is needed to hold base fru inventory path in case there is ECC or
1348 // vpd exception while parsing the file
1349 std::string baseFruInventoryPath = {};
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301350
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001351 // severity for PEL
1352 PelSeverity pelSeverity = PelSeverity::WARNING;
1353
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301354 try
1355 {
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301356 App app{"ibm-read-vpd - App to read IPZ format VPD, parse it and store "
1357 "in DBUS"};
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301358
1359 app.add_option("-f, --file", file, "File containing VPD (IPZ/KEYWORD)")
Alpana Kumari2f793042020-08-18 05:51:03 -05001360 ->required();
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301361
1362 CLI11_PARSE(app, argc, argv);
1363
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001364 // PEL severity should be ERROR in case of any system VPD failure
1365 if (file == systemVpdFilePath)
1366 {
1367 pelSeverity = PelSeverity::ERROR;
1368 }
1369
Santosh Puranik0246a4d2020-11-04 16:57:39 +05301370 auto jsonToParse = INVENTORY_JSON_DEFAULT;
1371
1372 // If the symlink exists, it means it has been setup for us, switch the
1373 // path
1374 if (fs::exists(INVENTORY_JSON_SYM_LINK))
1375 {
1376 jsonToParse = INVENTORY_JSON_SYM_LINK;
1377 }
1378
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301379 // Make sure that the file path we get is for a supported EEPROM
Santosh Puranik0246a4d2020-11-04 16:57:39 +05301380 ifstream inventoryJson(jsonToParse);
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001381 if (!inventoryJson)
1382 {
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001383 throw(VpdJsonException("Failed to access Json path", jsonToParse));
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001384 }
1385
1386 try
1387 {
1388 js = json::parse(inventoryJson);
1389 }
Patrick Williams8e15b932021-10-06 13:04:22 -05001390 catch (const json::parse_error& ex)
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001391 {
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001392 throw(VpdJsonException("Json parsing failed", jsonToParse));
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001393 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301394
Santosh Puranik12e24ff2021-05-11 19:33:50 +05301395 // Do we have the mandatory "frus" section?
1396 if (js.find("frus") == js.end())
1397 {
1398 throw(VpdJsonException("FRUs section not found in JSON",
1399 jsonToParse));
1400 }
1401
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301402 // Check if it's a udev path - patterned as(/ahb/ahb:apb/ahb:apb:bus@)
1403 if (file.find("/ahb:apb") != string::npos)
1404 {
1405 // Translate udev path to a generic /sys/bus/.. file path.
1406 udevToGenericPath(file);
Santosh Puranik12e24ff2021-05-11 19:33:50 +05301407
1408 if ((js["frus"].find(file) != js["frus"].end()) &&
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301409 (file == systemVpdFilePath))
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301410 {
Santosh Puranik6b2b5372022-06-02 20:49:02 +05301411 // We have already collected system VPD, skip.
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301412 return 0;
1413 }
1414 }
1415
1416 if (file.empty())
1417 {
1418 cerr << "The EEPROM path <" << file << "> is not valid.";
1419 return 0;
1420 }
Santosh Puranik12e24ff2021-05-11 19:33:50 +05301421 if (js["frus"].find(file) == js["frus"].end())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301422 {
Santosh Puranik88edeb62020-03-02 12:00:09 +05301423 return 0;
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301424 }
1425
Alpana Kumari2f793042020-08-18 05:51:03 -05001426 if (!fs::exists(file))
1427 {
1428 cout << "Device path: " << file
1429 << " does not exist. Spurious udev event? Exiting." << endl;
1430 return 0;
1431 }
1432
Santosh Puranikdedb5a62022-12-19 23:58:32 +05301433 // In case of system VPD it will already be filled, Don't have to
1434 // overwrite that.
1435 if (baseFruInventoryPath.empty())
1436 {
1437 baseFruInventoryPath = js["frus"][file][0]["inventoryPath"];
1438 }
1439
Santosh Puranik85893752020-11-10 21:31:43 +05301440 // Check if we can read the VPD file based on the power state
Santosh Puranik27a5e952021-10-07 22:08:01 -05001441 // We skip reading VPD when the power is ON in two scenarios:
Santosh Puranik31d50fa2022-04-04 12:04:37 +05301442 // 1) The eeprom we are trying to read is that of the system VPD and the
1443 // JSON symlink is already setup (the symlink's existence tells us we
1444 // are not coming out of a factory reset)
1445 // 2) The JSON tells us that the FRU EEPROM cannot be
1446 // read when we are powered ON.
Santosh Puranik27a5e952021-10-07 22:08:01 -05001447 if (js["frus"][file].at(0).value("powerOffOnly", false) ||
Santosh Puranik31d50fa2022-04-04 12:04:37 +05301448 (file == systemVpdFilePath && fs::exists(INVENTORY_JSON_SYM_LINK)))
Santosh Puranik85893752020-11-10 21:31:43 +05301449 {
1450 if ("xyz.openbmc_project.State.Chassis.PowerState.On" ==
1451 getPowerState())
1452 {
1453 cout << "This VPD cannot be read when power is ON" << endl;
1454 return 0;
1455 }
1456 }
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001457
Santosh Puranike9c57532022-03-15 16:51:51 +05301458 // Check if this VPD should be recollected at all
1459 if (!needsRecollection(js, file))
1460 {
1461 cout << "Skip VPD recollection for: " << file << endl;
1462 return 0;
1463 }
1464
Alpana Kumari2f793042020-08-18 05:51:03 -05001465 try
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301466 {
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001467 vpdVector = getVpdDataInVector(js, file);
Sunny Srivastavaf31a91b2022-06-09 08:11:29 -05001468 ParserInterface* parser = ParserFactory::getParser(
1469 vpdVector, (pimPath + baseFruInventoryPath));
Alpana Kumari2f793042020-08-18 05:51:03 -05001470 variant<KeywordVpdMap, Store> parseResult;
1471 parseResult = parser->parse();
SunnySrivastava19849a195542020-09-07 06:04:50 -05001472
Alpana Kumari2f793042020-08-18 05:51:03 -05001473 if (auto pVal = get_if<Store>(&parseResult))
1474 {
1475 populateDbus(pVal->getVpdMap(), js, file);
1476 }
1477 else if (auto pVal = get_if<KeywordVpdMap>(&parseResult))
1478 {
1479 populateDbus(*pVal, js, file);
1480 }
1481
1482 // release the parser object
1483 ParserFactory::freeParser(parser);
1484 }
Patrick Williams8e15b932021-10-06 13:04:22 -05001485 catch (const exception& e)
Alpana Kumari2f793042020-08-18 05:51:03 -05001486 {
Alpana Kumari735dee92022-03-25 01:24:40 -05001487 executePostFailAction(js, file);
PriyangaRamasamya504c3e2020-12-06 12:14:52 -06001488 throw;
Alpana Kumari2f793042020-08-18 05:51:03 -05001489 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301490 }
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001491 catch (const VpdJsonException& ex)
1492 {
1493 additionalData.emplace("JSON_PATH", ex.getJsonPath());
1494 additionalData.emplace("DESCRIPTION", ex.what());
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -05001495 createPEL(additionalData, pelSeverity, errIntfForJsonFailure, nullptr);
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001496
1497 cerr << ex.what() << "\n";
1498 rc = -1;
1499 }
1500 catch (const VpdEccException& ex)
1501 {
1502 additionalData.emplace("DESCRIPTION", "ECC check failed");
1503 additionalData.emplace("CALLOUT_INVENTORY_PATH",
1504 INVENTORY_PATH + baseFruInventoryPath);
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -05001505 createPEL(additionalData, pelSeverity, errIntfForEccCheckFail, nullptr);
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001506 dumpBadVpd(file, vpdVector);
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001507 cerr << ex.what() << "\n";
1508 rc = -1;
1509 }
1510 catch (const VpdDataException& ex)
1511 {
alpana075cb3b1f2021-12-16 11:19:36 -06001512 if (isThisPcieOnPass1planar(js, file))
1513 {
1514 cout << "Pcie_device [" << file
1515 << "]'s VPD is not valid on PASS1 planar.Ignoring.\n";
1516 rc = 0;
1517 }
Santosh Puranik53b38ed2022-04-10 23:15:22 +05301518 else if (!(isPresent(js, file).value_or(true)))
1519 {
1520 cout << "FRU at: " << file
1521 << " is not detected present. Ignore parser error.\n";
1522 rc = 0;
1523 }
alpana075cb3b1f2021-12-16 11:19:36 -06001524 else
1525 {
1526 string errorMsg =
1527 "VPD file is either empty or invalid. Parser failed for [";
1528 errorMsg += file;
1529 errorMsg += "], with error = " + std::string(ex.what());
1530
1531 additionalData.emplace("DESCRIPTION", errorMsg);
1532 additionalData.emplace("CALLOUT_INVENTORY_PATH",
1533 INVENTORY_PATH + baseFruInventoryPath);
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -05001534 createPEL(additionalData, pelSeverity, errIntfForInvalidVPD,
1535 nullptr);
alpana075cb3b1f2021-12-16 11:19:36 -06001536
1537 rc = -1;
1538 }
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001539 }
Patrick Williams8e15b932021-10-06 13:04:22 -05001540 catch (const exception& e)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301541 {
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001542 dumpBadVpd(file, vpdVector);
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301543 cerr << e.what() << "\n";
1544 rc = -1;
1545 }
1546
1547 return rc;
Alpana Kumari735dee92022-03-25 01:24:40 -05001548}