Skip to content

Commit 05e6490

Browse files
committed
vpd-tool: Add module VPD sanity check
Added one new option to vpd-tool to do the santity check for all the module vpds. It takes one at a time and checks for it's header, TOC and all it's records. Test: ./vpd-tool -h --sanityCheck Do the sanity check for module vpd. It validates primary eeprom and then redundant eeprom ... Module vpd sanity check: vpd-tool --sanityCheck ./vpd-tool --sanityCheck DBG: received file path:/sys/bus/spi/drivers/at25/spi12.0/eeprom DBG: Processing all records DBG: received file path:/sys/bus/spi/drivers/at25/spi13.0/eeprom DBG: Processing all records Signed-off-by: Alpana Kumari <[email protected]>
1 parent 4abf6c6 commit 05e6490

File tree

6 files changed

+472
-13
lines changed

6 files changed

+472
-13
lines changed

meson.build

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ configure_file(output: 'config.h', configuration: conf_data)
6161

6262
services = ['service_files/vpd-manager.service']
6363

64+
libgpiodcxx = dependency('libgpiodcxx', default_options: ['bindings=cxx'])
65+
66+
libvpdecc_src = files('vpdecc/vpdecc.c', 'vpdecc/vpdecc_support.c')
67+
68+
libvpdecc = shared_library(
69+
'vpdecc',
70+
libvpdecc_src,
71+
version: meson.project_version(),
72+
install: true,
73+
)
74+
75+
6476
if get_option('ibm_system').allowed()
6577
subdir('vpd-tool')
6678
scripts = ['scripts/wait-vpd-status.sh']
@@ -85,17 +97,6 @@ if get_option('ibm_system').allowed()
8597
)
8698
endif
8799

88-
libgpiodcxx = dependency('libgpiodcxx', default_options: ['bindings=cxx'])
89-
90-
libvpdecc_src = files('vpdecc/vpdecc.c', 'vpdecc/vpdecc_support.c')
91-
92-
libvpdecc = shared_library(
93-
'vpdecc',
94-
libvpdecc_src,
95-
version: meson.project_version(),
96-
install: true,
97-
)
98-
99100
subdir('vpd-manager')
100101

101102
systemd_system_unit_dir = dependency('systemd').get_variable(

vpd-tool/include/tool_types.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,15 @@ using BiosAttributeMetaData = std::tuple<std::string, uint8_t, std::optional<uin
113113
//{Record, Keyword} -> {attribute name, number of bits in keyword, starting bit
114114
// position, enabled value, disabled value}
115115
using BiosAttributeKeywordMap = std::unordered_map<IpzType,std::vector<BiosAttributeMetaData>,IpzKeyHash,IpzKeyEqual>;
116+
117+
using KwSize = uint8_t;
118+
using RecordId = uint8_t;
119+
using RecordSize = uint16_t;
120+
using RecordType = uint16_t;
121+
using RecordOffset = uint16_t;
122+
using RecordLength = uint16_t;
123+
using ECCOffset = uint16_t;
124+
using ECCLength = uint16_t;
125+
116126
} // namespace types
117127
} // namespace vpd

vpd-tool/include/tool_utils.hpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,5 +996,45 @@ inline types::BinaryVector convertIntegralTypeToBytes(
996996
return l_result;
997997
}
998998

