Skip to content

Commit f457a3e

Browse files
committedApr 20, 2023
Additional change to support ee1004 driver
changed the code to remove hardcoding of driver changed read parser executable to take driver as input Change-Id: I6909e2d56d4572e3ff78610248683a75337bbd72 Signed-off-by: jinuthomas <jinu.joy.thomas@in.ibm.com>
1 parent d90aadb commit f457a3e

File tree

5 files changed

+70
-38
lines changed

5 files changed

+70
-38
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
build*/
22
subprojects/*
33
!subprojects/*.wrap
4+
.*

‎const.hpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,13 @@ constexpr auto errIntfForEssentialFru = "com.ibm.VPD.Error.RequiredFRUMissing";
110110
constexpr auto errIntfForGpioError = "com.ibm.VPD.Error.GPIOError";
111111
constexpr auto motherBoardInterface =
112112
"xyz.openbmc_project.Inventory.Item.Board.Motherboard";
113-
constexpr auto systemVpdFilePath = "/sys/bus/i2c/drivers/at24/8-0050/eeprom";
114-
constexpr auto i2cPathPrefix = "/sys/bus/i2c/drivers/at24/";
115-
constexpr auto spiPathPrefix = "/sys/bus/spi/drivers/at25/";
116113
constexpr auto invItemIntf = "xyz.openbmc_project.Inventory.Item";
114+
constexpr auto systemVpdFilePath = "/sys/bus/i2c/drivers/at24/8-0050/eeprom";
115+
constexpr auto i2cPathPrefix = "/sys/bus/i2c/drivers/";
116+
constexpr auto spiPathPrefix = "/sys/bus/spi/drivers/";
117+
constexpr auto at24driver = "at24";
118+
constexpr auto at25driver = "at25";
119+
constexpr auto ee1004driver = "ee1004";
117120

118121
namespace lengths
119122
{
@@ -166,7 +169,7 @@ enum vpdType
166169
DDR5_DDIMM_MEMORY_VPD, /**< DDR5 DDIMM Memory VPD type */
167170
DDR4_ISDIMM_MEMORY_VPD, /**< DDR4 ISDIMM Memory VPD type */
168171
DDR5_ISDIMM_MEMORY_VPD, /**< DDR5 ISDIMM Memory VPD type */
169-
INVALID_VPD_FORMAT /**< Invalid VPD type */
172+
INVALID_VPD_FORMAT /**< Invalid VPD type Format */
170173
};
171174

172175
enum PelSeverity

‎ibm_vpd_app.cpp

