Skip to contentSkip to conversation

imx: Add a common way for detecting NXP boards revision

PATCH Superseded Fabio Estevam 3 participants 11 messages Nov 22, 2017 – Nov 27, 2017

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Fabio Estevam

author reviewer
#0 lore raw

PATCH 1/3 imx: Add a common way for detecting NXP boards revision

From: Fabio Estevam <[email protected]>

NXP development boards based on i.MX6/i.MX7 contain the board revision information stored in the fuses.

Introduce a common function that can be shared by different boards and convert mx6sabreauto to use this new mechanism.

---
 arch/arm/include/asm/mach-imx/sys_proto.h   |  3 ++
 arch/arm/mach-imx/Kconfig                   |  8 +++++
 arch/arm/mach-imx/cpu.c                     | 27 +++++++++++++++++
 board/freescale/mx6sabreauto/mx6sabreauto.c | 47 ++---------------------------
 configs/mx6sabreauto_defconfig              |  1 +
 5 files changed, 41 insertions(+), 45 deletions(-)
arch/arm/include/asm/mach-imx/sys_proto.h +3 -0
index 7036343..d5e3eec 100644
@@ -109,6 +109,9 @@ void imx_set_wdog_powerdown(bool enable);
 
 int board_mmc_get_env_dev(int devno);
 
+int nxp_board_rev(void);
+const char *nxp_board_rev_string(void);
+
 /*
  * Initializes on-chip ethernet controllers.
  * to override, implement board_eth_init()
arch/arm/mach-imx/Kconfig +8 -0
index cd8b8d2..81ab125 100644
@@ -61,3 +61,11 @@ config CMD_HDMIDETECT
 	help
 	  This enables the 'hdmidet' command which detects if an HDMI monitor
 	  is connected.
+
+config NXP_BOARD_REVISION
+	bool "Read NXP board revision from fuses"
+	depends on ARCH_MX6 || ARCH_MX7
+	help
+	  NXP boards based on i.MX6/7 contain the board revision information
+	  stored in the fuses. Select this option if you want to be able to
+	  retrieve the board revision information.
arch/arm/mach-imx/cpu.c +27 -0
index 18205dc..84e829e 100644
@@ -323,3 +323,30 @@ void set_chipselect_size(int const cs_size)
 
 	writel(reg, &iomuxc_regs->gpr[1]);
 }
+
+#ifdef CONFIG_NXP_BOARD_REVISION
+int nxp_board_rev(void)
+{
+	/*
+	 * Get Board ID information from OCOTP_GP1[15:8]
+	 * RevA: 0x1
+	 * RevB: 0x2
+	 * RevC: 0x3
+	 */
+	struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
+	struct fuse_bank *bank = &ocotp->bank[4];
+	struct fuse_bank4_regs *fuse =
+			(struct fuse_bank4_regs *)bank->fuse_regs;
+
+	return (readl(&fuse->gp1) >> 8 & 0x0F);
+}
+
+const char *nxp_board_rev_string(void)
+{
+	char *rev = "A" - 1;
+
+	rev += nxp_board_rev();
+
+	return rev;
+}
+#endif
board/freescale/mx6sabreauto/mx6sabreauto.c +2 -45

61 lines not on this page · raw message

configs/mx6sabreauto_defconfig +1 -0
index 418a836..215700b 100644
@@ -8,6 +8,7 @@ CONFIG_SPL_MMC_SUPPORT=y
 CONFIG_SPL_SERIAL_SUPPORT=y
 CONFIG_SPL_LIBDISK_SUPPORT=y
 CONFIG_SPL_WATCHDOG_SUPPORT=y
+CONFIG_NXP_BOARD_REVISION=y
 CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=arch/arm/mach-imx/spl_sd.cfg"
 # CONFIG_CONSOLE_MUX is not set
 CONFIG_SYS_CONSOLE_IS_IN_ENV=y
Signature · 1 line
2.7.4
author reviewer
#1 lore raw

PATCH 2/3 mx6sxsabresd: Load the correct dtb for revA board

From: Fabio Estevam <[email protected]>

Currently only imx6sx-sdb.dtb is loaded, but if revA board is used the correct dtb is imx6sx-sdb-reva.dtb, so make this possible.

While at it, remove an extra 'mmc dev'.

---
 arch/arm/mach-imx/mx6/Kconfig               |  1 +
 board/freescale/mx6sxsabresd/mx6sxsabresd.c | 16 +++++++++++++++-
 configs/mx6sxsabresd_defconfig              |  1 +
 include/configs/mx6sxsabresd.h              |  8 ++++++--
 4 files changed, 23 insertions(+), 3 deletions(-)
arch/arm/mach-imx/mx6/Kconfig +1 -0
index 6f5a92a..52d9984 100644
@@ -266,6 +266,7 @@ config TARGET_MX6SLLEVK
 
 config TARGET_MX6SXSABRESD
 	bool "mx6sxsabresd"
