blob: e7ba65055c52834287ef8c15eafef773a8348fa5 [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";
87 }
88 return bmcState;
89}
90
91/**
92 * @brief Check if the FRU is in the cache
93 *
94 * Checks if the FRU associated with the supplied D-Bus object path is already
95 * on D-Bus. This can be used to test if a VPD collection is required for this
96 * FRU. It uses the "xyz.openbmc_project.Inventory.Item, Present" property to
97 * determine the presence of a FRU in the cache.
98 *
99 * @param objectPath - The D-Bus object path without the PIM prefix.
100 * @return true if the object exists on D-Bus, false otherwise.
101 */
102static auto isFruInVpdCache(const std::string& objectPath)
103{
104 try
105 {
106 auto bus = sdbusplus::bus::new_default();
107 auto invPath = std::string{pimPath} + objectPath;
108 auto props = bus.new_method_call(
109 "xyz.openbmc_project.Inventory.Manager", invPath.c_str(),
110 "org.freedesktop.DBus.Properties", "Get");
111 props.append("xyz.openbmc_project.Inventory.Item");
112 props.append("Present");
113 auto result = bus.call(props);
114 std::variant<bool> present;
115 result.read(present);
116 if (auto pVal = std::get_if<bool>(&present))
117 {
118 return *pVal;
119 }
120 return false;
121 }
122 catch (const sdbusplus::exception::SdBusError& e)
123 {
124 std::cout << "FRU: " << objectPath << " not in D-Bus\n";
125 // Assume not present in case of an error
126 return false;
127 }
128}
129
130/**
131 * @brief Check if VPD recollection is needed for the given EEPROM
132 *
133 * Not all FRUs can be swapped at BMC ready state. This function does the
134 * following:
135 * -- Check if the FRU is marked as "pluggableAtStandby" OR
136 * "concurrentlyMaintainable". If so, return true.
137 * -- Check if we are at BMC NotReady state. If we are, then return true.
138 * -- Else check if the FRU is not present in the VPD cache (to cover for VPD
139 * force collection). If not found in the cache, return true.
140 * -- Else return false.
141 *
142 * @param js - JSON Object.
143 * @param filePath - The EEPROM file.
144 * @return true if collection should be attempted, false otherwise.
145 */
146static auto needsRecollection(const nlohmann::json& js, const string& filePath)
147{
148 if (js["frus"][filePath].at(0).value("pluggableAtStandby", false) ||
149 js["frus"][filePath].at(0).value("concurrentlyMaintainable", false))
150 {
151 return true;
152 }
153 if (getBMCState() == "xyz.openbmc_project.State.BMC.BMCState.NotReady")
154 {
155 return true;
156 }
157 if (!isFruInVpdCache(js["frus"][filePath].at(0).value("inventoryPath", "")))
158 {
159 return true;
160 }
161 return false;
162}
163
164/**
Santosh Puranik88edeb62020-03-02 12:00:09 +0530165 * @brief Expands location codes
166 */
167static auto expandLocationCode(const string& unexpanded, const Parsed& vpdMap,
168 bool isSystemVpd)
169{
170 auto expanded{unexpanded};
171 static constexpr auto SYSTEM_OBJECT = "/system/chassis/motherboard";
172 static constexpr auto VCEN_IF = "com.ibm.ipzvpd.VCEN";
173 static constexpr auto VSYS_IF = "com.ibm.ipzvpd.VSYS";
174 size_t idx = expanded.find("fcs");
175 try
176 {
177 if (idx != string::npos)
178 {
179 string fc{};
180 string se{};
181 if (isSystemVpd)
182 {
183 const auto& fcData = vpdMap.at("VCEN").at("FC");
184 const auto& seData = vpdMap.at("VCEN").at("SE");
185 fc = string(fcData.data(), fcData.size());
186 se = string(seData.data(), seData.size());
187 }
188 else
189 {
190 fc = readBusProperty(SYSTEM_OBJECT, VCEN_IF, "FC");
191 se = readBusProperty(SYSTEM_OBJECT, VCEN_IF, "SE");
192 }
193
Alpana Kumari81671f62021-02-10 02:21:59 -0600194 // TODO: See if ND0 can be placed in the JSON
195 expanded.replace(idx, 3, fc.substr(0, 4) + ".ND0." + se);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530196 }
197 else
198 {
199 idx = expanded.find("mts");
200 if (idx != string::npos)
201 {
202 string mt{};
203 string se{};
204 if (isSystemVpd)
205 {
206 const auto& mtData = vpdMap.at("VSYS").at("TM");
207 const auto& seData = vpdMap.at("VSYS").at("SE");
208 mt = string(mtData.data(), mtData.size());
209 se = string(seData.data(), seData.size());
210 }
211 else
212 {
213 mt = readBusProperty(SYSTEM_OBJECT, VSYS_IF, "TM");
214 se = readBusProperty(SYSTEM_OBJECT, VSYS_IF, "SE");
215 }
216
217 replace(mt.begin(), mt.end(), '-', '.');
218 expanded.replace(idx, 3, mt + "." + se);
219 }
220 }
221 }
Patrick Williams8e15b932021-10-06 13:04:22 -0500222 catch (const exception& e)
Santosh Puranik88edeb62020-03-02 12:00:09 +0530223 {
jinuthomasf457a3e2023-04-13 12:22:48 -0500224 std::cerr << "Failed to expand location code with exception: "
225 << e.what() << "\n";
Santosh Puranik88edeb62020-03-02 12:00:09 +0530226 }
227 return expanded;
228}
Alpana Kumari2f793042020-08-18 05:51:03 -0500229
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530230/**
231 * @brief Populate FRU specific interfaces.
232 *
233 * This is a common method which handles both
234 * ipz and keyword specific interfaces thus,
235 * reducing the code redundancy.
236 * @param[in] map - Reference to the innermost keyword-value map.
237 * @param[in] preIntrStr - Reference to the interface string.
238 * @param[out] interfaces - Reference to interface map.
239 */
240template <typename T>
241static void populateFruSpecificInterfaces(const T& map,
242 const string& preIntrStr,
243 inventory::InterfaceMap& interfaces)
244{
245 inventory::PropertyMap prop;
246
247 for (const auto& kwVal : map)
248 {
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530249 auto kw = kwVal.first;
250
251 if (kw[0] == '#')
252 {
Alpana Kumari58e22142020-05-05 00:22:12 -0500253 kw = string("PD_") + kw[1];
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530254 }
Alpana Kumari8ea3f6d2020-04-02 00:26:07 -0500255 else if (isdigit(kw[0]))
256 {
Alpana Kumari58e22142020-05-05 00:22:12 -0500257 kw = string("N_") + kw;
Alpana Kumari8ea3f6d2020-04-02 00:26:07 -0500258 }
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000259 if constexpr (is_same<T, KeywordVpdMap>::value)
260 {
jinuthomasd640f692023-03-28 04:13:23 -0500261 if (auto keywordValue = get_if<Binary>(&kwVal.second))
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000262 {
jinuthomasd640f692023-03-28 04:13:23 -0500263 Binary vec((*keywordValue).begin(), (*keywordValue).end());
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000264 prop.emplace(move(kw), move(vec));
265 }
jinuthomasd640f692023-03-28 04:13:23 -0500266 else if (auto keywordValue = get_if<std::string>(&kwVal.second))
267 {
268 Binary vec((*keywordValue).begin(), (*keywordValue).end());
269 prop.emplace(move(kw), move(vec));
270 }
271 else if (auto keywordValue = get_if<size_t>(&kwVal.second))
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000272 {
273 if (kw == "MemorySizeInKB")
274 {
275 inventory::PropertyMap memProp;
jinuthomasd640f692023-03-28 04:13:23 -0500276 memProp.emplace(move(kw), ((*keywordValue)));
277 interfaces.emplace(
278 "xyz.openbmc_project.Inventory.Item.Dimm",
279 move(memProp));
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000280 }
jinuthomasd640f692023-03-28 04:13:23 -0500281 else
282 {
jinuthomasf457a3e2023-04-13 12:22:48 -0500283 std::cerr << "Unknown Keyword[" << kw << "] found ";
jinuthomasd640f692023-03-28 04:13:23 -0500284 }
285 }
286 else
287 {
jinuthomasf457a3e2023-04-13 12:22:48 -0500288 std::cerr << "Unknown Variant found ";
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000289 }
290 }
291 else
292 {
293 Binary vec(kwVal.second.begin(), kwVal.second.end());
294 prop.emplace(move(kw), move(vec));
295 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530296 }
297
298 interfaces.emplace(preIntrStr, move(prop));
299}
300
301/**
302 * @brief Populate Interfaces.
303 *
304 * This method populates common and extra interfaces to dbus.
305 * @param[in] js - json object
306 * @param[out] interfaces - Reference to interface map
307 * @param[in] vpdMap - Reference to the parsed vpd map.
Santosh Puranik88edeb62020-03-02 12:00:09 +0530308 * @param[in] isSystemVpd - Denotes whether we are collecting the system VPD.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530309 */
310template <typename T>
311static void populateInterfaces(const nlohmann::json& js,
312 inventory::InterfaceMap& interfaces,
Santosh Puranik88edeb62020-03-02 12:00:09 +0530313 const T& vpdMap, bool isSystemVpd)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530314{
315 for (const auto& ifs : js.items())
316 {
Santosh Puranik88edeb62020-03-02 12:00:09 +0530317 string inf = ifs.key();
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530318 inventory::PropertyMap props;
319
320 for (const auto& itr : ifs.value().items())
321 {
Santosh Puranik88edeb62020-03-02 12:00:09 +0530322 const string& busProp = itr.key();
323
Alpana Kumari31970de2020-02-17 06:49:57 -0600324 if (itr.value().is_boolean())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530325 {
Santosh Puranik88edeb62020-03-02 12:00:09 +0530326 props.emplace(busProp, itr.value().get<bool>());
327 }
328 else if (itr.value().is_string())
329 {
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600330 if (busProp == "LocationCode" && inf == IBM_LOCATION_CODE_INF)
Santosh Puranik88edeb62020-03-02 12:00:09 +0530331 {
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600332 std::string prop;
333 if constexpr (is_same<T, Parsed>::value)
Santosh Puranik88edeb62020-03-02 12:00:09 +0530334 {
Alpana Kumari414d5ae2021-03-04 21:06:35 +0000335 // TODO deprecate the com.ibm interface later
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600336 prop = expandLocationCode(itr.value().get<string>(),
337 vpdMap, isSystemVpd);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530338 }
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600339 else if constexpr (is_same<T, KeywordVpdMap>::value)
Santosh Puranik88edeb62020-03-02 12:00:09 +0530340 {
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600341 // Send empty Parsed object to expandLocationCode api.
342 prop = expandLocationCode(itr.value().get<string>(),
343 Parsed{}, false);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530344 }
Priyanga Ramasamy0d61c582022-01-21 04:38:22 -0600345 props.emplace(busProp, prop);
346 interfaces.emplace(XYZ_LOCATION_CODE_INF, props);
347 interfaces.emplace(IBM_LOCATION_CODE_INF, props);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530348 }
349 else
350 {
351 props.emplace(busProp, itr.value().get<string>());
352 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530353 }
Santosh Puraniked609af2021-06-21 11:30:07 +0530354 else if (itr.value().is_array())
355 {
356 try
357 {
358 props.emplace(busProp, itr.value().get<Binary>());
359 }
Patrick Williams8e15b932021-10-06 13:04:22 -0500360 catch (const nlohmann::detail::type_error& e)
Santosh Puraniked609af2021-06-21 11:30:07 +0530361 {
362 std::cerr << "Type exception: " << e.what() << "\n";
363 // Ignore any type errors
364 }
365 }
Alpana Kumari31970de2020-02-17 06:49:57 -0600366 else if (itr.value().is_object())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530367 {
Alpana Kumari31970de2020-02-17 06:49:57 -0600368 const string& rec = itr.value().value("recordName", "");
369 const string& kw = itr.value().value("keywordName", "");
370 const string& encoding = itr.value().value("encoding", "");
371
Alpana Kumari58e22142020-05-05 00:22:12 -0500372 if constexpr (is_same<T, Parsed>::value)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530373 {
Santosh Puranik88edeb62020-03-02 12:00:09 +0530374 if (!rec.empty() && !kw.empty() && vpdMap.count(rec) &&
375 vpdMap.at(rec).count(kw))
Alpana Kumari31970de2020-02-17 06:49:57 -0600376 {
Patrick Williamsc78d8872023-05-10 07:50:56 -0500377 auto encoded = encodeKeyword(vpdMap.at(rec).at(kw),
378 encoding);
Santosh Puranik88edeb62020-03-02 12:00:09 +0530379 props.emplace(busProp, encoded);
Alpana Kumari31970de2020-02-17 06:49:57 -0600380 }
381 }
Alpana Kumari58e22142020-05-05 00:22:12 -0500382 else if constexpr (is_same<T, KeywordVpdMap>::value)
Alpana Kumari31970de2020-02-17 06:49:57 -0600383 {
384 if (!kw.empty() && vpdMap.count(kw))
385 {
jinuthomasd640f692023-03-28 04:13:23 -0500386 if (auto kwValue = get_if<Binary>(&vpdMap.at(kw)))
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000387 {
Patrick Williamsc78d8872023-05-10 07:50:56 -0500388 auto prop = string((*kwValue).begin(),
389 (*kwValue).end());
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000390
391 auto encoded = encodeKeyword(prop, encoding);
392
393 props.emplace(busProp, encoded);
394 }
jinuthomasd640f692023-03-28 04:13:23 -0500395 else if (auto kwValue =
396 get_if<std::string>(&vpdMap.at(kw)))
397 {
Patrick Williamsc78d8872023-05-10 07:50:56 -0500398 auto prop = string((*kwValue).begin(),
399 (*kwValue).end());
jinuthomasd640f692023-03-28 04:13:23 -0500400
401 auto encoded = encodeKeyword(prop, encoding);
402
403 props.emplace(busProp, encoded);
404 }
405 else if (auto uintValue =
406 get_if<size_t>(&vpdMap.at(kw)))
Alpana Kumari3ab26a72021-04-05 19:09:19 +0000407 {
408 props.emplace(busProp, *uintValue);
409 }
jinuthomasd640f692023-03-28 04:13:23 -0500410 else
411 {
412 std::cerr << " Unknown Keyword [" << kw
413 << "] Encountered";
414 }
Alpana Kumari31970de2020-02-17 06:49:57 -0600415 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530416 }
417 }
Matt Spinlerb1e64bb2021-09-08 09:57:48 -0500418 else if (itr.value().is_number())
419 {
420 // For now assume the value is a size_t. In the future it would
421 // be nice to come up with a way to get the type from the JSON.
422 props.emplace(busProp, itr.value().get<size_t>());
423 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530424 }
Priyanga Ramasamyaa8a8932022-01-27 09:12:41 -0600425 insertOrMerge(interfaces, inf, move(props));
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530426 }
427}
428
alpana075cb3b1f2021-12-16 11:19:36 -0600429/**
430 * @brief This API checks if this FRU is pcie_devices. If yes then it further
431 * checks whether it is PASS1 planar.
432 */
433static bool isThisPcieOnPass1planar(const nlohmann::json& js,
434 const string& file)
435{
436 auto isThisPCIeDev = false;
437 auto isPASS1 = false;
438
439 // Check if it is a PCIE device
440 if (js["frus"].find(file) != js["frus"].end())
441 {
Santosh Puranikc03f3902022-04-14 10:58:26 +0530442 if ((js["frus"][file].at(0).find("extraInterfaces") !=
443 js["frus"][file].at(0).end()))
alpana075cb3b1f2021-12-16 11:19:36 -0600444 {
Santosh Puranikc03f3902022-04-14 10:58:26 +0530445 if (js["frus"][file].at(0)["extraInterfaces"].find(
alpana075cb3b1f2021-12-16 11:19:36 -0600446 "xyz.openbmc_project.Inventory.Item.PCIeDevice") !=
Santosh Puranikc03f3902022-04-14 10:58:26 +0530447 js["frus"][file].at(0)["extraInterfaces"].end())
alpana075cb3b1f2021-12-16 11:19:36 -0600448 {
449 isThisPCIeDev = true;
450 }
451 }
452 }
453
454 if (isThisPCIeDev)
455 {
Alpana Kumaria6181e22022-05-12 05:01:53 -0500456 // Collect HW version and SystemType to know if it is PASS1 planar.
alpana075cb3b1f2021-12-16 11:19:36 -0600457 auto bus = sdbusplus::bus::new_default();
Alpana Kumaria6181e22022-05-12 05:01:53 -0500458 auto property1 = bus.new_method_call(
alpana075cb3b1f2021-12-16 11:19:36 -0600459 INVENTORY_MANAGER_SERVICE,
460 "/xyz/openbmc_project/inventory/system/chassis/motherboard",
461 "org.freedesktop.DBus.Properties", "Get");
Alpana Kumaria6181e22022-05-12 05:01:53 -0500462 property1.append("com.ibm.ipzvpd.VINI");
463 property1.append("HW");
464 auto result1 = bus.call(property1);
465 inventory::Value hwVal;
466 result1.read(hwVal);
alpana075cb3b1f2021-12-16 11:19:36 -0600467
Alpana Kumaria6181e22022-05-12 05:01:53 -0500468 // SystemType
469 auto property2 = bus.new_method_call(
470 INVENTORY_MANAGER_SERVICE,
471 "/xyz/openbmc_project/inventory/system/chassis/motherboard",
472 "org.freedesktop.DBus.Properties", "Get");
473 property2.append("com.ibm.ipzvpd.VSBP");
474 property2.append("IM");
475 auto result2 = bus.call(property2);
476 inventory::Value imVal;
477 result2.read(imVal);
478
479 auto pVal1 = get_if<Binary>(&hwVal);
480 auto pVal2 = get_if<Binary>(&imVal);
481
482 if (pVal1 && pVal2)
alpana075cb3b1f2021-12-16 11:19:36 -0600483 {
Alpana Kumaria6181e22022-05-12 05:01:53 -0500484 auto hwVersion = *pVal1;
485 auto systemType = *pVal2;
486
487 // IM kw for Everest
488 Binary everestSystem{80, 00, 48, 00};
489
490 if (systemType == everestSystem)
491 {
492 if (hwVersion[1] < 21)
493 {
494 isPASS1 = true;
495 }
496 }
497 else if (hwVersion[1] < 2)
498 {
alpana075cb3b1f2021-12-16 11:19:36 -0600499 isPASS1 = true;
Alpana Kumaria6181e22022-05-12 05:01:53 -0500500 }
alpana075cb3b1f2021-12-16 11:19:36 -0600501 }
502 }
503
504 return (isThisPCIeDev && isPASS1);
505}
506
Alpana Kumari735dee92022-03-25 01:24:40 -0500507/** Performs any pre-action needed to get the FRU setup for collection.
Alpana Kumari2f793042020-08-18 05:51:03 -0500508 *
509 * @param[in] json - json object
510 * @param[in] file - eeprom file path
511 */
512static void preAction(const nlohmann::json& json, const string& file)
513{
Alpana Kumari735dee92022-03-25 01:24:40 -0500514 if ((json["frus"][file].at(0)).find("preAction") ==
Alpana Kumari2f793042020-08-18 05:51:03 -0500515 json["frus"][file].at(0).end())
516 {
Alpana Kumari735dee92022-03-25 01:24:40 -0500517 return;
Alpana Kumari2f793042020-08-18 05:51:03 -0500518 }
519
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500520 try
Alpana Kumari2f793042020-08-18 05:51:03 -0500521 {
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500522 if (executePreAction(json, file))
Alpana Kumari2f793042020-08-18 05:51:03 -0500523 {
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500524 if (json["frus"][file].at(0).find("devAddress") !=
525 json["frus"][file].at(0).end())
Alpana Kumari40d1c192022-03-09 21:16:02 -0600526 {
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500527 // Now bind the device
528 string bind = json["frus"][file].at(0).value("devAddress", "");
jinuthomasf457a3e2023-04-13 12:22:48 -0500529 std::cout << "Binding device " << bind << std::endl;
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500530 string bindCmd = string("echo \"") + bind +
531 string("\" > /sys/bus/i2c/drivers/at24/bind");
jinuthomasf457a3e2023-04-13 12:22:48 -0500532 std::cout << bindCmd << std::endl;
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500533 executeCmd(bindCmd);
534
535 // Check if device showed up (test for file)
536 if (!fs::exists(file))
537 {
jinuthomasf457a3e2023-04-13 12:22:48 -0500538 std::cerr << "EEPROM " << file
539 << " does not exist. Take failure action"
540 << std::endl;
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500541 // If not, then take failure postAction
542 executePostFailAction(json, file);
543 }
544 }
545 else
546 {
547 // missing required informations
jinuthomasf457a3e2023-04-13 12:22:48 -0500548 std::cerr << "VPD inventory JSON missing basic informations of "
549 "preAction "
550 "for this FRU : ["
551 << file << "]. Executing executePostFailAction."
552 << std::endl;
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500553
554 // Take failure postAction
Alpana Kumari40d1c192022-03-09 21:16:02 -0600555 executePostFailAction(json, file);
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500556 return;
Alpana Kumari40d1c192022-03-09 21:16:02 -0600557 }
558 }
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530559 else
560 {
561 // If the FRU is not there, clear the VINI/CCIN data.
562 // Enity manager probes for this keyword to look for this
563 // FRU, now if the data is persistent on BMC and FRU is
564 // removed this can lead to ambiguity. Hence clearing this
565 // Keyword if FRU is absent.
566 const auto& invPath =
567 json["frus"][file].at(0).value("inventoryPath", "");
568
569 if (!invPath.empty())
570 {
571 inventory::ObjectMap pimObjMap{
572 {invPath, {{"com.ibm.ipzvpd.VINI", {{"CC", Binary{}}}}}}};
573
574 common::utility::callPIM(move(pimObjMap));
575 }
576 else
577 {
578 throw std::runtime_error("Path empty in Json");
579 }
580 }
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500581 }
582 catch (const GpioException& e)
583 {
584 PelAdditionalData additionalData{};
585 additionalData.emplace("DESCRIPTION", e.what());
586 createPEL(additionalData, PelSeverity::WARNING, errIntfForGpioError,
587 nullptr);
Alpana Kumari2f793042020-08-18 05:51:03 -0500588 }
Alpana Kumari2f793042020-08-18 05:51:03 -0500589}
590
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530591/**
Santosh Puranikf3e69682022-03-31 17:52:38 +0530592 * @brief Fills the Decorator.AssetTag property into the interfaces map
593 *
594 * This function should only be called in cases where we did not find a JSON
595 * symlink. A missing symlink in /var/lib will be considered as a factory reset
596 * and this function will be used to default the AssetTag property.
597 *
598 * @param interfaces A possibly pre-populated map of inetrfaces to properties.
599 * @param vpdMap A VPD map of the system VPD data.
600 */
601static void fillAssetTag(inventory::InterfaceMap& interfaces,
602 const Parsed& vpdMap)
603{
604 // Read the system serial number and MTM
605 // Default asset tag is Server-MTM-System Serial
606 inventory::Interface assetIntf{
607 "xyz.openbmc_project.Inventory.Decorator.AssetTag"};
608 inventory::PropertyMap assetTagProps;
609 std::string defaultAssetTag =
610 std::string{"Server-"} + getKwVal(vpdMap, "VSYS", "TM") +
611 std::string{"-"} + getKwVal(vpdMap, "VSYS", "SE");
612 assetTagProps.emplace("AssetTag", defaultAssetTag);
613 insertOrMerge(interfaces, assetIntf, std::move(assetTagProps));
614}
615
616/**
Santosh Puranikd3a379a2021-08-23 19:12:59 +0530617 * @brief Set certain one time properties in the inventory
618 * Use this function to insert the Functional and Enabled properties into the
619 * inventory map. This function first checks if the object in question already
620 * has these properties hosted on D-Bus, if the property is already there, it is
621 * not modified, hence the name "one time". If the property is not already
622 * present, it will be added to the map with a suitable default value (true for
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530623 * Functional and Enabled)
Santosh Puranikd3a379a2021-08-23 19:12:59 +0530624 *
625 * @param[in] object - The inventory D-Bus obejct without the inventory prefix.
626 * @param[inout] interfaces - Reference to a map of inventory interfaces to
627 * which the properties will be attached.
628 */
629static void setOneTimeProperties(const std::string& object,
630 inventory::InterfaceMap& interfaces)
631{
632 auto bus = sdbusplus::bus::new_default();
633 auto objectPath = INVENTORY_PATH + object;
634 auto prop = bus.new_method_call("xyz.openbmc_project.Inventory.Manager",
635 objectPath.c_str(),
636 "org.freedesktop.DBus.Properties", "Get");
637 prop.append("xyz.openbmc_project.State.Decorator.OperationalStatus");
638 prop.append("Functional");
639 try
640 {
641 auto result = bus.call(prop);
642 }
643 catch (const sdbusplus::exception::SdBusError& e)
644 {
645 // Treat as property unavailable
646 inventory::PropertyMap prop;
647 prop.emplace("Functional", true);
648 interfaces.emplace(
649 "xyz.openbmc_project.State.Decorator.OperationalStatus",
650 move(prop));
651 }
652 prop = bus.new_method_call("xyz.openbmc_project.Inventory.Manager",
653 objectPath.c_str(),
654 "org.freedesktop.DBus.Properties", "Get");
655 prop.append("xyz.openbmc_project.Object.Enable");
656 prop.append("Enabled");
657 try
658 {
659 auto result = bus.call(prop);
660 }
661 catch (const sdbusplus::exception::SdBusError& e)
662 {
663 // Treat as property unavailable
664 inventory::PropertyMap prop;
Santosh Puranikdedb5a62022-12-19 23:58:32 +0530665 prop.emplace("Enabled", true);
Santosh Puranikd3a379a2021-08-23 19:12:59 +0530666 interfaces.emplace("xyz.openbmc_project.Object.Enable", move(prop));
667 }
668}
669
670/**
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530671 * @brief Prime the Inventory
672 * Prime the inventory by populating only the location code,
673 * type interface and the inventory object for the frus
674 * which are not system vpd fru.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530675 *
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530676 * @param[in] jsObject - Reference to vpd inventory json object
677 * @param[in] vpdMap - Reference to the parsed vpd map
678 *
679 * @returns Map of items in extraInterface.
680 */
681template <typename T>
682inventory::ObjectMap primeInventory(const nlohmann::json& jsObject,
683 const T& vpdMap)
684{
685 inventory::ObjectMap objects;
686
687 for (auto& itemFRUS : jsObject["frus"].items())
688 {
689 for (auto& itemEEPROM : itemFRUS.value())
690 {
Alpana Kumari2e6c6f72020-12-03 00:10:03 -0600691 // Take pre actions if needed
692 if (itemEEPROM.find("preAction") != itemEEPROM.end())
693 {
694 preAction(jsObject, itemFRUS.key());
695 }
696
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530697 inventory::InterfaceMap interfaces;
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530698 inventory::Object object(itemEEPROM.at("inventoryPath"));
699
Santosh Puranik50f60bf2021-05-26 17:55:06 +0530700 if ((itemFRUS.key() != systemVpdFilePath) &&
701 !itemEEPROM.value("noprime", false))
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530702 {
Alpana Kumaricfd7a752021-02-07 23:23:01 -0600703 inventory::PropertyMap presProp;
Priyanga Ramasamye358acb2022-03-21 14:21:50 -0500704
705 // Do not populate Present property for frus whose
Priyanga Ramasamyaca61372023-01-24 08:02:28 -0600706 // synthesized=true. synthesized=true says the fru VPD is
707 // synthesized and owned by a separate component.
708 // In some cases, the FRU has its own VPD, but still a separate
709 // application handles the FRU's presence. So VPD parser skips
710 // populating Present property by checking the JSON flag,
711 // "handlePresence".
Priyanga Ramasamye358acb2022-03-21 14:21:50 -0500712 if (!itemEEPROM.value("synthesized", false))
713 {
Priyanga Ramasamyaca61372023-01-24 08:02:28 -0600714 if (itemEEPROM.value("handlePresence", true))
715 {
716 presProp.emplace("Present", false);
717 interfaces.emplace("xyz.openbmc_project.Inventory.Item",
718 presProp);
719 }
Priyanga Ramasamye358acb2022-03-21 14:21:50 -0500720 }
Priyanga Ramasamyaca61372023-01-24 08:02:28 -0600721
Santosh Puranikd3a379a2021-08-23 19:12:59 +0530722 setOneTimeProperties(object, interfaces);
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530723 if (itemEEPROM.find("extraInterfaces") != itemEEPROM.end())
724 {
725 for (const auto& eI : itemEEPROM["extraInterfaces"].items())
726 {
727 inventory::PropertyMap props;
Alpana Kumari414d5ae2021-03-04 21:06:35 +0000728 if (eI.key() == IBM_LOCATION_CODE_INF)
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530729 {
730 if constexpr (std::is_same<T, Parsed>::value)
731 {
732 for (auto& lC : eI.value().items())
733 {
734 auto propVal = expandLocationCode(
735 lC.value().get<string>(), vpdMap, true);
736
737 props.emplace(move(lC.key()),
738 move(propVal));
Santosh Puranikb0f37492021-06-21 09:42:47 +0530739 interfaces.emplace(XYZ_LOCATION_CODE_INF,
740 props);
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530741 interfaces.emplace(move(eI.key()),
742 move(props));
743 }
744 }
745 }
746 else if (eI.key().find("Inventory.Item.") !=
747 string::npos)
748 {
749 interfaces.emplace(move(eI.key()), move(props));
750 }
Santosh Puranikd3a379a2021-08-23 19:12:59 +0530751 else if (eI.key() ==
752 "xyz.openbmc_project.Inventory.Item")
753 {
754 for (auto& val : eI.value().items())
755 {
756 if (val.key() == "PrettyName")
757 {
758 presProp.emplace(val.key(),
759 val.value().get<string>());
760 }
761 }
762 // Use insert_or_assign here as we may already have
763 // inserted the present property only earlier in
764 // this function under this same interface.
765 interfaces.insert_or_assign(eI.key(),
766 move(presProp));
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"},
815 {BONNELL, "conf-aspeed-bmc-ibm-bonnell.dtb"}};
Alpana Kumari65b83602020-09-01 00:24:56 -0500816
817 if (deviceTreeSystemTypeMap.find(systemType) !=
818 deviceTreeSystemTypeMap.end())
819 {
820 newDeviceTree = deviceTreeSystemTypeMap.at(systemType);
821 }
Alpana Kumari37e72702021-11-18 11:18:04 -0600822 else
823 {
824 // System type not supported
Alpana Kumariab1e22c2021-11-24 11:03:38 -0600825 string err = "This System type not found/supported in dtb table " +
826 systemType +
827 ".Please check the HW and IM keywords in the system "
828 "VPD.Breaking...";
829
830 // map to hold additional data in case of logging pel
831 PelAdditionalData additionalData{};
832 additionalData.emplace("DESCRIPTION", err);
833 createPEL(additionalData, PelSeverity::WARNING,
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -0500834 errIntfForInvalidSystemType, nullptr);
Alpana Kumariab1e22c2021-11-24 11:03:38 -0600835 exit(-1);
Alpana Kumari37e72702021-11-18 11:18:04 -0600836 }
Alpana Kumari65b83602020-09-01 00:24:56 -0500837
838 string readVarValue;
839 bool envVarFound = false;
840
841 vector<string> output = executeCmd("/sbin/fw_printenv");
842 for (const auto& entry : output)
843 {
844 size_t pos = entry.find("=");
845 string key = entry.substr(0, pos);
846 if (key != "fitconfig")
847 {
848 continue;
849 }
850
851 envVarFound = true;
852 if (pos + 1 < entry.size())
853 {
854 readVarValue = entry.substr(pos + 1);
855 if (readVarValue.find(newDeviceTree) != string::npos)
856 {
857 // fitconfig is Updated. No action needed
858 break;
859 }
860 }
861 // set env and reboot and break.
862 setEnvAndReboot(key, newDeviceTree);
863 exit(0);
864 }
865
866 // check If env var Not found
867 if (!envVarFound)
868 {
869 setEnvAndReboot("fitconfig", newDeviceTree);
870 }
871}
872
PriyangaRamasamy8e140a12020-04-13 19:24:03 +0530873/**
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500874 * @brief Parse the given EEPROM file.
875 *
876 * @param[in] vpdFilePath - Path of EEPROM file
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500877 * @param[in] js- Reference to vpd inventory json object
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500878 * @return Parsed VPD map
879 */
880std::variant<KeywordVpdMap, openpower::vpd::Store>
Sunny Srivastava37992a62023-07-11 05:18:41 -0500881 parseVpdFile(const std::string& vpdFilePath, const nlohmann::json& js)
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500882{
883 uint32_t vpdStartOffset = 0;
884 for (const auto& item : js["frus"][vpdFilePath])
885 {
886 if (item.find("offset") != item.end())
887 {
888 vpdStartOffset = item["offset"];
Sunny Srivastava37992a62023-07-11 05:18:41 -0500889 break;
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500890 }
891 }
892
893 Binary vpdVector = getVpdDataInVector(js, vpdFilePath);
894
895 ParserInterface* parser = ParserFactory::getParser(
Sunny Srivastava37992a62023-07-11 05:18:41 -0500896 vpdVector,
897 (pimPath + js["frus"][vpdFilePath][0]["inventoryPath"]
898 .get_ref<const nlohmann::json::string_t&>()),
899 vpdFilePath, vpdStartOffset);
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500900
901 auto parseResult = parser->parse();
902
903 // release the parser object
904 ParserFactory::freeParser(parser);
905
906 return parseResult;
907}
908
909/*
910 * @brief This API retrieves the hardware backup in map
911 *
912 * @param[in] systemVpdBackupPath - The path that backs up the system VPD.
913 * @param[in] backupVpdInvPath - FRU inventory path.
914 * @param[in] js - JSON object.
915 * @param[out] backupVpdMap - An IPZ VPD map containing the parsed backup VPD.
916 *
917 * */
918void getBackupVpdInMap(const string& systemVpdBackupPath,
919 const string& backupVpdInvPath, const nlohmann::json& js,
920 Parsed& backupVpdMap)
921{
922 PelAdditionalData additionalData{};
923
924 if (!fs::exists(systemVpdBackupPath))
925 {
926 string errorMsg = "Device path ";
927 errorMsg += systemVpdBackupPath;
928 errorMsg += " does not exist";
929
930 additionalData.emplace("DESCRIPTION", errorMsg);
931
932 additionalData.emplace("CALLOUT_INVENTORY_PATH",
933 INVENTORY_PATH + backupVpdInvPath);
934
935 createPEL(additionalData, PelSeverity::ERROR, errIntfForStreamFail,
936 nullptr);
937 }
938 else
939 {
Sunny Srivastava37992a62023-07-11 05:18:41 -0500940 auto backupVpdParsedResult = parseVpdFile(systemVpdBackupPath, js);
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500941
942 if (auto pVal = get_if<Store>(&backupVpdParsedResult))
943 {
944 backupVpdMap = pVal->getVpdMap();
945 }
Sunny Srivastava37992a62023-07-11 05:18:41 -0500946 else
947 {
948 std::cerr << "Invalid format of VPD in back up. Restore aborted."
949 << std::endl;
950 }
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500951 }
952}
953
954void updateVpdDataOnHw(const std::string& vpdFilePath, nlohmann::json& js,
955 const std::string& recName, const std::string& kwName,
956 const Binary& kwdData)
957{
958 const std::string& fruInvPath =
959 js["frus"][vpdFilePath][0]["inventoryPath"]
960 .get_ref<const nlohmann::json::string_t&>();
961
962 EditorImpl edit(vpdFilePath, js, recName, kwName, fruInvPath);
963
964 uint32_t offset = 0;
965 // Setup offset, if any
966 for (const auto& item : js["frus"][vpdFilePath])
967 {
968 if (item.find("offset") != item.end())
969 {
970 offset = item["offset"];
971 break;
972 }
973 }
974
975 // update keyword data on to EEPROM file
976 // Note: Updating keyword data on cache is
977 // handled via PIM Notify call hence passing
978 // the updCache flag value as false here.
979 edit.updateKeyword(kwdData, offset, false);
980}
981
982/**
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500983 * @brief API to check if we need to restore system VPD
984 * This functionality is only applicable for IPZ VPD data.
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500985
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500986 * @param[in] vpdMap - IPZ vpd map
987 * @param[in] objectPath - Object path for the FRU
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500988 * @param[in] js - JSON Object
989 * @param[in] isBackupOnCache - Denotes whether the backup is on cache/hardware
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500990 */
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500991void restoreSystemVPD(Parsed& vpdMap, const string& objectPath,
992 nlohmann::json& js, bool isBackupOnCache = true)
SunnySrivastava19849094d4f2020-08-05 09:32:29 -0500993{
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -0500994 std::string systemVpdBackupPath{};
995 std::string backupVpdInvPath{};
996 Parsed backupVpdMap{};
997
998 if (!isBackupOnCache)
999 {
1000 // Get the value of systemvpdBackupPath field from json
1001 systemVpdBackupPath = js["frus"][systemVpdFilePath].at(0).value(
1002 "systemVpdBackupPath", "");
1003
1004 backupVpdInvPath = js["frus"][systemVpdBackupPath][0]["inventoryPath"]
1005 .get_ref<const nlohmann::json::string_t&>();
1006
1007 getBackupVpdInMap(systemVpdBackupPath, backupVpdInvPath, js,
1008 backupVpdMap);
1009
1010 if (backupVpdMap.empty())
1011 {
Sunny Srivastava37992a62023-07-11 05:18:41 -05001012 std::cerr << "Backup VPD map is empty" << std::endl;
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001013 return;
1014 }
1015 }
1016
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001017 for (const auto& systemRecKwdPair : svpdKwdMap)
1018 {
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001019 const string& recordName = systemRecKwdPair.first;
1020 auto it = vpdMap.find(recordName);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001021
1022 // check if record is found in map we got by parser
1023 if (it != vpdMap.end())
1024 {
1025 const auto& kwdListForRecord = systemRecKwdPair.second;
Priyanga Ramasamy952d6c52022-11-07 07:20:24 -06001026 for (const auto& keywordInfo : kwdListForRecord)
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001027 {
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001028 const auto keywordName = get<0>(keywordInfo);
Priyanga Ramasamy952d6c52022-11-07 07:20:24 -06001029
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001030 DbusPropertyMap& kwdValMap = it->second;
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001031 auto iterator = kwdValMap.find(keywordName);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001032
1033 if (iterator != kwdValMap.end())
1034 {
1035 string& kwdValue = iterator->second;
1036
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001037 std::string backupValue{};
Priyanga Ramasamy952d6c52022-11-07 07:20:24 -06001038 const auto& defaultValue = get<1>(keywordInfo);
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001039 const auto& backupVpdRecName = get<4>(keywordInfo);
1040 const auto& backupVpdKwName = get<5>(keywordInfo);
1041
1042 // If the 'isBackupOnCache' flag is false, we need
1043 // to backup the systemVPD on the specified fru's eeprom
1044 // path or restore it from the specified fru's eeprom path.
1045 if (isBackupOnCache)
1046 {
1047 // check bus data
1048 backupValue = readBusProperty(
1049 objectPath, ipzVpdInf + recordName, keywordName);
1050 }
1051 else
1052 {
Sunny Srivastava37992a62023-07-11 05:18:41 -05001053 backupValue = getKwVal(backupVpdMap, backupVpdRecName,
1054 backupVpdKwName);
1055
1056 if (backupValue.empty())
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001057 {
Sunny Srivastava37992a62023-07-11 05:18:41 -05001058 string errorMsg{};
1059 if (backupVpdMap.find(backupVpdRecName) ==
1060 backupVpdMap.end())
1061 {
1062 errorMsg = backupVpdRecName +
1063 " Record does not exist in "
1064 "the EEPROM file ";
1065 }
1066 else
1067 {
1068 errorMsg = backupVpdKwName +
1069 " Keyword not found or empty.";
1070 }
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001071
1072 errorMsg += systemVpdBackupPath;
1073
1074 PelAdditionalData additionalData;
1075 additionalData.emplace("DESCRIPTION", errorMsg);
1076
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001077 createPEL(additionalData, PelSeverity::ERROR,
1078 errIntfForInvalidVPD, nullptr);
1079
1080 continue;
1081 }
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001082 }
1083
1084 Binary backupDataInBinary(backupValue.begin(),
1085 backupValue.end());
1086
Priyanga Ramasamy952d6c52022-11-07 07:20:24 -06001087 Binary kwdDataInBinary(kwdValue.begin(), kwdValue.end());
Sunny Srivastavaa559c2d2022-05-02 11:56:45 -05001088
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001089 if (backupDataInBinary != defaultValue)
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001090 {
Priyanga Ramasamy952d6c52022-11-07 07:20:24 -06001091 if (kwdDataInBinary != defaultValue)
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001092 {
1093 // both the data are present, check for mismatch
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001094 if (backupValue != kwdValue)
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001095 {
Priyanga Ramasamy24942232023-01-05 04:54:59 -06001096 string errMsg = "Mismatch found between backup "
1097 "and primary VPD for record: ";
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001098 errMsg += (*it).first;
1099 errMsg += " and keyword: ";
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001100 errMsg += keywordName;
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001101
Santosh Puranikdedb5a62022-12-19 23:58:32 +05301102 std::ostringstream busStream;
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001103 for (uint16_t byte : backupValue)
Santosh Puranikdedb5a62022-12-19 23:58:32 +05301104 {
1105 busStream << std::setfill('0')
1106 << std::setw(2) << std::hex
1107 << "0x" << byte << " ";
1108 }
1109
1110 std::ostringstream vpdStream;
1111 for (uint16_t byte : kwdValue)
1112 {
1113 vpdStream << std::setfill('0')
1114 << std::setw(2) << std::hex
1115 << "0x" << byte << " ";
1116 }
1117
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001118 // data mismatch
1119 PelAdditionalData additionalData;
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001120
1121 additionalData.emplace("DESCRIPTION", errMsg);
Santosh Puranikdedb5a62022-12-19 23:58:32 +05301122 additionalData.emplace(
Priyanga Ramasamy24942232023-01-05 04:54:59 -06001123 "Value read from Backup: ",
1124 busStream.str());
1125 additionalData.emplace(
1126 "Value read from Primary: ",
Santosh Puranikdedb5a62022-12-19 23:58:32 +05301127 vpdStream.str());
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001128
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001129 createPEL(additionalData, PelSeverity::WARNING,
Priyanga Ramasamy24942232023-01-05 04:54:59 -06001130 errIntfForVPDMismatch, nullptr);
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001131
1132 if (!isBackupOnCache)
1133 {
1134 // Backing up or restoring from a hardware
1135 // path does not requires copying the backup
1136 // data to the VPD map, as this will result
1137 // in a mismatch between the primary VPD and
1138 // its cache.
1139 continue;
1140 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001141 }
Sunny Srivastava37992a62023-07-11 05:18:41 -05001142 else
1143 {
1144 // both the backup and primary data is
1145 // non-default and same. Nothing needs to be
1146 // done.
1147 continue;
1148 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001149 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001150
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001151 // If the backup is on the cache we need to copy the
1152 // backup data to the VPD map to ensure there is no
1153 // mimatch b/n them. So if backup data is not default,
1154 // then irrespective of primary data(default or other
1155 // than backup), copy the backup data to vpd map as we
1156 // don't need to change the backup data in either case
1157 // in the process of restoring system vpd.
1158 kwdValue = backupValue;
1159
1160 // If the backup data is on the base panel the restoring
1161 // of Backup VPD on to the system backplane VPD
1162 // file is done here not through the VPD manager code
1163 // path. This is to have the logic of restoring data on
1164 // to the cache & hardware in the same code path.
1165 if (!isBackupOnCache)
1166 {
1167 // copy backup VPD on to system backplane
1168 // EEPROM file.
1169 updateVpdDataOnHw(systemVpdFilePath, js, recordName,
1170 keywordName, backupDataInBinary);
1171 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001172 }
Priyanga Ramasamy952d6c52022-11-07 07:20:24 -06001173 else if (kwdDataInBinary == defaultValue &&
1174 get<2>(keywordInfo)) // Check isPELRequired is true
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001175 {
Priyanga Ramasamy24942232023-01-05 04:54:59 -06001176 string errMsg = "Found default value on both backup "
1177 "and primary VPD for record: ";
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001178 errMsg += (*it).first;
1179 errMsg += " and keyword: ";
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001180 errMsg += keywordName;
Sunny Srivastava37992a62023-07-11 05:18:41 -05001181 errMsg += ". Update primary VPD.";
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001182
Priyanga Ramasamy24942232023-01-05 04:54:59 -06001183 // mfg default on both backup and primary, log PEL
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001184 PelAdditionalData additionalData;
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001185 additionalData.emplace("DESCRIPTION", errMsg);
1186
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001187 createPEL(additionalData, PelSeverity::ERROR,
Priyanga Ramasamy24942232023-01-05 04:54:59 -06001188 errIntfForVPDDefault, nullptr);
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001189
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001190 continue;
1191 }
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001192 else if ((kwdDataInBinary != defaultValue) &&
1193 (!isBackupOnCache))
1194 {
1195 // update primary VPD on to backup VPD file
1196 updateVpdDataOnHw(systemVpdBackupPath, js,
1197 backupVpdRecName, backupVpdKwName,
1198 kwdDataInBinary);
1199
1200 // copy primary VPD to backup VPD to publish on
1201 // DBus
1202 backupVpdMap.find(backupVpdRecName)
1203 ->second.find(backupVpdKwName)
1204 ->second = kwdValue;
1205 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001206 }
1207 }
1208 }
1209 }
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001210}
1211
1212/**
alpana077ce68722021-07-25 13:23:59 -05001213 * @brief This checks for is this FRU a processor
1214 * And if yes, then checks for is this primary
1215 *
1216 * @param[in] js- vpd json to get the information about this FRU
1217 * @param[in] filePath- FRU vpd
1218 *
1219 * @return true/false
1220 */
1221bool isThisPrimaryProcessor(nlohmann::json& js, const string& filePath)
1222{
1223 bool isProcessor = false;
1224 bool isPrimary = false;
1225
1226 for (const auto& item : js["frus"][filePath])
1227 {
1228 if (item.find("extraInterfaces") != item.end())
1229 {
1230 for (const auto& eI : item["extraInterfaces"].items())
1231 {
1232 if (eI.key().find("Inventory.Item.Cpu") != string::npos)
1233 {
1234 isProcessor = true;
1235 }
1236 }
1237 }
1238
1239 if (isProcessor)
1240 {
1241 string cpuType = item.value("cpuType", "");
1242 if (cpuType == "primary")
1243 {
1244 isPrimary = true;
1245 }
1246 }
1247 }
1248
1249 return (isProcessor && isPrimary);
1250}
1251
1252/**
1253 * @brief This finds DIMM vpd in vpd json and enables them by binding the device
1254 * driver
1255 * @param[in] js- vpd json to iterate through and take action if it is DIMM
1256 */
1257void doEnableAllDimms(nlohmann::json& js)
1258{
1259 // iterate over each fru
1260 for (const auto& eachFru : js["frus"].items())
1261 {
1262 // skip the driver binding if eeprom already exists
1263 if (fs::exists(eachFru.key()))
1264 {
1265 continue;
1266 }
1267
1268 for (const auto& eachInventory : eachFru.value())
1269 {
1270 if (eachInventory.find("extraInterfaces") != eachInventory.end())
1271 {
1272 for (const auto& eI : eachInventory["extraInterfaces"].items())
1273 {
1274 if (eI.key().find("Inventory.Item.Dimm") != string::npos)
1275 {
1276 string dimmVpd = eachFru.key();
1277 // fetch it from
1278 // "/sys/bus/i2c/drivers/at24/414-0050/eeprom"
1279
1280 regex matchPatern("([0-9]+-[0-9]{4})");
1281 smatch matchFound;
1282 if (regex_search(dimmVpd, matchFound, matchPatern))
1283 {
1284 vector<string> i2cReg;
1285 boost::split(i2cReg, matchFound.str(0),
1286 boost::is_any_of("-"));
1287
1288 // remove 0s from begining
1289 const regex pattern("^0+(?!$)");
1290 for (auto& i : i2cReg)
1291 {
1292 i = regex_replace(i, pattern, "");
1293 }
1294
Jinu Joy Thomas63cce0f2024-01-29 00:47:47 -06001295 // For ISDIMM which uses ee1004 driver
1296 // the below is done
1297 size_t stringFound = dimmVpd.find("ee1004");
1298 if (stringFound != string::npos)
1299 {
1300 // echo ee1004 0x50 >
1301 // /sys/bus/i2c/devices/i2c-110/new_device
1302 string cmnd = "echo ee1004 0x" + i2cReg[1] +
1303 " > /sys/bus/i2c/devices/i2c-" +
1304 i2cReg[0] + "/new_device";
1305 executeCmd(cmnd);
1306 }
1307 else if (i2cReg.size() == 2)
alpana077ce68722021-07-25 13:23:59 -05001308 {
1309 // echo 24c32 0x50 >
1310 // /sys/bus/i2c/devices/i2c-16/new_device
1311 string cmnd = "echo 24c32 0x" + i2cReg[1] +
1312 " > /sys/bus/i2c/devices/i2c-" +
1313 i2cReg[0] + "/new_device";
alpana077ce68722021-07-25 13:23:59 -05001314 executeCmd(cmnd);
1315 }
1316 }
1317 }
1318 }
1319 }
1320 }
1321 }
1322}
1323
1324/**
Priyanga Ramasamy6abdeb62022-01-09 23:15:11 -06001325 * @brief Check if the given CPU is an IO only chip.
1326 * The CPU is termed as IO, whose all of the cores are bad and can never be
1327 * used. Those CPU chips can be used for IO purpose like connecting PCIe devices
1328 * etc., The CPU whose every cores are bad, can be identified from the CP00
1329 * record's PG keyword, only if all of the 8 EQs' value equals 0xE7F9FF. (1EQ
1330 * has 4 cores grouped together by sharing its cache memory.)
1331 * @param [in] pgKeyword - PG Keyword of CPU.
1332 * @return true if the given cpu is an IO, false otherwise.
1333 */
1334static bool isCPUIOGoodOnly(const string& pgKeyword)
1335{
1336 const unsigned char io[] = {0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9,
1337 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7,
1338 0xF9, 0xFF, 0xE7, 0xF9, 0xFF, 0xE7, 0xF9, 0xFF};
1339 // EQ0 index (in PG keyword) starts at 97 (with offset starting from 0).
1340 // Each EQ carries 3 bytes of data. Totally there are 8 EQs. If all EQs'
1341 // value equals 0xE7F9FF, then the cpu has no good cores and its treated as
1342 // IO.
1343 if (memcmp(io, pgKeyword.data() + 97, 24) == 0)
1344 {
1345 return true;
1346 }
1347
1348 // The CPU is not an IO
1349 return false;
1350}
1351
1352/**
Jinu Joy Thomas9a60c8b2024-01-16 22:52:25 -06001353 * @brief Function to bring MUX out of idle state
1354 *
1355 * This finds All the MUX defined in the system json and enables
1356 * them by setting the holdidle parameter to 0.
1357 * @param[in] js- system json to iterate through and take action
1358 */
1359void doEnableAllMuxChips(const nlohmann::json& js)
1360{
1361 // Do we have the mandatory "muxes" section?
1362 if (js.find("muxes") != js.end())
1363 {
1364 std::cout << "Enabling all the MUX on the system " << std::endl;
1365 // iterate over each MUX detail and enable them
1366 for (const auto& item : js["muxes"])
1367 {
1368 if (item.find("holdidlepath") != item.end())
1369 {
Jinu Joy Thomas63cce0f2024-01-29 00:47:47 -06001370 const std::string& holdidle = item["holdidlepath"];
Jinu Joy Thomas9a60c8b2024-01-16 22:52:25 -06001371 std::cout << "Setting holdidle state for " << holdidle
1372 << "to 0 " << std::endl;
1373 string cmd = "echo 0 > " + holdidle;
1374 executeCmd(cmd);
1375 }
1376 }
1377 std::cout << "Completed enabling all the MUX on the system "
1378 << std::endl;
1379 }
1380 else
1381 {
1382 std::cout << "No MUX was defined for the system" << std::endl;
1383 }
1384}
1385
1386/**
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301387 * @brief Populate Dbus.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301388 * This method invokes all the populateInterface functions
1389 * and notifies PIM about dbus object.
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301390 * @param[in] vpdMap - Either IPZ vpd map or Keyword vpd map based on the
1391 * input.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301392 * @param[in] js - Inventory json object
1393 * @param[in] filePath - Path of the vpd file
1394 * @param[in] preIntrStr - Interface string
1395 */
1396template <typename T>
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001397static void populateDbus(T& vpdMap, nlohmann::json& js, const string& filePath)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301398{
1399 inventory::InterfaceMap interfaces;
1400 inventory::ObjectMap objects;
1401 inventory::PropertyMap prop;
Shantappa Teekappanavar6aa54502021-12-09 12:59:56 -06001402 string ccinFromVpd;
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301403
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301404 bool isSystemVpd = (filePath == systemVpdFilePath);
1405 if constexpr (is_same<T, Parsed>::value)
1406 {
Shantappa Teekappanavar6aa54502021-12-09 12:59:56 -06001407 ccinFromVpd = getKwVal(vpdMap, "VINI", "CC");
1408 transform(ccinFromVpd.begin(), ccinFromVpd.end(), ccinFromVpd.begin(),
1409 ::toupper);
1410
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301411 if (isSystemVpd)
1412 {
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301413 string mboardPath =
1414 js["frus"][filePath].at(0).value("inventoryPath", "");
1415
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001416 // Get the value of systemvpdBackupPath field from json
1417 const std::string& systemVpdBackupPath =
1418 js["frus"][filePath].at(0).value("systemVpdBackupPath", "");
1419
1420 if (systemVpdBackupPath.empty())
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301421 {
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001422 std::vector<std::string> interfaces = {motherBoardInterface};
1423 // call mapper to check for object path creation
1424 MapperResponse subTree =
1425 getObjectSubtreeForInterfaces(pimPath, 0, interfaces);
1426
1427 // Attempt system VPD restore if we have a motherboard
1428 // object in the inventory.
1429 if ((subTree.size() != 0) &&
1430 (subTree.find(pimPath + mboardPath) != subTree.end()))
1431 {
1432 restoreSystemVPD(vpdMap, mboardPath, js);
1433 }
1434 else
1435 {
1436 log<level::ERR>("No object path found");
1437 }
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301438 }
1439 else
1440 {
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001441 restoreSystemVPD(vpdMap, mboardPath, js, false);
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301442 }
1443 }
alpana077ce68722021-07-25 13:23:59 -05001444 else
1445 {
1446 // check if it is processor vpd.
1447 auto isPrimaryCpu = isThisPrimaryProcessor(js, filePath);
1448
1449 if (isPrimaryCpu)
1450 {
1451 auto ddVersion = getKwVal(vpdMap, "CRP0", "DD");
1452
1453 auto chipVersion = atoi(ddVersion.substr(1, 2).c_str());
1454
1455 if (chipVersion >= 2)
1456 {
1457 doEnableAllDimms(js);
Santosh Puranik253fbe92022-10-06 22:38:09 +05301458 // Sleep for a few seconds to let the DIMM parses start
1459 using namespace std::chrono_literals;
1460 std::this_thread::sleep_for(5s);
alpana077ce68722021-07-25 13:23:59 -05001461 }
1462 }
1463 }
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301464 }
1465
Santosh Puranikf3e69682022-03-31 17:52:38 +05301466 auto processFactoryReset = false;
1467
Priyanga Ramasamy32c687f2022-01-04 23:14:03 -06001468 if (isSystemVpd)
1469 {
1470 string systemJsonName{};
1471 if constexpr (is_same<T, Parsed>::value)
1472 {
1473 // pick the right system json
1474 systemJsonName = getSystemsJson(vpdMap);
1475 }
1476
1477 fs::path target = systemJsonName;
1478 fs::path link = INVENTORY_JSON_SYM_LINK;
1479
Santosh Puranikf3e69682022-03-31 17:52:38 +05301480 // If the symlink does not exist, we treat that as a factory reset
1481 processFactoryReset = !fs::exists(INVENTORY_JSON_SYM_LINK);
1482
Priyanga Ramasamy32c687f2022-01-04 23:14:03 -06001483 // Create the directory for hosting the symlink
1484 fs::create_directories(VPD_FILES_PATH);
1485 // unlink the symlink previously created (if any)
1486 remove(INVENTORY_JSON_SYM_LINK);
1487 // create a new symlink based on the system
1488 fs::create_symlink(target, link);
1489
1490 // Reloading the json
1491 ifstream inventoryJson(link);
1492 js = json::parse(inventoryJson);
1493 inventoryJson.close();
1494 }
1495
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301496 for (const auto& item : js["frus"][filePath])
1497 {
1498 const auto& objectPath = item["inventoryPath"];
1499 sdbusplus::message::object_path object(objectPath);
SunnySrivastava19849094d4f2020-08-05 09:32:29 -05001500
Shantappa Teekappanavar6aa54502021-12-09 12:59:56 -06001501 vector<string> ccinList;
1502 if (item.find("ccin") != item.end())
1503 {
1504 for (const auto& cc : item["ccin"])
1505 {
1506 string ccin = cc;
1507 transform(ccin.begin(), ccin.end(), ccin.begin(), ::toupper);
1508 ccinList.push_back(ccin);
1509 }
1510 }
1511
1512 if (!ccinFromVpd.empty() && !ccinList.empty() &&
1513 (find(ccinList.begin(), ccinList.end(), ccinFromVpd) ==
1514 ccinList.end()))
1515 {
1516 continue;
1517 }
1518
Priyanga Ramasamye3fed702022-01-11 01:05:32 -06001519 if ((isSystemVpd) || (item.value("noprime", false)))
Santosh Puranikd3a379a2021-08-23 19:12:59 +05301520 {
Priyanga Ramasamye3fed702022-01-11 01:05:32 -06001521 // Populate one time properties for the system VPD and its sub-frus
1522 // and for other non-primeable frus.
Santosh Puranikd3a379a2021-08-23 19:12:59 +05301523 // For the remaining FRUs, this will get handled as a part of
1524 // priming the inventory.
1525 setOneTimeProperties(objectPath, interfaces);
1526 }
1527
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301528 // Populate the VPD keywords and the common interfaces only if we
1529 // are asked to inherit that data from the VPD, else only add the
1530 // extraInterfaces.
1531 if (item.value("inherit", true))
1532 {
Alpana Kumari58e22142020-05-05 00:22:12 -05001533 if constexpr (is_same<T, Parsed>::value)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301534 {
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301535 // Each record in the VPD becomes an interface and all
1536 // keyword within the record are properties under that
1537 // interface.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301538 for (const auto& record : vpdMap)
1539 {
1540 populateFruSpecificInterfaces(
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001541 record.second, ipzVpdInf + record.first, interfaces);
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301542 }
1543 }
Alpana Kumari58e22142020-05-05 00:22:12 -05001544 else if constexpr (is_same<T, KeywordVpdMap>::value)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301545 {
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001546 populateFruSpecificInterfaces(vpdMap, kwdVpdInf, interfaces);
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301547 }
Santosh Puranik88edeb62020-03-02 12:00:09 +05301548 if (js.find("commonInterfaces") != js.end())
1549 {
1550 populateInterfaces(js["commonInterfaces"], interfaces, vpdMap,
1551 isSystemVpd);
1552 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301553 }
Santosh Puranik0859eb62020-03-16 02:56:29 -05001554 else
1555 {
1556 // Check if we have been asked to inherit specific record(s)
Alpana Kumari58e22142020-05-05 00:22:12 -05001557 if constexpr (is_same<T, Parsed>::value)
Santosh Puranik0859eb62020-03-16 02:56:29 -05001558 {
1559 if (item.find("copyRecords") != item.end())
1560 {
1561 for (const auto& record : item["copyRecords"])
1562 {
1563 const string& recordName = record;
1564 if (vpdMap.find(recordName) != vpdMap.end())
1565 {
1566 populateFruSpecificInterfaces(
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001567 vpdMap.at(recordName), ipzVpdInf + recordName,
Santosh Puranik0859eb62020-03-16 02:56:29 -05001568 interfaces);
1569 }
1570 }
1571 }
1572 }
1573 }
Santosh Puranik32c46502022-02-10 08:55:07 +05301574 // Populate interfaces and properties that are common to every FRU
1575 // and additional interface that might be defined on a per-FRU
1576 // basis.
1577 if (item.find("extraInterfaces") != item.end())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301578 {
Santosh Puranik32c46502022-02-10 08:55:07 +05301579 populateInterfaces(item["extraInterfaces"], interfaces, vpdMap,
1580 isSystemVpd);
Priyanga Ramasamy6abdeb62022-01-09 23:15:11 -06001581 if constexpr (is_same<T, Parsed>::value)
1582 {
1583 if (item["extraInterfaces"].find(
1584 "xyz.openbmc_project.Inventory.Item.Cpu") !=
1585 item["extraInterfaces"].end())
1586 {
1587 if (isCPUIOGoodOnly(getKwVal(vpdMap, "CP00", "PG")))
1588 {
Priyanga Ramasamy2c607a92022-04-08 00:30:17 -05001589 interfaces[invItemIntf]["PrettyName"] = "IO Module";
Priyanga Ramasamy6abdeb62022-01-09 23:15:11 -06001590 }
1591 }
1592 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301593 }
Priyanga Ramasamye358acb2022-03-21 14:21:50 -05001594
1595 // embedded property(true or false) says whether the subfru is embedded
1596 // into the parent fru (or) not. VPD sets Present property only for
1597 // embedded frus. If the subfru is not an embedded FRU, the subfru may
1598 // or may not be physically present. Those non embedded frus will always
1599 // have Present=false irrespective of its physical presence or absence.
1600 // Eg: nvme drive in nvme slot is not an embedded FRU. So don't set
1601 // Present to true for such sub frus.
1602 // Eg: ethernet port is embedded into bmc card. So set Present to true
1603 // for such sub frus. Also donot populate present property for embedded
1604 // subfru which is synthesized. Currently there is no subfru which are
1605 // both embedded and synthesized. But still the case is handled here.
1606 if ((item.value("embedded", true)) &&
1607 (!item.value("synthesized", false)))
1608 {
Priyanga Ramasamyaca61372023-01-24 08:02:28 -06001609 // Check if its required to handle presence for this FRU.
1610 if (item.value("handlePresence", true))
1611 {
1612 inventory::PropertyMap presProp;
1613 presProp.emplace("Present", true);
1614 insertOrMerge(interfaces, invItemIntf, move(presProp));
1615 }
Priyanga Ramasamye358acb2022-03-21 14:21:50 -05001616 }
Priyanga Ramasamyaa8a8932022-01-27 09:12:41 -06001617
Santosh Puranikf3e69682022-03-31 17:52:38 +05301618 if constexpr (is_same<T, Parsed>::value)
1619 {
1620 // Restore asset tag, if needed
1621 if (processFactoryReset && objectPath == "/system")
1622 {
1623 fillAssetTag(interfaces, vpdMap);
1624 }
1625 }
1626
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301627 objects.emplace(move(object), move(interfaces));
1628 }
1629
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301630 if (isSystemVpd)
1631 {
1632 inventory::ObjectMap primeObject = primeInventory(js, vpdMap);
1633 objects.insert(primeObject.begin(), primeObject.end());
Alpana Kumari65b83602020-09-01 00:24:56 -05001634
Alpana Kumarif05effd2021-04-07 07:32:53 -05001635 // set the U-boot environment variable for device-tree
1636 if constexpr (is_same<T, Parsed>::value)
1637 {
Santosh Puranike5f177a2022-01-24 20:14:46 +05301638 setDevTreeEnv(fs::path(getSystemsJson(vpdMap)).filename());
Alpana Kumarif05effd2021-04-07 07:32:53 -05001639 }
PriyangaRamasamy8e140a12020-04-13 19:24:03 +05301640 }
1641
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301642 // Notify PIM
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -05001643 common::utility::callPIM(move(objects));
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301644}
1645
1646int main(int argc, char** argv)
1647{
1648 int rc = 0;
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001649 json js{};
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001650 Binary vpdVector{};
1651 string file{};
jinuthomasf457a3e2023-04-13 12:22:48 -05001652 string driver{};
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001653 // map to hold additional data in case of logging pel
1654 PelAdditionalData additionalData{};
1655
1656 // this is needed to hold base fru inventory path in case there is ECC or
1657 // vpd exception while parsing the file
1658 std::string baseFruInventoryPath = {};
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301659
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001660 // It holds the backup EEPROM file path for the system backplane's critical
1661 // data
1662 std::string systemVpdBackupPath{};
1663
1664 // It holds the inventory path of backup EEPROM file
1665 std::string backupVpdInvPath{};
1666
1667 bool isSystemVpd = false;
1668
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001669 // severity for PEL
1670 PelSeverity pelSeverity = PelSeverity::WARNING;
1671
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301672 try
1673 {
jinuthomasf457a3e2023-04-13 12:22:48 -05001674 App app{"ibm-read-vpd - App to read IPZ/Jedec format VPD, parse it and "
1675 "store it in DBUS"};
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301676
1677 app.add_option("-f, --file", file, "File containing VPD (IPZ/KEYWORD)")
Alpana Kumari2f793042020-08-18 05:51:03 -05001678 ->required();
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301679
jinuthomasf457a3e2023-04-13 12:22:48 -05001680 app.add_option("--driver", driver,
1681 "Driver used by kernel (at24,at25,ee1004)")
1682 ->required();
1683
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301684 CLI11_PARSE(app, argc, argv);
1685
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001686 // PEL severity should be ERROR in case of any system VPD failure
1687 if (file == systemVpdFilePath)
1688 {
1689 pelSeverity = PelSeverity::ERROR;
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001690 isSystemVpd = true;
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001691 }
1692
jinuthomasf457a3e2023-04-13 12:22:48 -05001693 // Check if input file is not empty.
1694 if ((file.empty()) || (driver.empty()))
1695 {
1696 std::cerr << "Encountered empty input parameter file [" << file
1697 << "] driver [" << driver << "]" << std::endl;
1698 return 0;
1699 }
1700
1701 // Check if currently supported driver or not
1702 if ((driver != at24driver) && (driver != at25driver) &&
1703 (driver != ee1004driver))
1704 {
1705 std::cerr << "The driver [" << driver << "] is not supported."
1706 << std::endl;
1707 return 0;
1708 }
1709
Santosh Puranik0246a4d2020-11-04 16:57:39 +05301710 auto jsonToParse = INVENTORY_JSON_DEFAULT;
1711
1712 // If the symlink exists, it means it has been setup for us, switch the
1713 // path
1714 if (fs::exists(INVENTORY_JSON_SYM_LINK))
1715 {
1716 jsonToParse = INVENTORY_JSON_SYM_LINK;
1717 }
1718
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301719 // Make sure that the file path we get is for a supported EEPROM
Santosh Puranik0246a4d2020-11-04 16:57:39 +05301720 ifstream inventoryJson(jsonToParse);
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001721 if (!inventoryJson)
1722 {
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001723 throw(VpdJsonException("Failed to access Json path", jsonToParse));
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001724 }
1725
1726 try
1727 {
1728 js = json::parse(inventoryJson);
1729 }
Patrick Williams8e15b932021-10-06 13:04:22 -05001730 catch (const json::parse_error& ex)
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001731 {
Sunny Srivastava0746eee2021-03-22 13:36:54 -05001732 throw(VpdJsonException("Json parsing failed", jsonToParse));
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001733 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301734
Santosh Puranik12e24ff2021-05-11 19:33:50 +05301735 // Do we have the mandatory "frus" section?
1736 if (js.find("frus") == js.end())
1737 {
1738 throw(VpdJsonException("FRUs section not found in JSON",
1739 jsonToParse));
1740 }
1741
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301742 // Check if it's a udev path - patterned as(/ahb/ahb:apb/ahb:apb:bus@)
1743 if (file.find("/ahb:apb") != string::npos)
1744 {
1745 // Translate udev path to a generic /sys/bus/.. file path.
jinuthomasf457a3e2023-04-13 12:22:48 -05001746 udevToGenericPath(file, driver);
Santosh Puranik12e24ff2021-05-11 19:33:50 +05301747
1748 if ((js["frus"].find(file) != js["frus"].end()) &&
Santosh Puranik50f60bf2021-05-26 17:55:06 +05301749 (file == systemVpdFilePath))
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301750 {
jinuthomasf457a3e2023-04-13 12:22:48 -05001751 std::cout << "We have already collected system VPD, skiping."
1752 << std::endl;
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301753 return 0;
1754 }
1755 }
1756
Jinu Joy Thomas2cb67692024-01-30 10:30:26 -06001757 // Enable all mux which are used for connecting to the i2c on the pcie
1758 // slots for pcie cards. These are not enabled by kernel due to an issue
1759 // seen with Castello cards, where the i2c line hangs on a probe.
1760 // To run it only once have kept it under System vpd check.
1761 // we need to run this on all BMC reboots so kept here
1762 if (file == systemVpdFilePath)
1763 {
1764 doEnableAllMuxChips(js);
1765 }
1766
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301767 if (file.empty())
1768 {
jinuthomasf457a3e2023-04-13 12:22:48 -05001769 std::cerr << "The EEPROM path <" << file << "> is not valid.";
PriyangaRamasamy647868e2020-09-08 17:03:19 +05301770 return 0;
1771 }
Santosh Puranik12e24ff2021-05-11 19:33:50 +05301772 if (js["frus"].find(file) == js["frus"].end())
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301773 {
jinuthomasf457a3e2023-04-13 12:22:48 -05001774 std::cerr << "The EEPROM path [" << file
1775 << "] is not found in the json." << std::endl;
Santosh Puranik88edeb62020-03-02 12:00:09 +05301776 return 0;
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301777 }
1778
Alpana Kumari2f793042020-08-18 05:51:03 -05001779 if (!fs::exists(file))
1780 {
jinuthomasf457a3e2023-04-13 12:22:48 -05001781 std::cout << "Device path: " << file
1782 << " does not exist. Spurious udev event? Exiting."
1783 << std::endl;
Alpana Kumari2f793042020-08-18 05:51:03 -05001784 return 0;
1785 }
1786
Santosh Puranikdedb5a62022-12-19 23:58:32 +05301787 // In case of system VPD it will already be filled, Don't have to
1788 // overwrite that.
1789 if (baseFruInventoryPath.empty())
1790 {
1791 baseFruInventoryPath = js["frus"][file][0]["inventoryPath"];
1792 }
1793
Santosh Puranik85893752020-11-10 21:31:43 +05301794 // Check if we can read the VPD file based on the power state
Santosh Puranik27a5e952021-10-07 22:08:01 -05001795 // We skip reading VPD when the power is ON in two scenarios:
Santosh Puranik31d50fa2022-04-04 12:04:37 +05301796 // 1) The eeprom we are trying to read is that of the system VPD and the
1797 // JSON symlink is already setup (the symlink's existence tells us we
1798 // are not coming out of a factory reset)
1799 // 2) The JSON tells us that the FRU EEPROM cannot be
1800 // read when we are powered ON.
Santosh Puranik27a5e952021-10-07 22:08:01 -05001801 if (js["frus"][file].at(0).value("powerOffOnly", false) ||
Santosh Puranik31d50fa2022-04-04 12:04:37 +05301802 (file == systemVpdFilePath && fs::exists(INVENTORY_JSON_SYM_LINK)))
Santosh Puranik85893752020-11-10 21:31:43 +05301803 {
1804 if ("xyz.openbmc_project.State.Chassis.PowerState.On" ==
1805 getPowerState())
1806 {
jinuthomasf457a3e2023-04-13 12:22:48 -05001807 std::cout << "This VPD cannot be read when power is ON"
1808 << std::endl;
Santosh Puranik85893752020-11-10 21:31:43 +05301809 return 0;
1810 }
1811 }
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001812
Santosh Puranike9c57532022-03-15 16:51:51 +05301813 // Check if this VPD should be recollected at all
1814 if (!needsRecollection(js, file))
1815 {
jinuthomasf457a3e2023-04-13 12:22:48 -05001816 std::cout << "Skip VPD recollection for: " << file << std::endl;
Santosh Puranike9c57532022-03-15 16:51:51 +05301817 return 0;
1818 }
1819
Alpana Kumari2f793042020-08-18 05:51:03 -05001820 try
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301821 {
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001822 variant<KeywordVpdMap, Store> parseResult;
Sunny Srivastava37992a62023-07-11 05:18:41 -05001823 parseResult = parseVpdFile(file, js);
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001824
1825 if (isSystemVpd)
girik18bb9852022-11-16 05:48:13 -06001826 {
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001827 // Get the value of systemVpdBackupPath field from json
1828 systemVpdBackupPath = js["frus"][systemVpdFilePath].at(0).value(
1829 "systemVpdBackupPath", "");
1830
1831 if (!systemVpdBackupPath.empty())
girik18bb9852022-11-16 05:48:13 -06001832 {
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001833 backupVpdInvPath =
1834 js["frus"][systemVpdBackupPath][0]["inventoryPath"]
1835 .get_ref<const nlohmann::json::string_t&>();
girik18bb9852022-11-16 05:48:13 -06001836 }
1837 }
SunnySrivastava19849a195542020-09-07 06:04:50 -05001838
Alpana Kumari2f793042020-08-18 05:51:03 -05001839 if (auto pVal = get_if<Store>(&parseResult))
1840 {
1841 populateDbus(pVal->getVpdMap(), js, file);
1842 }
1843 else if (auto pVal = get_if<KeywordVpdMap>(&parseResult))
1844 {
1845 populateDbus(*pVal, js, file);
1846 }
Alpana Kumari2f793042020-08-18 05:51:03 -05001847 }
Patrick Williams8e15b932021-10-06 13:04:22 -05001848 catch (const exception& e)
Alpana Kumari2f793042020-08-18 05:51:03 -05001849 {
Sunny Srivastava37992a62023-07-11 05:18:41 -05001850 if (!systemVpdBackupPath.empty())
1851 {
1852 file = systemVpdBackupPath;
1853 baseFruInventoryPath = backupVpdInvPath;
1854 }
1855
Alpana Kumari735dee92022-03-25 01:24:40 -05001856 executePostFailAction(js, file);
PriyangaRamasamya504c3e2020-12-06 12:14:52 -06001857 throw;
Alpana Kumari2f793042020-08-18 05:51:03 -05001858 }
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301859 }
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001860 catch (const VpdJsonException& ex)
1861 {
1862 additionalData.emplace("JSON_PATH", ex.getJsonPath());
1863 additionalData.emplace("DESCRIPTION", ex.what());
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -05001864 createPEL(additionalData, pelSeverity, errIntfForJsonFailure, nullptr);
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001865
jinuthomasf457a3e2023-04-13 12:22:48 -05001866 std::cerr << ex.what() << "\n";
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001867 rc = -1;
1868 }
1869 catch (const VpdEccException& ex)
1870 {
1871 additionalData.emplace("DESCRIPTION", "ECC check failed");
1872 additionalData.emplace("CALLOUT_INVENTORY_PATH",
1873 INVENTORY_PATH + baseFruInventoryPath);
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -05001874 createPEL(additionalData, pelSeverity, errIntfForEccCheckFail, nullptr);
Kantesh Nagaradder38ee9c82023-04-07 00:58:12 -05001875
1876 if (systemVpdBackupPath.empty())
1877 {
1878 dumpBadVpd(file, vpdVector);
1879 }
1880
jinuthomasf457a3e2023-04-13 12:22:48 -05001881 std::cerr << ex.what() << "\n";
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001882 rc = -1;
1883 }
1884 catch (const VpdDataException& ex)
1885 {
alpana075cb3b1f2021-12-16 11:19:36 -06001886 if (isThisPcieOnPass1planar(js, file))
1887 {
jinuthomasf457a3e2023-04-13 12:22:48 -05001888 std::cout << "Pcie_device [" << file
1889 << "]'s VPD is not valid on PASS1 planar.Ignoring.\n";
alpana075cb3b1f2021-12-16 11:19:36 -06001890 rc = 0;
1891 }
Santosh Puranik53b38ed2022-04-10 23:15:22 +05301892 else if (!(isPresent(js, file).value_or(true)))
1893 {
jinuthomasf457a3e2023-04-13 12:22:48 -05001894 std::cout << "FRU at: " << file
1895 << " is not detected present. Ignore parser error.\n";
Santosh Puranik53b38ed2022-04-10 23:15:22 +05301896 rc = 0;
1897 }
alpana075cb3b1f2021-12-16 11:19:36 -06001898 else
1899 {
1900 string errorMsg =
1901 "VPD file is either empty or invalid. Parser failed for [";
1902 errorMsg += file;
1903 errorMsg += "], with error = " + std::string(ex.what());
1904
1905 additionalData.emplace("DESCRIPTION", errorMsg);
1906 additionalData.emplace("CALLOUT_INVENTORY_PATH",
1907 INVENTORY_PATH + baseFruInventoryPath);
Sunny Srivastavaa2ddc962022-06-29 08:53:16 -05001908 createPEL(additionalData, pelSeverity, errIntfForInvalidVPD,
1909 nullptr);
alpana075cb3b1f2021-12-16 11:19:36 -06001910
1911 rc = -1;
1912 }
SunnySrivastava1984a20be8e2020-08-26 02:00:50 -05001913 }
Patrick Williams8e15b932021-10-06 13:04:22 -05001914 catch (const exception& e)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301915 {
PriyangaRamasamyc2fe40f2021-03-02 06:27:33 -06001916 dumpBadVpd(file, vpdVector);
jinuthomasf457a3e2023-04-13 12:22:48 -05001917 std::cerr << e.what() << "\n";
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301918 rc = -1;
1919 }
1920
1921 return rc;
Patrick Williamsc78d8872023-05-10 07:50:56 -05001922}