FruDevice: print checksum values on checksum error
Following up adding verbose diagnostic on FRU decoding, this adds
printing exact checksum values against to just printing mismatch error.
Tested: 1) tested with good FRU: no changes
2) tested with invalid FRU: got message in the log:
fru-device[355]: Checksum error in FRU area PRODUCT
fru-device[355]: Computed checksum: 0xb0
fru-device[355]: The read checksum: 0x28
Change-Id: Ieabc143d81a6f816351eebf0ba5ab7552a7f5ee3
Signed-off-by: Bruce Mitchell <Bruce_Mitchell@phoenix.com>
Signed-off-by: Andrei Kartashev <a.kartashev@yadro.com>
diff --git a/src/FruDevice.cpp b/src/FruDevice.cpp
index 44ca05d..45d0fd9 100644
--- a/src/FruDevice.cpp
+++ b/src/FruDevice.cpp
@@ -1022,11 +1022,18 @@
fruBytes.begin() + offset + fruAreaSize - 1;
++fruBytesIter;
- if (calculateChecksum(fruBytes.begin() + offset, fruBytesIterEndArea) !=
- *fruBytesIterEndArea)
+ uint8_t fruComputedChecksum =
+ calculateChecksum(fruBytes.begin() + offset, fruBytesIterEndArea);
+ if (fruComputedChecksum != *fruBytesIterEndArea)
{
- std::cerr << "Checksum error in FRU area " << getFruAreaName(area)
- << "\n";
+ std::stringstream ss;
+ ss << std::hex << std::setfill('0');
+ ss << "Checksum error in FRU area " << getFruAreaName(area) << "\n";
+ ss << "\tComputed checksum: 0x" << std::setw(2)
+ << static_cast<int>(fruComputedChecksum) << "\n";
+ ss << "\tThe read checksum: 0x" << std::setw(2)
+ << static_cast<int>(*fruBytesIterEndArea) << "\n";
+ std::cerr << ss.str();
return false;
}