+	select BOARD_LATE_INIT
 	select MX6SX
 	select SUPPORT_SPL
 	select DM
board/freescale/mx6sxsabresd/mx6sxsabresd.c +15 -1
index 2aeef61..8a918a5 100644
@@ -540,9 +540,23 @@ int board_init(void)
 	return 0;
 }
 
+static bool is_reva(void)
+{
+	return (nxp_board_rev() == 1);
+}
+
+int board_late_init(void)
+{
+#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
+	if (is_reva())
+		env_set("board_rev", "REVA");
+#endif
+	return 0;
+}
+
 int checkboard(void)
 {
-	puts("Board: MX6SX SABRE SDB\n");
+	printf("Board: MX6SX SABRE SDB rev%s\n", nxp_board_rev_string());
 
 	return 0;
 }
configs/mx6sxsabresd_defconfig +1 -0
index c4eb7ca..ac36a18 100644
@@ -2,6 +2,7 @@ CONFIG_ARM=y
 CONFIG_ARCH_MX6=y
 CONFIG_TARGET_MX6SXSABRESD=y
 # CONFIG_CMD_BMODE is not set
+CONFIG_NXP_BOARD_REVISION=y
 CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/freescale/mx6sxsabresd/imximage.cfg"
 # CONFIG_CONSOLE_MUX is not set
 CONFIG_SYS_CONSOLE_IS_IN_ENV=y
include/configs/mx6sxsabresd.h +6 -2
index 5ef78a7..85b8601 100644
@@ -43,6 +43,7 @@
 #define UPDATE_M4_ENV ""
 #endif
 
+#define CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 #define CONFIG_EXTRA_ENV_SETTINGS \
 	UPDATE_M4_ENV \
 	"script=boot.scr\0" \
@@ -104,10 +105,13 @@
 			"fi; " \
 		"else " \
 			"bootz; " \
-		"fi;\0"
+		"fi;\0" \
+	"findfdt="\
+		"if test test $board_rev = REVA ; then " \
+			"setenv fdt_file imx6sx-sdb-reva.dtb; fi; " \
 
 #define CONFIG_BOOTCOMMAND \
-	   "mmc dev ${mmcdev};" \
+	   "run findfdt; " \
 	   "mmc dev ${mmcdev}; if mmc rescan; then " \
 		   "if run loadbootscript; then " \
 			   "run bootscript; " \
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/3 mx6sxsabresd: Load the correct dtb for revA board

Quoted 87 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

Currently only imx6sx-sdb.dtb is loaded, but if revA board is used the correct dtb is imx6sx-sdb-reva.dtb, so make this possible.

While at it, remove an extra 'mmc dev'.

---
 arch/arm/mach-imx/mx6/Kconfig               |  1 +
 board/freescale/mx6sxsabresd/mx6sxsabresd.c | 16 +++++++++++++++-
 configs/mx6sxsabresd_defconfig              |  1 +
 include/configs/mx6sxsabresd.h              |  8 ++++++--
 4 files changed, 23 insertions(+), 3 deletions(-)
arch/arm/mach-imx/mx6/Kconfig +1 -0
index 6f5a92a..52d9984 100644
@@ -266,6 +266,7 @@ config TARGET_MX6SLLEVK
 
 config TARGET_MX6SXSABRESD
 	bool "mx6sxsabresd"
+	select BOARD_LATE_INIT
 	select MX6SX
 	select SUPPORT_SPL
 	select DM
board/freescale/mx6sxsabresd/mx6sxsabresd.c +15 -1
index 2aeef61..8a918a5 100644
@@ -540,9 +540,23 @@ int board_init(void)
 	return 0;
 }
 
+static bool is_reva(void)
+{
+	return (nxp_board_rev() == 1);
+}
+
+int board_late_init(void)
+{
+#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
+	if (is_reva())
+		env_set("board_rev", "REVA");
+#endif
+	return 0;
+}
+
 int checkboard(void)
 {
-	puts("Board: MX6SX SABRE SDB\n");
+	printf("Board: MX6SX SABRE SDB rev%s\n", nxp_board_rev_string());
 
 	return 0;
 }
configs/mx6sxsabresd_defconfig +1 -0
index c4eb7ca..ac36a18 100644
@@ -2,6 +2,7 @@ CONFIG_ARM=y
 CONFIG_ARCH_MX6=y
 CONFIG_TARGET_MX6SXSABRESD=y
 # CONFIG_CMD_BMODE is not set
+CONFIG_NXP_BOARD_REVISION=y
 CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/freescale/mx6sxsabresd/imximage.cfg"
 # CONFIG_CONSOLE_MUX is not set
 CONFIG_SYS_CONSOLE_IS_IN_ENV=y
include/configs/mx6sxsabresd.h +2 -1
index 5ef78a7..85b8601 100644
@@ -43,6 +43,7 @@
 #define UPDATE_M4_ENV ""
 #endif
 