+57-30
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ static auto expandLocationCode(const string& unexpanded, const Parsed& vpdMap,
203203
}
204204
catch (const exception& e)
205205
{
206-
cerr << "Failed to expand location code with exception: " << e.what()
207-
<< "\n";
206+
std::cerr << "Failed to expand location code with exception: "
207+
<< e.what() << "\n";
208208
}
209209
return expanded;
210210
}
@@ -262,12 +262,12 @@ static void populateFruSpecificInterfaces(const T& map,
262262
}
263263
else
264264
{
265-
cerr << "Unknown Keyword[" << kw << "] found ";
265+
std::cerr << "Unknown Keyword[" << kw << "] found ";
266266
}
267267
}
268268
else
269269
{
270-
cerr << "Unknown Variant found ";
270+
std::cerr << "Unknown Variant found ";
271271
}
272272
}
273273
else
@@ -508,29 +508,30 @@ static void preAction(const nlohmann::json& json, const string& file)
508508
{
509509
// Now bind the device
510510
string bind = json["frus"][file].at(0).value("devAddress", "");
511-
cout << "Binding device " << bind << std::endl;
511+
std::cout << "Binding device " << bind << std::endl;
512512
string bindCmd = string("echo \"") + bind +
513513
string("\" > /sys/bus/i2c/drivers/at24/bind");
514-
cout << bindCmd << std::endl;
514+
std::cout << bindCmd << std::endl;
515515
executeCmd(bindCmd);
516516

517517
// Check if device showed up (test for file)
518518
if (!fs::exists(file))
519519
{
520-
cerr << "EEPROM " << file
521-
<< " does not exist. Take failure action" << std::endl;
520+
std::cerr << "EEPROM " << file
521+
<< " does not exist. Take failure action"
522+
<< std::endl;
522523
// If not, then take failure postAction
523524
executePostFailAction(json, file);
524525
}
525526
}
526527
else
527528
{
528529
// missing required informations
529-
cerr << "VPD inventory JSON missing basic informations of "
530-
"preAction "
531-
"for this FRU : ["
532-
<< file << "]. Executing executePostFailAction."
533-
<< std::endl;
530+
std::cerr << "VPD inventory JSON missing basic informations of "
531+
"preAction "
532+
"for this FRU : ["
533+
<< file << "]. Executing executePostFailAction."
534+
<< std::endl;
534535

535536
// Take failure postAction
536537
executePostFailAction(json, file);
@@ -1354,6 +1355,7 @@ int main(int argc, char** argv)
13541355
json js{};
13551356
Binary vpdVector{};
13561357
string file{};
1358+
string driver{};
13571359
// map to hold additional data in case of logging pel
13581360
PelAdditionalData additionalData{};
13591361

@@ -1366,12 +1368,16 @@ int main(int argc, char** argv)
13661368

13671369
try
13681370
{
1369-
App app{"ibm-read-vpd - App to read IPZ format VPD, parse it and store "
1370-
"in DBUS"};
1371+
App app{"ibm-read-vpd - App to read IPZ/Jedec format VPD, parse it and "
1372+
"store it in DBUS"};
13711373

13721374
app.add_option("-f, --file", file, "File containing VPD (IPZ/KEYWORD)")
13731375
->required();
13741376

1377+
app.add_option("--driver", driver,
1378+
"Driver used by kernel (at24,at25,ee1004)")
1379+
->required();
1380+
13751381
CLI11_PARSE(app, argc, argv);
13761382

13771383
// PEL severity should be ERROR in case of any system VPD failure
@@ -1380,6 +1386,23 @@ int main(int argc, char** argv)
13801386
pelSeverity = PelSeverity::ERROR;
13811387
}
13821388

1389+
// Check if input file is not empty.
1390+
if ((file.empty()) || (driver.empty()))
1391+
{
1392+
std::cerr << "Encountered empty input parameter file [" << file
1393+
<< "] driver [" << driver << "]" << std::endl;
1394+
return 0;
1395+
}
1396+
1397+
// Check if currently supported driver or not
1398+
if ((driver != at24driver) && (driver != at25driver) &&
1399+
(driver != ee1004driver))
1400+
{
1401+
std::cerr << "The driver [" << driver << "] is not supported."
1402+
<< std::endl;
1403+
return 0;
1404+
}
1405+
13831406
auto jsonToParse = INVENTORY_JSON_DEFAULT;
13841407

13851408
// If the symlink exists, it means it has been setup for us, switch the
@@ -1416,31 +1439,34 @@ int main(int argc, char** argv)
14161439
if (file.find("/ahb:apb") != string::npos)
14171440
{
14181441
// Translate udev path to a generic /sys/bus/.. file path.
1419-
udevToGenericPath(file);
1442+
udevToGenericPath(file, driver);
14201443

14211444
if ((js["frus"].find(file) != js["frus"].end()) &&
14221445
(file == systemVpdFilePath))
14231446
{
1424-
// We have already collected system VPD, skip.
1447+
std::cout << "We have already collected system VPD, skiping."
1448+
<< std::endl;
14251449
return 0;
14261450
}
14271451
}
14281452

14291453
if (file.empty())
14301454
{
1431-
cerr << "The EEPROM path <" << file << "> is not valid.";
1455+
std::cerr << "The EEPROM path <" << file << "> is not valid.";
14321456
return 0;
14331457
}
14341458
if (js["frus"].find(file) == js["frus"].end())
14351459
{
1460+
std::cerr << "The EEPROM path [" << file
1461+
<< "] is not found in the json." << std::endl;
14361462
return 0;
14371463
}
14381464

14391465
if (!fs::exists(file))
14401466
{
1441-
cout << "Device path: " << file
1442-
<< " does not exist. Spurious udev event? Exiting."
1443-
<< std::endl;
1467+
std::cout << "Device path: " << file
1468+
<< " does not exist. Spurious udev event? Exiting."
1469+
<< std::endl;
14441470
return 0;
14451471
}
14461472

@@ -1464,15 +1490,16 @@ int main(int argc, char** argv)
14641490
if ("xyz.openbmc_project.State.Chassis.PowerState.On" ==
14651491
getPowerState())
14661492
{
1467-
cout << "This VPD cannot be read when power is ON" << std::endl;
1493+
std::cout << "This VPD cannot be read when power is ON"
1494+
<< std::endl;
14681495
return 0;
14691496
}
14701497
}
14711498

