xilinx: Fru tool update
cover 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(-)
Signature · 1 line
2.35.1
PATCH 1/4 fru: ops: Clear fru table before storing data
From: Ashok Reddy Soma <[email protected]>
Fill fru table with 0's before using it, to avoid junk data.
---
board/xilinx/common/fru_ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
board/xilinx/common/fru_ops.c +1 -1
@@ -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 ));
Signature · 1 line
2.35.1
PATCH 2/4 fru: ops: Return error from checksum if data is all zero's
In reply to Michal SimekFrom: Ashok Reddy Soma <[email protected]>
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.
---
board/xilinx/common/fru_ops.c | 8 ++++++++ 1 file changed, 8 insertions(+)
board/xilinx/common/fru_ops.c +8 -0
@@ -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; }
Signature · 1 line
2.35.1
PATCH 3/4 xilinx: common: Optimise updating ethaddr from eeprom
In reply to Michal SimekFrom: Ashok Reddy Soma <[email protected]>
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.
---
board/xilinx/common/board.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
board/xilinx/common/board.c +1 -1
@@ -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",
Signature · 1 line
2.35.1
PATCH 4/4 fru: ops: Add support to read mac addresses from multirecord
In reply to Michal SimekFrom: Ashok Reddy Soma <[email protected]>
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().
---
board/xilinx/common/board.c | 9 ++++++++ board/xilinx/common/fru.h | 21 +++++++++++++++++++ board/xilinx/common/fru_ops.c | 39 +++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+)
board/xilinx/common/board.c +9 -0
@@ -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:
board/xilinx/common/fru.h +21 -0
@@ -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 4struct __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
board/xilinx/common/fru_ops.c +39 -0
@@ -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 ; }
Signature · 1 line
2.35.1
Michal Simek
Appliedst 23. 2. 2022 v 15:01 odesílatel Michal Simek <[email protected]> napsal:
Quoted 19 lines
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,
MichalAshok 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
Quoted 8 lines
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
Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91 w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel - Xilinx Microblaze Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs