blob: 476d802f3bacc946270f7c272ab2bff0dcd5973c [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"
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05005#include "editor_impl.hpp"
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -05006#include "ibm_vpd_utils.hpp"
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05007#include "ipz_parser.hpp"
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05308#include "keyword_vpd_parser.hpp"
Alpana Kumaria00936f2020-04-14 07:15:46 -05009#include "memory_vpd_parser.hpp"
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050010#include "parser_factory.hpp"
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -050011#include "vpd_exceptions.hpp"
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053012
SunnySrivastava19849094d4f2020-08-05 09:32:29 -050013#include <assert.h>
Alpana Kumari8ea3f6d2020-04-02 00:26:07 -050014#include <ctype.h>
15
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053016#include <CLI/CLI.hpp>
alpana077ce68722021-07-25 13:23:59 -050017#include <boost/algorithm/string.hpp>
Patrick Williamsc78d8872023-05-10 07:50:56 -050018#include <gpiod.hpp>
19#include <phosphor-logging/log.hpp>
20
21#include <algorithm>
Alpana Kumari65b83602020-09-01 00:24:56 -050022#include <cstdarg>
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053023#include <exception>
PriyangaRamasamy83a1d5d2020-04-30 19:15:43 +053024#include <filesystem>
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053025#include <fstream>
26#include <iostream>
27#include <iterator>
alpana077ce68722021-07-25 13:23:59 -050028#include <regex>
Santosh Puranik253fbe92022-10-06 22:38:09 +053029#include <thread>
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053030
31using namespace std;
32using namespace openpower::vpd;
33using namespace CLI;
34using namespace vpd::keyword::parser;
PriyangaRamasamy83a1d5d2020-04-30 19:15:43 +053035using namespace openpower::vpd::constants;
36namespace fs = filesystem;
37using json = nlohmann::json;
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050038using namespace openpower::vpd::parser::factory;
SunnySrivastava1984945a02d2020-05-06 01:55:41 -050039using namespace openpower::vpd::inventory;
Alpana Kumaria00936f2020-04-14 07:15:46 -050040using namespace openpower::vpd::memory::parser;
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050041using namespace openpower::vpd::parser::interface;
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -050042using namespace openpower::vpd::exceptions;
Andrew Geissler280197e2020-12-08 20:51:49 -060043using namespace phosphor::logging;
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -050044using namespace openpower::vpd::manager::editor;
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053045
Santosh Puranik88edeb62020-03-02 12:00:09 +053046/**
Sunny Srivastava37992a62023-07-11 05:18:41 -050047 * @brief API declaration, Populate Dbus.
48 *
49 * This method invokes all the populateInterface functions
50 * and notifies PIM about dbus object.
51 *
52 * @param[in] vpdMap - Either IPZ vpd map or Keyword vpd map based on the
53 * input.
54 * @param[in] js - Inventory json object
55 * @param[in] filePath - Path of the vpd file
56 * @param[in] preIntrStr - Interface string
57 */
58template <typename T>
59static void populateDbus(T& vpdMap, nlohmann::json& js, const string& filePath);
60
61/**
Santosh Puranike9c57532022-03-15 16:51:51 +053062 * @brief Returns the BMC state
63 */
64static auto getBMCState()
65{
66 std::string bmcState;
67 try
68 {
69 auto bus = sdbusplus::bus::new_default();
70 auto properties = bus.new_method_call(
71 "xyz.openbmc_project.State.BMC", "/xyz/openbmc_project/state/bmc0",
72 "org.freedesktop.DBus.Properties", "Get");
73 properties.append("xyz.openbmc_project.State.BMC");
74 properties.append("CurrentBMCState");
75 auto result = bus.call(properties);
76 std::variant<std::string> val;
77 result.read(val);
78 if (auto pVal = std::get_if<std::string>(&val))
79 {
80 bmcState = *pVal;
81 }
82 }
83 catch (const sdbusplus::exception::SdBusError& e)
84 {
85 // Ignore any error
86 std::cerr << "Failed to get BMC state: " << e.what() << "\n";
Jinu Joy Thomas0b33b342024-02-27 21:44:24 -060087 // Since we failed set to not ready state
88 bmcState = "xyz.openbmc_project.State.BMC.BMCState.NotReady";
Santosh Puranike9c57532022-03-15 16:51:51 +053089 }
90 return bmcState;
91}
92
93/**
94 * @brief Check if the FRU is in the cache
95 *
96 * Checks if the FRU associated with the supplied D-Bus object path is already
97 * on D-Bus. This can be used to test if a VPD collection is required for this
98 * FRU. It uses the "xyz.openbmc_project.Inventory.Item, Present" property to
99 * determine the presence of a FRU in the cache.
100 *
101 * @param objectPath - The D-Bus object path without the PIM prefix.
102 * @return true if the object exists on D-Bus, false otherwise.
103 */
104static auto isFruInVpdCache(const std::string& objectPath)
105{
106 try
107 {
108 auto bus = sdbusplus::bus::new_default();
109 auto invPath = std::string{pimPath} + objectPath;
110 auto props = bus.new_method_call(
111 "xyz.openbmc_project.Inventory.Manager", invPath.c_str(),
112 "org.freedesktop.DBus.Properties", "Get");
113 props.append("xyz.openbmc_project.Inventory.Item");
114 props.append("Present");
115 auto result = bus.call(props);
116 std::variant<bool> present;
117 result.read(present);
118 if (auto pVal = std::get_if<bool>(&present))
119 {
120 return *pVal;
121 }
122 return false;
123 }
124 catch (const sdbusplus::exception::SdBusError& e)
125 {
126 std::cout << "FRU: " << objectPath << " not in D-Bus\n";
127 // Assume not present in case of an error
128 return false;
129 }
130}
131
132/**
133 * @brief Check if VPD recollection is needed for the given EEPROM
134 *
135 * Not all FRUs can be swapped at BMC ready state. This function does the
136 * following:
137 * -- Check if the FRU is marked as "pluggableAtStandby" OR
138 * "concurrentlyMaintainable". If so, return true.
139 * -- Check if we are at BMC NotReady state. If we are, then return true.
140 * -- Else check if the FRU is not present in the VPD cache (to cover for VPD
141 * force collection). If not found in the cache, return true.
142 * -- Else return false.
143 *
144 * @param js - JSON Object.
145 * @param filePath - The EEPROM file.
146 * @return true if collection should be attempted, false otherwise.
147 */
148static auto needsRecollection(const nlohmann::json& js, const string& filePath)
149{
150 if (js["frus"][filePath].at(0).value("pluggableAtStandby", false) ||
151 js["frus"][filePath].at(0).value("concurrentlyMaintainable", false))
152 {
153 return true;
154 }
155 if (getBMCState() == "xyz.openbmc_project.State.BMC.BMCState.NotReady")
156 {
157 return true;
158 }
159 if (!isFruInVpdCache(js["frus"][filePath].at(0).value("inventoryPath", "")))
160 {
161 return true;
162 }
163 return false;
164}
165
166/**
Santosh Puranik88edeb62020-03-02 12:00:09 +0530167 * @brief Expands location codes
168 */
169static auto expandLocationCode(const string& unexpanded, const Parsed& vpdMap,
170 bool isSystemVpd)
171{
172 auto expanded{unexpanded};
173 static constexpr auto SYSTEM_OBJECT = "/system/chassis/motherboard";
174 static constexpr auto VCEN_IF = "com.ibm.ipzvpd.VCEN";
175 static constexpr auto VSYS_IF = "com.ibm.ipzvpd.VSYS";
176 size_t idx = expanded.find("fcs");
177 try
178 {
179 if (idx != string::npos)
180 {
181 string fc{};
182 string se{};
183 if (isSystemVpd)
184 {
185 const auto& fcData = vpdMap.at("VCEN").at("FC");
186 const auto& seData = vpdMap.at("VCEN").at("SE");
187 fc = string(fcData.data(), fcData.size());
188 se = string(seData.data(), seData.size());
189 }
190 else
191 {
192 fc = readBusProperty(SYSTEM_OBJECT, VCEN_IF, "FC");
193 se = readBusProperty(SYSTEM_OBJECT, VCEN_IF, "SE");
194 }
195
Alpana Kumari81671f62021-02-10 02:21:59 -0600196 // TODO: See if ND0 can be placed in the JSON
197 expanded.replace(idx, 3, fc.substr(0, 4) + ".ND0." + se);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530198 }
199 else
200 {
201 idx = expanded.find("mts");
202 if (idx != string::npos)
203 {
204 string mt{};
205 string se{};
206 if (isSystemVpd)
207 {
208 const auto& mtData = vpdMap.at("VSYS").at("TM");
209 const auto& seData = vpdMap.at("VSYS").at("SE");
210 mt = string(mtData.data(), mtData.size());
211 se = string(seData.data(), seData.size());
212 }
213 else
214 {
215 mt = readBusProperty(SYSTEM_OBJECT, VSYS_IF, "TM");
216 se = readBusProperty(SYSTEM_OBJECT, VSYS_IF, "SE");
217 }
218
219 replace(mt.begin(), mt.end(), '-', '.');
220 expanded.replace(idx, 3, mt + "." + se);
221 }
222 }
223 }
Patrick Williams8e15b932021-10-06 13:04:22 -0500224 catch (const exception& e)
Santosh Puranik88edeb62020-03-02 12:00:09 +0530225 {
jinuthomasf457a3e2023-04-13 12:22:48 -0500226 std::cerr << "Failed to expand location code with exception: "
227 << e.what() << "\n";
Santosh Puranik88edeb62020-03-02 12:00:09 +0530228 }
229 return expanded;
230}
Alpana Kumari2f793042020-08-18 05:51:03 -0500231
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530232/**
233 * @brief Populate FRU specific interfaces.
234 *
235 * This is a common method which handles both
236 * ipz and keyword specific interfaces thus,
237 * reducing the code redundancy.
238 * @param[in] map - Reference to the innermost keyword-value map.
239 * @param[in] preIntrStr - Reference to the interface string.
240 * @param[out] interfaces - Reference to interface map.
241 */
242template <typename T>
Patrick Williams08dc31c2024-08-16 15:21:06 -0400243static void populateFruSpecificInterfaces(
244 const T& map, const string& preIntrStr, inventory::InterfaceMap& interfaces)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530245{
246 inventory::PropertyMap prop;
247
248 for (const auto& kwVal : map)
249 {
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530250 auto kw = kwVal.first;
251
252 if (kw[0] == '#')
253 {
Alpana Kumari58e22142020-05-05 00:22:12 -0500254 kw = string("PD_") + kw[1];
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530255 }
Alpana Kumari8ea3f6d2020-04-02 00:26:07 -0500256 else if (isdigit(kw[0]))
257 {
Alpana Kumari58e22142020-05-05 00:22:12 -0500258 kw = string("N_") + kw;
Alpana Kumari8ea3f6d2020-04-02 00:26:07 -0500259 }
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000260 if constexpr (is_same<T, KeywordVpdMap>::value)
261 {
jinuthomasd640f692023-03-28 04:13:23 -0500262 if (auto keywordValue = get_if<Binary>(&kwVal.second))
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000263 {
jinuthomasd640f692023-03-28 04:13:23 -0500264 Binary vec((*keywordValue).begin(), (*keywordValue).end());
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000265 prop.emplace(move(kw), move(vec));
266 }
jinuthomasd640f692023-03-28 04:13:23 -0500267 else if (auto keywordValue = get_if<std::string>(&kwVal.second))
268 {
269 Binary vec((*keywordValue).begin(), (*keywordValue).end());
270 prop.emplace(move(kw), move(vec));
271 }
272 else if (auto keywordValue = get_if<size_t>(&kwVal.second))
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000273 {
274 if (kw == "MemorySizeInKB")
275 {
276 inventory::PropertyMap memProp;
jinuthomasd640f692023-03-28 04:13:23 -0500277 memProp.emplace(move(kw), ((*keywordValue)));
278 interfaces.emplace(
279 "xyz.openbmc_project.Inventory.Item.Dimm",
280 move(memProp));
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000281 }
jinuthomasd640f692023-03-28 04:13:23 -0500282 else
283 {
jinuthomasf457a3e2023-04-13 12:22:48 -0500284 std::cerr << "Unknown Keyword[" << kw << "] found ";
jinuthomasd640f692023-03-28 04:13:23 -0500285 }
286 }
287 else
288 {
jinuthomasf457a3e2023-04-13 12:22:48 -0500289 std::cerr << "Unknown Variant found ";
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000290 }
291 }
292 else
293 {
294 Binary vec(kwVal.second.begin(), kwVal.second.end());
295 prop.emplace(move(kw), move(vec));
296 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530297 }
298
299 interfaces.emplace(preIntrStr, move(prop));
300}
301
302/**
303 * @brief Populate Interfaces.
304 *
305 * This method populates common and extra interfaces to dbus.
306 * @param[in] js - json object
307 * @param[out] interfaces - Reference to interface map
308 * @param[in] vpdMap - Reference to the parsed vpd map.
Santosh Puranik88edeb62020-03-02 12:00:09 +0530309 * @param[in] isSystemVpd - Denotes whether we are collecting the system VPD.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530310 */
311template <typename T>
312static void populateInterfaces(const nlohmann::json& js,
313 inventory::InterfaceMap& interfaces,
Santosh Puranik88edeb62020-03-02 12:00:09 +0530314 const T& vpdMap, bool isSystemVpd)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530315{
316 for (const auto& ifs : js.items())
317 {
Santosh Puranik88edeb62020-03-02 12:00:09 +0530318 string inf = ifs.key();
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530319 inventory::PropertyMap props;
320
321 for (const auto& itr : ifs.value().items())
322 {
Santosh Puranik88edeb62020-03-02 12:00:09 +0530323 const string& busProp = itr.key();
324
Alpana Kumari31970de2020-02-17 06:49:57 -0600325 if (itr.value().is_boolean())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530326 {
Santosh Puranik88edeb62020-03-02 12:00:09 +0530327 props.emplace(busProp, itr.value().get<bool>());
328 }
329 else if (itr.value().is_string())
330 {
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600331 if (busProp == "LocationCode" && inf == IBM_LOCATION_CODE_INF)
Santosh Puranik88edeb62020-03-02 12:00:09 +0530332 {
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600333 std::string prop;
334 if constexpr (is_same<T, Parsed>::value)
Santosh Puranik88edeb62020-03-02 12:00:09 +0530335 {
Alpana Kumari414d5ae2021-03-04 21:06:35 +0000336 // TODO deprecate the com.ibm interface later
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600337 prop = expandLocationCode(itr.value().get<string>(),
338 vpdMap, isSystemVpd);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530339 }
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600340 else if constexpr (is_same<T, KeywordVpdMap>::value)
Santosh Puranik88edeb62020-03-02 12:00:09 +0530341 {
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600342 // Send empty Parsed object to expandLocationCode api.
343 prop = expandLocationCode(itr.value().get<string>(),
344 Parsed{}, false);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530345 }
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600346 props.emplace(busProp, prop);
347 interfaces.emplace(XYZ_LOCATION_CODE_INF, props);
348 interfaces.emplace(IBM_LOCATION_CODE_INF, props);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530349 }
350 else
351 {
352 props.emplace(busProp, itr.value().get<string>());
353 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530354 }
Santosh Puraniked609af2021-06-21 11:30:07 +0530355 else if (itr.value().is_array())
356 {
357 try
358 {
359 props.emplace(busProp, itr.value().get<Binary>());
360 }
Patrick Williams8e15b932021-10-06 13:04:22 -0500361 catch (const nlohmann::detail::type_error& e)
Santosh Puraniked609af2021-06-21 11:30:07 +0530362 {
363 std::cerr << "Type exception: " << e.what() << "\n";
364 // Ignore any type errors
365 }
366 }
Alpana Kumari31970de2020-02-17 06:49:57 -0600367 else if (itr.value().is_object())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530368 {
Alpana Kumari31970de2020-02-17 06:49:57 -0600369 const string& rec = itr.value().value("recordName", "");
370 const string& kw = itr.value().value("keywordName", "");
371 const string& encoding = itr.value().value("encoding", "");
372
Alpana Kumari58e22142020-05-05 00:22:12 -0500373 if constexpr (is_same<T, Parsed>::value)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530374 {
Santosh Puranik88edeb62020-03-02 12:00:09 +0530375 if (!rec.empty() && !kw.empty() && vpdMap.count(rec) &&
376 vpdMap.at(rec).count(kw))
Alpana Kumari31970de2020-02-17 06:49:57 -0600377 {
Patrick Williams08dc31c2024-08-16 15:21:06 -0400378 auto encoded =
379 encodeKeyword(vpdMap.at(rec).at(kw), encoding);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530380 props.emplace(busProp, encoded);
Alpana Kumari31970de2020-02-17 06:49:57 -0600381 }
382 }
Alpana Kumari58e22142020-05-05 00:22:12 -0500383 else if constexpr (is_same<T, KeywordVpdMap>::value)
Alpana Kumari31970de2020-02-17 06:49:57 -0600384 {
385 if (!kw.empty() && vpdMap.count(kw))
386 {
jinuthomasd640f692023-03-28 04:13:23 -0500387 if (auto kwValue = get_if<Binary>(&vpdMap.at(kw)))
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000388 {
Patrick Williams08dc31c2024-08-16 15:21:06 -0400389 auto prop =
390 string((*kwValue).begin(), (*kwValue).end());
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000391
392 auto encoded = encodeKeyword(prop, encoding);
393
394 props.emplace(busProp, encoded);
395 }
jinuthomasd640f692023-03-28 04:13:23 -0500396 else if (auto kwValue =
397 get_if<std::string>(&vpdMap.at(kw)))
398 {
Patrick Williams08dc31c2024-08-16 15:21:06 -0400399 auto prop =
400 string((*kwValue).begin(), (*kwValue).end());
jinuthomasd640f692023-03-28 04:13:23 -0500401
402 auto encoded = encodeKeyword(prop, encoding);
403
404 props.emplace(busProp, encoded);
405 }
406 else if (auto uintValue =
407 get_if<size_t>(&vpdMap.at(kw)))
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000408 {
409 props.emplace(busProp, *uintValue);
410 }
jinuthomasd640f692023-03-28 04:13:23 -0500411 else
412 {
413 std::cerr << " Unknown Keyword [" << kw
414 << "] Encountered";
415 }
Alpana Kumari31970de2020-02-17 06:49:57 -0600416 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530417 }
418 }
Matt Spinlerb1e64bb2021-09-08 09:57:48 -0500419 else if (itr.value().is_number())
420 {
421 // For now assume the value is a size_t. In the future it would
422 // be nice to come up with a way to get the type from the JSON.
423 props.emplace(busProp, itr.value().get<size_t>());
424 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530425 }
Priyanga Ramasamyaa8a8932022-01-27 09:12:41 -0600426 insertOrMerge(interfaces, inf, move(props));
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530427 }
428}
429
alpana075cb3b1f2021-12-16 11:19:36 -0600430/**
431 * @brief This API checks if this FRU is pcie_devices. If yes then it further
432 * checks whether it is PASS1 planar.
433 */
434static bool isThisPcieOnPass1planar(const nlohmann::json& js,
435 const string& file)
436{
437 auto isThisPCIeDev = false;
438 auto isPASS1 = false;
439
440 // Check if it is a PCIE device
441 if (js["frus"].find(file) != js["frus"].end())
442 {
Santosh Puranikc03f3902022-04-14 10:58:26 +0530443 if ((js["frus"][file].at(0).find("extraInterfaces") !=
444 js["frus"][file].at(0).end()))
alpana075cb3b1f2021-12-16 11:19:36 -0600445 {
Santosh Puranikc03f3902022-04-14 10:58:26 +0530446 if (js["frus"][file].at(0)["extraInterfaces"].find(
alpana075cb3b1f2021-12-16 11:19:36 -0600447 "xyz.openbmc_project.Inventory.Item.PCIeDevice") !=
Santosh Puranikc03f3902022-04-14 10:58:26 +0530448 js["frus"][file].at(0)["extraInterfaces"].end())
alpana075cb3b1f2021-12-16 11:19:36 -0600449 {
450 isThisPCIeDev = true;
451 }
452 }
453 }
454
455 if (isThisPCIeDev)
456 {
Alpana Kumaria6181e22022-05-12 05:01:53 -0500457 // Collect HW version and SystemType to know if it is PASS1 planar.
alpana075cb3b1f2021-12-16 11:19:36 -0600458 auto bus = sdbusplus::bus::new_default();
Alpana Kumaria6181e22022-05-12 05:01:53 -0500459 auto property1 = bus.new_method_call(
alpana075cb3b1f2021-12-16 11:19:36 -0600460 INVENTORY_MANAGER_SERVICE,
461 "/xyz/openbmc_project/inventory/system/chassis/motherboard",
462 "org.freedesktop.DBus.Properties", "Get");
Alpana Kumaria6181e22022-05-12 05:01:53 -0500463 property1.append("com.ibm.ipzvpd.VINI");
464 property1.append("HW");
465 auto result1 = bus.call(property1);
466 inventory::Value hwVal;
467 result1.read(hwVal);
alpana075cb3b1f2021-12-16 11:19:36 -0600468
Alpana Kumaria6181e22022-05-12 05:01:53 -0500469 // SystemType
470 auto property2 = bus.new_method_call(
471 INVENTORY_MANAGER_SERVICE,
472 "/xyz/openbmc_project/inventory/system/chassis/motherboard",
473 "org.freedesktop.DBus.Properties", "Get");
474 property2.append("com.ibm.ipzvpd.VSBP");
475 property2.append("IM");
476 auto result2 = bus.call(property2);
477 inventory::Value imVal;
478 result2.read(imVal);
479
480 auto pVal1 = get_if<Binary>(&hwVal);
481 auto pVal2 = get_if<Binary>(&imVal);
482
483 if (pVal1 && pVal2)
alpana075cb3b1f2021-12-16 11:19:36 -0600484 {
Alpana Kumaria6181e22022-05-12 05:01:53 -0500485 auto hwVersion = *pVal1;
486 auto systemType = *pVal2;
487
488 // IM kw for Everest
489 Binary everestSystem{80, 00, 48, 00};
490
491 if (systemType == everestSystem)
492 {
493 if (hwVersion[1] < 21)
494 {
495 isPASS1 = true;
496 }
497 }
498 else if (hwVersion[1] < 2)
499 {
alpana075cb3b1f2021-12-16 11:19:36 -0600500 isPASS1 = true;
Alpana Kumaria6181e22022-05-12 05:01:53 -0500501 }
alpana075cb3b1f2021-12-16 11:19:36 -0600502 }
503 }
504
505 return (isThisPCIeDev && isPASS1);
506}
507
Alpana Kumari735dee92022-03-25 01:24:40 -0500508/** Performs any pre-action needed to get the FRU setup for collection.
Alpana Kumari2f793042020-08-18 05:51:03 -0500509 *
510 * @param[in] json - json object
511 * @param[in] file - eeprom file path
512 */
513static void preAction(const nlohmann::json& json, const string& file)
514{
Alpana Kumari735dee92022-03-25 01:24:40 -0500515 if ((json["frus"][file].at(0)).find("preAction") ==
Alpana Kumari2f793042020-08-18 05:51:03 -0500516 json["frus"][file].at(0).end())
517 {
Alpana Kumari735dee92022-03-25 01:24:40 -0500518 return;
Alpana Kumari2f793042020-08-18 05:51:03 -0500519 }
520
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500521 try
Alpana Kumari2f793042020-08-18 05:51:03 -0500522 {
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500523 if (executePreAction(json, file))
Alpana Kumari2f793042020-08-18 05:51:03 -0500524 {
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500525 if (json["frus"][file].at(0).find("devAddress") !=
526 json["frus"][file].at(0).end())
Alpana Kumari40d1c192022-03-09 21:16:02 -0600527 {
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500528 // Now bind the device
529 string bind = json["frus"][file].at(0).value("devAddress", "");
jinuthomasf457a3e2023-04-13 12:22:48 -0500530 std::cout << "Binding device " << bind << std::endl;
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500531 string bindCmd = string("echo \"") + bind +
532 string("\" > /sys/bus/i2c/drivers/at24/bind");
jinuthomasf457a3e2023-04-13 12:22:48 -0500533 std::cout << bindCmd << std::endl;
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500534 executeCmd(bindCmd);
535
536 // Check if device showed up (test for file)
537 if (!fs::exists(file))
538 {
Patrick Williams08dc31c2024-08-16 15:21:06 -0400539 std::cerr
540 << "EEPROM " << file
541 << " does not exist. Take failure action" << std::endl;
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500542 // If not, then take failure postAction
543 executePostFailAction(json, file);
544 }
545 }
546 else
547 {
Manojkiran Edaaf921752024-06-17 15:10:21 +0530548 // missing required information
549 std::cerr << "VPD inventory JSON missing basic information of "
jinuthomasf457a3e2023-04-13 12:22:48 -0500550 "preAction "
551 "for this FRU : ["
552 << file << "]. Executing executePostFailAction."
553 << std::endl;
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500554
555 // Take failure postAction
Alpana Kumari40d1c192022-03-09 21:16:02 -0600556 executePostFailAction(json, file);
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500557 return;
Alpana Kumari40d1c192022-03-09 21:16:02 -0600558 }
559 }
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530560 else
561 {
562 // If the FRU is not there, clear the VINI/CCIN data.
Manojkiran Edaaf921752024-06-17 15:10:21 +0530563 // Entity manager probes for this keyword to look for this
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530564 // FRU, now if the data is persistent on BMC and FRU is
565 // removed this can lead to ambiguity. Hence clearing this
566 // Keyword if FRU is absent.
567 const auto& invPath =
568 json["frus"][file].at(0).value("inventoryPath", "");
569
570 if (!invPath.empty())
571 {
572 inventory::ObjectMap pimObjMap{
573 {invPath, {{"com.ibm.ipzvpd.VINI", {{"CC", Binary{}}}}}}};
574
575 common::utility::callPIM(move(pimObjMap));
576 }
577 else
578 {
579 throw std::runtime_error("Path empty in Json");
580 }
581 }
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500582 }
583 catch (const GpioException& e)
584 {
585 PelAdditionalData additionalData{};
586 additionalData.emplace("DESCRIPTION", e.what());
587 createPEL(additionalData, PelSeverity::WARNING, errIntfForGpioError,
588 nullptr);
Alpana Kumari2f793042020-08-18 05:51:03 -0500589 }
Alpana Kumari2f793042020-08-18 05:51:03 -0500590}
591
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530592/**
Santosh Puranikf3e69682022-03-31 17:52:38 +0530593 * @brief Fills the Decorator.AssetTag property into the interfaces map
594 *
595 * This function should only be called in cases where we did not find a JSON
596 * symlink. A missing symlink in /var/lib will be considered as a factory reset
597 * and this function will be used to default the AssetTag property.
598 *
599 * @param interfaces A possibly pre-populated map of inetrfaces to properties.
600 * @param vpdMap A VPD map of the system VPD data.
601 */
602static void fillAssetTag(inventory::InterfaceMap& interfaces,
603 const Parsed& vpdMap)
604{
605 // Read the system serial number and MTM
606 // Default asset tag is Server-MTM-System Serial
607 inventory::Interface assetIntf{
608 "xyz.openbmc_project.Inventory.Decorator.AssetTag"};
609 inventory::PropertyMap assetTagProps;
610 std::string defaultAssetTag =
611 std::string{"Server-"} + getKwVal(vpdMap, "VSYS", "TM") +
612 std::string{"-"} + getKwVal(vpdMap, "VSYS", "SE");
613 assetTagProps.emplace("AssetTag", defaultAssetTag);
614 insertOrMerge(interfaces, assetIntf, std::move(assetTagProps));
615}
616
617/**
Santosh Puranikd3a379a2021-08-23 19:12:59 +0530618 * @brief Set certain one time properties in the inventory
619 * Use this function to insert the Functional and Enabled properties into the
620 * inventory map. This function first checks if the object in question already
621 * has these properties hosted on D-Bus, if the property is already there, it is
622 * not modified, hence the name "one time". If the property is not already
623 * present, it will be added to the map with a suitable default value (true for
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530624 * Functional and Enabled)
Santosh Puranikd3a379a2021-08-23 19:12:59 +0530625 *
Manojkiran Edaaf921752024-06-17 15:10:21 +0530626 * @param[in] object - The inventory D-Bus object without the inventory prefix.
627 * @param[in,out] interfaces - Reference to a map of inventory interfaces to
Santosh Puranikd3a379a2021-08-23 19:12:59 +0530628 * which the properties will be attached.
629 */
630static void setOneTimeProperties(const std::string& object,
631 inventory::InterfaceMap& interfaces)
632{
633 auto bus = sdbusplus::bus::new_default();
634 auto objectPath = INVENTORY_PATH + object;
635 auto prop = bus.new_method_call("xyz.openbmc_project.Inventory.Manager",
636 objectPath.c_str(),
637 "org.freedesktop.DBus.Properties", "Get");
638 prop.append("xyz.openbmc_project.State.Decorator.OperationalStatus");
639 prop.append("Functional");
640 try
641 {
642 auto result = bus.call(prop);
643 }
644 catch (const sdbusplus::exception::SdBusError& e)
645 {
646 // Treat as property unavailable
647 inventory::PropertyMap prop;
648 prop.emplace("Functional", true);
649 interfaces.emplace(
650 "xyz.openbmc_project.State.Decorator.OperationalStatus",
651 move(prop));
652 }
653 prop = bus.new_method_call("xyz.openbmc_project.Inventory.Manager",
654 objectPath.c_str(),
655 "org.freedesktop.DBus.Properties", "Get");
656 prop.append("xyz.openbmc_project.Object.Enable");
657 prop.append("Enabled");
658 try
659 {
660 auto result = bus.call(prop);
661 }
662 catch (const sdbusplus::exception::SdBusError& e)
663 {
664 // Treat as property unavailable
665 inventory::PropertyMap prop;
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530666 prop.emplace("Enabled", true);
Santosh Puranikd3a379a2021-08-23 19:12:59 +0530667 interfaces.emplace("xyz.openbmc_project.Object.Enable", move(prop));
668 }
669}
670
671/**
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530672 * @brief Prime the Inventory
673 * Prime the inventory by populating only the location code,
674 * type interface and the inventory object for the frus
675 * which are not system vpd fru.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530676 *
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530677 * @param[in] jsObject - Reference to vpd inventory json object
678 * @param[in] vpdMap - Reference to the parsed vpd map
679 *
680 * @returns Map of items in extraInterface.
681 */
682template <typename T>
Patrick Williams08dc31c2024-08-16 15:21:06 -0400683inventory::ObjectMap
684 primeInventory(const nlohmann::json& jsObject, const T& vpdMap)
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530685{
686 inventory::ObjectMap objects;
687
688 for (auto& itemFRUS : jsObject["frus"].items())
689 {
690 for (auto& itemEEPROM : itemFRUS.value())
691 {
Alpana Kumari2e6c6f72020-12-03 00:10:03 -0600692 // Take pre actions if needed
693 if (itemEEPROM.find("preAction") != itemEEPROM.end())
694 {
695 preAction(jsObject, itemFRUS.key());
696 }
697
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530698 inventory::InterfaceMap interfaces;
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530699 inventory::Object object(itemEEPROM.at("inventoryPath"));
700
Santosh Puranik50f60bf2021-05-26 17:55:06 +0530701 if ((itemFRUS.key() != systemVpdFilePath) &&
702 !itemEEPROM.value("noprime", false))
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530703 {
Alpana Kumaricfd7a752021-02-07 23:23:01 -0600704 inventory::PropertyMap presProp;
Priyanga Ramasamye358acb2022-03-21 14:21:50 -0500705
706 // Do not populate Present property for frus whose
Priyanga Ramasamyaca61372023-01-24 08:02:28 -0600707 // synthesized=true. synthesized=true says the fru VPD is
708 // synthesized and owned by a separate component.
709 // In some cases, the FRU has its own VPD, but still a separate
710 // application handles the FRU's presence. So VPD parser skips
711 // populating Present property by checking the JSON flag,
712 // "handlePresence".
Priyanga Ramasamye358acb2022-03-21 14:21:50 -0500713 if (!itemEEPROM.value("synthesized", false))
714 {
Priyanga Ramasamyaca61372023-01-24 08:02:28 -0600715 if (itemEEPROM.value("handlePresence", true))
716 {
717 presProp.emplace("Present", false);
718 interfaces.emplace("xyz.openbmc_project.Inventory.Item",
719 presProp);
720 }
Priyanga Ramasamye358acb2022-03-21 14:21:50 -0500721 }
Priyanga Ramasamyaca61372023-01-24 08:02:28 -0600722
Santosh Puranikd3a379a2021-08-23 19:12:59 +0530723 setOneTimeProperties(object, interfaces);
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530724 if (itemEEPROM.find("extraInterfaces") != itemEEPROM.end())
725 {
726 for (const auto& eI : itemEEPROM["extraInterfaces"].items())
727 {
728 inventory::PropertyMap props;
Alpana Kumari414d5ae2021-03-04 21:06:35 +0000729 if (eI.key() == IBM_LOCATION_CODE_INF)
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530730 {
731 if constexpr (std::is_same<T, Parsed>::value)
732 {
733 for (auto& lC : eI.value().items())
734 {
735 auto propVal = expandLocationCode(
736 lC.value().get<string>(), vpdMap, true);
737
738 props.emplace(move(lC.key()),
739 move(propVal));
Santosh Puranikb0f37492021-06-21 09:42:47 +0530740 interfaces.emplace(XYZ_LOCATION_CODE_INF,
741 props);
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530742 interfaces.emplace(move(eI.key()),
743 move(props));
744 }
745 }
746 }
Santosh Puranikd3a379a2021-08-23 19:12:59 +0530747 else if (eI.key() ==
748 "xyz.openbmc_project.Inventory.Item")
749 {
750 for (auto& val : eI.value().items())
751 {
752 if (val.key() == "PrettyName")
753 {
754 presProp.emplace(val.key(),
755 val.value().get<string>());
756 }
757 }
758 // Use insert_or_assign here as we may already have
759 // inserted the present property only earlier in
760 // this function under this same interface.
761 interfaces.insert_or_assign(eI.key(),
762 move(presProp));
763 }
Sunny Srivastava1bb87162024-02-13 00:09:09 -0600764 else
765 {
766 interfaces.emplace(move(eI.key()), move(props));
767 }
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530768 }
769 }
770 objects.emplace(move(object), move(interfaces));
771 }
772 }
773 }
774 return objects;
775}
776
Alpana Kumari65b83602020-09-01 00:24:56 -0500777/**
778 * @brief This API executes command to set environment variable
779 * And then reboot the system
780 * @param[in] key -env key to set new value
781 * @param[in] value -value to set.
782 */
783void setEnvAndReboot(const string& key, const string& value)
784{
785 // set env and reboot and break.
786 executeCmd("/sbin/fw_setenv", key, value);
Andrew Geissler280197e2020-12-08 20:51:49 -0600787 log<level::INFO>("Rebooting BMC to pick up new device tree");
Alpana Kumari65b83602020-09-01 00:24:56 -0500788 // make dbus call to reboot
789 auto bus = sdbusplus::bus::new_default_system();
790 auto method = bus.new_method_call(
791 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
792 "org.freedesktop.systemd1.Manager", "Reboot");
793 bus.call_noreply(method);
794}
795
796/*
797 * @brief This API checks for env var fitconfig.
798 * If not initialised OR updated as per the current system type,
799 * update this env var and reboot the system.
800 *
801 * @param[in] systemType IM kwd in vpd tells about which system type it is.
802 * */
803void setDevTreeEnv(const string& systemType)
804{
Alpana Kumari37e72702021-11-18 11:18:04 -0600805 // Init with default dtb
806 string newDeviceTree = "conf-aspeed-bmc-ibm-rainier-p1.dtb";
Santosh Puranike5f177a2022-01-24 20:14:46 +0530807 static const deviceTreeMap deviceTreeSystemTypeMap = {
808 {RAINIER_2U, "conf-aspeed-bmc-ibm-rainier-p1.dtb"},
809 {RAINIER_2U_V2, "conf-aspeed-bmc-ibm-rainier.dtb"},
810 {RAINIER_4U, "conf-aspeed-bmc-ibm-rainier-4u-p1.dtb"},
811 {RAINIER_4U_V2, "conf-aspeed-bmc-ibm-rainier-4u.dtb"},
812 {RAINIER_1S4U, "conf-aspeed-bmc-ibm-rainier-1s4u.dtb"},
Alpana Kumari1b026112022-03-02 23:41:38 -0600813 {EVEREST, "conf-aspeed-bmc-ibm-everest.dtb"},
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530814 {EVEREST_V2, "conf-aspeed-bmc-ibm-everest.dtb"},
Jinu Joy Thomas3b61ff52024-07-18 23:24:01 -0500815 {BONNELL, "conf-aspeed-bmc-ibm-bonnell.dtb"},
816 {BLUERIDGE_2U, "conf-aspeed-bmc-ibm-blueridge-p1.dtb"},
817 {BLUERIDGE_2U_V2, "conf-aspeed-bmc-ibm-blueridge.dtb"},
818 {BLUERIDGE_4U, "conf-aspeed-bmc-ibm-blueridge-4u-p1.dtb"},
819 {BLUERIDGE_4U_V2, "conf-aspeed-bmc-ibm-blueridge-4u.dtb"},
820 {BLUERIDGE_1S4U, "conf-aspeed-bmc-ibm-blueridge-1s4u.dtb"},
821 {FUJI, "conf-aspeed-bmc-ibm-fuji.dtb"},
822 {FUJI_V2, "conf-aspeed-bmc-ibm-fuji.dtb"}};
Alpana Kumari65b83602020-09-01 00:24:56 -0500823
824 if (deviceTreeSystemTypeMap.find(systemType) !=
825 deviceTreeSystemTypeMap.end())
826 {
827 newDeviceTree = deviceTreeSystemTypeMap.at(systemType);
828 }
Alpana Kumari37e72702021-11-18 11:18:04 -0600829 else
830 {
831 // System type not supported
Alpana Kumariab1e22c2021-11-24 11:03:38 -0600832 string err = "This System type not found/supported in dtb table " +
833 systemType +
834 ".Please check the HW and IM keywords in the system "
835 "VPD.Breaking...";
836
837 // map to hold additional data in case of logging pel
838 PelAdditionalData additionalData{};
839 additionalData.emplace("DESCRIPTION", err);
840 createPEL(additionalData, PelSeverity::WARNING,
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500841 errIntfForInvalidSystemType, nullptr);
Alpana Kumariab1e22c2021-11-24 11:03:38 -0600842 exit(-1);
Alpana Kumari37e72702021-11-18 11:18:04 -0600843 }
Alpana Kumari65b83602020-09-01 00:24:56 -0500844
845 string readVarValue;
846 bool envVarFound = false;
847
848 vector<string> output = executeCmd("/sbin/fw_printenv");
849 for (const auto& entry : output)
850 {
851 size_t pos = entry.find("=");
852 string key = entry.substr(0, pos);
853 if (key != "fitconfig")
854 {
855 continue;
856 }
857
858 envVarFound = true;
859 if (pos + 1 < entry.size())
860 {
861 readVarValue = entry.substr(pos + 1);
862 if (readVarValue.find(newDeviceTree) != string::npos)
863 {
864 // fitconfig is Updated. No action needed
865 break;
866 }
867 }
868 // set env and reboot and break.
869 setEnvAndReboot(key, newDeviceTree);
870 exit(0);
871 }
872
873 // check If env var Not found
874 if (!envVarFound)
875 {
876 setEnvAndReboot("fitconfig", newDeviceTree);
877 }
878}
879
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530880/**
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500881 * @brief Parse the given EEPROM file.
882 *
883 * @param[in] vpdFilePath - Path of EEPROM file
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500884 * @param[in] js- Reference to vpd inventory json object
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500885 * @return Parsed VPD map
886 */
887std::variant<KeywordVpdMap, openpower::vpd::Store>
Sunny Srivastava37992a62023-07-11 05:18:41 -0500888 parseVpdFile(const std::string& vpdFilePath, const nlohmann::json& js)
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500889{
890 uint32_t vpdStartOffset = 0;
891 for (const auto& item : js["frus"][vpdFilePath])
892 {
893 if (item.find("offset") != item.end())
894 {
895 vpdStartOffset = item["offset"];
Sunny Srivastava37992a62023-07-11 05:18:41 -0500896 break;
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500897 }
898 }
899
900 Binary vpdVector = getVpdDataInVector(js, vpdFilePath);
901
902 ParserInterface* parser = ParserFactory::getParser(
Sunny Srivastava37992a62023-07-11 05:18:41 -0500903 vpdVector,
904 (pimPath + js["frus"][vpdFilePath][0]["inventoryPath"]
905 .get_ref<const nlohmann::json::string_t&>()),
906 vpdFilePath, vpdStartOffset);
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500907
908 auto parseResult = parser->parse();
909
910 // release the parser object
911 ParserFactory::freeParser(parser);
912
913 return parseResult;
914}
915
916/*
917 * @brief This API retrieves the hardware backup in map
918 *
919 * @param[in] systemVpdBackupPath - The path that backs up the system VPD.
920 * @param[in] backupVpdInvPath - FRU inventory path.
921 * @param[in] js - JSON object.
922 * @param[out] backupVpdMap - An IPZ VPD map containing the parsed backup VPD.
923 *
924 * */
925void getBackupVpdInMap(const string& systemVpdBackupPath,
926 const string& backupVpdInvPath, const nlohmann::json& js,
927 Parsed& backupVpdMap)
928{
929 PelAdditionalData additionalData{};
930
931 if (!fs::exists(systemVpdBackupPath))
932 {
933 string errorMsg = "Device path ";
934 errorMsg += systemVpdBackupPath;
935 errorMsg += " does not exist";
936
937 additionalData.emplace("DESCRIPTION", errorMsg);
938
939 additionalData.emplace("CALLOUT_INVENTORY_PATH",
940 INVENTORY_PATH + backupVpdInvPath);
941
942 createPEL(additionalData, PelSeverity::ERROR, errIntfForStreamFail,
943 nullptr);
944 }
945 else
946 {
Sunny Srivastava37992a62023-07-11 05:18:41 -0500947 auto backupVpdParsedResult = parseVpdFile(systemVpdBackupPath, js);
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500948
949 if (auto pVal = get_if<Store>(&backupVpdParsedResult))
950 {
951 backupVpdMap = pVal->getVpdMap();
952 }
Sunny Srivastava37992a62023-07-11 05:18:41 -0500953 else
954 {
955 std::cerr << "Invalid format of VPD in back up. Restore aborted."
956 << std::endl;
957 }
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500958 }
959}
960
961void updateVpdDataOnHw(const std::string& vpdFilePath, nlohmann::json& js,
962 const std::string& recName, const std::string& kwName,
963 const Binary& kwdData)
964{
965 const std::string& fruInvPath =
966 js["frus"][vpdFilePath][0]["inventoryPath"]
967 .get_ref<const nlohmann::json::string_t&>();
968
969 EditorImpl edit(vpdFilePath, js, recName, kwName, fruInvPath);
970
971 uint32_t offset = 0;
972 // Setup offset, if any
973 for (const auto& item : js["frus"][vpdFilePath])
974 {
975 if (item.find("offset") != item.end())
976 {
977 offset = item["offset"];
978 break;
979 }
980 }
981
982 // update keyword data on to EEPROM file
983 // Note: Updating keyword data on cache is
984 // handled via PIM Notify call hence passing
985 // the updCache flag value as false here.
986 edit.updateKeyword(kwdData, offset, false);
987}
988
989/**
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500990 * @brief API to check if we need to restore system VPD
991 * This functionality is only applicable for IPZ VPD data.
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500992
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500993 * @param[in] vpdMap - IPZ vpd map
994 * @param[in] objectPath - Object path for the FRU
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500995 * @param[in] js - JSON Object
996 * @param[in] isBackupOnCache - Denotes whether the backup is on cache/hardware
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500997 */
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500998void restoreSystemVPD(Parsed& vpdMap, const string& objectPath,
999 nlohmann::json& js, bool isBackupOnCache = true)
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001000{
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001001 std::string systemVpdBackupPath{};
1002 std::string backupVpdInvPath{};
1003 Parsed backupVpdMap{};
1004
1005 if (!isBackupOnCache)
1006 {
1007 // Get the value of systemvpdBackupPath field from json
1008 systemVpdBackupPath = js["frus"][systemVpdFilePath].at(0).value(
1009 "systemVpdBackupPath", "");
1010
1011 backupVpdInvPath = js["frus"][systemVpdBackupPath][0]["inventoryPath"]
1012 .get_ref<const nlohmann::json::string_t&>();
1013
1014 getBackupVpdInMap(systemVpdBackupPath, backupVpdInvPath, js,
1015 backupVpdMap);
1016
1017 if (backupVpdMap.empty())
1018 {
Sunny Srivastava37992a62023-07-11 05:18:41 -05001019 std::cerr << "Backup VPD map is empty" << std::endl;
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001020 return;
1021 }
1022 }
1023
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001024 for (const auto& systemRecKwdPair : svpdKwdMap)
1025 {
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001026 const string& recordName = systemRecKwdPair.first;
1027 auto it = vpdMap.find(recordName);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001028
1029 // check if record is found in map we got by parser
1030 if (it != vpdMap.end())
1031 {
1032 const auto& kwdListForRecord = systemRecKwdPair.second;
Priyanga Ramasamy952d6c52022-11-07 07:20:24 -06001033 for (const auto& keywordInfo : kwdListForRecord)
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001034 {
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001035 const auto keywordName = get<0>(keywordInfo);
Priyanga Ramasamy952d6c52022-11-07 07:20:24 -06001036
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001037 DbusPropertyMap& kwdValMap = it->second;
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001038 auto iterator = kwdValMap.find(keywordName);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001039
1040 if (iterator != kwdValMap.end())
1041 {
1042 string& kwdValue = iterator->second;
1043
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001044 std::string backupValue{};
Priyanga Ramasamy952d6c52022-11-07 07:20:24 -06001045 const auto& defaultValue = get<1>(keywordInfo);
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001046 const auto& backupVpdRecName = get<4>(keywordInfo);
1047 const auto& backupVpdKwName = get<5>(keywordInfo);
1048
1049 // If the 'isBackupOnCache' flag is false, we need
1050 // to backup the systemVPD on the specified fru's eeprom
1051 // path or restore it from the specified fru's eeprom path.
1052 if (isBackupOnCache)
1053 {
1054 // check bus data
1055 backupValue = readBusProperty(
1056 objectPath, ipzVpdInf + recordName, keywordName);
1057 }
1058 else
1059 {
Sunny Srivastava37992a62023-07-11 05:18:41 -05001060 backupValue = getKwVal(backupVpdMap, backupVpdRecName,
1061 backupVpdKwName);
1062
1063 if (backupValue.empty())
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001064 {
Sunny Srivastava37992a62023-07-11 05:18:41 -05001065 string errorMsg{};
1066 if (backupVpdMap.find(backupVpdRecName) ==
1067 backupVpdMap.end())
1068 {
1069 errorMsg = backupVpdRecName +
1070 " Record does not exist in "
1071 "the EEPROM file ";
1072 }
1073 else
1074 {
1075 errorMsg = backupVpdKwName +
1076 " Keyword not found or empty.";
1077 }
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001078
1079 errorMsg += systemVpdBackupPath;
1080
1081 PelAdditionalData additionalData;
1082 additionalData.emplace("DESCRIPTION", errorMsg);
1083
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001084 createPEL(additionalData, PelSeverity::ERROR,
1085 errIntfForInvalidVPD, nullptr);
1086
1087 continue;
1088 }
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001089 }
1090
1091 Binary backupDataInBinary(backupValue.begin(),
1092 backupValue.end());
1093
Priyanga Ramasamy952d6c52022-11-07 07:20:24 -06001094 Binary kwdDataInBinary(kwdValue.begin(), kwdValue.end());
Sunny Srivastavaa559c2d2022-05-02 11:56:45 -05001095
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001096 if (backupDataInBinary != defaultValue)
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001097 {
Priyanga Ramasamy952d6c52022-11-07 07:20:24 -06001098 if (kwdDataInBinary != defaultValue)
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001099 {
1100 // both the data are present, check for mismatch
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001101 if (backupValue != kwdValue)
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001102 {
Priyanga Ramasamy24942232023-01-05 04:54:59 -06001103 string errMsg = "Mismatch found between backup "
1104 "and primary VPD for record: ";
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001105 errMsg += (*it).first;
1106 errMsg += " and keyword: ";
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001107 errMsg += keywordName;
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001108
Santosh Puranikdedb5a62022-12-19 23:58:32 +05301109 std::ostringstream busStream;
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001110 for (uint16_t byte : backupValue)
Santosh Puranikdedb5a62022-12-19 23:58:32 +05301111 {
Patrick Williams08dc31c2024-08-16 15:21:06 -04001112 busStream
1113 << std::setfill('0') << std::setw(2)
1114 << std::hex << "0x" << byte << " ";
Santosh Puranikdedb5a62022-12-19 23:58:32 +05301115 }
1116
1117 std::ostringstream vpdStream;
1118 for (uint16_t byte : kwdValue)
1119 {
Patrick Williams08dc31c2024-08-16 15:21:06 -04001120 vpdStream
1121 << std::setfill('0') << std::setw(2)
1122 << std::hex << "0x" << byte << " ";
Santosh Puranikdedb5a62022-12-19 23:58:32 +05301123 }
1124
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001125 // data mismatch
1126 PelAdditionalData additionalData;
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001127
1128 additionalData.emplace("DESCRIPTION", errMsg);
Santosh Puranikdedb5a62022-12-19 23:58:32 +05301129 additionalData.emplace(
Priyanga Ramasamy24942232023-01-05 04:54:59 -06001130 "Value read from Backup: ",
1131 busStream.str());
1132 additionalData.emplace(
1133 "Value read from Primary: ",
Santosh Puranikdedb5a62022-12-19 23:58:32 +05301134 vpdStream.str());
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001135
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001136 createPEL(additionalData, PelSeverity::WARNING,
Priyanga Ramasamy24942232023-01-05 04:54:59 -06001137 errIntfForVPDMismatch, nullptr);
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001138
1139 if (!isBackupOnCache)
1140 {
1141 // Backing up or restoring from a hardware
1142 // path does not requires copying the backup
1143 // data to the VPD map, as this will result
1144 // in a mismatch between the primary VPD and
1145 // its cache.
1146 continue;
1147 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001148 }
Sunny Srivastava37992a62023-07-11 05:18:41 -05001149 else
1150 {
1151 // both the backup and primary data is
1152 // non-default and same. Nothing needs to be
1153 // done.
1154 continue;
1155 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001156 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001157
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001158 // If the backup is on the cache we need to copy the
1159 // backup data to the VPD map to ensure there is no
Manojkiran Edaaf921752024-06-17 15:10:21 +05301160 // mismatch b/n them. So if backup data is not default,
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001161 // then irrespective of primary data(default or other
1162 // than backup), copy the backup data to vpd map as we
1163 // don't need to change the backup data in either case
1164 // in the process of restoring system vpd.
1165 kwdValue = backupValue;
1166
1167 // If the backup data is on the base panel the restoring
1168 // of Backup VPD on to the system backplane VPD
1169 // file is done here not through the VPD manager code
1170 // path. This is to have the logic of restoring data on
1171 // to the cache & hardware in the same code path.
1172 if (!isBackupOnCache)
1173 {
1174 // copy backup VPD on to system backplane
1175 // EEPROM file.
1176 updateVpdDataOnHw(systemVpdFilePath, js, recordName,
1177 keywordName, backupDataInBinary);
1178 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001179 }
Priyanga Ramasamy952d6c52022-11-07 07:20:24 -06001180 else if (kwdDataInBinary == defaultValue &&
1181 get<2>(keywordInfo)) // Check isPELRequired is true
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001182 {
Priyanga Ramasamy24942232023-01-05 04:54:59 -06001183 string errMsg = "Found default value on both backup "
1184 "and primary VPD for record: ";
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001185 errMsg += (*it).first;
1186 errMsg += " and keyword: ";
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001187 errMsg += keywordName;
Sunny Srivastava37992a62023-07-11 05:18:41 -05001188 errMsg += ". Update primary VPD.";
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001189
Priyanga Ramasamy24942232023-01-05 04:54:59 -06001190 // mfg default on both backup and primary, log PEL
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001191 PelAdditionalData additionalData;
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001192 additionalData.emplace("DESCRIPTION", errMsg);
1193
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001194 createPEL(additionalData, PelSeverity::ERROR,
Priyanga Ramasamy24942232023-01-05 04:54:59 -06001195 errIntfForVPDDefault, nullptr);
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001196
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001197 continue;
1198 }
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001199 else if ((kwdDataInBinary != defaultValue) &&
1200 (!isBackupOnCache))
1201 {
1202 // update primary VPD on to backup VPD file
1203 updateVpdDataOnHw(systemVpdBackupPath, js,
1204 backupVpdRecName, backupVpdKwName,
1205 kwdDataInBinary);
1206
1207 // copy primary VPD to backup VPD to publish on
1208 // DBus
1209 backupVpdMap.find(backupVpdRecName)
1210 ->second.find(backupVpdKwName)
1211 ->second = kwdValue;
1212 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001213 }
1214 }
1215 }
1216 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001217}
1218
1219/**
alpana077ce68722021-07-25 13:23:59 -05001220 * @brief This checks for is this FRU a processor
1221 * And if yes, then checks for is this primary
1222 *
1223 * @param[in] js- vpd json to get the information about this FRU
1224 * @param[in] filePath- FRU vpd
1225 *
1226 * @return true/false
1227 */
1228bool isThisPrimaryProcessor(nlohmann::json& js, const string& filePath)
1229{
1230 bool isProcessor = false;
1231 bool isPrimary = false;
1232
1233 for (const auto& item : js["frus"][filePath])
1234 {
1235 if (item.find("extraInterfaces") != item.end())
1236 {
1237 for (const auto& eI : item["extraInterfaces"].items())
1238 {
1239 if (eI.key().find("Inventory.Item.Cpu") != string::npos)
1240 {
1241 isProcessor = true;
1242 }
1243 }
1244 }
1245
1246 if (isProcessor)
1247 {
1248 string cpuType = item.value("cpuType", "");
1249 if (cpuType == "primary")
1250 {
1251 isPrimary = true;
1252 }
1253 }
1254 }
1255
1256 return (isProcessor && isPrimary);
1257}
1258
1259/**
1260 * @brief This finds DIMM vpd in vpd json and enables them by binding the device
1261 * driver
1262 * @param[in] js- vpd json to iterate through and take action if it is DIMM
1263 */
1264void doEnableAllDimms(nlohmann::json& js)
1265{
1266 // iterate over each fru
1267 for (const auto& eachFru : js["frus"].items())
1268 {
1269 // skip the driver binding if eeprom already exists
1270 if (fs::exists(eachFru.key()))
1271 {
1272 continue;
1273 }
1274
1275 for (const auto& eachInventory : eachFru.value())
1276 {
1277 if (eachInventory.find("extraInterfaces") != eachInventory.end())
1278 {
1279 for (const auto& eI : eachInventory["extraInterfaces"].items())
1280 {
1281 if (eI.key().find("Inventory.Item.Dimm") != string::npos)
1282 {
1283 string dimmVpd = eachFru.key();
1284 // fetch it from
1285 // "/sys/bus/i2c/drivers/at24/414-0050/eeprom"
1286
1287 regex matchPatern("([0-9]+-[0-9]{4})");
1288 smatch matchFound;
1289 if (regex_search(dimmVpd, matchFound, matchPatern))
1290 {
1291 vector<string> i2cReg;
1292 boost::split(i2cReg, matchFound.str(0),
1293 boost::is_any_of("-"));
1294
Manojkiran Edaaf921752024-06-17 15:10:21 +05301295 // remove 0s from beginning
alpana077ce68722021-07-25 13:23:59 -05001296 const regex pattern("^0+(?!$)");
1297 for (auto& i : i2cReg)
1298 {
1299 i = regex_replace(i, pattern, "");
1300 }
1301
Jinu Joy Thomas63cce0f2024-01-29 00:47:47 -06001302 // For ISDIMM which uses ee1004 driver
1303 // the below is done
1304 size_t stringFound = dimmVpd.find("ee1004");
1305 if (stringFound != string::npos)
1306 {
1307 // echo ee1004 0x50 >
1308 // /sys/bus/i2c/devices/i2c-110/new_device
1309 string cmnd = "echo ee1004 0x" + i2cReg[1] +
1310 " > /sys/bus/i2c/devices/i2c-" +
1311 i2cReg[0] + "/new_device";
1312 executeCmd(cmnd);
1313 }
1314 else if (i2cReg.size() == 2)
alpana077ce68722021-07-25 13:23:59 -05001315 {
1316 // echo 24c32 0x50 >
1317 // /sys/bus/i2c/devices/i2c-16/new_device
1318 string cmnd = "echo 24c32 0x" + i2cReg[1] +
1319 " > /sys/bus/i2c/devices/i2c-" +
1320 i2cReg[0] + "/new_device";
alpana077ce68722021-07-25 13:23:59 -05001321 executeCmd(cmnd);
1322 }
1323 }
1324 }
1325 }
1326 }
1327 }
1328 }
1329}
1330
1331/**
Priyanga Ramasamy6abdeb62022-01-09 23:15:11 -06001332 * @brief Check if the given CPU is an IO only chip.
1333 * The CPU is termed as IO, whose all of the cores are bad and can never be
1334 * used. Those CPU chips can be used for IO purpose like connecting PCIe devices
1335 * etc., The CPU whose every cores are bad, can be identified from the CP00
1336 * record's PG keyword, only if all of the 8 EQs' value equals 0xE7F9FF. (1EQ
1337 * has 4 cores grouped together by sharing its cache memory.)
1338 * @param [in] pgKeyword - PG Keyword of CPU.
1339 * @return true if the given cpu is an IO, false otherwise.
1340 */
1341static bool isCPUIOGoodOnly(const string& pgKeyword)
1342{
1343 const unsigned char io[] = {0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9,
1344 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7,
1345 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF};
1346 // EQ0 index (in PG keyword) starts at 97 (with offset starting from 0).
1347 // Each EQ carries 3 bytes of data. Totally there are 8 EQs. If all EQs'
1348 // value equals 0xE7F9FF, then the cpu has no good cores and its treated as
1349 // IO.
1350 if (memcmp(io, pgKeyword.data() + 97, 24) == 0)
1351 {
1352 return true;
1353 }
1354
1355 // The CPU is not an IO
1356 return false;
1357}
1358
1359/**
Jinu Joy Thomas9a60c8b2024-01-16 22:52:25 -06001360 * @brief Function to bring MUX out of idle state
1361 *
1362 * This finds All the MUX defined in the system json and enables
1363 * them by setting the holdidle parameter to 0.
1364 * @param[in] js- system json to iterate through and take action
1365 */
1366void doEnableAllMuxChips(const nlohmann::json& js)
1367{
1368 // Do we have the mandatory "muxes" section?
1369 if (js.find("muxes") != js.end())
1370 {
1371 std::cout << "Enabling all the MUX on the system " << std::endl;
1372 // iterate over each MUX detail and enable them
1373 for (const auto& item : js["muxes"])
1374 {
1375 if (item.find("holdidlepath") != item.end())
1376 {
Jinu Joy Thomas63cce0f2024-01-29 00:47:47 -06001377 const std::string& holdidle = item["holdidlepath"];
Jinu Joy Thomas9a60c8b2024-01-16 22:52:25 -06001378 std::cout << "Setting holdidle state for " << holdidle
1379 << "to 0 " << std::endl;
1380 string cmd = "echo 0 > " + holdidle;
1381 executeCmd(cmd);
1382 }
1383 }
1384 std::cout << "Completed enabling all the MUX on the system "
1385 << std::endl;
1386 }
1387 else
1388 {
1389 std::cout << "No MUX was defined for the system" << std::endl;
1390 }
1391}
1392
1393/**
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301394 * @brief Populate Dbus.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301395 * This method invokes all the populateInterface functions
1396 * and notifies PIM about dbus object.
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301397 * @param[in] vpdMap - Either IPZ vpd map or Keyword vpd map based on the
1398 * input.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301399 * @param[in] js - Inventory json object
1400 * @param[in] filePath - Path of the vpd file
1401 * @param[in] preIntrStr - Interface string
1402 */
1403template <typename T>
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001404static void populateDbus(T& vpdMap, nlohmann::json& js, const string& filePath)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301405{
1406 inventory::InterfaceMap interfaces;
1407 inventory::ObjectMap objects;
1408 inventory::PropertyMap prop;
Shantappa Teekappanavar6aa54502021-12-09 12:59:56 -06001409 string ccinFromVpd;
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301410
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301411 bool isSystemVpd = (filePath == systemVpdFilePath);
1412 if constexpr (is_same<T, Parsed>::value)
1413 {
Shantappa Teekappanavar6aa54502021-12-09 12:59:56 -06001414 ccinFromVpd = getKwVal(vpdMap, "VINI", "CC");
1415 transform(ccinFromVpd.begin(), ccinFromVpd.end(), ccinFromVpd.begin(),
1416 ::toupper);
1417
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301418 if (isSystemVpd)
1419 {
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301420 string mboardPath =
1421 js["frus"][filePath].at(0).value("inventoryPath", "");
1422
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001423 // Get the value of systemvpdBackupPath field from json
1424 const std::string& systemVpdBackupPath =
1425 js["frus"][filePath].at(0).value("systemVpdBackupPath", "");
1426
1427 if (systemVpdBackupPath.empty())
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301428 {
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001429 std::vector<std::string> interfaces = {motherBoardInterface};
1430 // call mapper to check for object path creation
1431 MapperResponse subTree =
1432 getObjectSubtreeForInterfaces(pimPath, 0, interfaces);
1433
1434 // Attempt system VPD restore if we have a motherboard
1435 // object in the inventory.
1436 if ((subTree.size() != 0) &&
1437 (subTree.find(pimPath + mboardPath) != subTree.end()))
1438 {
1439 restoreSystemVPD(vpdMap, mboardPath, js);
1440 }
1441 else
1442 {
1443 log<level::ERR>("No object path found");
1444 }
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301445 }
1446 else
1447 {
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001448 restoreSystemVPD(vpdMap, mboardPath, js, false);
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301449 }
1450 }
alpana077ce68722021-07-25 13:23:59 -05001451 else
1452 {
1453 // check if it is processor vpd.
1454 auto isPrimaryCpu = isThisPrimaryProcessor(js, filePath);
1455
1456 if (isPrimaryCpu)
1457 {
1458 auto ddVersion = getKwVal(vpdMap, "CRP0", "DD");
1459
1460 auto chipVersion = atoi(ddVersion.substr(1, 2).c_str());
1461
1462 if (chipVersion >= 2)
1463 {
1464 doEnableAllDimms(js);
Santosh Puranik253fbe92022-10-06 22:38:09 +05301465 // Sleep for a few seconds to let the DIMM parses start
1466 using namespace std::chrono_literals;
1467 std::this_thread::sleep_for(5s);
alpana077ce68722021-07-25 13:23:59 -05001468 }
1469 }
1470 }
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301471 }
1472
Santosh Puranikf3e69682022-03-31 17:52:38 +05301473 auto processFactoryReset = false;
1474
Priyanga Ramasamy32c687f2022-01-04 23:14:03 -06001475 if (isSystemVpd)
1476 {
1477 string systemJsonName{};
1478 if constexpr (is_same<T, Parsed>::value)
1479 {
1480 // pick the right system json
1481 systemJsonName = getSystemsJson(vpdMap);
1482 }
1483
1484 fs::path target = systemJsonName;
1485 fs::path link = INVENTORY_JSON_SYM_LINK;
1486
Santosh Puranikf3e69682022-03-31 17:52:38 +05301487 // If the symlink does not exist, we treat that as a factory reset
1488 processFactoryReset = !fs::exists(INVENTORY_JSON_SYM_LINK);
1489
Priyanga Ramasamy32c687f2022-01-04 23:14:03 -06001490 // Create the directory for hosting the symlink
1491 fs::create_directories(VPD_FILES_PATH);
1492 // unlink the symlink previously created (if any)
1493 remove(INVENTORY_JSON_SYM_LINK);
1494 // create a new symlink based on the system
1495 fs::create_symlink(target, link);
1496
1497 // Reloading the json
1498 ifstream inventoryJson(link);
1499 js = json::parse(inventoryJson);
1500 inventoryJson.close();
Sunny Srivastava7ef9c8c2024-05-03 00:57:43 -05001501
1502 // enable the muxes again here to cover the case where during first boot
1503 // after reset, system would have come up with default JSON
1504 // configuration and have skipped enabling mux at the beginning.
1505 // Default config JSON does not have mux entries.
1506 doEnableAllMuxChips(js);
Priyanga Ramasamy32c687f2022-01-04 23:14:03 -06001507 }
1508
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301509 for (const auto& item : js["frus"][filePath])
1510 {
1511 const auto& objectPath = item["inventoryPath"];
1512 sdbusplus::message::object_path object(objectPath);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001513
Shantappa Teekappanavar6aa54502021-12-09 12:59:56 -06001514 vector<string> ccinList;
1515 if (item.find("ccin") != item.end())
1516 {
1517 for (const auto& cc : item["ccin"])
1518 {
1519 string ccin = cc;
1520 transform(ccin.begin(), ccin.end(), ccin.begin(), ::toupper);
1521 ccinList.push_back(ccin);
1522 }
1523 }
1524
1525 if (!ccinFromVpd.empty() && !ccinList.empty() &&
1526 (find(ccinList.begin(), ccinList.end(), ccinFromVpd) ==
1527 ccinList.end()))
1528 {
1529 continue;
1530 }
1531
Priyanga Ramasamye3fed702022-01-11 01:05:32 -06001532 if ((isSystemVpd) || (item.value("noprime", false)))
Santosh Puranikd3a379a2021-08-23 19:12:59 +05301533 {
Priyanga Ramasamye3fed702022-01-11 01:05:32 -06001534 // Populate one time properties for the system VPD and its sub-frus
1535 // and for other non-primeable frus.
Santosh Puranikd3a379a2021-08-23 19:12:59 +05301536 // For the remaining FRUs, this will get handled as a part of
1537 // priming the inventory.
1538 setOneTimeProperties(objectPath, interfaces);
1539 }
1540
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301541 // Populate the VPD keywords and the common interfaces only if we
1542 // are asked to inherit that data from the VPD, else only add the
1543 // extraInterfaces.
1544 if (item.value("inherit", true))
1545 {
Alpana Kumari58e22142020-05-05 00:22:12 -05001546 if constexpr (is_same<T, Parsed>::value)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301547 {
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301548 // Each record in the VPD becomes an interface and all
1549 // keyword within the record are properties under that
1550 // interface.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301551 for (const auto& record : vpdMap)
1552 {
1553 populateFruSpecificInterfaces(
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001554 record.second, ipzVpdInf + record.first, interfaces);
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301555 }
1556 }
Alpana Kumari58e22142020-05-05 00:22:12 -05001557 else if constexpr (is_same<T, KeywordVpdMap>::value)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301558 {
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001559 populateFruSpecificInterfaces(vpdMap, kwdVpdInf, interfaces);
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301560 }
Santosh Puranik88edeb62020-03-02 12:00:09 +05301561 if (js.find("commonInterfaces") != js.end())
1562 {
1563 populateInterfaces(js["commonInterfaces"], interfaces, vpdMap,
1564 isSystemVpd);
1565 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301566 }
Santosh Puranik0859eb62020-03-16 02:56:29 -05001567 else
1568 {
1569 // Check if we have been asked to inherit specific record(s)
Alpana Kumari58e22142020-05-05 00:22:12 -05001570 if constexpr (is_same<T, Parsed>::value)
Santosh Puranik0859eb62020-03-16 02:56:29 -05001571 {
1572 if (item.find("copyRecords") != item.end())
1573 {
1574 for (const auto& record : item["copyRecords"])
1575 {
1576 const string& recordName = record;
1577 if (vpdMap.find(recordName) != vpdMap.end())
1578 {
1579 populateFruSpecificInterfaces(
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001580 vpdMap.at(recordName), ipzVpdInf + recordName,
Santosh Puranik0859eb62020-03-16 02:56:29 -05001581 interfaces);
1582 }
1583 }
1584 }
1585 }
1586 }
Santosh Puranik32c46502022-02-10 08:55:07 +05301587 // Populate interfaces and properties that are common to every FRU
1588 // and additional interface that might be defined on a per-FRU
1589 // basis.
1590 if (item.find("extraInterfaces") != item.end())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301591 {
Santosh Puranik32c46502022-02-10 08:55:07 +05301592 populateInterfaces(item["extraInterfaces"], interfaces, vpdMap,
1593 isSystemVpd);
Priyanga Ramasamy6abdeb62022-01-09 23:15:11 -06001594 if constexpr (is_same<T, Parsed>::value)
1595 {
1596 if (item["extraInterfaces"].find(
1597 "xyz.openbmc_project.Inventory.Item.Cpu") !=
1598 item["extraInterfaces"].end())
1599 {
1600 if (isCPUIOGoodOnly(getKwVal(vpdMap, "CP00", "PG")))
1601 {
Priyanga Ramasamy2c607a92022-04-08 00:30:17 -05001602 interfaces[invItemIntf]["PrettyName"] = "IO Module";
Priyanga Ramasamy6abdeb62022-01-09 23:15:11 -06001603 }
1604 }
1605 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301606 }
Priyanga Ramasamye358acb2022-03-21 14:21:50 -05001607
1608 // embedded property(true or false) says whether the subfru is embedded
1609 // into the parent fru (or) not. VPD sets Present property only for
1610 // embedded frus. If the subfru is not an embedded FRU, the subfru may
1611 // or may not be physically present. Those non embedded frus will always
1612 // have Present=false irrespective of its physical presence or absence.
1613 // Eg: nvme drive in nvme slot is not an embedded FRU. So don't set
1614 // Present to true for such sub frus.
1615 // Eg: ethernet port is embedded into bmc card. So set Present to true
Manojkiran Edaaf921752024-06-17 15:10:21 +05301616 // for such sub frus. Also do not populate present property for embedded
Priyanga Ramasamye358acb2022-03-21 14:21:50 -05001617 // subfru which is synthesized. Currently there is no subfru which are
1618 // both embedded and synthesized. But still the case is handled here.
1619 if ((item.value("embedded", true)) &&
1620 (!item.value("synthesized", false)))
1621 {
Priyanga Ramasamyaca61372023-01-24 08:02:28 -06001622 // Check if its required to handle presence for this FRU.
1623 if (item.value("handlePresence", true))
1624 {
1625 inventory::PropertyMap presProp;
1626 presProp.emplace("Present", true);
1627 insertOrMerge(interfaces, invItemIntf, move(presProp));
1628 }
Priyanga Ramasamye358acb2022-03-21 14:21:50 -05001629 }
Priyanga Ramasamyaa8a8932022-01-27 09:12:41 -06001630
Santosh Puranikf3e69682022-03-31 17:52:38 +05301631 if constexpr (is_same<T, Parsed>::value)
1632 {
1633 // Restore asset tag, if needed
1634 if (processFactoryReset && objectPath == "/system")
1635 {
1636 fillAssetTag(interfaces, vpdMap);
1637 }
1638 }
1639
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301640 objects.emplace(move(object), move(interfaces));
1641 }
1642
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301643 if (isSystemVpd)
1644 {
1645 inventory::ObjectMap primeObject = primeInventory(js, vpdMap);
1646 objects.insert(primeObject.begin(), primeObject.end());
Alpana Kumari65b83602020-09-01 00:24:56 -05001647
Alpana Kumarif05effd2021-04-07 07:32:53 -05001648 // set the U-boot environment variable for device-tree
1649 if constexpr (is_same<T, Parsed>::value)
1650 {
Santosh Puranike5f177a2022-01-24 20:14:46 +05301651 setDevTreeEnv(fs::path(getSystemsJson(vpdMap)).filename());
Alpana Kumarif05effd2021-04-07 07:32:53 -05001652 }
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301653 }
1654
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301655 // Notify PIM
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -05001656 common::utility::callPIM(move(objects));
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301657}
1658
1659int main(int argc, char** argv)
1660{
1661 int rc = 0;
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001662 json js{};
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001663 Binary vpdVector{};
1664 string file{};
jinuthomasf457a3e2023-04-13 12:22:48 -05001665 string driver{};
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001666 // map to hold additional data in case of logging pel
1667 PelAdditionalData additionalData{};
1668
1669 // this is needed to hold base fru inventory path in case there is ECC or
1670 // vpd exception while parsing the file
1671 std::string baseFruInventoryPath = {};
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301672
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001673 // It holds the backup EEPROM file path for the system backplane's critical
1674 // data
1675 std::string systemVpdBackupPath{};
1676
1677 // It holds the inventory path of backup EEPROM file
1678 std::string backupVpdInvPath{};
1679
1680 bool isSystemVpd = false;
1681
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001682 // severity for PEL
1683 PelSeverity pelSeverity = PelSeverity::WARNING;
1684
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301685 try
1686 {
jinuthomasf457a3e2023-04-13 12:22:48 -05001687 App app{"ibm-read-vpd - App to read IPZ/Jedec format VPD, parse it and "
1688 "store it in DBUS"};
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301689
1690 app.add_option("-f, --file", file, "File containing VPD (IPZ/KEYWORD)")
Alpana Kumari2f793042020-08-18 05:51:03 -05001691 ->required();
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301692
jinuthomasf457a3e2023-04-13 12:22:48 -05001693 app.add_option("--driver", driver,
1694 "Driver used by kernel (at24,at25,ee1004)")
1695 ->required();
1696
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301697 CLI11_PARSE(app, argc, argv);
1698
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001699 // PEL severity should be ERROR in case of any system VPD failure
1700 if (file == systemVpdFilePath)
1701 {
1702 pelSeverity = PelSeverity::ERROR;
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001703 isSystemVpd = true;
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001704 }
1705
jinuthomasf457a3e2023-04-13 12:22:48 -05001706 // Check if input file is not empty.
1707 if ((file.empty()) || (driver.empty()))
1708 {
1709 std::cerr << "Encountered empty input parameter file [" << file
1710 << "] driver [" << driver << "]" << std::endl;
1711 return 0;
1712 }
1713
1714 // Check if currently supported driver or not
1715 if ((driver != at24driver) && (driver != at25driver) &&
1716 (driver != ee1004driver))
1717 {
1718 std::cerr << "The driver [" << driver << "] is not supported."
1719 << std::endl;
1720 return 0;
1721 }
1722
Santosh Puranik0246a4d2020-11-04 16:57:39 +05301723 auto jsonToParse = INVENTORY_JSON_DEFAULT;
1724
1725 // If the symlink exists, it means it has been setup for us, switch the
1726 // path
1727 if (fs::exists(INVENTORY_JSON_SYM_LINK))
1728 {
1729 jsonToParse = INVENTORY_JSON_SYM_LINK;
1730 }
1731
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301732 // Make sure that the file path we get is for a supported EEPROM
Santosh Puranik0246a4d2020-11-04 16:57:39 +05301733 ifstream inventoryJson(jsonToParse);
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001734 if (!inventoryJson)
1735 {
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001736 throw(VpdJsonException("Failed to access Json path", jsonToParse));
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001737 }
1738
1739 try
1740 {
1741 js = json::parse(inventoryJson);
1742 }
Patrick Williams8e15b932021-10-06 13:04:22 -05001743 catch (const json::parse_error& ex)
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001744 {
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001745 throw(VpdJsonException("Json parsing failed", jsonToParse));
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001746 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301747
Santosh Puranik12e24ff2021-05-11 19:33:50 +05301748 // Do we have the mandatory "frus" section?
1749 if (js.find("frus") == js.end())
1750 {
1751 throw(VpdJsonException("FRUs section not found in JSON",
1752 jsonToParse));
1753 }
1754
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301755 // Check if it's a udev path - patterned as(/ahb/ahb:apb/ahb:apb:bus@)
1756 if (file.find("/ahb:apb") != string::npos)
1757 {
1758 // Translate udev path to a generic /sys/bus/.. file path.
jinuthomasf457a3e2023-04-13 12:22:48 -05001759 udevToGenericPath(file, driver);
Santosh Puranik12e24ff2021-05-11 19:33:50 +05301760
1761 if ((js["frus"].find(file) != js["frus"].end()) &&
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301762 (file == systemVpdFilePath))
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301763 {
Manojkiran Edaaf921752024-06-17 15:10:21 +05301764 std::cout << "We have already collected system VPD, skipping."
jinuthomasf457a3e2023-04-13 12:22:48 -05001765 << std::endl;
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301766 return 0;
1767 }
1768 }
1769
Jinu Joy Thomas2cb67692024-01-30 10:30:26 -06001770 // Enable all mux which are used for connecting to the i2c on the pcie
1771 // slots for pcie cards. These are not enabled by kernel due to an issue
1772 // seen with Castello cards, where the i2c line hangs on a probe.
1773 // To run it only once have kept it under System vpd check.
1774 // we need to run this on all BMC reboots so kept here
1775 if (file == systemVpdFilePath)
1776 {
1777 doEnableAllMuxChips(js);
1778 }
1779
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301780 if (file.empty())
1781 {
jinuthomasf457a3e2023-04-13 12:22:48 -05001782 std::cerr << "The EEPROM path <" << file << "> is not valid.";
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301783 return 0;
1784 }
Santosh Puranik12e24ff2021-05-11 19:33:50 +05301785 if (js["frus"].find(file) == js["frus"].end())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301786 {
jinuthomasf457a3e2023-04-13 12:22:48 -05001787 std::cerr << "The EEPROM path [" << file
1788 << "] is not found in the json." << std::endl;
Santosh Puranik88edeb62020-03-02 12:00:09 +05301789 return 0;
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301790 }
1791
Alpana Kumari2f793042020-08-18 05:51:03 -05001792 if (!fs::exists(file))
1793 {
jinuthomasf457a3e2023-04-13 12:22:48 -05001794 std::cout << "Device path: " << file
1795 << " does not exist. Spurious udev event? Exiting."
1796 << std::endl;
Alpana Kumari2f793042020-08-18 05:51:03 -05001797 return 0;
1798 }
1799
Santosh Puranikdedb5a62022-12-19 23:58:32 +05301800 // In case of system VPD it will already be filled, Don't have to
1801 // overwrite that.
1802 if (baseFruInventoryPath.empty())
1803 {
1804 baseFruInventoryPath = js["frus"][file][0]["inventoryPath"];
1805 }
1806
Santosh Puranik85893752020-11-10 21:31:43 +05301807 // Check if we can read the VPD file based on the power state
Santosh Puranik27a5e952021-10-07 22:08:01 -05001808 // We skip reading VPD when the power is ON in two scenarios:
Santosh Puranik31d50fa2022-04-04 12:04:37 +05301809 // 1) The eeprom we are trying to read is that of the system VPD and the
1810 // JSON symlink is already setup (the symlink's existence tells us we
1811 // are not coming out of a factory reset)
1812 // 2) The JSON tells us that the FRU EEPROM cannot be
1813 // read when we are powered ON.
Santosh Puranik27a5e952021-10-07 22:08:01 -05001814 if (js["frus"][file].at(0).value("powerOffOnly", false) ||
Santosh Puranik31d50fa2022-04-04 12:04:37 +05301815 (file == systemVpdFilePath && fs::exists(INVENTORY_JSON_SYM_LINK)))
Santosh Puranik85893752020-11-10 21:31:43 +05301816 {
1817 if ("xyz.openbmc_project.State.Chassis.PowerState.On" ==
1818 getPowerState())
1819 {
jinuthomasf457a3e2023-04-13 12:22:48 -05001820 std::cout << "This VPD cannot be read when power is ON"
1821 << std::endl;
Santosh Puranik85893752020-11-10 21:31:43 +05301822 return 0;
1823 }
1824 }
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001825
Santosh Puranike9c57532022-03-15 16:51:51 +05301826 // Check if this VPD should be recollected at all
1827 if (!needsRecollection(js, file))
1828 {
jinuthomasf457a3e2023-04-13 12:22:48 -05001829 std::cout << "Skip VPD recollection for: " << file << std::endl;
Santosh Puranike9c57532022-03-15 16:51:51 +05301830 return 0;
1831 }
1832
Alpana Kumari2f793042020-08-18 05:51:03 -05001833 try
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301834 {
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001835 variant<KeywordVpdMap, Store> parseResult;
Sunny Srivastava37992a62023-07-11 05:18:41 -05001836 parseResult = parseVpdFile(file, js);
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001837
1838 if (isSystemVpd)
girik18bb9852022-11-16 05:48:13 -06001839 {
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001840 // Get the value of systemVpdBackupPath field from json
1841 systemVpdBackupPath = js["frus"][systemVpdFilePath].at(0).value(
1842 "systemVpdBackupPath", "");
1843
1844 if (!systemVpdBackupPath.empty())
girik18bb9852022-11-16 05:48:13 -06001845 {
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001846 backupVpdInvPath =
1847 js["frus"][systemVpdBackupPath][0]["inventoryPath"]
1848 .get_ref<const nlohmann::json::string_t&>();
girik18bb9852022-11-16 05:48:13 -06001849 }
1850 }
SunnySrivastava19849a195542020-09-07 06:04:50 -05001851
Alpana Kumari2f793042020-08-18 05:51:03 -05001852 if (auto pVal = get_if<Store>(&parseResult))
1853 {
1854 populateDbus(pVal->getVpdMap(), js, file);
1855 }
1856 else if (auto pVal = get_if<KeywordVpdMap>(&parseResult))
1857 {
1858 populateDbus(*pVal, js, file);
1859 }
Alpana Kumari2f793042020-08-18 05:51:03 -05001860 }
Patrick Williams8e15b932021-10-06 13:04:22 -05001861 catch (const exception& e)
Alpana Kumari2f793042020-08-18 05:51:03 -05001862 {
Sunny Srivastava37992a62023-07-11 05:18:41 -05001863 if (!systemVpdBackupPath.empty())
1864 {
1865 file = systemVpdBackupPath;
1866 baseFruInventoryPath = backupVpdInvPath;
1867 }
1868
Alpana Kumari735dee92022-03-25 01:24:40 -05001869 executePostFailAction(js, file);
PriyangaRamasamya504c3e2020-12-06 12:14:52 -06001870 throw;
Alpana Kumari2f793042020-08-18 05:51:03 -05001871 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301872 }
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001873 catch (const VpdJsonException& ex)
1874 {
1875 additionalData.emplace("JSON_PATH", ex.getJsonPath());
1876 additionalData.emplace("DESCRIPTION", ex.what());
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -05001877 createPEL(additionalData, pelSeverity, errIntfForJsonFailure, nullptr);
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001878
jinuthomasf457a3e2023-04-13 12:22:48 -05001879 std::cerr << ex.what() << "\n";
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001880 rc = -1;
1881 }
1882 catch (const VpdEccException& ex)
1883 {
1884 additionalData.emplace("DESCRIPTION", "ECC check failed");
1885 additionalData.emplace("CALLOUT_INVENTORY_PATH",
1886 INVENTORY_PATH + baseFruInventoryPath);
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -05001887 createPEL(additionalData, pelSeverity, errIntfForEccCheckFail, nullptr);
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001888
1889 if (systemVpdBackupPath.empty())
1890 {
1891 dumpBadVpd(file, vpdVector);
1892 }
1893
jinuthomasf457a3e2023-04-13 12:22:48 -05001894 std::cerr << ex.what() << "\n";
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001895 rc = -1;
1896 }
1897 catch (const VpdDataException& ex)
1898 {
alpana075cb3b1f2021-12-16 11:19:36 -06001899 if (isThisPcieOnPass1planar(js, file))
1900 {
jinuthomasf457a3e2023-04-13 12:22:48 -05001901 std::cout << "Pcie_device [" << file
1902 << "]'s VPD is not valid on PASS1 planar.Ignoring.\n";
alpana075cb3b1f2021-12-16 11:19:36 -06001903 rc = 0;
1904 }
Santosh Puranik53b38ed2022-04-10 23:15:22 +05301905 else if (!(isPresent(js, file).value_or(true)))
1906 {
jinuthomasf457a3e2023-04-13 12:22:48 -05001907 std::cout << "FRU at: " << file
1908 << " is not detected present. Ignore parser error.\n";
Santosh Puranik53b38ed2022-04-10 23:15:22 +05301909 rc = 0;
1910 }
alpana075cb3b1f2021-12-16 11:19:36 -06001911 else
1912 {
1913 string errorMsg =
1914 "VPD file is either empty or invalid. Parser failed for [";
1915 errorMsg += file;
1916 errorMsg += "], with error = " + std::string(ex.what());
1917
1918 additionalData.emplace("DESCRIPTION", errorMsg);
1919 additionalData.emplace("CALLOUT_INVENTORY_PATH",
1920 INVENTORY_PATH + baseFruInventoryPath);
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -05001921 createPEL(additionalData, pelSeverity, errIntfForInvalidVPD,
1922 nullptr);
alpana075cb3b1f2021-12-16 11:19:36 -06001923
1924 rc = -1;
1925 }
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001926 }
Patrick Williams8e15b932021-10-06 13:04:22 -05001927 catch (const exception& e)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301928 {
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001929 dumpBadVpd(file, vpdVector);
jinuthomasf457a3e2023-04-13 12:22:48 -05001930 std::cerr << e.what() << "\n";
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301931 rc = -1;
1932 }
1933
1934 return rc;
Patrick Williamsc78d8872023-05-10 07:50:56 -05001935}