X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=common%2Fddr_spd.c;h=58dc9b3781b7ca93eb2e5d51908a440dfc01c817;hb=9b2c8c30668c2d3ea8637cdce436be67241981b3;hp=a7a30de22bb567777f600f00e0b9d670523a316e;hpb=3707f3b0b5a3af4be41c9dcf791b3338732d8c7c;p=oweals%2Fu-boot.git diff --git a/common/ddr_spd.c b/common/ddr_spd.c index a7a30de22b..58dc9b3781 100644 --- a/common/ddr_spd.c +++ b/common/ddr_spd.c @@ -1,9 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 /* - * Copyright 2008 Freescale Semiconductor, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * Version 2 as published by the Free Software Foundation. + * Copyright 2008-2014 Freescale Semiconductor, Inc. */ #include @@ -18,7 +15,7 @@ spd_check(const u8 *buf, u8 spd_rev, u8 spd_cksum) /* * Check SPD revision supported - * Rev 1.2 or less supported by this code + * Rev 1.X or less supported by this code */ if (spd_rev >= 0x20) { printf("SPD revision %02X not supported by this code\n", @@ -116,3 +113,46 @@ ddr3_spd_check(const ddr3_spd_eeprom_t *spd) return 1; } } + +unsigned int ddr4_spd_check(const struct ddr4_spd_eeprom_s *spd) +{ + char *p = (char *)spd; + int csum16; + int len; + char crc_lsb; /* byte 126 */ + char crc_msb; /* byte 127 */ + + len = 126; + csum16 = crc16(p, len); + + crc_lsb = (char) (csum16 & 0xff); + crc_msb = (char) (csum16 >> 8); + + if (spd->crc[0] != crc_lsb || spd->crc[1] != crc_msb) { + printf("SPD checksum unexpected.\n" + "Checksum lsb in SPD = %02X, computed SPD = %02X\n" + "Checksum msb in SPD = %02X, computed SPD = %02X\n", + spd->crc[0], crc_lsb, spd->crc[1], crc_msb); + return 1; + } + + p = (char *)((ulong)spd + 128); + len = 126; + csum16 = crc16(p, len); + + crc_lsb = (char) (csum16 & 0xff); + crc_msb = (char) (csum16 >> 8); + + if (spd->mod_section.uc[126] != crc_lsb || + spd->mod_section.uc[127] != crc_msb) { + printf("SPD checksum unexpected.\n" + "Checksum lsb in SPD = %02X, computed SPD = %02X\n" + "Checksum msb in SPD = %02X, computed SPD = %02X\n", + spd->mod_section.uc[126], + crc_lsb, spd->mod_section.uc[127], + crc_msb); + return 1; + } + + return 0; +}