]>
git.ipfire.org Git - people/ms/u-boot.git/blob - common/ddr_spd.c
2 * Copyright 2008-2014 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0
10 /* used for ddr1 and ddr2 spd */
12 spd_check(const u8
*buf
, u8 spd_rev
, u8 spd_cksum
)
14 unsigned int cksum
= 0;
18 * Check SPD revision supported
19 * Rev 1.X or less supported by this code
21 if (spd_rev
>= 0x20) {
22 printf("SPD revision %02X not supported by this code\n",
27 printf("SPD revision %02X not verified by this code\n",
34 for (i
= 0; i
< 63; i
++) {
39 if (cksum
!= spd_cksum
) {
40 printf("SPD checksum unexpected. "
41 "Checksum in SPD = %02X, computed SPD = %02X\n",
50 ddr1_spd_check(const ddr1_spd_eeprom_t
*spd
)
52 const u8
*p
= (const u8
*)spd
;
54 return spd_check(p
, spd
->spd_rev
, spd
->cksum
);
58 ddr2_spd_check(const ddr2_spd_eeprom_t
*spd
)
60 const u8
*p
= (const u8
*)spd
;
62 return spd_check(p
, spd
->spd_rev
, spd
->cksum
);
66 * CRC16 compute for DDR3 SPD
67 * Copied from DDR3 SPD spec.
70 crc16(char *ptr
, int count
)
75 while (--count
>= 0) {
76 crc
= crc
^ (int)*ptr
++ << 8;
77 for (i
= 0; i
< 8; ++i
)
79 crc
= crc
<< 1 ^ 0x1021;
87 ddr3_spd_check(const ddr3_spd_eeprom_t
*spd
)
89 char *p
= (char *)spd
;
92 char crc_lsb
; /* byte 126 */
93 char crc_msb
; /* byte 127 */
96 * SPD byte0[7] - CRC coverage
97 * 0 = CRC covers bytes 0~125
98 * 1 = CRC covers bytes 0~116
101 len
= !(spd
->info_size_crc
& 0x80) ? 126 : 117;
102 csum16
= crc16(p
, len
);
104 crc_lsb
= (char) (csum16
& 0xff);
105 crc_msb
= (char) (csum16
>> 8);
107 if (spd
->crc
[0] == crc_lsb
&& spd
->crc
[1] == crc_msb
) {
110 printf("SPD checksum unexpected.\n"
111 "Checksum lsb in SPD = %02X, computed SPD = %02X\n"
112 "Checksum msb in SPD = %02X, computed SPD = %02X\n",
113 spd
->crc
[0], crc_lsb
, spd
->crc
[1], crc_msb
);
118 unsigned int ddr4_spd_check(const struct ddr4_spd_eeprom_s
*spd
)
120 char *p
= (char *)spd
;
123 char crc_lsb
; /* byte 126 */
124 char crc_msb
; /* byte 127 */
127 csum16
= crc16(p
, len
);
129 crc_lsb
= (char) (csum16
& 0xff);
130 crc_msb
= (char) (csum16
>> 8);
132 if (spd
->crc
[0] != crc_lsb
|| spd
->crc
[1] != crc_msb
) {
133 printf("SPD checksum unexpected.\n"
134 "Checksum lsb in SPD = %02X, computed SPD = %02X\n"
135 "Checksum msb in SPD = %02X, computed SPD = %02X\n",
136 spd
->crc
[0], crc_lsb
, spd
->crc
[1], crc_msb
);
140 p
= (char *)((ulong
)spd
+ 128);
142 csum16
= crc16(p
, len
);
144 crc_lsb
= (char) (csum16
& 0xff);
145 crc_msb
= (char) (csum16
>> 8);
147 if (spd
->mod_section
.uc
[126] != crc_lsb
||
148 spd
->mod_section
.uc
[127] != crc_msb
) {
149 printf("SPD checksum unexpected.\n"
150 "Checksum lsb in SPD = %02X, computed SPD = %02X\n"
151 "Checksum msb in SPD = %02X, computed SPD = %02X\n",
152 spd
->mod_section
.uc
[126],
153 crc_lsb
, spd
->mod_section
.uc
[127],