+#define CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 #define CONFIG_EXTRA_ENV_SETTINGS \
 	UPDATE_M4_ENV \
 	"script=boot.scr\0" \
@@ -104,10 +105,13 @@
 			"fi; " \
 		"else " \
 			"bootz; " \
-		"fi;\0"
+		"fi;\0" \

include/configs/mx6sxsabresd.h line 117

Quoted 10 lines
include/configs/mx6sxsabresd.h +4 -1
+	"findfdt="\
+		"if test test $board_rev = REVA ; then " \
+			"setenv fdt_file imx6sx-sdb-reva.dtb; fi; " \
 
 #define CONFIG_BOOTCOMMAND \
-	   "mmc dev ${mmcdev};" \
+	   "run findfdt; " \
 	   "mmc dev ${mmcdev}; if mmc rescan; then " \
 		   "if run loadbootscript; then " \
 			   "run bootscript; " \

Best regards,
Stefano

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: sbabic at denx.de
=====================================================================
#3 lore raw

PATCH 2/3 mx6sxsabresd: Load the correct dtb for revA board

In reply to Fabio Estevam
Quoted 86 lines · On Wed, 22 Nov 2017 11:15:27 -0200 Fabio Estevam <[email protected]> wrote:

From: Fabio Estevam <[email protected]>

Currently only imx6sx-sdb.dtb is loaded, but if revA board is used the correct dtb is imx6sx-sdb-reva.dtb, so make this possible.

While at it, remove an extra 'mmc dev'.

---
 arch/arm/mach-imx/mx6/Kconfig               |  1 +
 board/freescale/mx6sxsabresd/mx6sxsabresd.c | 16 +++++++++++++++-
 configs/mx6sxsabresd_defconfig              |  1 +
 include/configs/mx6sxsabresd.h              |  8 ++++++--
 4 files changed, 23 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/arch/arm/mach-imx/mx6/Kconfig index 6f5a92a..52d9984 100644

arch/arm/mach-imx/mx6/Kconfig +1 -0
@@ -266,6 +266,7 @@ config TARGET_MX6SLLEVK
 
 config TARGET_MX6SXSABRESD
 	bool "mx6sxsabresd"
+	select BOARD_LATE_INIT
 	select MX6SX
 	select SUPPORT_SPL
 	select DM
(quoted diff) +0 -0

b/board/freescale/mx6sxsabresd/mx6sxsabresd.c index 2aeef61..8a918a5 100644 --- a/board/freescale/mx6sxsabresd/mx6sxsabresd.c +++ b/board/freescale/mx6sxsabresd/mx6sxsabresd.c

board/freescale/mx6sxsabresd/mx6sxsabresd.c +15 -1
@@ -540,9 +540,23 @@ int board_init(void)
 	return 0;
 }
 
+static bool is_reva(void)
+{
+	return (nxp_board_rev() == 1);
+}
+
+int board_late_init(void)
+{
+#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
+	if (is_reva())
+		env_set("board_rev", "REVA");
+#endif
+	return 0;
+}
+
 int checkboard(void)
 {
-	puts("Board: MX6SX SABRE SDB\n");
+	printf("Board: MX6SX SABRE SDB rev%s\n",
 nxp_board_rev_string()); 
 	return 0;
 }
(quoted diff) +0 -0

b/configs/mx6sxsabresd_defconfig index c4eb7ca..ac36a18 100644

configs/mx6sxsabresd_defconfig +1 -0
@@ -2,6 +2,7 @@ CONFIG_ARM=y
 CONFIG_ARCH_MX6=y
 CONFIG_TARGET_MX6SXSABRESD=y
 # CONFIG_CMD_BMODE is not set
+CONFIG_NXP_BOARD_REVISION=y
 CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/freescale/mx6sxsabresd/imximage.cfg"
 # CONFIG_CONSOLE_MUX is not set
 CONFIG_SYS_CONSOLE_IS_IN_ENV=y
(quoted diff) +0 -0

b/include/configs/mx6sxsabresd.h index 5ef78a7..85b8601 100644

include/configs/mx6sxsabresd.h +2 -1
@@ -43,6 +43,7 @@
 #define UPDATE_M4_ENV ""
 #endif
 
+#define CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 #define CONFIG_EXTRA_ENV_SETTINGS \
 	UPDATE_M4_ENV \
 	"script=boot.scr\0" \
@@ -104,10 +105,13 @@
 			"fi; " \
 		"else " \
 			"bootz; " \
-		"fi;\0"
+		"fi;\0" \

include/configs/mx6sxsabresd.h line 117

Quoted 10 lines
include/configs/mx6sxsabresd.h +4 -1
+	"findfdt="\
+		"if test test $board_rev = REVA ; then " \
+			"setenv fdt_file imx6sx-sdb-reva.dtb; fi; " \
 
 #define CONFIG_BOOTCOMMAND \
