All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tim Harvey <tharvey@gateworks.com>
To: u-boot@lists.denx.de
Subject: [PATCH 06/11] imx: ventana: convert U-Boot to OF_CONTROL using FIT image
Date: Mon,  1 Mar 2021 14:33:32 -0800	[thread overview]
Message-ID: <20210301223337.7763-7-tharvey@gateworks.com> (raw)
In-Reply-To: <20210301223337.7763-1-tharvey@gateworks.com>

In preparation for dm conversion convert to OF_CONTROL by adding FIT image
support and multi dtb.

Add a board_fit_config_name_match to match the dtb based off of EEPROM
model.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
---
 board/gateworks/gw_ventana/gsc.c            | 88 +++++++++++++++++++++
 board/gateworks/gw_ventana/gsc.h            |  1 +
 board/gateworks/gw_ventana/gw_ventana.c     | 20 ++++-
 board/gateworks/gw_ventana/gw_ventana_spl.c | 10 ++-
 configs/gwventana_emmc_defconfig            | 10 ++-
 configs/gwventana_gw5904_defconfig          | 10 ++-
 configs/gwventana_nand_defconfig            | 10 ++-
 7 files changed, 144 insertions(+), 5 deletions(-)

diff --git a/board/gateworks/gw_ventana/gsc.c b/board/gateworks/gw_ventana/gsc.c
index bcb6bca346..ffed6b5fc8 100644
--- a/board/gateworks/gw_ventana/gsc.c
+++ b/board/gateworks/gw_ventana/gsc.c
@@ -14,6 +14,8 @@
 #include <i2c.h>
 #include <linux/ctype.h>
 
+#include <asm/arch/sys_proto.h>
+
 #include "ventana_eeprom.h"
 #include "gsc.h"
 
@@ -179,6 +181,92 @@ int gsc_boot_wd_disable(void)
 	return 1;
 }
 
+/* determine BOM revision from model */
+int get_bom_rev(const char *str)
+{
+	int  rev_bom = 0;
+	int i;
+
+	for (i = strlen(str) - 1; i > 0; i--) {
+		if (str[i] == '-')
+			break;
+		if (str[i] >= '1' && str[i] <= '9') {
+			rev_bom = str[i] - '0';
+			break;
+		}
+	}
+	return rev_bom;
+}
+
+/* determine PCB revision from model */
+char get_pcb_rev(const char *str)
+{
+	char rev_pcb = 'A';
+	int i;
+
+	for (i = strlen(str) - 1; i > 0; i--) {
+		if (str[i] == '-')
+			break;
+		if (str[i] >= 'A') {
+			rev_pcb = str[i];
+			break;
+		}
+	}
+	return rev_pcb;
+}
+
+/*
+ * get dt name based on model and detail level:
+ */
+const char *gsc_get_dtb_name(int level, char *buf, int sz)
+{
+	const char *model = (const char *)ventana_info.model;
+	const char *pre = is_mx6dq() ? "imx6q-" : "imx6dl-";
+	int modelno, rev_pcb, rev_bom;
+
+	/* a few board models are dt equivalents to other models */
+	if (strncasecmp(model, "gw5906", 6) == 0)
+		model = "gw552x-d";
+	else if (strncasecmp(model, "gw5908", 6) == 0)
+		model = "gw53xx-f";
+	else if (strncasecmp(model, "gw5905", 6) == 0)
+		model = "gw5904-a";
+
+	modelno = ((model[2] - '0') * 1000)
+		  + ((model[3] - '0') * 100)
+		  + ((model[4] - '0') * 10)
+		  + (model[5] - '0');
+	rev_pcb = tolower(get_pcb_rev(model));
+	rev_bom = get_bom_rev(model);
+
+	/* compare model/rev/bom in order of most specific to least */
+	snprintf(buf, sz, "%s%04d", pre, modelno);
+	switch (level) {
+	case 0: /* full model first (ie gw5400-a1) */
+		if (rev_bom) {
+			snprintf(buf, sz, "%sgw%04d-%c%d", pre, modelno, rev_pcb, rev_bom);
+			break;
+		}
+		fallthrough;
+	case 1: /* don't care about bom rev (ie gw5400-a) */
+		snprintf(buf, sz, "%sgw%04d-%c", pre, modelno, rev_pcb);
+		break;
+	case 2: /* don't care about the pcb rev (ie gw5400) */
+		snprintf(buf, sz, "%sgw%04d", pre, modelno);
+		break;
+	case 3: /* look for generic model (ie gw540x) */
+		snprintf(buf, sz, "%sgw%03dx", pre, modelno / 10);
+		break;
+	case 4: /* look for more generic model (ie gw54xx) */
+		snprintf(buf, sz, "%sgw%02dxx", pre, modelno / 100);
+		break;
+	default: /* give up */
+		return NULL;
+	}
+
+	return buf;
+}
+
 #if defined(CONFIG_CMD_GSC) && !defined(CONFIG_SPL_BUILD)
 static int do_gsc_sleep(struct cmd_tbl *cmdtp, int flag, int argc,
 			char *const argv[])
