Angel Pons | 60ec365 | 2020-04-03 01:22:13 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Mariusz Szafranski | faf7a8e | 2017-08-02 18:51:47 +0200 | [diff] [blame] | 2 | |
Mariusz Szafranski | faf7a8e | 2017-08-02 18:51:47 +0200 | [diff] [blame] | 3 | #include <cbfs.h> |
| 4 | #include <console/console.h> |
Mariusz Szafranski | faf7a8e | 2017-08-02 18:51:47 +0200 | [diff] [blame] | 5 | |
| 6 | #include "spd.h" |
| 7 | |
| 8 | /* Get SPD data for on-board memory */ |
| 9 | uint8_t *mainboard_find_spd_data() |
| 10 | { |
| 11 | uint8_t *spd_data; |
| 12 | int spd_index; |
| 13 | size_t spd_file_len; |
| 14 | char *spd_file; |
| 15 | |
| 16 | spd_index = 0; |
| 17 | |
Julius Werner | 834b3ec | 2020-03-04 16:52:08 -0800 | [diff] [blame^] | 18 | spd_file = cbfs_map("spd.bin", &spd_file_len); |
Mariusz Szafranski | faf7a8e | 2017-08-02 18:51:47 +0200 | [diff] [blame] | 19 | if (!spd_file) |
| 20 | die("SPD data not found."); |
| 21 | |
| 22 | if (spd_file_len < ((spd_index + 1) * SPD_LEN)) { |
| 23 | printk(BIOS_ERR, |
| 24 | "SPD index override to 0 due to incorrect SPD index.\n"); |
| 25 | spd_index = 0; |
| 26 | } |
| 27 | |
| 28 | if (spd_file_len < SPD_LEN) |
| 29 | die("Missing SPD data."); |
| 30 | |
| 31 | /* Assume same memory in both channels */ |
| 32 | spd_index *= SPD_LEN; |
| 33 | spd_data = (uint8_t *)(spd_file + spd_index); |
| 34 | |
| 35 | /* Make sure a valid SPD was found */ |
| 36 | if (spd_data[0] == 0) |
| 37 | die("Invalid SPD data."); |
| 38 | |
| 39 | return spd_data; |
| 40 | } |