Skip to contentSkip to conversation

Add support for I2C Legacy/FRU decoding

PATCH New Michal Simek 2 participants 6 messages Oct 20, 2020 – Oct 27, 2020 Arm/Zynq architecture

lore
Share & tools
lore
#0 lore raw

cover Add support for I2C Legacy/FRU decoding

Hi,

the whole series add support for I2C based FRU eeprom board identification. EEPROMs are referenced by nvmem alias which was suggested by Rob Herring (dt maintainer). Previous code was using chosen xlnx,eeprom property. And because no platform is setting up nvmem alias the code is doing nothing on all boards.

If you want to try it and test it just choose board and define nvmem aliases and you should see similar logs like this.

zcu104 with legacy format and FRU on FMC

U-Boot 2020.10-00835-g819dc03ff784 (Oct 20 2020 - 12:48:12 +0200)

Model: ZynqMP ZCU104 RevC
Board: Xilinx ZynqMP
DRAM:  2 GiB
PMUFW:  v1.1
Xilinx I2C Legacy format at nvmem0:
 Board name:    zcu104
 Board rev:     c
 Board SN:      895527361843-94820
 Ethernet mac:  00:0a:35:04:eb:93

Xilinx I2C FRU format at nvmem1:
Manufacturer Name: XILINX
Product Name: XXX-XXX
Serial No: 1231
Part Number: dd
File ID: U-Boot generator
Revision Number: rev_A

EL Level:       EL2
Chip ID:        zu7e
WDT:   Started with servicing (60s timeout)
NAND:  0 MiB
MMC:   mmc at ff170000: 0

Loading Environment from FAT... *** Warning - bad CRC, using default environment

In:    serial at ff000000
Out:   serial at ff000000
Err:   serial at ff000000
Bootmode: LVL_SHFT_SD_MODE1
Reset reason:   EXTERNAL

Net:
ZYNQ GEM: ff0e0000, mdio bus ff0e0000, phyaddr 12, interface rgmii-id
eth0: ethernet at ff0e0000
Hit any key to stop autoboot: 0
ZynqMP>

Based on https://lists.denx.de/pipermail/u-boot/2020-October/429382.html

Thanks,
Michal

Michal Simek (3):
xilinx: common: Add Makefile to common folder
xilinx: cmd: Add basic fru format generator
xilinx: board: Add FRU decoder support

Siva Durga Prasad Paladugu (1):
xilinx: cmd: Add support for FRU commands

 board/xilinx/Kconfig            |   8 +
 board/xilinx/common/Makefile    |  10 +
 board/xilinx/common/board.c     |  83 +++++++-
 board/xilinx/common/fru.c       |  91 ++++++++
 board/xilinx/common/fru.h       |  83 ++++++++
 board/xilinx/common/fru_ops.c   | 362 ++++++++++++++++++++++++++++++++
 board/xilinx/versal/Makefile    |   1 -
 board/xilinx/zynq/Makefile      |   1 -
 board/xilinx/zynqmp/MAINTAINERS |   1 +
 board/xilinx/zynqmp/Makefile    |   1 -
 10 files changed, 637 insertions(+), 4 deletions(-)
 create mode 100644 board/xilinx/common/Makefile
 create mode 100644 board/xilinx/common/fru.c
 create mode 100644 board/xilinx/common/fru.h
 create mode 100644 board/xilinx/common/fru_ops.c
Signature · 1 line
2.28.0
#1 lore raw

PATCH 1/4 xilinx: common: Add Makefile to common folder

There is no need to reference files in common folder back. Simply adding Makefile to this folder does the job because this "common" location is already wired in main Makefile.

---

 board/xilinx/common/Makefile | 7 +++++++
 board/xilinx/versal/Makefile | 1 -
 board/xilinx/zynq/Makefile   | 1 -
 board/xilinx/zynqmp/Makefile | 1 -
 4 files changed, 7 insertions(+), 3 deletions(-)
 create mode 100644 board/xilinx/common/Makefile