diff --git a/board/gateworks/gw_ventana/gsc.h b/board/gateworks/gw_ventana/gsc.h
index 6dcaafadf3..29d375b3a7 100644
--- a/board/gateworks/gw_ventana/gsc.h
+++ b/board/gateworks/gw_ventana/gsc.h
@@ -67,5 +67,6 @@ int gsc_i2c_read(uchar chip, uint addr, int alen, uchar *buf, int len);
 int gsc_i2c_write(uchar chip, uint addr, int alen, uchar *buf, int len);
 int gsc_info(int verbose);
 int gsc_boot_wd_disable(void);
+const char *gsc_get_dtb_name(int level, char *buf, int sz);
 #endif
 
diff --git a/board/gateworks/gw_ventana/gw_ventana.c b/board/gateworks/gw_ventana/gw_ventana.c
index 9f043d815a..a310f9bbfe 100644
--- a/board/gateworks/gw_ventana/gw_ventana.c
+++ b/board/gateworks/gw_ventana/gw_ventana.c
@@ -55,7 +55,6 @@ DECLARE_GLOBAL_DATA_PTR;
  * read it once.
  */
 struct ventana_board_info ventana_info;
-
 static int board_type;
 
 /* ENET */
@@ -676,6 +675,25 @@ int board_init(void)
 	return 0;
 }
 
