Kyösti Mälkki | 36abdc4 | 2014-05-05 16:40:15 +0300 | [diff] [blame^] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013 Advanced Micro Devices, Inc. |
| 5 | * Copyright (C) 2013 Sage Electronic Engineering, LLC |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | #include <cbfs.h> |
| 22 | #include <console/console.h> |
| 23 | #include <device/dram/ddr3.h> |
| 24 | #include <spd_cache.h> |
| 25 | #include <stdint.h> |
| 26 | #include <string.h> |
| 27 | |
| 28 | #define SPD_SIZE 128 |
| 29 | #define SPD_CRC_HI 127 |
| 30 | #define SPD_CRC_LO 126 |
| 31 | |
| 32 | int read_spd_from_cbfs(u8 *buf, int idx) |
| 33 | { |
| 34 | const char *spd_file; |
| 35 | size_t spd_file_len = 0; |
| 36 | size_t min_len = (idx + 1) * SPD_SIZE; |
| 37 | |
| 38 | printk(BIOS_DEBUG, "read SPD\n"); |
| 39 | spd_file = cbfs_get_file_content(CBFS_DEFAULT_MEDIA, "spd.bin", 0xab, |
| 40 | &spd_file_len); |
| 41 | if (!spd_file) |
| 42 | printk(BIOS_EMERG, "file [spd.bin] not found in CBFS"); |
| 43 | if (spd_file_len < min_len) |
| 44 | printk(BIOS_EMERG, "Missing SPD data."); |
| 45 | if (!spd_file || spd_file_len < min_len) |
| 46 | return -1; |
| 47 | |
| 48 | memcpy(buf, spd_file + (idx * SPD_SIZE), SPD_SIZE); |
| 49 | |
| 50 | u16 crc = spd_ddr3_calc_crc(buf, SPD_SIZE); |
| 51 | |
| 52 | if (((buf[SPD_CRC_LO] == 0) && (buf[SPD_CRC_HI] == 0)) |
| 53 | || (buf[SPD_CRC_LO] != (crc & 0xff)) |
| 54 | || (buf[SPD_CRC_HI] != (crc >> 8))) { |
| 55 | printk(BIOS_WARNING, "SPD has a invalid or zero-valued CRC\n"); |
| 56 | buf[SPD_CRC_LO] = crc & 0xff; |
| 57 | buf[SPD_CRC_HI] = crc >> 8; |
| 58 | u16 i; |
| 59 | printk(BIOS_WARNING, "\nDisplay the SPD"); |
| 60 | for (i = 0; i < SPD_SIZE; i++) { |
| 61 | if((i % 16) == 0x00) |
| 62 | printk(BIOS_WARNING, "\n%02x: ", i); |
| 63 | printk(BIOS_WARNING, "%02x ", buf[i]); |
| 64 | } |
| 65 | printk(BIOS_WARNING, "\n"); |
| 66 | } |
| 67 | return 0; |
| 68 | } |