-	   "mmc dev ${mmcdev};" \
+	   "run findfdt; " \
 	   "mmc dev ${mmcdev}; if mmc rescan; then " \
 		   "if run loadbootscript; then " \
 			   "run bootscript; " \

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171123/d58dc009/attachment.sig>

author reviewer
#4 lore raw

PATCH 3/3 mx6sxsabresd: Use PARTUUID to specify the rootfs location

In reply to Fabio Estevam

From: Fabio Estevam <[email protected]>

mx6sxsabresd can run different kernel versions, such as NXP 4.1 or mainline.

Currently the rootfs location is passed via mmcblk number and the problem with this approach is that the mmcblk number for the SD card changes depending on the kernel version.

In order to avoid such issue, use the UUID method to specify the rootfs location.

---
 configs/mx6sxsabresd_defconfig | 1 +
 include/configs/mx6sxsabresd.h | 5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)
configs/mx6sxsabresd_defconfig +1 -0
index ac36a18..b707322 100644
@@ -12,6 +12,7 @@ CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_MMC=y
+CONFIG_CMD_PART=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_USB=y
 # CONFIG_CMD_SETEXPR is not set
include/configs/mx6sxsabresd.h +3 -2
index 85b8601..906e677 100644
@@ -58,9 +58,9 @@
 	"videomode=video=ctfb:x:800,y:480,depth:24,pclk:29850,le:89,ri:164,up:23,lo:10,hs:10,vs:10,sync:0,vmode:0\0" \
 	"mmcdev=2\0" \
 	"mmcpart=1\0" \
-	"mmcroot=/dev/mmcblk0p2 rootwait rw\0" \
+	"finduuid=part uuid mmc 2:2 uuid\0" \
 	"mmcargs=setenv bootargs console=${console},${baudrate} " \
-		"root=${mmcroot}\0" \
+		"root=PARTUUID=${uuid} rootwait rw\0" \
 	"loadbootscript=" \
 		"fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${script};\0" \
 	"bootscript=echo Running bootscript from mmc ...; " \
@@ -68,6 +68,7 @@
 	"loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${image}\0" \
 	"loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr} ${fdt_file}\0" \
 	"mmcboot=echo Booting from mmc ...; " \
+		"run finduuid; " \
 		"run mmcargs; " \
 		"if test ${boot_fdt} = yes || test ${boot_fdt} = try; then " \
 			"if run loadfdt; then " \
Signature · 1 line
2.7.4
#5 lore raw

PATCH 3/3 mx6sxsabresd: Use PARTUUID to specify the rootfs location

Quoted 47 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

mx6sxsabresd can run different kernel versions, such as NXP 4.1 or mainline.

Currently the rootfs location is passed via mmcblk number and the problem with this approach is that the mmcblk number for the SD card changes depending on the kernel version.

In order to avoid such issue, use the UUID method to specify the rootfs location.

---
 configs/mx6sxsabresd_defconfig | 1 +
 include/configs/mx6sxsabresd.h | 5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)
configs/mx6sxsabresd_defconfig +1 -0
index ac36a18..b707322 100644
@@ -12,6 +12,7 @@ CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_MMC=y
+CONFIG_CMD_PART=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_USB=y
 # CONFIG_CMD_SETEXPR is not set
include/configs/mx6sxsabresd.h +2 -2
index 85b8601..906e677 100644
@@ -58,9 +58,9 @@
 	"videomode=video=ctfb:x:800,y:480,depth:24,pclk:29850,le:89,ri:164,up:23,lo:10,hs:10,vs:10,sync:0,vmode:0\0" \
 	"mmcdev=2\0" \
 	"mmcpart=1\0" \
-	"mmcroot=/dev/mmcblk0p2 rootwait rw\0" \
+	"finduuid=part uuid mmc 2:2 uuid\0" \
 	"mmcargs=setenv bootargs console=${console},${baudrate} " \
-		"root=${mmcroot}\0" \
+		"root=PARTUUID=${uuid} rootwait rw\0" \
 	"loadbootscript=" \
 		"fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${script};\0" \
 	"bootscript=echo Running bootscript from mmc ...; " \

include/configs/mx6sxsabresd.h line 74

Quoted 7 lines
include/configs/mx6sxsabresd.h +1 -0
@@ -68,6 +68,7 @@
 	"loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${image}\0" \
 	"loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr} ${fdt_file}\0" \
 	"mmcboot=echo Booting from mmc ...; " \
+		"run finduuid; " \
 		"run mmcargs; " \
 		"if test ${boot_fdt} = yes || test ${boot_fdt} = try; then " \
 			"if run loadfdt; then " \

Best regards,
Stefano

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: sbabic at denx.de
=====================================================================
#6 lore raw

PATCH 3/3 mx6sxsabresd: Use PARTUUID to specify the rootfs location

