Skip to contentSkip to conversation

imx8mm-cl-iot-gate: Add SPL EEPROM support

PATCH New Fabio Estevam 2 participants 10 messages Apr 12, 2022

Subsystems (2)
lore
Share & tools
lore

Fabio Estevam

author reviewer
#0 lore raw

PATCH v2 1/5 imx8mm-cl-iot-gate: Add SPL EEPROM support

From: Fabio Estevam <[email protected]>

imx8mm-cl-iot-gate supports multiple DDR sizes and models.

The DDR type can be retrieved from the EEPROM, so add SPL code that can be used to get the DDR information.

Based on the original code from Compulab's U-Boot.

---
Changes since v1:
- None

 board/compulab/imx8mm-cl-iot-gate/Makefile    |   2 +-
 .../compulab/imx8mm-cl-iot-gate/eeprom_spl.c  | 130 ++++++++++++++++++
 2 files changed, 131 insertions(+), 1 deletion(-)
 create mode 100644 board/compulab/imx8mm-cl-iot-gate/eeprom_spl.c
board/compulab/imx8mm-cl-iot-gate/Makefile +1 -1
index 3a2bfc4dc4b1..3800b21a6fd0 100644
@@ -8,6 +8,6 @@
 obj-y += imx8mm-cl-iot-gate.o
 
 ifdef CONFIG_SPL_BUILD
-obj-y += spl.o
+obj-y += spl.o eeprom_spl.o
 obj-y += ddr/
 endif
board/compulab/imx8mm-cl-iot-gate/eeprom_spl.c new file +130 -0

130 lines not on this page · raw message

Signature · 1 line
2.25.1
author reviewer
#1 lore raw

PATCH v2 2/5 imx8mm-cl-iot-gate: Retrieve the DDR type from EEPROM

From: Fabio Estevam <[email protected]>

Currently, the DDR type is retrieved by iteracting inside an array of possible DDR types.

This may take saveral attempts, which slows the overall U-Boot process and does not provide a good user experience:

U-Boot SPL 2021.07 (Feb 28 2022 - 06:39:32 +0000)
DDRINFO: Cfg attempt: [ 1/6 ]
DDRINFO(M): mr5-8 [ 0xff000010 ]
DDRINFO(T): mr5-8 [ 0x5000010 ]
resetting ...

U-Boot SPL 2021.07 (Feb 28 2022 - 06:39:32 +0000)
DDRINFO: Cfg attempt: [ 2/6 ]
DDRINFO(M): mr5-8 [ 0xff000010 ]
DDRINFO(T): mr5-8 [ 0x1061010 ]
resetting ...

U-Boot SPL 2021.07 (Feb 28 2022 - 06:39:32 +0000)
DDRINFO: Cfg attempt: [ 3/6 ]
DDRINFO(M): mr5-8 [ 0xff000010 ]
DDRINFO(T): mr5-8 [ 0xff000010 ]
Normal Boot
WDT: Not starting
Trying to boot from MMC2

NOTICE:  BL31: v2.5(release):v2.5
NOTICE:  BL31: Built : 07:12:44, Jan 24 2022

Improve the boot time by retrieving the correct DDR information from the EEPROM:

U-Boot SPL 2022.04-rc4-00045-g6d02bc40d58c (Mar 19 2022 - 08:22:29 -0300) DDRINFO(D): Kingston 4096G
DDRINFO(M): mr5-8 [ 0xff000010 ]
DDRINFO(E): mr5-8 [ 0xff000010 ]
Normal Boot
WDT: Started watchdog@30280000 with servicing (60s timeout)
Trying to boot from MMC2

NOTICE:  BL31: v2.5(release):v2.5
NOTICE:  BL31: Built : 22:28:11, Mar 15 2022

Based on the original code from Compulab's U-Boot.

Tested on a imx8mm-cl-iot-gate board populated with 4GB of RAM.

---
Changes since v1:
- None

 board/compulab/imx8mm-cl-iot-gate/ddr/ddr.c | 24 ++++++++++++++++++---
 board/compulab/imx8mm-cl-iot-gate/ddr/ddr.h |  5 +++++
 2 files changed, 26 insertions(+), 3 deletions(-)
board/compulab/imx8mm-cl-iot-gate/ddr/ddr.c +21 -3
index 42dd0dbf18fa..5b93491923e9 100644
@@ -22,6 +22,8 @@
 #include <asm/mach-imx/gpio.h>
 #include "ddr.h"
 
