diff --git a/src/mainboard/prodrive/hermes/eeprom.c b/src/mainboard/prodrive/hermes/eeprom.c index d7ecdeca48..bff834036a 100644 --- a/src/mainboard/prodrive/hermes/eeprom.c +++ b/src/mainboard/prodrive/hermes/eeprom.c @@ -2,12 +2,17 @@ #include #include +#include #include #include +#include + #include "variants/baseboard/include/eeprom.h" #define I2C_ADDR_EEPROM 0x57 +#define EEPROM_OFFSET_BOARD_SETTINGS 0x1f00 + /* * Check Signature in EEPROM (M24C32-FMN6TP) * If signature is there we assume that that the content is valid @@ -28,6 +33,41 @@ int check_signature(const size_t offset, const uint64_t signature) return 0; } +/* + * Read board settings from the EEPROM and verify their checksum. + * If checksum is valid, we assume the settings are sane as well. + */ +static bool get_board_settings_from_eeprom(struct eeprom_board_settings *board_cfg) +{ + if (read_write_config(board_cfg, EEPROM_OFFSET_BOARD_SETTINGS, 0, sizeof(*board_cfg))) { + printk(BIOS_ERR, "CFG EEPROM: Failed to read board settings\n"); + return false; + } + + const uint32_t crc = + CRC(&board_cfg->raw_settings, sizeof(board_cfg->raw_settings), crc32_byte); + + if (crc != board_cfg->signature) { + printk(BIOS_ERR, "CFG EEPROM: Board settings have invalid checksum\n"); + return false; + } + return true; +} + +struct eeprom_board_settings *get_board_settings(void) +{ + static struct eeprom_board_settings board_cfg = {0}; + + /* Tri-state: -1: settings are invalid, 0: uninitialized, 1: settings are valid */ + static int checked_valid = 0; + + if (checked_valid == 0) { + const bool success = get_board_settings_from_eeprom(&board_cfg); + checked_valid = success ? 1 : -1; + } + return checked_valid > 0 ? &board_cfg : NULL; +} + /* Read data from offset and write it to offset in UPD */ bool read_write_config(void *blob, size_t read_offset, size_t write_offset, size_t size) { diff --git a/src/mainboard/prodrive/hermes/variants/baseboard/include/eeprom.h b/src/mainboard/prodrive/hermes/variants/baseboard/include/eeprom.h index 95024b6ccd..d5a79cd9f9 100644 --- a/src/mainboard/prodrive/hermes/variants/baseboard/include/eeprom.h +++ b/src/mainboard/prodrive/hermes/variants/baseboard/include/eeprom.h @@ -18,6 +18,24 @@ .size = member_size(FSP_S_CONFIG, x)} #endif /* ENV_ROMSTAGE */ +__packed struct eeprom_board_settings { + uint32_t signature; + union { + struct { + uint8_t secureboot; + uint8_t primary_video; + uint8_t deep_sx_enabled; + uint8_t wake_on_usb; + uint8_t usb_powered_in_s5; + uint8_t power_state_after_g3; + uint8_t blue_rear_vref; + uint8_t internal_audio_connection; + uint8_t pxe_boot_capability; + }; + uint8_t raw_settings[9]; + }; +}; + typedef struct { size_t offset; size_t size; @@ -25,3 +43,4 @@ typedef struct { bool read_write_config(void *blob, size_t read_offset, size_t write_offset, size_t size); int check_signature(const size_t offset, const uint64_t signature); +struct eeprom_board_settings *get_board_settings(void);