In reply to Fabio Estevam

Hi Fabio,

Quoted 46 lines

From: Fabio Estevam <[email protected]>

mx6sxsabresd can run different kernel versions, such as NXP 4.1 or mainline.
Currently the rootfs location is passed via mmcblk number and the problem with this approach is that the mmcblk number for the SD card changes depending on the kernel version.

In order to avoid such issue, use the UUID method to specify the rootfs location.

---
 configs/mx6sxsabresd_defconfig | 1 +
 include/configs/mx6sxsabresd.h | 5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/configs/mx6sxsabresd_defconfig index ac36a18..b707322 100644

configs/mx6sxsabresd_defconfig +1 -0
@@ -12,6 +12,7 @@ CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_MMC=y
+CONFIG_CMD_PART=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_USB=y
 # CONFIG_CMD_SETEXPR is not set
(quoted diff) +0 -0

b/include/configs/mx6sxsabresd.h index 85b8601..906e677 100644

include/configs/mx6sxsabresd.h +2 -2
@@ -58,9 +58,9 @@
 	"videomode=video=ctfb:x:800,y:480,depth:24,pclk:29850,le:89,ri:164,up:23,lo:10,hs:10,vs:10,sync:0,vmode:0\0"
 \ "mmcdev=2\0" \
 	"mmcpart=1\0" \
-	"mmcroot=/dev/mmcblk0p2 rootwait rw\0" \
+	"finduuid=part uuid mmc 2:2 uuid\0" \
 	"mmcargs=setenv bootargs console=${console},${baudrate} " \
-		"root=${mmcroot}\0" \
+		"root=PARTUUID=${uuid} rootwait rw\0" \
 	"loadbootscript=" \
 		"fatload mmc ${mmcdev}:${mmcpart} ${loadaddr}
 ${script};\0" \ "bootscript=echo Running bootscript from mmc ...; " \

include/configs/mx6sxsabresd.h line 74

Quoted 7 lines
include/configs/mx6sxsabresd.h +1 -0
@@ -68,6 +68,7 @@
 	"loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr}
 ${image}\0" \ "loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr}
 ${fdt_file}\0" \ "mmcboot=echo Booting from mmc ...; " \
+		"run finduuid; " \
 		"run mmcargs; " \
 		"if test ${boot_fdt} = yes || test ${boot_fdt} =
 try; then " \ "if run loadfdt; then " \

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171123/479f33a4/attachment.sig>

#7 lore raw

PATCH 1/3 imx: Add a common way for detecting NXP boards revision

In reply to Fabio Estevam

Hi Fabio,

Quoted 5 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

NXP development boards based on i.MX6/i.MX7 contain the board revision information stored in the fuses.

This is a good idea.

arch/arm/mach-imx/cpu.c

Quoted 46 lines

Introduce a common function that can be shared by different boards and convert mx6sabreauto to use this new mechanism.

---
 arch/arm/include/asm/mach-imx/sys_proto.h   |  3 ++
 arch/arm/mach-imx/Kconfig                   |  8 +++++
 arch/arm/mach-imx/cpu.c                     | 27 +++++++++++++++++
 board/freescale/mx6sabreauto/mx6sabreauto.c | 47 ++---------------------------
 configs/mx6sabreauto_defconfig              |  1 +
 5 files changed, 41 insertions(+), 45 deletions(-)
arch/arm/include/asm/mach-imx/sys_proto.h +3 -0
index 7036343..d5e3eec 100644
@@ -109,6 +109,9 @@ void imx_set_wdog_powerdown(bool enable);
 
 int board_mmc_get_env_dev(int devno);
 
+int nxp_board_rev(void);
+const char *nxp_board_rev_string(void);
+
 /*
  * Initializes on-chip ethernet controllers.
  * to override, implement board_eth_init()
arch/arm/mach-imx/Kconfig +8 -0
index cd8b8d2..81ab125 100644
@@ -61,3 +61,11 @@ config CMD_HDMIDETECT
 	help
 	  This enables the 'hdmidet' command which detects if an HDMI monitor
 	  is connected.
+
+config NXP_BOARD_REVISION
+	bool "Read NXP board revision from fuses"
+	depends on ARCH_MX6 || ARCH_MX7
+	help
+	  NXP boards based on i.MX6/7 contain the board revision information
+	  stored in the fuses. Select this option if you want to be able to
+	  retrieve the board revision information.
arch/arm/mach-imx/cpu.c +0 -0
index 18205dc..84e829e 100644

ACK. And maybe this can be used by other boards, too, instead of reinvent the wheel any time :-)

Quoted 104 lines
arch/arm/mach-imx/cpu.c +27 -0
@@ -323,3 +323,30 @@ void set_chipselect_size(int const cs_size)
 
 	writel(reg, &iomuxc_regs->gpr[1]);
 }
+
+#ifdef CONFIG_NXP_BOARD_REVISION
+int nxp_board_rev(void)
+{
+	/*
+	 * Get Board ID information from OCOTP_GP1[15:8]
+	 * RevA: 0x1
+	 * RevB: 0x2
+	 * RevC: 0x3
+	 */
+	struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
+	struct fuse_bank *bank = &ocotp->bank[4];
+	struct fuse_bank4_regs *fuse =
+			(struct fuse_bank4_regs *)bank->fuse_regs;
+
+	return (readl(&fuse->gp1) >> 8 & 0x0F);
+}
+
+const char *nxp_board_rev_string(void)
+{
+	char *rev = "A" - 1;
+
+	rev += nxp_board_rev();
+
+	return rev;
+}
+#endif
board/freescale/mx6sabreauto/mx6sabreauto.c +2 -45
index bdeb5f7..ced254a 100644
@@ -397,39 +397,9 @@ int board_eth_init(bd_t *bis)
 	return cpu_eth_init(bis);
 }
 