board/xilinx/common/Makefile new file +7 -0
new file mode 100644
index 000000000000..3600da464b87
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# (C) Copyright 2020 Xilinx, Inc.
+# Michal Simek <[email protected]>
+#
+
+obj-y	+= board.o
board/xilinx/versal/Makefile +0 -1
index 90e034315406..4a46ca02d705 100644
@@ -6,4 +6,3 @@
 
 obj-y	:= board.o
 obj-$(CONFIG_CMD_VERSAL)	+= cmds.o
-obj-y	+= ../common/board.o
board/xilinx/zynq/Makefile +0 -1
index 096a7aceb939..856617158917 100644
@@ -4,7 +4,6 @@
 # Wolfgang Denk, DENX Software Engineering, wd at denx.de.
 
 obj-y	:= board.o
-obj-y	+= ../common/board.o
 
 ifneq ($(CONFIG_XILINX_PS_INIT_FILE),"")
 PS_INIT_FILE := $(shell cd $(srctree); readlink -f $(CONFIG_XILINX_PS_INIT_FILE))
board/xilinx/zynqmp/Makefile +0 -1
index 398c6aaa452a..7d8277ca4004 100644
@@ -4,7 +4,6 @@
 # Michal Simek <[email protected]>
 
 obj-y	:= zynqmp.o
-obj-y	+= ../common/board.o
 
 ifneq ($(CONFIG_XILINX_PS_INIT_FILE),"")
 PS_INIT_FILE := $(shell cd $(srctree); readlink -f $(CONFIG_XILINX_PS_INIT_FILE))
Signature · 1 line
2.28.0
#2 lore raw

PATCH 2/4 xilinx: cmd: Add support for FRU commands

In reply to Michal Simek

From: Siva Durga Prasad Paladugu <[email protected]>

This patch adds support for fru commands "fru capture" and "fru display". The fru capture parses the FRU table present at an address and stores in a structure for later use. The fru display prints the content of captured structured in a readable format.

As of now, it supports only common header and board area of FRU. Also, it supports only English language code and ASCII8/BINARY formats.

fru_data variable is placed to data section because fru parser can be called very early before bss is initialized. And also information needs to be shared that's why it is exported via header.

---

 board/xilinx/Kconfig            |   8 +
 board/xilinx/common/Makefile    |   3 +
 board/xilinx/common/fru.c       |  73 +++++++++
 board/xilinx/common/fru.h       |  66 ++++++++
 board/xilinx/common/fru_ops.c   | 263 ++++++++++++++++++++++++++++++++
 board/xilinx/zynqmp/MAINTAINERS |   1 +
 6 files changed, 414 insertions(+)
 create mode 100644 board/xilinx/common/fru.c
 create mode 100644 board/xilinx/common/fru.h
 create mode 100644 board/xilinx/common/fru_ops.c
board/xilinx/Kconfig +8 -0
index 01d7f8eac1c9..51f6d2bac8ad 100644
@@ -73,3 +73,11 @@ config ZYNQ_GEM_I2C_MAC_OFFSET
 	  Set the MAC offset for i2C.
 
 endif
+
+config CMD_FRU
+	bool "FRU information for product"
+	help
+	  This option enables FRU commands to capture and display FRU
+	  information present in the device. The FRU Information is used
+	  to primarily to provide "inventory" information about the boards
+	  that the FRU Information Device is located on.
board/xilinx/common/Makefile +3 -0
index 3600da464b87..212028478c0e 100644
@@ -5,3 +5,6 @@
 #
 
 obj-y	+= board.o
+ifndef CONFIG_SPL_BUILD
+obj-$(CONFIG_CMD_FRU) += fru.o fru_ops.o
+endif
board/xilinx/common/fru.c new file +73 -0

73 lines not on this page · raw message

board/xilinx/common/fru.h new file +66 -0

66 lines not on this page · raw message

board/xilinx/common/fru_ops.c new file +263 -0

263 lines not on this page · raw message

board/xilinx/zynqmp/MAINTAINERS +1 -0
index 04fc7f32fe86..9cd4f3f53efd 100644
@@ -3,6 +3,7 @@ M:	Michal Simek <[email protected]>
 S:	Maintained
 F:	arch/arm/dts/zynqmp-*
 F:	arch/arm/dts/avnet-ultra96*
