fru-device: use FRUReader API to simplify FRU parsing I/O
FRUReader::read() abstracts away SMBus block-size limits, which allows
us to replace the loop at the end of readFRUContents() with a single
reader.read() call.
FRUReader also (due its caching) eliminates the need to share I/O
buffers between the IPMI and Tyan parsers. We can thus restructure the
parsing code to try each of them separately in turn, reusing the same
FRUReader to avoid duplicating I/O. This eliminates the findFRUHeader()
function (each parser just looks for a header where it expects it);
tests are updated accordingly to exercise readFRUContents() instead.
testFRUData was generated via https://github.com/ipmitool/frugen using
the '--ascii' flag and the following JSON:
{
"chassis": {
"type": 17,
"pn": "OBMC_TEST_CHASSIS",
"serial": "XYZ123"
},
"board": {
"mfg": "OpenBMC Project",
"pname": "OBMC_TEST_BOARD",
"serial": "ABC012",
"pn": "BOARD_PARTNUM"
},
"product": {
"lang": 1,
"mfg": "OpenBMC Project",
"pname": "OBMC_TEST_PRODUCT",
"serial": "9999",
}
}
Tested: on an ASRock Rack romed8hm3, fru-device successfully recognizes
and parses the baseboard FRU EEPROM as it did prior to this patch.
Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Change-Id: I215bb2f6da0e1b23e5f52727c749993452c031e9
diff --git a/include/fru_utils.hpp b/include/fru_utils.hpp
index ed019ad..2d0c719 100644
--- a/include/fru_utils.hpp
+++ b/include/fru_utils.hpp
@@ -137,18 +137,6 @@
ssize_t getFieldLength(uint8_t fruFieldTypeLenValue);
-/// \brief Find a FRU header.
-/// \param reader the BaseFRUReader to read via
-/// \param errorHelp and a helper string for failures
-/// \param blockData buffer to return the last read block
-/// \param baseOffset the offset to start the search at;
-/// set to 0 to perform search;
-/// returns the offset at which a header was found
-/// \return whether a header was found
-bool findFRUHeader(BaseFRUReader& reader, const std::string& errorHelp,
- std::array<uint8_t, I2C_SMBUS_BLOCK_MAX>& blockData,
- off_t& baseOffset);
-
/// \brief Read and validate FRU contents.
/// \param reader the BaseFRUReader to read via
/// \param errorHelp and a helper string for failures
@@ -157,9 +145,9 @@
const std::string& errorHelp);
/// \brief Validate an IPMI FRU common header
-/// \param blockData the bytes comprising the common header
+/// \param hdr the bytes comprising the common header
/// \return true if valid
-bool validateHeader(const std::array<uint8_t, I2C_SMBUS_BLOCK_MAX>& blockData);
+bool validateIPMIHeader(const std::vector<uint8_t>& hdr);
/// \brief Get offset for a common header area
/// \param area - the area