[coreboot-gerrit] Change in coreboot[master]: device/dram/ddr2.c: Add methods to compute to identify dram

Arthur Heymans (Code Review) gerrit at coreboot.org
Mon Jan 22 01:44:39 CET 2018


Arthur Heymans has uploaded this change for review. ( https://review.coreboot.org/23345


Change subject: device/dram/ddr2.c: Add methods to compute to identify dram
......................................................................

device/dram/ddr2.c: Add methods to compute to identify dram

DDR2 DIMMs are uniquely defined by SPD byte 64 till 72 and 93 till
98. Compute a crc16 over that data to provide a solid way to check
DIMM identify.

Change-Id: I3c0c42786197f9b4eb3e42261c10ff5e4266120f
Signed-off-by: Arthur Heymans <arthur at aheymans.xyz>
---
M src/device/dram/ddr2.c
M src/include/device/dram/ddr2.h
2 files changed, 44 insertions(+), 0 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/45/23345/1

diff --git a/src/device/dram/ddr2.c b/src/device/dram/ddr2.c
index 0117b93..a4775d3 100644
--- a/src/device/dram/ddr2.c
+++ b/src/device/dram/ddr2.c
@@ -71,6 +71,49 @@
 	return c;
 }
 
+
+static u16 crc16(const u8 *ptr, int n_crc)
+{
+	int i;
+	u16 crc = 0;
+
+	while (--n_crc >= 0) {
+		crc = crc ^ ((int)*ptr++ << 8);
+		for (i = 0; i < 8; ++i) {
+			if (crc & 0x8000)
+				crc = (crc << 1) ^ 0x1021;
+			else
+				crc = crc << 1;
+		}
+	}
+
+	return crc;
+}
+
+/**
+ * \brief Calculate the CRC of a DDR2 SPD unique identifier
+ *
+ * @param spd pointer to raw SPD data
+ * @param len length of data in SPD
+ *
+ * @return the CRC of SPD data bytes 64..72 and 93..98, or 0
+ *  when spd data is truncated.
+ */
+u16 spd_ddr2_calc_unique_crc(u8 *spd, int len)
+{
+	u8 id_bytes[15];
+	int i, j = 0;
+	if (len < 98)
+		/* Not enough bytes available to get the CRC */
+		return 0;
+	for (i = 64; i <= 72; i++)
+		id_bytes[j++] = spd[i];
+	for (i = 93; i <= 98; i++)
+		id_bytes[j++] = spd[i];
+
+	return crc16(id_bytes, 15);
+}
+
 /**
  * \brief Return size of SPD.
  *
diff --git a/src/include/device/dram/ddr2.h b/src/include/device/dram/ddr2.h
index 7322b12..1566276 100644
--- a/src/include/device/dram/ddr2.h
+++ b/src/include/device/dram/ddr2.h
@@ -218,5 +218,6 @@
 void dram_print_spd_ddr2(const struct dimm_attr_st *dimm);
 void normalize_tck(u32 *tclk);
 u8 spd_get_msbs(u8 c);
+u16 spd_ddr2_calc_unique_crc(u8 *spd, int len);
 
 #endif /* DEVICE_DRAM_DDR2L_H */

-- 
To view, visit https://review.coreboot.org/23345
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3c0c42786197f9b4eb3e42261c10ff5e4266120f
Gerrit-Change-Number: 23345
Gerrit-PatchSet: 1
Gerrit-Owner: Arthur Heymans <arthur at aheymans.xyz>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180122/44087703/attachment.html>


More information about the coreboot-gerrit mailing list