+F:	board/xilinx/common/
 F:	board/xilinx/zynqmp/
 F:	include/configs/xilinx_zynqmp*
 F:	configs/xilinx_zynqmp*
Signature · 1 line
2.28.0
#3 lore raw

PATCH 3/4 xilinx: cmd: Add basic fru format generator

In reply to Michal Simek

Idea is to have something what can be used for board bringup from generic board perspective.

There is a violation compare to spec that FRU ID is ASCII8 instead of binary format but this is really for having something to pass boot and boot to OS which has better generating options.
Also time should be filled properly.

For example:
fru board_gen 1000 XILINX versal-x-prc-01-revA serialX partX

There is also support for revision field which is Xilinx specific field.

---

 board/xilinx/common/fru.c     |  20 ++++++-
 board/xilinx/common/fru.h     |  17 ++++++
 board/xilinx/common/fru_ops.c | 101 +++++++++++++++++++++++++++++++++-
 3 files changed, 136 insertions(+), 2 deletions(-)
board/xilinx/common/fru.c +19 -1
index 0ab9f2a78bd9..ccf48723ff89 100644
@@ -33,9 +33,23 @@ static int do_fru_display(struct cmd_tbl *cmdtp, int flag, int argc,
 	return CMD_RET_SUCCESS;
 }
 
