[PATCH 0/4] xilinx: Fru tool update

Hi,
the first 3 patches are fixes in current fru implementation to make sure that code is not working with incorrect data or not waste time. The last patch adds decoder for xilinx multirecord which stores MAC addresses for DUT.
Thanks, Michal
Ashok Reddy Soma (4): fru: ops: Clear fru table before storing data fru: ops: Return error from checksum if data is all zero's xilinx: common: Optimise updating ethaddr from eeprom fru: ops: Add support to read mac addresses from multirecord
board/xilinx/common/board.c | 11 +++++++- board/xilinx/common/fru.h | 21 +++++++++++++++ board/xilinx/common/fru_ops.c | 49 ++++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 2 deletions(-)

From: Ashok Reddy Soma ashok.reddy.soma@xilinx.com
Fill fru table with 0's before using it, to avoid junk data.
Signed-off-by: Ashok Reddy Soma ashok.reddy.soma@xilinx.com Signed-off-by: Michal Simek michal.simek@xilinx.com ---
board/xilinx/common/fru_ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/board/xilinx/common/fru_ops.c b/board/xilinx/common/fru_ops.c index 6ed63bb7ee11..a0a1441a8eef 100644 --- a/board/xilinx/common/fru_ops.c +++ b/board/xilinx/common/fru_ops.c @@ -222,7 +222,7 @@ int fru_capture(unsigned long addr) }
hdr = (struct fru_common_hdr *)addr; - + memset((void *)&fru_data, 0, sizeof(fru_data)); memcpy((void *)&fru_data, (void *)hdr, sizeof(struct fru_common_hdr));

From: Ashok Reddy Soma ashok.reddy.soma@xilinx.com
fru_checksum function is simply adding all the bytes and returning the sum. If the data passed to this function is all zero's then it will return 0, and the functions calling this api will assume that checksum is correct. Ideally this is not good. Fix this by returning error if all the data is 0's.
Signed-off-by: Ashok Reddy Soma ashok.reddy.soma@xilinx.com Signed-off-by: Michal Simek michal.simek@xilinx.com ---
board/xilinx/common/fru_ops.c | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/board/xilinx/common/fru_ops.c b/board/xilinx/common/fru_ops.c index a0a1441a8eef..058e750c442f 100644 --- a/board/xilinx/common/fru_ops.c +++ b/board/xilinx/common/fru_ops.c @@ -39,12 +39,20 @@ static int fru_check_language(u8 code) u8 fru_checksum(u8 *addr, u8 len) { u8 checksum = 0; + u8 cnt = len;
while (len--) { + if (*addr == 0) + cnt--; + checksum += *addr; addr++; }
+ /* If all data bytes are 0's return error */ + if (!cnt) + return EINVAL; + return checksum; }

