From b9af5133dd2d1be972b9157e8a6860eedd13a766 Mon Sep 17 00:00:00 2001 From: Angel Pons Date: Thu, 1 Sep 2022 15:21:34 +0200 Subject: mb/prodrive/hermes: Factor out serial reading logic Add the `eeprom_read_serial()` function to read serials from the EEPROM. Note that there's only one buffer now: this means only one serial can be accessed at the same time, and the buffer needs to be cleared so that it does not contain old data from other serials. Given that the serials are copied one at a time into SMBIOS tables, having one shared buffer is not a problem. Change-Id: I5c9781e4e599043be756514cfd6dd86dedcf580c Signed-off-by: Angel Pons Reviewed-on: https://review.coreboot.org/c/coreboot/+/67275 Reviewed-by: Lean Sheng Tan Tested-by: build bot (Jenkins) --- src/mainboard/prodrive/hermes/eeprom.c | 12 ++++++++++++ src/mainboard/prodrive/hermes/eeprom.h | 1 + src/mainboard/prodrive/hermes/smbios.c | 14 ++------------ 3 files changed, 15 insertions(+), 12 deletions(-) (limited to 'src/mainboard') diff --git a/src/mainboard/prodrive/hermes/eeprom.c b/src/mainboard/prodrive/hermes/eeprom.c index 7a92fe3757..54e0e11ec7 100644 --- a/src/mainboard/prodrive/hermes/eeprom.c +++ b/src/mainboard/prodrive/hermes/eeprom.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "eeprom.h" @@ -88,6 +89,17 @@ struct eeprom_bmc_settings *get_bmc_settings(void) return &bmc_cfg; } +const char *eeprom_read_serial(const size_t offset, const char *const fallback) +{ + static char serial_no[HERMES_SERIAL_NUMBER_LENGTH] = { 0 }; + memset(serial_no, 0, sizeof(serial_no)); + + if (eeprom_read_buffer(serial_no, offset, sizeof(serial_no)) == 0) + return serial_no; + else + return fallback; +} + uint8_t get_bmc_hsi(void) { uint8_t hsi = 0; diff --git a/src/mainboard/prodrive/hermes/eeprom.h b/src/mainboard/prodrive/hermes/eeprom.h index 2f7eac7253..63e84afb6d 100644 --- a/src/mainboard/prodrive/hermes/eeprom.h +++ b/src/mainboard/prodrive/hermes/eeprom.h @@ -105,6 +105,7 @@ bool eeprom_read_buffer(void *blob, size_t read_offset, size_t size); int check_signature(const size_t offset, const uint64_t signature); struct eeprom_board_settings *get_board_settings(void); struct eeprom_bmc_settings *get_bmc_settings(void); +const char *eeprom_read_serial(size_t offset, const char *fallback); uint8_t get_bmc_hsi(void); void report_eeprom_error(const size_t off); bool write_board_settings(const struct eeprom_board_layout *new_layout); diff --git a/src/mainboard/prodrive/hermes/smbios.c b/src/mainboard/prodrive/hermes/smbios.c index c1325d4771..923ce8170c 100644 --- a/src/mainboard/prodrive/hermes/smbios.c +++ b/src/mainboard/prodrive/hermes/smbios.c @@ -9,23 +9,13 @@ const char *smbios_system_serial_number(void) { const size_t offset = offsetof(struct eeprom_layout, system_serial_number); - static char serial_no[HERMES_SERIAL_NUMBER_LENGTH] = { 0 }; - - if (eeprom_read_buffer(serial_no, offset, sizeof(serial_no)) == 0) - return serial_no; - else - return CONFIG_MAINBOARD_SERIAL_NUMBER; + return eeprom_read_serial(offset, CONFIG_MAINBOARD_SERIAL_NUMBER); } const char *smbios_mainboard_serial_number(void) { const size_t offset = offsetof(struct eeprom_layout, board_serial_number); - static char serial_no[HERMES_SERIAL_NUMBER_LENGTH] = { 0 }; - - if (eeprom_read_buffer(serial_no, offset, sizeof(serial_no)) == 0) - return serial_no; - else - return CONFIG_MAINBOARD_SERIAL_NUMBER; + return eeprom_read_serial(offset, CONFIG_MAINBOARD_SERIAL_NUMBER); } const char *smbios_mainboard_version(void) -- cgit v1.2.3