+int board_fit_config_name_match(const char *name)
+{
+	static char init;
+	const char *dtb;
+	char buf[32];
+	int i = 0;
+
+	do {
+		dtb = gsc_get_dtb_name(i++, buf, sizeof(buf));
+		if (dtb && !strcmp(dtb, name)) {
+			if (!init++)
+				printf("DTB:   %s\n", name);
+			return 0;
+		}
+	} while (dtb);
+
+	return -1;
+}
+
 #if defined(CONFIG_DISPLAY_BOARDINFO_LATE)
 /*
  * called during late init (after relocation and after board_init())
diff --git a/board/gateworks/gw_ventana/gw_ventana_spl.c b/board/gateworks/gw_ventana/gw_ventana_spl.c
index e0e4bac161..a4f64395a1 100644
--- a/board/gateworks/gw_ventana/gw_ventana_spl.c
+++ b/board/gateworks/gw_ventana/gw_ventana_spl.c
@@ -731,8 +731,16 @@ void board_boot_order(u32 *spl_boot_list)
 /* its our chance to print info about boot device */
 void spl_board_init(void)
 {
+	u32 boot_device;
+	int board_type;
+
 	/* determine boot device from SRC_SBMR1 (BOOT_CFG[4:1]) or SRC_GPR9 */
-	u32 boot_device = spl_boot_device();
+	boot_device = spl_boot_device();
+
+	/* read eeprom again now that we have gd */
+	board_type = read_eeprom(CONFIG_I2C_GSC, &ventana_info);
+	if (board_type == GW_UNKNOWN)
+		hang();
 
 	switch (boot_device) {
 	case BOOT_DEVICE_MMC1:
diff --git a/configs/gwventana_emmc_defconfig b/configs/gwventana_emmc_defconfig
index 41e190bf1e..453c80dd4c 100644
--- a/configs/gwventana_emmc_defconfig
+++ b/configs/gwventana_emmc_defconfig
@@ -18,8 +18,12 @@ CONFIG_SPL_STACK_R_ADDR=0x18000000
 CONFIG_SPL=y
 CONFIG_ENV_OFFSET_REDUND=0xD1400
 CONFIG_CMD_HDMIDETECT=y
+CONFIG_DEFAULT_DEVICE_TREE="imx6q-gw54xx"
 CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
+CONFIG_SPL_LOAD_FIT=y
+# CONFIG_USE_SPL_FIT_GENERATOR is not set
+# CONFIG_LEGACY_IMAGE_FORMAT is not set
 CONFIG_SUPPORT_RAW_INITRD=y
 CONFIG_OF_BOARD_SETUP=y
 CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=arch/arm/mach-imx/spl_sd.cfg"
@@ -31,6 +35,7 @@ CONFIG_BOARD_EARLY_INIT_F=y
 CONFIG_MISC_INIT_R=y
 CONFIG_SPL_BOARD_INIT=y
 CONFIG_SPL_STACK_R=y
+CONFIG_SPL_FIT_IMAGE_TINY=y
 CONFIG_SPL_DMA=y
 CONFIG_SPL_I2C_SUPPORT=y
 CONFIG_SPL_OS_BOOT=y
@@ -62,6 +67,9 @@ CONFIG_CMD_MTDPARTS=y
 CONFIG_MTDIDS_DEFAULT="nand0=nand"
 CONFIG_MTDPARTS_DEFAULT="mtdparts=nand:16m(uboot),1m(env),-(rootfs)"
 CONFIG_CMD_UBI=y
+CONFIG_OF_CONTROL=y
+CONFIG_OF_LIST="imx6q-gw51xx imx6dl-gw51xx imx6q-gw52xx imx6dl-gw52xx imx6q-gw53xx imx6dl-gw53xx imx6q-gw54xx imx6dl-gw54xx imx6q-gw551x imx6dl-gw551x imx6q-gw552x imx6dl-gw552x imx6q-gw553x imx6dl-gw553x imx6q-gw560x imx6dl-gw560x imx6q-gw5903 imx6dl-gw5903 imx6q-gw5904 imx6dl-gw5904 imx6q-gw5907 imx6dl-gw5907 imx6q-gw5910 imx6dl-gw5910 imx6q-gw5912 imx6dl-gw5912 imx6q-gw5913 imx6dl-gw5913"
+CONFIG_MULTI_DTB_FIT=y
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_MMC=y
 CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
@@ -79,6 +87,7 @@ CONFIG_PHYLIB=y
 CONFIG_E1000=y
 CONFIG_MII=y
 CONFIG_PCI=y
+CONFIG_CONS_INDEX=2
 CONFIG_DM_SERIAL=y
 CONFIG_MXC_UART=y
 CONFIG_DM_THERMAL=y
@@ -107,5 +116,4 @@ CONFIG_DM_VIDEO=y
 CONFIG_SYS_WHITE_ON_BLACK=y
 # CONFIG_PANEL is not set
 CONFIG_VIDEO_IPUV3=y
-CONFIG_OF_LIBFDT=y
 CONFIG_FDT_FIXUP_PARTITIONS=y
diff --git a/configs/gwventana_gw5904_defconfig b/configs/gwventana_gw5904_defconfig
index 66b0441978..4dc636637f 100644
--- a/configs/gwventana_gw5904_defconfig
+++ b/configs/gwventana_gw5904_defconfig
@@ -18,8 +18,12 @@ CONFIG_SPL_STACK_R_ADDR=0x18000000
 CONFIG_SPL=y
 CONFIG_ENV_OFFSET_REDUND=0xD1400
 CONFIG_CMD_HDMIDETECT=y
+CONFIG_DEFAULT_DEVICE_TREE="imx6q-gw54xx"
 CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
+CONFIG_SPL_LOAD_FIT=y
+# CONFIG_USE_SPL_FIT_GENERATOR is not set
+# CONFIG_LEGACY_IMAGE_FORMAT is not set
 CONFIG_SUPPORT_RAW_INITRD=y
 CONFIG_OF_BOARD_SETUP=y
 CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=arch/arm/mach-imx/spl_sd.cfg"
@@ -31,6 +35,7 @@ CONFIG_BOARD_EARLY_INIT_F=y
 CONFIG_MISC_INIT_R=y
 CONFIG_SPL_BOARD_INIT=y
 CONFIG_SPL_STACK_R=y
+CONFIG_SPL_FIT_IMAGE_TINY=y
 CONFIG_SPL_DMA=y
 CONFIG_SPL_I2C_SUPPORT=y
 CONFIG_SPL_OS_BOOT=y
@@ -62,6 +67,9 @@ CONFIG_CMD_MTDPARTS=y
 CONFIG_MTDIDS_DEFAULT="nand0=nand"
 CONFIG_MTDPARTS_DEFAULT="mtdparts=nand:16m(uboot),1m(env),-(rootfs)"
 CONFIG_CMD_UBI=y
+CONFIG_OF_CONTROL=y
+CONFIG_OF_LIST="imx6q-gw51xx imx6dl-gw51xx imx6q-gw52xx imx6dl-gw52xx imx6q-gw53xx imx6dl-gw53xx imx6q-gw54xx imx6dl-gw54xx imx6q-gw551x imx6dl-gw551x imx6q-gw552x imx6dl-gw552x imx6q-gw553x imx6dl-gw553x imx6q-gw560x imx6dl-gw560x imx6q-gw5903 imx6dl-gw5903 imx6q-gw5904 imx6dl-gw5904 imx6q-gw5907 imx6dl-gw5907 imx6q-gw5910 imx6dl-gw5910 imx6q-gw5912 imx6dl-gw5912 imx6q-gw5913 imx6dl-gw5913"
+CONFIG_MULTI_DTB_FIT=y
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_MMC=y
 CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
@@ -83,6 +91,7 @@ CONFIG_MV88E61XX_FIXED_PORTS=0x0
 CONFIG_E1000=y
 CONFIG_MII=y
 CONFIG_PCI=y
+CONFIG_CONS_INDEX=2
 CONFIG_DM_SERIAL=y
 CONFIG_MXC_UART=y
 CONFIG_DM_THERMAL=y
@@ -111,5 +120,4 @@ CONFIG_DM_VIDEO=y
 CONFIG_SYS_WHITE_ON_BLACK=y
 # CONFIG_PANEL is not set
 CONFIG_VIDEO_IPUV3=y
-CONFIG_OF_LIBFDT=y
 CONFIG_FDT_FIXUP_PARTITIONS=y
diff --git a/configs/gwventana_nand_defconfig b/configs/gwventana_nand_defconfig
index 9022f350d1..bd84340308 100644
--- a/configs/gwventana_nand_defconfig
+++ b/configs/gwventana_nand_defconfig
@@ -18,8 +18,12 @@ CONFIG_SPL_STACK_R_ADDR=0x18000000
 CONFIG_SPL=y
 CONFIG_ENV_OFFSET_REDUND=0x1080000
 CONFIG_CMD_HDMIDETECT=y
+CONFIG_DEFAULT_DEVICE_TREE="imx6q-gw54xx"
 CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
+CONFIG_SPL_LOAD_FIT=y
+# CONFIG_USE_SPL_FIT_GENERATOR is not set
+# CONFIG_LEGACY_IMAGE_FORMAT is not set
 CONFIG_SUPPORT_RAW_INITRD=y
 CONFIG_OF_BOARD_SETUP=y
 CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=arch/arm/mach-imx/spl_sd.cfg"
@@ -31,6 +35,7 @@ CONFIG_BOARD_EARLY_INIT_F=y
 CONFIG_MISC_INIT_R=y
 CONFIG_SPL_BOARD_INIT=y
 CONFIG_SPL_STACK_R=y
+CONFIG_SPL_FIT_IMAGE_TINY=y
 CONFIG_SPL_DMA=y
 CONFIG_SPL_I2C_SUPPORT=y
 CONFIG_SPL_NAND_SUPPORT=y
@@ -65,6 +70,9 @@ CONFIG_CMD_MTDPARTS=y
 CONFIG_MTDIDS_DEFAULT="nand0=nand"
 CONFIG_MTDPARTS_DEFAULT="mtdparts=nand:16m(uboot),1m(env),-(rootfs)"
 CONFIG_CMD_UBI=y
+CONFIG_OF_CONTROL=y
+CONFIG_OF_LIST="imx6q-gw51xx imx6dl-gw51xx imx6q-gw52xx imx6dl-gw52xx imx6q-gw53xx imx6dl-gw53xx imx6q-gw54xx imx6dl-gw54xx imx6q-gw551x imx6dl-gw551x imx6q-gw552x imx6dl-gw552x imx6q-gw553x imx6dl-gw553x imx6q-gw560x imx6dl-gw560x imx6q-gw5903 imx6dl-gw5903 imx6q-gw5904 imx6dl-gw5904 imx6q-gw5907 imx6dl-gw5907 imx6q-gw5910 imx6dl-gw5910 imx6q-gw5912 imx6dl-gw5912 imx6q-gw5913 imx6dl-gw5913"
+CONFIG_MULTI_DTB_FIT=y
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_NAND=y
 CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
@@ -83,6 +91,7 @@ CONFIG_PHYLIB=y
 CONFIG_E1000=y
 CONFIG_MII=y
 CONFIG_PCI=y
+CONFIG_CONS_INDEX=2
 CONFIG_DM_SERIAL=y
 CONFIG_MXC_UART=y
 CONFIG_DM_THERMAL=y
@@ -111,5 +120,4 @@ CONFIG_DM_VIDEO=y
 CONFIG_SYS_WHITE_ON_BLACK=y
 # CONFIG_PANEL is not set
 CONFIG_VIDEO_IPUV3=y
-CONFIG_OF_LIBFDT=y
 CONFIG_FDT_FIXUP_PARTITIONS=y
-- 
2.17.1

  parent reply	other threads:[~2021-03-01 22:33 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-01 22:33 [PATCH 00/11] imx: ventana: convert Gateworks Ventana to dm Tim Harvey
2021-03-01 22:33 ` [PATCH 01/11] spl: fit: nand: skip bad block handling if NAND chip not fully defined Tim Harvey
2021-03-02 13:28   ` Tom Rini
2021-04-08 20:57   ` sbabic at denx.de
2021-03-01 22:33 ` [PATCH 02/11] spl: fit: nand: allow for non-page-aligned elements Tim Harvey
2021-03-02 13:28   ` Tom Rini
2021-04-08 20:58   ` sbabic at denx.de
2021-03-01 22:33 ` [PATCH 03/11] dt-bindings: add tda1997x and bindings Tim Harvey
2021-03-02 13:28   ` Tom Rini
2021-04-08 20:57   ` sbabic at denx.de
2021-03-01 22:33 ` [PATCH 04/11] imx: ventana: add Gateworks Ventana dts Tim Harvey
2021-04-08 20:57   ` sbabic at denx.de
2021-03-01 22:33 ` [PATCH 05/11] arm: dts: imx6qdl-gw*: add dr_mode prop to dt to avoid error Tim Harvey
2021-04-05 21:27   ` Peter Robinson
2021-04-05 23:46     ` Tim Harvey
2021-04-08 20:57   ` sbabic at denx.de
2021-03-01 22:33 ` Tim Harvey [this message]
2021-04-08 20:57   ` [PATCH 06/11] imx: ventana: convert U-Boot to OF_CONTROL using FIT image sbabic at denx.de
     [not found]   ` <606f6e37.1c69fb81.a6d7.559aSMTPIN_ADDED_MISSING@mx.google.com>
2021-04-09 19:52     ` Tim Harvey
2021-04-09 20:00       ` Stefano Babic
2021-04-09 20:08         ` Tim Harvey
2021-04-09 20:14           ` Tim Harvey
2021-04-10  0:32             ` Tim Harvey
2021-03-01 22:33 ` [PATCH 07/11] imx: ventana: add pinctrl and remove unneeded UART init and config Tim Harvey
2021-04-08 20:57   ` sbabic at denx.de
2021-03-01 22:33 ` [PATCH 08/11] imx: ventana: enable dm support for USB Tim Harvey
2021-04-08 20:59   ` sbabic at denx.de
2021-03-01 22:33 ` [PATCH 09/11] imx: ventana: enable dm support for MMC and SATA Tim Harvey
2021-03-01 22:48   ` Peter Robinson
2021-03-02  0:19     ` Fabio Estevam
2021-03-02  1:41       ` Tim Harvey
2021-03-02 13:28         ` Tom Rini
2021-03-03  1:15     ` Kever Yang
2021-04-08 20:58   ` sbabic at denx.de
2021-03-01 22:33 ` [PATCH 10/11] imx: ventana: enable dm for MTD and NAND Tim Harvey
2021-04-08 20:59   ` sbabic at denx.de
2021-03-01 22:33 ` [PATCH 11/11] imx: ventana: enable dm for SPI Tim Harvey
2021-04-08 20:57   ` sbabic at denx.de
2021-03-25 13:59 ` [PATCH 00/11] imx: ventana: convert Gateworks Ventana to dm Tim Harvey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210301223337.7763-7-tharvey@gateworks.com \
    --to=tharvey@gateworks.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.