diff options
author | Renaud Barbier <renaud.barbier@ge.com> | 2013-06-26 18:33:40 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-06-27 08:38:04 +0200 |
commit | e06aa069652c99f5951f2e89a3af952aa484a3bc (patch) | |
tree | c258eedae2efacc1df1143d1bf10cccfed2c639b /common/ddr_spd.c | |
parent | 9bd04c9adb6f0adaf408773d114d0f183e8f6943 (diff) | |
download | barebox-e06aa069652c99f5951f2e89a3af952aa484a3bc.tar.gz barebox-e06aa069652c99f5951f2e89a3af952aa484a3bc.tar.xz |
common: DDR2 SPD checksum.
The code calculates the DDR2 SPD checksum as per JEDEC standard
No 21-C Appendix X (revision 1.2)
The code is based on the equivalent files from U-Boot version
git-a71d45d.
Signed-off-by: Renaud Barbier <renaud.barbier@ge.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/ddr_spd.c')
-rw-r--r-- | common/ddr_spd.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/common/ddr_spd.c b/common/ddr_spd.c new file mode 100644 index 0000000000..c8b73ff56c --- /dev/null +++ b/common/ddr_spd.c @@ -0,0 +1,39 @@ +/* + * 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. + */ + +#include <common.h> +#include <ddr_spd.h> + +uint32_t ddr2_spd_checksum_pass(const struct ddr2_spd_eeprom_s *spd) +{ + uint32_t i, cksum = 0; + const uint8_t *buf = (const uint8_t *)spd; + uint8_t rev, spd_cksum; + + rev = spd->spd_rev; + spd_cksum = spd->cksum; + + /* Rev 1.X or less supported by this code */ + if (rev >= 0x20) + goto error; + + /* + * The checksum is calculated on the first 64 bytes + * of the SPD as per JEDEC specification. + */ + for (i = 0; i < 63; i++) + cksum += *buf++; + cksum &= 0xFF; + + if (cksum != spd_cksum) + goto error; + + return 0; +error: + return 1; +} |