-#define BOARD_REV_B  0x200
-#define BOARD_REV_A  0x100
-
-static int mx6sabre_rev(void)
-{
-	/*
-	 * Get Board ID information from OCOTP_GP1[15:8]
-	 * i.MX6Q ARD RevA: 0x01
-	 * i.MX6Q ARD RevB: 0x02
-	 */
-	struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
-	struct fuse_bank *bank = &ocotp->bank[4];
-	struct fuse_bank4_regs *fuse =
-			(struct fuse_bank4_regs *)bank->fuse_regs;
-	int reg = readl(&fuse->gp1);
-	int ret;
-
-	switch (reg >> 8 & 0x0F) {
-	case 0x02:
-		ret = BOARD_REV_B;
-		break;
-	case 0x01:
-	default:
-		ret = BOARD_REV_A;
-		break;
-	}
-
-	return ret;
-}
-
 u32 get_board_rev(void)
 {
-	int rev = mx6sabre_rev();
+	int rev = nxp_board_rev();
 
 	return (get_cpu_rev() & ~(0xF << 8)) | rev;
 }
@@ -703,20 +673,7 @@ int board_late_init(void)
 
 int checkboard(void)
 {
-	int rev = mx6sabre_rev();
-	char *revname;
-
-	switch (rev) {
-	case BOARD_REV_B:
-		revname = "B";
-		break;
-	case BOARD_REV_A:
-	default:
-		revname = "A";
-		break;
-	}
-
-	printf("Board: MX6Q-Sabreauto rev%s\n", revname);
+	printf("Board: MX6Q-Sabreauto rev%s\n", nxp_board_rev_string());
 
 	return 0;
 }
configs/mx6sabreauto_defconfig +0 -0
index 418a836..215700b 100644

configs/mx6sabreauto_defconfig CONFIG_SPL_MMC_SUPPORT=y · line 14

Quoted 7 lines
configs/mx6sabreauto_defconfig +1 -0
@@ -8,6 +8,7 @@ CONFIG_SPL_MMC_SUPPORT=y
 CONFIG_SPL_SERIAL_SUPPORT=y
 CONFIG_SPL_LIBDISK_SUPPORT=y
 CONFIG_SPL_WATCHDOG_SUPPORT=y
+CONFIG_NXP_BOARD_REVISION=y
 CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=arch/arm/mach-imx/spl_sd.cfg"
 # CONFIG_CONSOLE_MUX is not set
 CONFIG_SYS_CONSOLE_IS_IN_ENV=y

Best regards,
Stefano

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: sbabic at denx.de
=====================================================================
#8 lore raw

PATCH 1/3 imx: Add a common way for detecting NXP boards revision

In reply to Fabio Estevam
Quoted 159 lines · On Wed, 22 Nov 2017 11:15:26 -0200 Fabio Estevam <[email protected]> wrote:

From: Fabio Estevam <[email protected]>

NXP development boards based on i.MX6/i.MX7 contain the board revision information stored in the fuses.

Introduce a common function that can be shared by different boards and convert mx6sabreauto to use this new mechanism.

---
 arch/arm/include/asm/mach-imx/sys_proto.h   |  3 ++
 arch/arm/mach-imx/Kconfig                   |  8 +++++
 arch/arm/mach-imx/cpu.c                     | 27 +++++++++++++++++
 board/freescale/mx6sabreauto/mx6sabreauto.c | 47

++---------------------------
configs/mx6sabreauto_defconfig | 1 + 5 files changed,
41 insertions(+), 45 deletions(-)

(quoted diff) +0 -0

b/arch/arm/include/asm/mach-imx/sys_proto.h index 7036343..d5e3eec 100644 --- a/arch/arm/include/asm/mach-imx/sys_proto.h +++ b/arch/arm/include/asm/mach-imx/sys_proto.h

