From: Jean Delvare <jdelvare@suse.de>
To: Linux I2C <linux-i2c@vger.kernel.org>
Subject: [PATCH 6/6] decode-dimms: Verify the CRC of DDR4 data block 1
Date: Sun, 19 Nov 2017 13:37:46 +0100 [thread overview]
Message-ID: <20171119133746.4c9e518b@endymion> (raw)
In-Reply-To: <20171119133309.67d4c596@endymion>
On DDR4 modules there is a separate CRC for the second block of 128
bytes. Check it.
---
eeprom/decode-dimms | 32 +++++++++++++++++++++++++-------
1 file changed, 25 insertions(+), 7 deletions(-)
--- i2c-tools.orig/eeprom/decode-dimms 2017-11-17 11:28:32.262363769 +0100
+++ i2c-tools/eeprom/decode-dimms 2017-11-17 11:29:23.760989692 +0100
@@ -1728,7 +1728,7 @@ use constant DDR4_UNBUFFERED => 1;
use constant DDR4_REGISTERED => 2;
use constant DDR4_LOAD_REDUCED => 4;
-# Parameter: EEPROM bytes 0-383 (using 1-130)
+# Parameter: EEPROM bytes 0-383 (using 1-255)
sub decode_ddr4_sdram($)
{
my $bytes = shift;
@@ -1761,6 +1761,15 @@ sub decode_ddr4_sdram($)
printl("Module Type", $module_types[$bytes->[3] & 0x0f]->{type});
+# CRC of block 1
+ my $crc_calc = calculate_crc($bytes, 128, 126);
+ my $crc_spd = ($bytes->[255] << 8) | $bytes->[254];
+ my $crc_block_1_ok = $crc_calc == $crc_spd;
+ printl("EEPROM CRC of bytes 128-253", $crc_block_1_ok ?
+ sprintf("OK (0x\%04X)", $crc_calc) :
+ sprintf("Bad\n(found 0x\%04X, calculated 0x\%04X)",
+ $crc_spd, $crc_calc));
+
# time bases
if (($bytes->[17] & 0x03) != 0x00 || ($bytes->[17] & 0xc0) != 0x00) {
print STDERR "Unknown time base values, can't decode\n";
@@ -1918,6 +1927,8 @@ sub decode_ddr4_sdram($)
$bytes->[14] & 0x80 ? "TSE2004 compliant" : "No");
# type-specific settings
+ return unless $crc_block_1_ok || $opt_igncheck;
+
if ($module_types[$bytes->[3] & 0x0f]->{family} == DDR4_UNBUFFERED ||
$module_types[$bytes->[3] & 0x0f]->{family} == DDR4_REGISTERED ||
$module_types[$bytes->[3] & 0x0f]->{family} == DDR4_LOAD_REDUCED) {
@@ -2288,15 +2299,14 @@ sub checksum($)
}
# Calculate and verify CRC
-sub check_crc($)
+sub calculate_crc($$$)
{
- my $bytes = shift;
+ my ($bytes, $start, $len) = @_;
my $crc = 0;
- my $crc_cover = $bytes->[0] & 0x80 ? 116 : 125;
- my $crc_ptr = 0;
+ my $crc_ptr = $start;
my $crc_bit;
- while ($crc_ptr <= $crc_cover) {
+ while ($crc_ptr < $start + $len) {
$crc = $crc ^ ($bytes->[$crc_ptr] << 8);
for ($crc_bit = 0; $crc_bit < 8; $crc_bit++) {
if ($crc & 0x8000) {
@@ -2307,7 +2317,15 @@ sub check_crc($)
}
$crc_ptr++;
}
- $crc &= 0xffff;
+
+ return $crc & 0xffff;
+}
+
+sub check_crc($)
+{
+ my $bytes = shift;
+ my $crc_cover = $bytes->[0] & 0x80 ? 116 : 125;
+ my $crc = calculate_crc($bytes, 0, $crc_cover + 1);
my $dimm_crc = ($bytes->[127] << 8) | $bytes->[126];
return ("EEPROM CRC of bytes 0-$crc_cover",
--
Jean Delvare
SUSE L3 Support
prev parent reply other threads:[~2017-11-19 12:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-19 12:33 [PATCH 0/6] decode-dimms: Add support for DDR4 SDRAM memory Jean Delvare
2017-11-19 12:33 ` [PATCH 1/6] decode-dimms: Add preliminary DDR4 support Jean Delvare
2017-11-19 12:34 ` [PATCH 2/6] decode-dimms: Decode size and timings of DDR4 Jean Delvare
2017-11-19 12:34 ` [PATCH 3/6] decode-dimms: Decode misc parameters " Jean Delvare
2017-11-19 12:35 ` [PATCH 4/6] decode-dimms: Decode physical characteristics " Jean Delvare
2017-11-19 12:36 ` [PATCH 5/6] decode-dimms: Documentation update for DDR4 Jean Delvare
2017-11-19 12:37 ` Jean Delvare [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171119133746.4c9e518b@endymion \
--to=jdelvare@suse.de \
--cc=linux-i2c@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.