summaryrefslogtreecommitdiff
path: root/board/xilinx/common
diff options
context:
space:
mode:
Diffstat (limited to 'board/xilinx/common')
-rw-r--r--board/xilinx/common/board.c57
-rw-r--r--board/xilinx/common/fru_ops.c43
2 files changed, 70 insertions, 30 deletions
diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c
index 59d87f23520..fbc76eef20d 100644
--- a/board/xilinx/common/board.c
+++ b/board/xilinx/common/board.c
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-2.0+
/*
- * (C) Copyright 2014 - 2020 Xilinx, Inc.
- * Michal Simek <michal.simek@xilinx.com>
+ * (C) Copyright 2014 - 2022, Xilinx, Inc.
+ * (C) Copyright 2022 - 2023, Advanced Micro Devices, Inc.
+ *
+ * Michal Simek <michal.simek@amd.com>
*/
#include <common.h>
@@ -9,6 +11,7 @@
#include <efi_loader.h>
#include <env.h>
#include <image.h>
+#include <init.h>
#include <lmb.h>
#include <log.h>
#include <asm/global_data.h>
@@ -22,6 +25,7 @@
#include <i2c_eeprom.h>
#include <net.h>
#include <generated/dt.h>
+#include <slre.h>
#include <soc.h>
#include <linux/ctype.h>
#include <linux/kernel.h>
@@ -82,7 +86,7 @@ static struct xilinx_board_description *board_info;
struct xilinx_legacy_format {
char board_sn[18]; /* 0x0 */
char unused0[14]; /* 0x12 */
- char eth_mac[6]; /* 0x20 */
+ char eth_mac[ETH_ALEN]; /* 0x20 */
char unused1[170]; /* 0x26 */
char board_name[11]; /* 0xd0 */
char unused2[5]; /* 0xdc */
@@ -98,9 +102,13 @@ static void xilinx_eeprom_legacy_cleanup(char *eeprom, int size)
for (i = 0; i < size; i++) {
byte = eeprom[i];
- /* Remove all ffs and spaces */
- if (byte == 0xff || byte == ' ')
+ /* Remove all non printable chars but ignore MAC address */
+ if ((i < offsetof(struct xilinx_legacy_format, eth_mac) ||
+ i >= offsetof(struct xilinx_legacy_format, unused1)) &&
+ (byte < '!' || byte > '~')) {
eeprom[i] = 0;
+ continue;
+ }
/* Convert strings to lower case */
if (byte >= 'A' && byte <= 'Z')
@@ -133,21 +141,25 @@ static int xilinx_read_eeprom_legacy(struct udevice *dev, char *name,
xilinx_eeprom_legacy_cleanup((char *)eeprom_content, size);
- printf("Xilinx I2C Legacy format at %s:\n", name);
- printf(" Board name:\t%s\n", eeprom_content->board_name);
- printf(" Board rev:\t%s\n", eeprom_content->board_revision);
- printf(" Board SN:\t%s\n", eeprom_content->board_sn);
+ /* Terminating \0 chars are the part of desc fields already */
+ strlcpy(desc->name, eeprom_content->board_name,
+ sizeof(eeprom_content->board_name) + 1);
+ strlcpy(desc->revision, eeprom_content->board_revision,
+ sizeof(eeprom_content->board_revision) + 1);
+ strlcpy(desc->serial, eeprom_content->board_sn,
+ sizeof(eeprom_content->board_sn) + 1);
eth_valid = is_valid_ethaddr((const u8 *)eeprom_content->eth_mac);
if (eth_valid)
- printf(" Ethernet mac:\t%pM\n", eeprom_content->eth_mac);
+ memcpy(desc->mac_addr[0], eeprom_content->eth_mac, ETH_ALEN);
+
+ printf("Xilinx I2C Legacy format at %s:\n", name);
+ printf(" Board name:\t%s\n", desc->name);
+ printf(" Board rev:\t%s\n", desc->revision);
+ printf(" Board SN:\t%s\n", desc->serial);
- /* Terminating \0 chars ensure end of string */
- strcpy(desc->name, eeprom_content->board_name);
- strcpy(desc->revision, eeprom_content->board_revision);
- strcpy(desc->serial, eeprom_content->board_sn);
if (eth_valid)
- memcpy(desc->mac_addr[0], eeprom_content->eth_mac, ETH_ALEN);
+ printf(" Ethernet mac:\t%pM\n", desc->mac_addr);
desc->header = EEPROM_HEADER_MAGIC;
@@ -468,6 +480,21 @@ int __maybe_unused board_fit_config_name_match(const char *name)
{
debug("%s: Check %s, default %s\n", __func__, name, board_name);
+#if !defined(CONFIG_SPL_BUILD)
+ if (CONFIG_IS_ENABLED(REGEX)) {
+ struct slre slre;
+ int ret;
+
+ ret = slre_compile(&slre, name);
+ if (ret) {
+ ret = slre_match(&slre, board_name, strlen(board_name),
+ NULL);
+ debug("%s: name match ret = %d\n", __func__, ret);
+ return !ret;
+ }
+ }
+#endif
+
if (!strcmp(name, board_name))
return 0;
diff --git a/board/xilinx/common/fru_ops.c b/board/xilinx/common/fru_ops.c
index c4f009affc5..167252c240c 100644
--- a/board/xilinx/common/fru_ops.c
+++ b/board/xilinx/common/fru_ops.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * (C) Copyright 2019 - 2020 Xilinx, Inc.
+ * (C) Copyright 2019 - 2022, Xilinx, Inc.
+ * (C) Copyright 2022 - 2023, Advanced Micro Devices, Inc.
*/
#include <common.h>
@@ -61,9 +62,6 @@ static int fru_check_type_len(u8 type_len, u8 language, u8 *type)
{
int len;
- if (type_len == FRU_TYPELEN_EOF)
- return -EINVAL;
-
*type = (type_len & FRU_TYPELEN_CODE_MASK) >> FRU_TYPELEN_TYPE_SHIFT;
len = type_len & FRU_TYPELEN_LEN_MASK;
@@ -172,9 +170,16 @@ static int fru_parse_board(unsigned long addr)
{
u8 i, type;
int len;
- u8 *data, *term, *limit;
+ u8 *data, *term, *limit, *next_addr, *eof;
memcpy(&fru_data.brd.ver, (void *)addr, 6);
+
+ /*
+ * eof marks the last data byte (without checksum). That's why checksum
+ * is address length - 1 and last data byte is length - 2.
+ */
+ eof = (u8 *)(fru_data.brd.len * 8 + addr - 2);
+
addr += 6;
data = (u8 *)&fru_data.brd.manufacturer_type_len;
@@ -184,10 +189,21 @@ static int fru_parse_board(unsigned long addr)
for (i = 0; ; i++, data += FRU_BOARD_MAX_LEN) {
len = fru_check_type_len(*(u8 *)addr, fru_data.brd.lang_code,
&type);
+ next_addr = (u8 *)addr + 1;
+
+ if ((u8 *)addr >= eof) {
+ debug("Reach EOF record: addr %lx, eof %lx\n", addr,
+ (unsigned long)eof);
+ break;
+ }
+
/*
- * Stop cature if it end of fields
+ * Stop capture if the type is ASCII and valid field length
+ * is 1 (0xc1) and next FRU data is less than 0x20 (space " ")
+ * or it is 0x7f (delete 'DEL').
*/
- if (len == -EINVAL)
+ if (type == FRU_TYPELEN_TYPE_ASCII8 && len == 1 &&
+ (*next_addr < 0x20 || *next_addr == 0x7F))
break;
/* Stop when amount of chars is more then fields to record */
@@ -332,9 +348,11 @@ static int fru_display_board(struct fru_board_data *brd, int verbose)
for (u8 i = 0; i < (sizeof(boardinfo) / sizeof(*boardinfo)); i++) {
len = fru_check_type_len(*data++, brd->lang_code,
&type);
- if (len == -EINVAL) {
- printf("**** EOF for Board Area ****\n");
- break;
+
+ /* Empty record has no len/type filled */
+ if (!len) {
+ debug("%s not found\n", boardinfo[i]);
+ continue;
}
if (type <= FRU_TYPELEN_TYPE_ASCII8 &&
@@ -344,11 +362,6 @@ static int fru_display_board(struct fru_board_data *brd, int verbose)
else
debug("Type code: %s\n", typecode[type + 1]);
- if (!len) {
- debug("%s not found\n", boardinfo[i]);
- continue;
- }
-
switch (type) {
case FRU_TYPELEN_TYPE_BINARY:
debug("Length: %d\n", len);