1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright 2008-2014 Freescale Semiconductor, Inc.
9 /* used for ddr1 and ddr2 spd */
11 spd_check(const u8 *buf, u8 spd_rev, u8 spd_cksum)
13 unsigned int cksum = 0;
17 * Check SPD revision supported
18 * Rev 1.X or less supported by this code
20 if (spd_rev >= 0x20) {
21 printf("SPD revision %02X not supported by this code\n",
26 printf("SPD revision %02X not verified by this code\n",
33 for (i = 0; i < 63; i++) {
38 if (cksum != spd_cksum) {
39 printf("SPD checksum unexpected. "
40 "Checksum in SPD = %02X, computed SPD = %02X\n",
49 ddr1_spd_check(const ddr1_spd_eeprom_t *spd)
51 const u8 *p = (const u8 *)spd;
53 return spd_check(p, spd->spd_rev, spd->cksum);
57 ddr2_spd_check(const ddr2_spd_eeprom_t *spd)
59 const u8 *p = (const u8 *)spd;
61 return spd_check(p, spd->spd_rev, spd->cksum);
65 * CRC16 compute for DDR3 SPD
66 * Copied from DDR3 SPD spec.
69 crc16(char *ptr, int count)
74 while (--count >= 0) {
75 crc = crc ^ (int)*ptr++ << 8;
76 for (i = 0; i < 8; ++i)
78 crc = crc << 1 ^ 0x1021;
86 ddr3_spd_check(const ddr3_spd_eeprom_t *spd)
88 char *p = (char *)spd;
91 char crc_lsb; /* byte 126 */
92 char crc_msb; /* byte 127 */
95 * SPD byte0[7] - CRC coverage
96 * 0 = CRC covers bytes 0~125
97 * 1 = CRC covers bytes 0~116
100 len = !(spd->info_size_crc & 0x80) ? 126 : 117;
101 csum16 = crc16(p, len);
103 crc_lsb = (char) (csum16 & 0xff);
104 crc_msb = (char) (csum16 >> 8);
106 if (spd->crc[0] == crc_lsb && spd->crc[1] == crc_msb) {
109 printf("SPD checksum unexpected.\n"
110 "Checksum lsb in SPD = %02X, computed SPD = %02X\n"
111 "Checksum msb in SPD = %02X, computed SPD = %02X\n",
112 spd->crc[0], crc_lsb, spd->crc[1], crc_msb);
117 unsigned int ddr4_spd_check(const struct ddr4_spd_eeprom_s *spd)
119 char *p = (char *)spd;
122 char crc_lsb; /* byte 126 */
123 char crc_msb; /* byte 127 */
126 csum16 = crc16(p, len);
128 crc_lsb = (char) (csum16 & 0xff);
129 crc_msb = (char) (csum16 >> 8);
131 if (spd->crc[0] != crc_lsb || spd->crc[1] != crc_msb) {
132 printf("SPD checksum unexpected.\n"
133 "Checksum lsb in SPD = %02X, computed SPD = %02X\n"
134 "Checksum msb in SPD = %02X, computed SPD = %02X\n",
135 spd->crc[0], crc_lsb, spd->crc[1], crc_msb);
139 p = (char *)((ulong)spd + 128);
141 csum16 = crc16(p, len);
143 crc_lsb = (char) (csum16 & 0xff);
144 crc_msb = (char) (csum16 >> 8);
146 if (spd->mod_section.uc[126] != crc_lsb ||
147 spd->mod_section.uc[127] != crc_msb) {
148 printf("SPD checksum unexpected.\n"
149 "Checksum lsb in SPD = %02X, computed SPD = %02X\n"
150 "Checksum msb in SPD = %02X, computed SPD = %02X\n",
151 spd->mod_section.uc[126],
152 crc_lsb, spd->mod_section.uc[127],