+static int do_fru_generate(struct cmd_tbl *cmdtp, int flag, int argc,
+			   char *const argv[])
+{
+	unsigned long addr;
+
+	if (argc < cmdtp->maxargs)
+		return CMD_RET_USAGE;
+
+	addr = simple_strtoul(argv[2], NULL, 16);
+
+	return fru_generate(addr, argv[3], argv[4], argv[5], argv[6], argv[7]);
+}
+
 static struct cmd_tbl cmd_fru_sub[] = {
 	U_BOOT_CMD_MKENT(capture, 3, 0, do_fru_capture, "", ""),
 	U_BOOT_CMD_MKENT(display, 2, 0, do_fru_display, "", ""),
+	U_BOOT_CMD_MKENT(board_gen, 8, 0, do_fru_generate, "", ""),
 };
 
 static int do_fru(struct cmd_tbl *cmdtp, int flag, int argc,
@@ -63,11 +77,15 @@ static char fru_help_text[] =
 	"capture <addr> - Parse and capture FRU table present at address.\n"
 	"fru display - Displays content of FRU table that was captured using\n"
 	"              fru capture command\n"
+	"fru board_gen <addr> <manufacturer> <board name> <serial number>\n"
+	"              <part number> <revision> - Generate FRU format with\n"
+	"              board info area filled based on parameters. <addr> is\n"
+	"              pointing to place where FRU is generated.\n"
 	;
 #endif
 
 U_BOOT_CMD(
-	fru, 3, 1, do_fru,
+	fru, 8, 1, do_fru,
 	"FRU table info",
 	fru_help_text
 )
board/xilinx/common/fru.h +17 -0
index a0413cf7f698..a3e652025714 100644
@@ -20,6 +20,18 @@ struct fru_common_hdr {
 
 #define FRU_BOARD_MAX_LEN	32
 
+struct __packed fru_board_info_header {
+	u8 ver;
+	u8 len;
+	u8 lang_code;
+	u8 time[3];
+};
+
+struct __packed fru_board_info_member {
+	u8 type_len;
+	u8 *name;
+};
+
 struct fru_board_data {
 	u8 ver;
 	u8 len;
@@ -35,6 +47,9 @@ struct fru_board_data {
 	u8 part_number[FRU_BOARD_MAX_LEN];
 	u8 file_id_type_len;
 	u8 file_id[FRU_BOARD_MAX_LEN];
+	/* Xilinx custom fields */
+	u8 rev_type_len;
+	u8 rev[FRU_BOARD_MAX_LEN];
 };
 
 struct fru_table {
@@ -59,6 +74,8 @@ struct fru_table {
 
 int fru_display(int verbose);
 int fru_capture(unsigned long addr);
+int fru_generate(unsigned long addr, char *manufacturer, char *board_name,
+		 char *serial_no, char *part_no, char *revision);
 u8 fru_checksum(u8 *addr, u8 len);
 
 extern struct fru_table fru_data;
board/xilinx/common/fru_ops.c +100 -1

113 lines not on this page · raw message

Signature · 1 line
2.28.0
#4 lore raw

PATCH 4/4 xilinx: board: Add FRU decoder support

In reply to Michal Simek

FMC cards are using FRU format for card identification. That's why add support for this format.

---

 board/xilinx/common/board.c | 83 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 82 insertions(+), 1 deletion(-)
board/xilinx/common/board.c +82 -1
index 0d0c21ca3d40..74e81c18bd5a 100644
@@ -17,6 +17,8 @@
 #include <i2c_eeprom.h>
 #include <net.h>
 
+#include "fru.h"
+
 #if defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET)
 int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
 {
@@ -65,7 +67,7 @@ struct xilinx_board_description {
 static int highest_id = -1;
 static struct xilinx_board_description **board_info;
 
-#define XILINX_I2C_DETECTION_BITS	8
+#define XILINX_I2C_DETECTION_BITS	sizeof(struct fru_common_hdr)
 
 /* Variable which stores pointer to array which stores eeprom content */
 struct xilinx_legacy_format {
@@ -160,6 +162,82 @@ static bool xilinx_detect_legacy(u8 *buffer)
 	return true;
 }
 
+static int xilinx_read_eeprom_fru(struct udevice *dev, char *name,
+				  struct xilinx_board_description *desc)
+{
+	int ret, eeprom_size;
+	u8 *fru_content;
+
+	/* FIXME this is shortcut - if eeprom type is wrong it will fail */
+	eeprom_size = i2c_eeprom_size(dev);
+
+	fru_content = calloc(1, eeprom_size);
+	if (!fru_content)
+		return -ENOMEM;
+
+	debug("%s: I2C EEPROM read pass data at %p\n", __func__,
+	      fru_content);
+
+	ret = dm_i2c_read(dev, 0, (uchar *)fru_content,
+			  eeprom_size);
+	if (ret) {
+		debug("%s: I2C EEPROM read failed\n", __func__);
+		free(fru_content);
+		return ret;
+	}
+
+	printf("Xilinx I2C FRU format at %s:\n", name);
+	fru_capture((unsigned long)fru_content);
+	ret = fru_display(0);
+	if (ret) {
+		printf("FRU format decoding failed.\n");
+		return ret;
+	}
+
+	if (desc->header == EEPROM_HEADER_MAGIC) {
+		debug("Information already filled\n");
+		return -EINVAL;
+	}
+
+	/* It is clear that FRU was captured and structures were filled */
+	strncpy(desc->manufacturer, (char *)fru_data.brd.manufacturer_name,
+		sizeof(desc->manufacturer));
+	strncpy(desc->name, (char *)fru_data.brd.product_name,
+		sizeof(desc->name));
+	strncpy(desc->revision, (char *)fru_data.brd.rev,
+		sizeof(desc->revision));
+	strncpy(desc->serial, (char *)fru_data.brd.serial_number,
+		sizeof(desc->serial));
+	desc->header = EEPROM_HEADER_MAGIC;
+
+	return 0;
+}
+
+static bool xilinx_detect_fru(u8 *buffer)
+{
+	u8 checksum = 0;
+	int i;
+
+	checksum = fru_checksum((u8 *)buffer, sizeof(struct fru_common_hdr));
+	if (checksum) {
+		debug("%s Common header CRC FAIL\n", __func__);
+		return false;
+	}
+
+	bool all_zeros = true;
+	/* Checksum over all zeros is also zero that's why detect this case */
+	for (i = 0; i < sizeof(struct fru_common_hdr); i++) {
+		if (buffer[i] != 0)
+			all_zeros = false;
+	}
+
+	if (all_zeros)
+		return false;
+
+	debug("%s Common header CRC PASS\n", __func__);
+	return true;
+}
+
 static int xilinx_read_eeprom_single(char *name,
 				     struct xilinx_board_description *desc)
 {
@@ -184,6 +262,9 @@ static int xilinx_read_eeprom_single(char *name,
 
 	debug("%s: i2c memory detected: %s\n", __func__, name);
 
+	if (CONFIG_IS_ENABLED(CMD_FRU) && xilinx_detect_fru(buffer))
+		return xilinx_read_eeprom_fru(dev, name, desc);
+
 	if (xilinx_detect_legacy(buffer))
 		return xilinx_read_eeprom_legacy(dev, name, desc);
 
Signature · 1 line
2.28.0
Applied
#5 lore raw

cover Add support for I2C Legacy/FRU decoding

In reply to Michal Simek

?t 20. 10. 2020 v 16:50 odes?latel Michal Simek
<[email protected]> napsal:

Quoted 80 lines

Hi,

the whole series add support for I2C based FRU eeprom board identification. EEPROMs are referenced by nvmem alias which was suggested by Rob Herring (dt maintainer). Previous code was using chosen xlnx,eeprom property. And because no platform is setting up nvmem alias the code is doing nothing on all boards.

If you want to try it and test it just choose board and define nvmem aliases and you should see similar logs like this.

zcu104 with legacy format and FRU on FMC

U-Boot 2020.10-00835-g819dc03ff784 (Oct 20 2020 - 12:48:12 +0200)

Model: ZynqMP ZCU104 RevC
Board: Xilinx ZynqMP
DRAM:  2 GiB
PMUFW:  v1.1
Xilinx I2C Legacy format at nvmem0:
 Board name:    zcu104
 Board rev:     c
 Board SN:      895527361843-94820
 Ethernet mac:  00:0a:35:04:eb:93

Xilinx I2C FRU format at nvmem1:
Manufacturer Name: XILINX
Product Name: XXX-XXX
Serial No: 1231
Part Number: dd
File ID: U-Boot generator
Revision Number: rev_A

EL Level:       EL2
Chip ID:        zu7e
WDT:   Started with servicing (60s timeout)
NAND:  0 MiB
MMC:   mmc at ff170000: 0

Loading Environment from FAT... *** Warning - bad CRC, using default environment

In:    serial at ff000000
Out:   serial at ff000000
Err:   serial at ff000000
Bootmode: LVL_SHFT_SD_MODE1
Reset reason:   EXTERNAL

Net:
ZYNQ GEM: ff0e0000, mdio bus ff0e0000, phyaddr 12, interface rgmii-id
eth0: ethernet at ff0e0000
Hit any key to stop autoboot: 0
ZynqMP>

Based on https://lists.denx.de/pipermail/u-boot/2020-October/429382.html

Thanks,
Michal

Michal Simek (3):
xilinx: common: Add Makefile to common folder
xilinx: cmd: Add basic fru format generator
xilinx: board: Add FRU decoder support

Siva Durga Prasad Paladugu (1):
xilinx: cmd: Add support for FRU commands

 board/xilinx/Kconfig            |   8 +
 board/xilinx/common/Makefile    |  10 +
 board/xilinx/common/board.c     |  83 +++++++-
 board/xilinx/common/fru.c       |  91 ++++++++
 board/xilinx/common/fru.h       |  83 ++++++++
 board/xilinx/common/fru_ops.c   | 362 ++++++++++++++++++++++++++++++++
 board/xilinx/versal/Makefile    |   1 -
 board/xilinx/zynq/Makefile      |   1 -
 board/xilinx/zynqmp/MAINTAINERS |   1 +
 board/xilinx/zynqmp/Makefile    |   1 -
 10 files changed, 637 insertions(+), 4 deletions(-)
 create mode 100644 board/xilinx/common/Makefile
 create mode 100644 board/xilinx/common/fru.c
 create mode 100644 board/xilinx/common/fru.h
 create mode 100644 board/xilinx/common/fru_ops.c
Quoted 3 lines

--
2.28.0

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