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. |
Kyösti Mälkki | 36abdc4 | 2014-05-05 16:40:15 +0300 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <cbfs.h> |
| 18 | #include <console/console.h> |
| 19 | #include <device/dram/ddr3.h> |
| 20 | #include <spd_cache.h> |
| 21 | #include <stdint.h> |
| 22 | #include <string.h> |
| 23 | |
| 24 | #define SPD_SIZE 128 |
| 25 | #define SPD_CRC_HI 127 |
| 26 | #define SPD_CRC_LO 126 |
| 27 | |
| 28 | int read_spd_from_cbfs(u8 *buf, int idx) |
| 29 | { |
| 30 | const char *spd_file; |
| 31 | size_t spd_file_len = 0; |
| 32 | size_t min_len = (idx + 1) * SPD_SIZE; |
| 33 | |
| 34 | printk(BIOS_DEBUG, "read SPD\n"); |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 35 | spd_file = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD, |
| 36 | &spd_file_len); |
Kyösti Mälkki | 36abdc4 | 2014-05-05 16:40:15 +0300 | [diff] [blame] | 37 | if (!spd_file) |
| 38 | printk(BIOS_EMERG, "file [spd.bin] not found in CBFS"); |
| 39 | if (spd_file_len < min_len) |
| 40 | printk(BIOS_EMERG, "Missing SPD data."); |
| 41 | if (!spd_file || spd_file_len < min_len) |
| 42 | return -1; |
| 43 | |
| 44 | memcpy(buf, spd_file + (idx * SPD_SIZE), SPD_SIZE); |
| 45 | |
| 46 | u16 crc = spd_ddr3_calc_crc(buf, SPD_SIZE); |
| 47 | |
| 48 | if (((buf[SPD_CRC_LO] == 0) && (buf[SPD_CRC_HI] == 0)) |
| 49 | || (buf[SPD_CRC_LO] != (crc & 0xff)) |
| 50 | || (buf[SPD_CRC_HI] != (crc >> 8))) { |
Tobias Diedrich | 992066a | 2014-11-10 22:21:58 +0100 | [diff] [blame] | 51 | printk(BIOS_WARNING, "SPD CRC %02x%02x is invalid, should be %04x\n", |
| 52 | buf[SPD_CRC_HI], buf[SPD_CRC_LO], crc); |
Kyösti Mälkki | 36abdc4 | 2014-05-05 16:40:15 +0300 | [diff] [blame] | 53 | buf[SPD_CRC_LO] = crc & 0xff; |
| 54 | buf[SPD_CRC_HI] = crc >> 8; |
| 55 | u16 i; |
| 56 | printk(BIOS_WARNING, "\nDisplay the SPD"); |
| 57 | for (i = 0; i < SPD_SIZE; i++) { |
| 58 | if((i % 16) == 0x00) |
| 59 | printk(BIOS_WARNING, "\n%02x: ", i); |
| 60 | printk(BIOS_WARNING, "%02x ", buf[i]); |
| 61 | } |
| 62 | printk(BIOS_WARNING, "\n"); |
| 63 | } |
| 64 | return 0; |
| 65 | } |