From: Ashok Reddy Soma ashok.reddy.soma@xilinx.com
In board_late_init_xilinx() eth*addr are updated from the values read from eeprom. Ideally the MAC addresses are updated sequencially. So if any MAC address is invalid, it means there are no further valid values. So optimise this logic by replacing continue with break.
Signed-off-by: Ashok Reddy Soma ashok.reddy.soma@xilinx.com Signed-off-by: Michal Simek michal.simek@xilinx.com ---
board/xilinx/common/board.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c index 0068cb879263..db089c4a0b17 100644 --- a/board/xilinx/common/board.c +++ b/board/xilinx/common/board.c @@ -416,7 +416,7 @@ int board_late_init_xilinx(void)
for (i = 0; i < EEPROM_HDR_NO_OF_MAC_ADDR; i++) { if (!desc->mac_addr[i]) - continue; + break;
if (is_valid_ethaddr((const u8 *)desc->mac_addr[i])) ret |= eth_env_set_enetaddr_by_index("eth",

From: Ashok Reddy Soma ashok.reddy.soma@xilinx.com
Add support to read MAC addresses from mac address multirecord. Check if multi record is found, then jump to mac address multirecord by comparing the record type field. If it matches mac address multirecord(0xD2), then copy mac addresses.
Copy these read MAC address in xilinx_read_eeprom_fru so that they are updated to eth*addr in board_late_init_xilinx().
Signed-off-by: Ashok Reddy Soma ashok.reddy.soma@xilinx.com Signed-off-by: Michal Simek michal.simek@xilinx.com ---
board/xilinx/common/board.c | 9 ++++++++ board/xilinx/common/fru.h | 21 +++++++++++++++++++ board/xilinx/common/fru_ops.c | 39 +++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+)
diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c index db089c4a0b17..0769189dcf21 100644 --- a/board/xilinx/common/board.c +++ b/board/xilinx/common/board.c @@ -171,6 +171,7 @@ static int xilinx_read_eeprom_fru(struct udevice *dev, char *name, { int i, ret, eeprom_size; u8 *fru_content; + u8 id = 0;
/* FIXME this is shortcut - if eeprom type is wrong it will fail */ eeprom_size = i2c_eeprom_size(dev); @@ -218,6 +219,14 @@ static int xilinx_read_eeprom_fru(struct udevice *dev, char *name, sizeof(desc->revision)); strncpy(desc->serial, (char *)fru_data.brd.serial_number, sizeof(desc->serial)); + + while (id < EEPROM_HDR_NO_OF_MAC_ADDR) { + if (is_valid_ethaddr((const u8 *)fru_data.mac.macid[id])) + memcpy(&desc->mac_addr[id], + (char *)fru_data.mac.macid[id], ETH_ALEN); + id++; + } + desc->header = EEPROM_HEADER_MAGIC;
end: diff --git a/board/xilinx/common/fru.h b/board/xilinx/common/fru.h index e7284709ddea..59f6b722cf12 100644 --- a/board/xilinx/common/fru.h +++ b/board/xilinx/common/fru.h @@ -6,6 +6,7 @@
#ifndef __FRU_H #define __FRU_H +#include <net.h>
struct fru_common_hdr { u8 version; @@ -19,6 +20,7 @@ struct fru_common_hdr { };
#define FRU_BOARD_MAX_LEN 32 +#define FRU_MAX_NO_OF_MAC_ADDR 4
struct __packed fru_board_info_header { u8 ver; @@ -56,9 +58,24 @@ struct fru_board_data { u8 uuid[FRU_BOARD_MAX_LEN]; };
+struct fru_multirec_hdr { + u8 rec_type; + u8 type; + u8 len; + u8 csum; + u8 hdr_csum; +}; + +struct fru_multirec_mac { + u8 xlnx_iana_id[3]; + u8 ver; + u8 macid[FRU_MAX_NO_OF_MAC_ADDR][ETH_ALEN]; +}; + struct fru_table { struct fru_common_hdr hdr; struct fru_board_data brd; + struct fru_multirec_mac mac; bool captured; };
@@ -69,6 +86,10 @@ struct fru_table { #define FRU_LANG_CODE_ENGLISH 0 #define FRU_LANG_CODE_ENGLISH_1 25 #define FRU_TYPELEN_EOF 0xC1 +#define FRU_MULTIREC_TYPE_OEM 0xD2 +#define FRU_MULTIREC_MAC_OFFSET 4 +#define FRU_LAST_REC BIT(7) +#define FRU_DUT_MACID 0x31
/* This should be minimum of fields */ #define FRU_BOARD_AREA_TOTAL_FIELDS 5 diff --git a/board/xilinx/common/fru_ops.c b/board/xilinx/common/fru_ops.c index 058e750c442f..49846ae3d660 100644 --- a/board/xilinx/common/fru_ops.c +++ b/board/xilinx/common/fru_ops.c @@ -9,6 +9,7 @@ #include <fdtdec.h> #include <log.h> #include <malloc.h> +#include <net.h> #include <asm/io.h> #include <asm/arch/hardware.h>
@@ -218,10 +219,43 @@ static int fru_parse_board(unsigned long addr) return 0; }
+static int fru_parse_multirec(unsigned long addr) +{ + struct fru_multirec_hdr mrc; + u8 checksum = 0; + u8 hdr_len = sizeof(struct fru_multirec_hdr); + int mac_len = 0; + + debug("%s: multirec addr %lx\n", __func__, addr); + + do { + memcpy(&mrc.rec_type, (void *)addr, hdr_len); + + checksum = fru_checksum((u8 *)addr, hdr_len); + if (checksum) { + debug("%s header CRC error\n", __func__); + return -EINVAL; + } + + if (mrc.rec_type == FRU_MULTIREC_TYPE_OEM) { + struct fru_multirec_mac *mac = (void *)addr + hdr_len; + + if (mac->ver == FRU_DUT_MACID) { + mac_len = mrc.len - FRU_MULTIREC_MAC_OFFSET; + memcpy(&fru_data.mac.macid, mac->macid, mac_len); + } + } + addr += mrc.len + hdr_len; + } while (!(mrc.type & FRU_LAST_REC)); + + return 0; +} + int fru_capture(unsigned long addr) { struct fru_common_hdr *hdr; u8 checksum = 0; + unsigned long multirec_addr = addr;
checksum = fru_checksum((u8 *)addr, sizeof(struct fru_common_hdr)); if (checksum) { @@ -243,6 +277,11 @@ int fru_capture(unsigned long addr)
env_set_hex("fru_addr", addr);
+ if (hdr->off_multirec) { + multirec_addr += fru_cal_area_len(hdr->off_multirec); + fru_parse_multirec(multirec_addr); + } + return 0; }

st 23. 2. 2022 v 15:01 odesÃlatel Michal Simek michal.simek@xilinx.com napsal:
Hi,
the first 3 patches are fixes in current fru implementation to make sure that code is not working with incorrect data or not waste time. The last patch adds decoder for xilinx multirecord which stores MAC addresses for DUT.
Thanks, Michal
Ashok Reddy Soma (4): fru: ops: Clear fru table before storing data fru: ops: Return error from checksum if data is all zero's xilinx: common: Optimise updating ethaddr from eeprom fru: ops: Add support to read mac addresses from multirecord
board/xilinx/common/board.c | 11 +++++++- board/xilinx/common/fru.h | 21 +++++++++++++++ board/xilinx/common/fru_ops.c | 49 ++++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 2 deletions(-)
-- 2.35.1
Applied. M
participants (2)
-
Michal Simek
-
Michal Simek