summaryrefslogtreecommitdiffstats
path: root/writefrudata.cpp
diff options
context:
space:
mode:
authorOskar Senft <osk@google.com>2018-12-04 15:52:31 -0500
committerOskar Senft <osk@google.com>2019-01-08 10:49:55 -0500
commit695408618ed50ba886080b898aa77b980589ee4c (patch)
tree123071efd52e85b707cb29e2813cb4f213496593 /writefrudata.cpp
parentec73c95892cbbabe9da556e1f68db70a7ff3d46a (diff)
downloadipmi-fru-parser-695408618ed50ba886080b898aa77b980589ee4c.tar.gz
ipmi-fru-parser-695408618ed50ba886080b898aa77b980589ee4c.zip
writefrudata: Fix verifyFruData to skip CRC check for internal use area.
The contents of the internal use area are not defined beyond the first byte, which means that we should not expect its last byte to be a CRC for the area. Change-Id: I15aba7f48e13f8a93c5a6b7e3262d9227da5dad7 Signed-off-by: Oskar Senft <osk@google.com>
Diffstat (limited to 'writefrudata.cpp')
-rw-r--r--writefrudata.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/writefrudata.cpp b/writefrudata.cpp
index 114e4e9..dbf96cb 100644
--- a/writefrudata.cpp
+++ b/writefrudata.cpp
@@ -360,13 +360,14 @@ ipmi_fru_area_type getFruAreaType(uint8_t areaOffset)
}
/**
- * Validates the data for CRC and mandatory fields.
+ * Validates the data for mandatory fields and CRC if selected.
*
* @param[in] data - the data to verify
* @param[in] len - the length of the region to verify
+ * @param[in] validateCrc - whether to validate the CRC
* @return non-zero on failure
*/
-int verifyFruData(const uint8_t* data, const size_t len)
+int verifyFruData(const uint8_t* data, const size_t len, bool validateCrc)
{
uint8_t checksum = 0;
int rc = -1;
@@ -386,6 +387,12 @@ int verifyFruData(const uint8_t* data, const size_t len)
}
#endif
+ if (!validateCrc)
+ {
+ // There's nothing else to do for this area.
+ return EXIT_SUCCESS;
+ }
+
// See if the calculated CRC matches with the embedded one.
// CRC to be calculated on all except the last one that is CRC itself.
checksum = calculateCRC(data, len - 1);
@@ -484,8 +491,11 @@ int ipmiPopulateFruAreas(uint8_t* fruData, const size_t dataLen,
// Save off the data.
std::memcpy(areaData, &((uint8_t*)fruData)[areaOffset], areaLen);
- // Validate the crc
- rc = verifyFruData(areaData, areaLen);
+ // Validate the CRC, but not for the internal use area, since its
+ // contents beyond the first byte are not defined in the spec and
+ // it may not end with a CRC byte.
+ bool validateCrc = fruEntry != IPMI_FRU_INTERNAL_OFFSET;
+ rc = verifyFruData(areaData, areaLen, validateCrc);
if (rc < 0)
{
log<level::ERR>("Err validating FRU area",
@@ -494,7 +504,7 @@ int ipmiPopulateFruAreas(uint8_t* fruData, const size_t dataLen,
}
else
{
- log<level::DEBUG>("Successfully verified area checksum.",
+ log<level::DEBUG>("Successfully verified area.",
entry("OFFSET=%d", areaOffset));
}
@@ -543,7 +553,7 @@ int ipmiValidateCommonHeader(const uint8_t* fruData, const size_t dataLen)
}
// Verify the CRC and size
- rc = verifyFruData(commonHdr, sizeof(commonHdr));
+ rc = verifyFruData(commonHdr, sizeof(commonHdr), true);
if (rc < 0)
{
log<level::ERR>("Failed to validate common header");
OpenPOWER on IntegriCloud