arch/arm/include/asm/mach-imx/sys_proto.h +3 -0
@@ -109,6 +109,9 @@ void imx_set_wdog_powerdown(bool enable);
 
 int board_mmc_get_env_dev(int devno);
 
+int nxp_board_rev(void);
+const char *nxp_board_rev_string(void);
+
 /*
  * Initializes on-chip ethernet controllers.
  * to override, implement board_eth_init()
arch/arm/mach-imx/Kconfig +0 -0
index cd8b8d2..81ab125 100644
@@ -61,3 +61,11 @@ config CMD_HDMIDETECT
 	help
 	  This enables the 'hdmidet' command which detects if an

HDMI monitor is connected.

arch/arm/mach-imx/Kconfig +6 -0
+
+config NXP_BOARD_REVISION
+	bool "Read NXP board revision from fuses"
+	depends on ARCH_MX6 || ARCH_MX7
+	help
+	  NXP boards based on i.MX6/7 contain the board revision

information

arch/arm/mach-imx/Kconfig +1 -0
+	  stored in the fuses. Select this option if you want to be

able to

arch/arm/mach-imx/Kconfig +1 -0
+	  retrieve the board revision information.
arch/arm/mach-imx/cpu.c +11 -0
index 18205dc..84e829e 100644
@@ -323,3 +323,30 @@ void set_chipselect_size(int const cs_size)
 
 	writel(reg, &iomuxc_regs->gpr[1]);
 }
+
+#ifdef CONFIG_NXP_BOARD_REVISION
+int nxp_board_rev(void)
+{
+	/*
+	 * Get Board ID information from OCOTP_GP1[15:8]
+	 * RevA: 0x1
+	 * RevB: 0x2
+	 * RevC: 0x3
+	 */
+	struct ocotp_regs *ocotp = (struct ocotp_regs

*)OCOTP_BASE_ADDR;

arch/arm/mach-imx/cpu.c +16 -0
+	struct fuse_bank *bank = &ocotp->bank[4];
+	struct fuse_bank4_regs *fuse =
+			(struct fuse_bank4_regs *)bank->fuse_regs;
+
+	return (readl(&fuse->gp1) >> 8 & 0x0F);
+}
+
+const char *nxp_board_rev_string(void)
+{
+	char *rev = "A" - 1;
+
+	rev += nxp_board_rev();
+
+	return rev;
+}
+#endif
(quoted diff) +0 -0

b/board/freescale/mx6sabreauto/mx6sabreauto.c index bdeb5f7..ced254a 100644 --- a/board/freescale/mx6sabreauto/mx6sabreauto.c +++ b/board/freescale/mx6sabreauto/mx6sabreauto.c

board/freescale/mx6sabreauto/mx6sabreauto.c +1 -31
@@ -397,39 +397,9 @@ int board_eth_init(bd_t *bis)
 	return cpu_eth_init(bis);
 }
 
-#define BOARD_REV_B  0x200
-#define BOARD_REV_A  0x100
-
-static int mx6sabre_rev(void)
-{
-	/*
-	 * Get Board ID information from OCOTP_GP1[15:8]
-	 * i.MX6Q ARD RevA: 0x01
-	 * i.MX6Q ARD RevB: 0x02
-	 */
-	struct ocotp_regs *ocotp = (struct ocotp_regs
 *)OCOTP_BASE_ADDR;
-	struct fuse_bank *bank = &ocotp->bank[4];
-	struct fuse_bank4_regs *fuse =
-			(struct fuse_bank4_regs *)bank->fuse_regs;
-	int reg = readl(&fuse->gp1);
-	int ret;
-
-	switch (reg >> 8 & 0x0F) {
-	case 0x02:
-		ret = BOARD_REV_B;
-		break;
-	case 0x01:
-	default:
-		ret = BOARD_REV_A;
-		break;
-	}
-
-	return ret;
-}
-
 u32 get_board_rev(void)
 {
-	int rev = mx6sabre_rev();
+	int rev = nxp_board_rev();
 
 	return (get_cpu_rev() & ~(0xF << 8)) | rev;

}

board/freescale/mx6sabreauto/mx6sabreauto.c +1 -14
@@ -703,20 +673,7 @@ int board_late_init(void)
 
 int checkboard(void)
 {
-	int rev = mx6sabre_rev();
-	char *revname;
-
-	switch (rev) {
-	case BOARD_REV_B:
-		revname = "B";
-		break;
-	case BOARD_REV_A:
-	default:
-		revname = "A";
-		break;
-	}
-
-	printf("Board: MX6Q-Sabreauto rev%s\n", revname);
+	printf("Board: MX6Q-Sabreauto rev%s\n",
 nxp_board_rev_string()); 
 	return 0;
 }
(quoted diff) +0 -0

b/configs/mx6sabreauto_defconfig index 418a836..215700b 100644

configs/mx6sabreauto_defconfig CONFIG_SPL_MMC_SUPPORT=y · line 14