+#include <linux/delay.h>
+
 static unsigned int lpddr4_mr_read(unsigned int mr_rank, unsigned int mr_addr)
 {
 	unsigned int tmp;
@@ -137,10 +139,11 @@ void spl_dram_init_compulab(void)
 		(struct lpddr4_tcm_desc *)SPL_TCM_DATA;
 
 	if (lpddr4_tcm_desc->sign != DEFAULT) {
-		/* if not in tcm scan mode */
+		/* get ddr type from the eeprom if not in tcm scan mode */
+		ddr_info = cl_eeprom_get_ddrinfo();
 		for (i = 0; i < ARRAY_SIZE(lpddr4_array); i++) {
 			if (lpddr4_array[i].id == ddr_info &&
-			    lpddr4_array[i].subind == 0xff) {
+			lpddr4_array[i].subind == cl_eeprom_get_subind()) {
 				ddr_found = 1;
 				break;
 			}
@@ -198,10 +201,25 @@ void spl_dram_init_compulab(void)
 
 	SPL_TCM_FINI;
 
+	if (ddr_found == 0) {
+		/* Update eeprom */
+		cl_eeprom_set_ddrinfo(ddr_info_mrr);
+		mdelay(10);
+		ddr_info = cl_eeprom_get_ddrinfo();
+		mdelay(10);
+		cl_eeprom_set_subind(lpddr4_array[i].subind);
+		/* make sure that the ddr_info has reached the eeprom */
+		printf("DDRINFO(E): mr5-8 [ 0x%x ], read back\n", ddr_info);
+		if (ddr_info_mrr != ddr_info || cl_eeprom_get_subind() != lpddr4_array[i].subind) {
+			printf("DDRINFO(EEPROM): make sure that the eeprom is accessible\n");
+			printf("DDRINFO(EEPROM): i2c dev 1; i2c md 0x51 0x40 0x50\n");
+		}
+	}
+
 	/* Pass the dram size to th U-Boot through the tcm memory */
 	{ /* To figure out what to store into the TCM buffer */
 	  /* For debug purpouse only. To override the real memsize */
-		unsigned int ddr_tcm_size = 0;
+		unsigned int ddr_tcm_size = cl_eeprom_get_osize();
 
 		if (ddr_tcm_size == 0 || ddr_tcm_size == -1)
 			ddr_tcm_size = lpddr4_array[i].size;
board/compulab/imx8mm-cl-iot-gate/ddr/ddr.h +5 -0
index 59c18911592e..f7d4fdc1016a 100644
@@ -23,4 +23,9 @@ struct lpddr4_tcm_desc {
 	unsigned int count;
 };
 
+u32 cl_eeprom_get_ddrinfo(void);
+u32 cl_eeprom_set_ddrinfo(u32 ddrinfo);
+u32 cl_eeprom_get_subind(void);
+u32 cl_eeprom_set_subind(u32 subind);
+u32 cl_eeprom_get_osize(void);
 #endif
Signature · 1 line
2.25.1
#2 lore raw

PATCH v2 2/5 imx8mm-cl-iot-gate: Retrieve the DDR type from EEPROM

Quoted 33 lines

From: Fabio Estevam <[email protected]>
Currently, the DDR type is retrieved by iteracting inside an array of possible DDR types.
This may take saveral attempts, which slows the overall U-Boot process and does not provide a good user experience:
U-Boot SPL 2021.07 (Feb 28 2022 - 06:39:32 +0000)
DDRINFO: Cfg attempt: [ 1/6 ]
DDRINFO(M): mr5-8 [ 0xff000010 ]
DDRINFO(T): mr5-8 [ 0x5000010 ]
resetting ...
U-Boot SPL 2021.07 (Feb 28 2022 - 06:39:32 +0000)
DDRINFO: Cfg attempt: [ 2/6 ]
DDRINFO(M): mr5-8 [ 0xff000010 ]
DDRINFO(T): mr5-8 [ 0x1061010 ]
resetting ...
U-Boot SPL 2021.07 (Feb 28 2022 - 06:39:32 +0000)
DDRINFO: Cfg attempt: [ 3/6 ]
DDRINFO(M): mr5-8 [ 0xff000010 ]
DDRINFO(T): mr5-8 [ 0xff000010 ]
Normal Boot
WDT: Not starting
Trying to boot from MMC2

NOTICE:  BL31: v2.5(release):v2.5
NOTICE:  BL31: Built : 07:12:44, Jan 24 2022

Improve the boot time by retrieving the correct DDR information from the EEPROM:
U-Boot SPL 2022.04-rc4-00045-g6d02bc40d58c (Mar 19 2022 - 08:22:29 -0300) DDRINFO(D): Kingston 4096G
DDRINFO(M): mr5-8 [ 0xff000010 ]
DDRINFO(E): mr5-8 [ 0xff000010 ]
Normal Boot
WDT: Started watchdog@30280000 with servicing (60s timeout)
Trying to boot from MMC2

Quoted 5 lines
NOTICE:  BL31: v2.5(release):v2.5
NOTICE:  BL31: Built : 22:28:11, Mar 15 2022

Based on the original code from Compulab's U-Boot. Tested on a imx8mm-cl-iot-gate board populated with 4GB of RAM.

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: [email protected]
=====================================================================
author reviewer
#3 lore raw

PATCH v2 3/5 imx8mm-cl-iot-gate: Retrieve the MAC address from EEPROM

In reply to Fabio Estevam

From: Fabio Estevam <[email protected]>

Currently the eth0 MAC address is randomly assigned.

Retrieve the MAC address from EEPROM.

---
Changes since v1:
- Also update imx8mm-cl-iot-gate-optee_defconfig to fix the build (Stefano).

 arch/arm/dts/imx8mm-cl-iot-gate.dts           | 12 ++++-
 .../imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c   | 51 +++++++++++++++++++
 configs/imx8mm-cl-iot-gate-optee_defconfig    |  2 +
 configs/imx8mm-cl-iot-gate_defconfig          |  2 +
 4 files changed, 66 insertions(+), 1 deletion(-)
arch/arm/dts/imx8mm-cl-iot-gate.dts +11 -1
index 62e8d0394933..425701204a0c 100644
@@ -17,6 +17,11 @@
 		stdout-path = &uart3;
 	};
 
+	aliases {
+		eeprom0 = &i2c_eeprom0;
+		eeprom1 = &i2c_eeprom1;
+	};
+
 	reg_vusb_5v: regulator-usdhc2 {
 		compatible = "regulator-fixed";
 		regulator-name = "VUSB_5V";
@@ -79,7 +84,7 @@
 	pinctrl-0 = <&pinctrl_i2c1>;
 	status = "okay";
 
-	eeprom@54 {
+	i2c_eeprom0: eeprom@54 {
 		  compatible = "atmel,24c08";
 		  reg = <0x54>;
 		  pagesize = <16>;
@@ -92,6 +97,11 @@
 	pinctrl-0 = <&pinctrl_i2c2>;
 	status = "okay";
 
+	i2c_eeprom1: eeprom@50 {
+		  compatible = "atmel,24c08";
+		  reg = <0x50>;
+		  pagesize = <16>;
+	};
 	rtc@69 {
 		compatible = "abracon,ab1805";
 		reg = <0x69>;
board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c +51 -0

69 lines not on this page · raw message

configs/imx8mm-cl-iot-gate-optee_defconfig +2 -0
index 2014509ed52d..c736fd84d91c 100644
@@ -84,6 +84,8 @@ CONFIG_FASTBOOT_FLASH_MMC_DEV=2
 CONFIG_MXC_GPIO=y
 CONFIG_DM_I2C=y
 CONFIG_DM_KEYBOARD=y
+CONFIG_MISC=y
+CONFIG_I2C_EEPROM=y
 CONFIG_SUPPORT_EMMC_RPMB=y
 CONFIG_SUPPORT_EMMC_BOOT=y
 CONFIG_FSL_USDHC=y
configs/imx8mm-cl-iot-gate_defconfig +2 -0
index 0ef9e2548e99..9265299e98f9 100644
@@ -85,6 +85,8 @@ CONFIG_FASTBOOT_FLASH_MMC_DEV=2
 CONFIG_MXC_GPIO=y
 CONFIG_DM_I2C=y
 CONFIG_DM_KEYBOARD=y
+CONFIG_MISC=y
+CONFIG_I2C_EEPROM=y
 CONFIG_SUPPORT_EMMC_RPMB=y
 CONFIG_SUPPORT_EMMC_BOOT=y
 CONFIG_FSL_USDHC=y
Signature · 1 line
2.25.1
#4 lore raw

PATCH v2 3/5 imx8mm-cl-iot-gate: Retrieve the MAC address from EEPROM

Quoted 4 lines

From: Fabio Estevam <[email protected]> Currently the eth0 MAC address is randomly assigned. Retrieve the MAC address from EEPROM.

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: [email protected]
=====================================================================
author reviewer
#5 lore raw

PATCH v2 4/5 imx8mm-cl-iot-gate: Retrieve the serial number from EEPROM

In reply to Fabio Estevam

From: Fabio Estevam <[email protected]>

The serial number is located at offset 0x14 of the EEPROM under i2c0 bus at address 0x54.

To print the serial number in Linux:

SERNUM=$(cat /proc/device-tree/serial-number)
echo $SERNUM

---
Changes since v1:
- None

 .../imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c   | 50 +++++++++++++++++++
 1 file changed, 50 insertions(+)
board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c +50 -0
index 779b64b140ad..27200f728efe 100644
@@ -463,6 +463,52 @@ static int setup_mac_address(void)
 	return 0;
 }
 
+static int read_serial_number(void)
+{
+	unsigned char serialnumber[6];
+	unsigned char reversed[6];
+	char serial_string[12];
+	struct udevice *dev;
+	int ret, off, i;
+
+	off = fdt_path_offset(gd->fdt_blob, "eeprom0");
+	if (off < 0) {
+		printf("No eeprom0 path offset found in DT\n");
+		return off;
+	}
+
+	ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev);
+	if (ret) {
+		printf("%s: Could not find EEPROM\n", __func__);
+		return ret;
+	}
+
+	ret = i2c_set_chip_offset_len(dev, 1);
+	if (ret)
+		return ret;
+
+	ret = i2c_eeprom_read(dev, 0x14, serialnumber, sizeof(serialnumber));
+	if (ret) {
+		printf("%s: Could not read EEPROM\n", __func__);
+		return ret;
+	}
+
+	for (i = sizeof(serialnumber) - 1; i >= 0; i--)
+		reversed[i] = serialnumber[sizeof(serialnumber) - 1 - i];
+
+	for (i = 0; i < sizeof(reversed); i++) {
+		serial_string[i * 2] = (reversed[i] >> 4) & 0xf;
+		serial_string[i * 2 + 1] = reversed[i] & 0xf;
+	}
+
+	for (i = 0; i < sizeof(serial_string); i++)
+		serial_string[i] += '0';
+
+	env_set("serial#", serial_string);
+
+	return 0;
+}
+
 int board_late_init(void)
 {
 	int ret;
@@ -476,5 +522,9 @@ int board_late_init(void)
 	if (ret < 0)
 		printf("Cannot set MAC address from EEPROM\n");
 
+	ret = read_serial_number();
+	if (ret < 0)
+		printf("Cannot read serial number from EEPROM\n");
+
 	return 0;
 }
Signature · 1 line
2.25.1
#6 lore raw

PATCH v2 4/5 imx8mm-cl-iot-gate: Retrieve the serial number from EEPROM

Quoted 7 lines

From: Fabio Estevam <[email protected]>
The serial number is located at offset 0x14 of the EEPROM under i2c0 bus at address 0x54.
To print the serial number in Linux:
SERNUM=$(cat /proc/device-tree/serial-number) echo $SERNUM

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: [email protected]
=====================================================================
author reviewer
#7 lore raw

PATCH v2 5/5 imx8mm-cl-iot-gate: Add redundand environment support

In reply to Fabio Estevam

From: Fabio Estevam <[email protected]>

Add redundand environment support as it is required by SWUpdate.

While at it, also adjust the CONFIG_ENV_OFFSET to a more appropriate larger offset as done on other i.MX8M defconfigs.

---
Changes since v1:
- None

 configs/imx8mm-cl-iot-gate_defconfig | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
configs/imx8mm-cl-iot-gate_defconfig +3 -1
index 9265299e98f9..c9946cacef11 100644
@@ -8,7 +8,9 @@ CONFIG_SPL_GPIO=y
 CONFIG_SPL_LIBCOMMON_SUPPORT=y
 CONFIG_SPL_LIBGENERIC_SUPPORT=y
 CONFIG_ENV_SIZE=0x4000
-CONFIG_ENV_OFFSET=0x4400
+CONFIG_ENV_OFFSET=0x200000
+CONFIG_ENV_OFFSET_REDUND=0x204000
+CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
 CONFIG_DM_GPIO=y
 CONFIG_DEFAULT_DEVICE_TREE="imx8mm-cl-iot-gate"
 CONFIG_SPL_TEXT_BASE=0x7E1000
Signature · 1 line
2.25.1
#8 lore raw

PATCH v2 5/5 imx8mm-cl-iot-gate: Add redundand environment support

Quoted 6 lines

From: Fabio Estevam <[email protected]>
Add redundand environment support as it is required
by SWUpdate.
While at it, also adjust the CONFIG_ENV_OFFSET to a more appropriate larger offset as done on other i.MX8M defconfigs.

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: [email protected]
=====================================================================
#9 lore raw

PATCH v2 1/5 imx8mm-cl-iot-gate: Add SPL EEPROM support

In reply to Fabio Estevam
Quoted 6 lines

From: Fabio Estevam <[email protected]> imx8mm-cl-iot-gate supports multiple DDR sizes and models. The DDR type can be retrieved from the EEPROM, so add SPL code that can be used to get the DDR information.
Based on the original code from Compulab's U-Boot.

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: [email protected]
=====================================================================