[PATCH 08/10] board: ti: am62x: Add support for detecting multiple device trees

Nitin Yadav n-yadav at ti.com
Wed Apr 26 11:39:04 CEST 2023


Update the board_fit_config_name_match() to choose the right
dtb based on the board name read from EEPROM. Update the
board_fit_config_name_match() to choose the right dtb based
on the board name read from EEPROM. Also restrict multiple
EEPROM reads by verifying if EEPROM is already read.

Signed-off-by: Nitin Yadav <n-yadav at ti.com>
---
 board/ti/am62x/evm.c | 148 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 148 insertions(+)

diff --git a/board/ti/am62x/evm.c b/board/ti/am62x/evm.c
index cc8e31824b..8b3a57c464 100644
--- a/board/ti/am62x/evm.c
+++ b/board/ti/am62x/evm.c
@@ -12,14 +12,24 @@
 #include <video.h>
 #include <splash.h>
 #include <k3-ddrss.h>
+#include <common.h>
 #include <fdt_support.h>
 #include <asm/io.h>
 #include <asm/arch/hardware.h>
+#include <asm/arch/sysfw-loader.h>
 #include <asm/arch/sys_proto.h>
+#include <dm.h>
+#include <dm/uclass-internal.h>
 #include <dm/uclass.h>
+#include <dm/root.h>
+
+#include "../common/board_detect.h"
 
 DECLARE_GLOBAL_DATA_PTR;
 
+#define board_is_am62x_skevm()  board_ti_k3_is("AM62-SKEVM")
+#define board_is_am62x_lp_skevm()  board_ti_k3_is("AM62-LP-SKEVM")
+
 #ifdef CONFIG_SPLASH_SCREEN
 static struct splash_location default_splash_locations[] = {
 	{
@@ -52,6 +62,26 @@ int dram_init_banksize(void)
 	return fdtdec_setup_memory_banksize();
 }
 
+#ifdef CONFIG_SPL_LOAD_FIT
+int board_fit_config_name_match(const char *name)
+{
+	bool eeprom_read = board_ti_was_eeprom_read();
+
+	if (!eeprom_read)
+		return -1;
+
+	if (board_is_am62x_skevm()) {
+		if (!strcmp(name, "k3-am625-r5-sk") || !strcmp(name, "k3-am625-sk"))
+			return 0;
+
+	} else if (board_is_am62x_lp_skevm()) {
+		if (!strcmp(name, "k3-am62-r5-lp-sk") || !strcmp(name, "k3-am62-lp-sk"))
+			return 0;
+	}
+	return -1;
+}
+#endif
+
 #if defined(CONFIG_SPL_BUILD)
 #if defined(CONFIG_K3_AM64_DDRSS)
 static void fixup_ddr_driver_for_ecc(struct spl_image_info *spl_image)
@@ -103,11 +133,129 @@ void spl_perform_fixups(struct spl_image_info *spl_image)
 }
 #endif
 
+#ifdef CONFIG_TI_I2C_BOARD_DETECT
+int do_board_detect(void)
+{
+	int ret;
+
+	ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
+					 CONFIG_EEPROM_CHIP_ADDRESS);
+
+	if (ret) {
+		printf("EEPROM not available at %d, trying to read at %d\n",
+		       CONFIG_EEPROM_CHIP_ADDRESS, CONFIG_EEPROM_CHIP_ADDRESS + 1);
+		ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
+						 CONFIG_EEPROM_CHIP_ADDRESS + 1);
+		if (ret)
+			pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
+			       CONFIG_EEPROM_CHIP_ADDRESS + 1, ret);
+	}
+	return ret;
+}
+
+int checkboard(void)
+{
+	struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
+
+	if (!do_board_detect())
+		printf("Board: %s rev %s\n", ep->name, ep->version);
+
+	return 0;
+}
+#endif
+
+#ifdef CONFIG_BOARD_LATE_INIT
+static void setup_board_eeprom_env(void)
+{
+	char *name = "am62x_skevm";
+
+	if (do_board_detect())
+		goto invalid_eeprom;
+
+	if (board_is_am62x_skevm())
+		name = "am62x_skevm";
+	else if (board_is_am62x_lp_skevm())
+		name = "am62x_lp_skevm";
+	else
+		printf("Unidentified board claims %s in eeprom header\n",
+		       board_ti_get_name());
+
+invalid_eeprom:
+	set_board_info_env_am6(name);
+}
+
+static void setup_serial(void)
+{
+	struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
+	unsigned long board_serial;
+	char *endp;
+	char serial_string[17] = { 0 };
+
+	if (env_get("serial#"))
+		return;
+
+	board_serial = simple_strtoul(ep->serial, &endp, 16);
+	if (*endp != '\0') {
+		pr_err("Error: Can't set serial# to %s\n", ep->serial);
+		return;
+	}
+
+	snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
+	env_set("serial#", serial_string);
+}
+
+int board_late_init(void)
+{
+	if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) {
+		struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
+
+		setup_board_eeprom_env();
+		setup_serial();
+		/*
+		 * The first MAC address for ethernet a.k.a. ethernet0 comes from
+		 * efuse populated via the am654 gigabit eth switch subsystem driver.
+		 * All the other ones are populated via EEPROM, hence continue with
+		 * an index of 1.
+		 */
+		board_ti_am6_set_ethaddr(1, ep->mac_addr_cnt);
+	}
+
+	return 0;
+}
+#endif
+
+#if defined(CONFIG_SPL_OF_LIST) && defined(CONFIG_TI_I2C_BOARD_DETECT)
+void do_dt_magic(void)
+{
+	int ret, rescan;
+
+	if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT))
+		do_board_detect();
+
+	/*
+	 * Board detection has been done. Let us see if
+	 * another dtb would be a better match for our
+	 * board.
+	 */
+	if (IS_ENABLED(CONFIG_CPU_V7R)) {
+		ret = fdtdec_resetup(&rescan);
+
+		if (!ret && rescan) {
+			dm_uninit();
+			dm_init_and_scan(true);
+		}
+	}
+}
+#endif
+
 #ifdef CONFIG_SPL_BUILD
 void board_init_f(ulong dummy)
 {
 	k3_spl_init();
 
+#if defined(CONFIG_SPL_OF_LIST) && defined(CONFIG_TI_I2C_BOARD_DETECT)
+	do_dt_magic();
+#endif
 	k3_spl_post_dt_magic();
 
 	k3_mem_init();
-- 
2.25.1



More information about the U-Boot mailing list