Quoted 7 lines
configs/mx6sabreauto_defconfig +1 -0
@@ -8,6 +8,7 @@ CONFIG_SPL_MMC_SUPPORT=y
 CONFIG_SPL_SERIAL_SUPPORT=y
 CONFIG_SPL_LIBDISK_SUPPORT=y
 CONFIG_SPL_WATCHDOG_SUPPORT=y
+CONFIG_NXP_BOARD_REVISION=y
 CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=arch/arm/mach-imx/spl_sd.cfg"
 # CONFIG_CONSOLE_MUX is not set
 CONFIG_SYS_CONSOLE_IS_IN_ENV=y

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171123/def0e992/attachment.sig>

#9 lore raw

PATCH 1/3 imx: Add a common way for detecting NXP boards revision

In reply to Fabio Estevam

Hi Fabio,

Quoted 68 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

NXP development boards based on i.MX6/i.MX7 contain the board revision information stored in the fuses.

Introduce a common function that can be shared by different boards and convert mx6sabreauto to use this new mechanism.

---
 arch/arm/include/asm/mach-imx/sys_proto.h   |  3 ++
 arch/arm/mach-imx/Kconfig                   |  8 +++++
 arch/arm/mach-imx/cpu.c                     | 27 +++++++++++++++++
 board/freescale/mx6sabreauto/mx6sabreauto.c | 47 ++---------------------------
 configs/mx6sabreauto_defconfig              |  1 +
 5 files changed, 41 insertions(+), 45 deletions(-)
arch/arm/include/asm/mach-imx/sys_proto.h +3 -0
index 7036343..d5e3eec 100644
@@ -109,6 +109,9 @@ void imx_set_wdog_powerdown(bool enable);
 
 int board_mmc_get_env_dev(int devno);
 
+int nxp_board_rev(void);
+const char *nxp_board_rev_string(void);
+
 /*
  * Initializes on-chip ethernet controllers.
  * to override, implement board_eth_init()
arch/arm/mach-imx/Kconfig +8 -0
index cd8b8d2..81ab125 100644
@@ -61,3 +61,11 @@ config CMD_HDMIDETECT
 	help
 	  This enables the 'hdmidet' command which detects if an HDMI monitor
 	  is connected.
+
+config NXP_BOARD_REVISION
+	bool "Read NXP board revision from fuses"
+	depends on ARCH_MX6 || ARCH_MX7
+	help
+	  NXP boards based on i.MX6/7 contain the board revision information
+	  stored in the fuses. Select this option if you want to be able to
+	  retrieve the board revision information.
arch/arm/mach-imx/cpu.c +13 -0
index 18205dc..84e829e 100644
@@ -323,3 +323,30 @@ void set_chipselect_size(int const cs_size)
 
 	writel(reg, &iomuxc_regs->gpr[1]);
 }
+
+#ifdef CONFIG_NXP_BOARD_REVISION
+int nxp_board_rev(void)
+{
+	/*
+	 * Get Board ID information from OCOTP_GP1[15:8]
+	 * RevA: 0x1
+	 * RevB: 0x2
+	 * RevC: 0x3
+	 */
+	struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
+	struct fuse_bank *bank = &ocotp->bank[4];
+	struct fuse_bank4_regs *fuse =

arch/arm/mach-imx/cpu.c void set_chipselect_size(int const cs_size) · line 348

Quoted 10 lines
arch/arm/mach-imx/cpu.c +10 -0
+			(struct fuse_bank4_regs *)bank->fuse_regs;
+
+	return (readl(&fuse->gp1) >> 8 & 0x0F);
+}
+
+const char *nxp_board_rev_string(void)
+{
+	char *rev = "A" - 1;
+
+	rev += nxp_board_rev();

I am applying this and I note this point. It looks like it does not do what you meant.

rev is a char pointer, it is set to a a fix string ("A", maybe rodata), and then the pointer is decreased to 1 (going to Nirvana ?).

Compiler is not happy, too, it notes that address is out of bounds.

I have also noted that mx6sxsabresd_spl_defconfig has not CONFIG_NXP_BOARD_REVISION set, and build is broken. Can you take a look and resend patch with fixes ?

Thanks,
Stefano

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: sbabic at denx.de
=====================================================================
author reviewer
#10 lore raw

PATCH 1/3 imx: Add a common way for detecting NXP boards revision

Hi Stefano,

Quoted 11 lines · Stefano Babic

I am applying this and I note this point. It looks like it does not do what you meant.

rev is a char pointer, it is set to a a fix string ("A", maybe rodata), and then the pointer is decreased to 1 (going to Nirvana ?).

Compiler is not happy, too, it notes that address is out of bounds.

I have also noted that mx6sxsabresd_spl_defconfig has not CONFIG_NXP_BOARD_REVISION set, and build is broken. Can you take a look and resend patch with fixes ?

I will fix and resend.

Thanks