14721499
// Check if this VPD should be recollected at all
14731500
if (!needsRecollection(js, file))
14741501
{
1475-
cout << "Skip VPD recollection for: " << file << std::endl;
1502+
std::cout << "Skip VPD recollection for: " << file << std::endl;
14761503
return 0;
14771504
}
14781505

@@ -1517,7 +1544,7 @@ int main(int argc, char** argv)
15171544
additionalData.emplace("DESCRIPTION", ex.what());
15181545
createPEL(additionalData, pelSeverity, errIntfForJsonFailure, nullptr);
15191546

1520-
cerr << ex.what() << "\n";
1547+
std::cerr << ex.what() << "\n";
15211548
rc = -1;
15221549
}
15231550
catch (const VpdEccException& ex)
@@ -1527,21 +1554,21 @@ int main(int argc, char** argv)
15271554
INVENTORY_PATH + baseFruInventoryPath);
15281555
createPEL(additionalData, pelSeverity, errIntfForEccCheckFail, nullptr);
15291556
dumpBadVpd(file, vpdVector);
1530-
cerr << ex.what() << "\n";
1557+
std::cerr << ex.what() << "\n";
15311558
rc = -1;
15321559
}
15331560
catch (const VpdDataException& ex)
15341561
{
15351562
if (isThisPcieOnPass1planar(js, file))
15361563
{
1537-
cout << "Pcie_device [" << file
1538-
<< "]'s VPD is not valid on PASS1 planar.Ignoring.\n";
1564+
std::cout << "Pcie_device [" << file
1565+
<< "]'s VPD is not valid on PASS1 planar.Ignoring.\n";
15391566
rc = 0;
15401567
}
15411568
else if (!(isPresent(js, file).value_or(true)))
15421569
{
1543-
cout << "FRU at: " << file
1544-
<< " is not detected present. Ignore parser error.\n";
1570+
std::cout << "FRU at: " << file
1571+
<< " is not detected present. Ignore parser error.\n";
15451572
rc = 0;
15461573
}
15471574
else
@@ -1563,7 +1590,7 @@ int main(int argc, char** argv)
15631590
catch (const exception& e)
15641591
{
15651592
dumpBadVpd(file, vpdVector);
1566-
cerr << e.what() << "\n";
1593+
std::cerr << e.what() << "\n";
15671594
rc = -1;
15681595
}
15691596

‎ibm_vpd_utils.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ std::string getSystemsJson(const Parsed& vpdMap)
533533
return jsonPath;
534534
}
535535

536-
void udevToGenericPath(std::string& file)
536+
void udevToGenericPath(std::string& file, const std::string& driver)
537537
{
538538
// Sample udevEvent i2c path :
539539
// "/sys/devices/platform/ahb/ahb:apb/ahb:apb:bus@1e78a000/1e78a480.i2c-bus/i2c-8/8-0051/8-00510/nvmem"
@@ -560,7 +560,7 @@ void udevToGenericPath(std::string& file)
560560
exit(EXIT_SUCCESS);
561561
}
562562
// Forming the generic file path
563-
file = i2cPathPrefix + i2cBusAddr + "/eeprom";
563+
file = i2cPathPrefix + driver + "/" + i2cBusAddr + "/eeprom";
564564
}
565565
// Sample udevEvent spi path :
566566
// "/sys/devices/platform/ahb/ahb:apb/1e79b000.fsi/fsi-master/fsi0/slave@00:00/00:00:00:04/spi_master/spi2/spi2.0/spi2.00/nvmem"
@@ -588,7 +588,7 @@ void udevToGenericPath(std::string& file)
588588
exit(EXIT_SUCCESS);
589589
}
590590
// Forming the generic path
591-
file = spiPathPrefix + spiBus + ".0/eeprom";
591+
file = spiPathPrefix + driver + "/" + spiBus + ".0/eeprom";
592592
}
593593
else
594594
{

‎ibm_vpd_utils.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,9 @@ const std::string getIM(const Parsed& vpdMap);
293293

294294
/** @brief Translate udev event generated path to a generic /sys/bus eeprom path
295295
* @param[io] file - path generated from udev event.
296+
* @param[in] driver - kernel driver used by the device.
296297
*/
297-
void udevToGenericPath(std::string& file);
298+
void udevToGenericPath(std::string& file, const std::string& driver);
298299

299300
/**
300301
* @brief API to generate a vpd name in some pattern.

0 commit comments

Comments
 (0)
Please sign in to comment.