999+
/**
1000+
* @brief An API to get VPD in a vector.
1001+
*
1002+
* The vector is required by the respective parser to fill the VPD map.
1003+
* Note: API throws exception in case of failure. Caller needs to handle.
1004+
*
1005+
* @param[in] vpdFilePath - EEPROM path of the FRU.
1006+
* @param[out] vpdVector - VPD in vector form.
1007+
* @param[in] vpdStartOffset - Offset of VPD data in EEPROM.
1008+
*/
1009+
inline void getVpdDataInVector(const std::string& vpdFilePath,
1010+
types::BinaryVector& vpdVector,
1011+
size_t& vpdStartOffset)
1012+
{
1013+
try
1014+
{
1015+
std::fstream vpdFileStream;
1016+
vpdFileStream.exceptions(
1017+
std::ifstream::badbit | std::ifstream::failbit);
1018+
vpdFileStream.open(vpdFilePath, std::ios::in | std::ios::binary);
1019+
auto vpdSizeToRead = std::min(std::filesystem::file_size(vpdFilePath),
1020+
static_cast<uintmax_t>(65504));
1021+
vpdVector.resize(vpdSizeToRead);
1022+
1023+
vpdFileStream.seekg(vpdStartOffset, std::ios_base::beg);
1024+
vpdFileStream.read(reinterpret_cast<char*>(&vpdVector[0]),
1025+
vpdSizeToRead);
1026+
1027+
vpdVector.resize(vpdFileStream.gcount());
1028+
vpdFileStream.clear(std::ios_base::eofbit);
1029+
}
1030+
catch (const std::ifstream::failure& fail)
1031+
{
1032+
std::cerr << "Exception in file handling [" << vpdFilePath
1033+
<< "] error : " << fail.what();
1034+
throw;
1035+
}
1036+
}
1037+
1038+
9991039
} // namespace utils
10001040
} // namespace vpd

vpd-tool/include/vpd_tool.hpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,5 +371,68 @@ class VpdTool
371371
* the directory from the filesystem
372372
*/
373373
void clearVpdDumpDir() const noexcept;
374+
375+
/**
376+
* @brief Check ECC of VPD header.
377+
*
378+
* @param[in] l_vpdVector - vpd vector to fetch the data.
379+
* @return true/false based on check result.
380+
*/
381+
bool vhdrEccCheck(const types::BinaryVector l_vpdVector);
382+
383+
/**
384+
* @brief API to check validity of VPD header.
385+
*
386+
* @param[in] itrToVPD - Iterator to the beginning of VPD file.
387+
* @param[in] l_vpdVector - vpd vector to fetch the data.
388+
*/
389+
void checkHeader(types::BinaryVector::const_iterator itrToVPD, const types::BinaryVector l_vpdVector);
390+
391+
/**
392+
* @brief Check ECC of VTOC.
393+
*
394+
* @param[in] l_vpdVector - vpd vector to fetch the data.
395+
* @return true/false based on check result.
396+
*/
397+
bool vtocEccCheck(const types::BinaryVector l_vpdVector);
398+
399+
/**
400+
* @brief API to read VTOC record.
401+
*
402+
* The API reads VTOC record and returns the length of PT keyword.
403+
*
404+
* @param[in] itrToVPD - Iterator to begining of VPD data.
405+
* @param[in] l_vpdVector - vpd vector to fetch the data.
406+
* @return Length of PT keyword.
407+
*/
408+
auto readTOC(types::BinaryVector::const_iterator& itrToVPD,const types::BinaryVector l_vpdVector);
409+
410+
/**
411+
* @brief Check ECC of a record.
412+
*
413+
* @param[in] iterator - Iterator to the record.
414+
* @param[in] l_vpdVector - vpd vector to fetch the data.
415+
* @return success/failure
416+
*/
417+
bool recordEccCheck(types::BinaryVector::const_iterator iterator, const types::BinaryVector l_vpdVector);
418+
419+
/**
420+
* @brief API to read PT record.
421+
*
422+
* @param[in] itrToPT - Iterator to PT record in VPD vector.
423+
* @param[in] l_vpdVector - vpd vector to fetch the data.
424+
* @param[in] ptLength - length of the PT record.
425+
* @return success/failure.
426+
*/
427+
uint8_t readPT(types::BinaryVector::const_iterator& itrToPT,
428+
const types::BinaryVector l_vpdVector,
429+
auto ptLength);
430+
/**
431+
* @brief API to perform sanity check EEPROM.
432+
*
433+
* @param[in] eepromPath - vpd path to perform sanity check
434+
* @return SUCCESS or FAILURE.
435+
*/
436+
uint8_t performSanityCheck(const std::string& eepromPath);
374437
};
375438
} // namespace vpd

0 commit comments

Comments
 (0)