All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2 0/6] toradex: config block handling
@ 2016-09-28  9:35 Marcel Ziswiler
  2016-09-28  9:35 ` [U-Boot] [PATCH v2 1/6] colibri_imx7/vf: move to custom checkboard_fallback() Marcel Ziswiler
                   ` (5 more replies)
  0 siblings, 6 replies; 18+ messages in thread
From: Marcel Ziswiler @ 2016-09-28  9:35 UTC (permalink / raw)
  To: u-boot


This series integrates Toradex factory configuration block handling. The
config block is a data structure which gets stored to flash during
production testing. The structure holds such information as board resp.
hardware revision, product ID and serial number which is used as the NIC
part of the Ethernet MAC address as well. The config block will be read
upon boot by the checkboard() function, displayed as part of the board
information and passed to Linux via device tree or ATAGs.

Changes in v2:
- fixed common.h include mess in board/toradex/common by renaming
  common* to tdx-common
- renamed TRDX to TDX and trdx to tdx as in common use internally
- consolidated makefiles and changed copyright message
- renamed configblock* to tdx-cfg-block* analogous to Kconfig symbols
- moved board/toradex/common/Kconfig sourcing from arch/arm/Kconfig
  into our own board Kconfig files
- use a named choice for the config block location for above to work
  without issuing any warnings (undocumented kbuild feature curtsey
  Arnaud Lacombe)
- added CUSTOM_BOARDINFO into our common Kconfig to avoid recent
  no_new_adhoc_configs_check error
- add Max' patch
  colibri_vf: usb gadget: toradex pid is now set generically

Marcel Ziswiler (5):
  colibri_imx7/vf: move to custom checkboard_fallback()
  apalis/colibri_t20/t30: deactivate displaying board info
  toradex: config block handling
  apalis/colibri_imx7/pxa270/t20/t30/vf: integrate config block handling
  apalis/colibri_t30: move environment location

Max Krummenacher (1):
  colibri_vf: usb gadget: toradex pid is now set generically

 board/toradex/apalis_t30/Kconfig              |  18 +
 board/toradex/apalis_t30/apalis_t30.c         |  12 +-
 board/toradex/colibri_imx7/Kconfig            |  16 +
 board/toradex/colibri_imx7/colibri_imx7.c     |   6 +-
 board/toradex/colibri_pxa270/Kconfig          |  11 +
 board/toradex/colibri_pxa270/colibri_pxa270.c |   8 +
 board/toradex/colibri_t20/Kconfig             |  11 +
 board/toradex/colibri_t20/colibri_t20.c       |  13 +
 board/toradex/colibri_t30/Kconfig             |  18 +
 board/toradex/colibri_t30/colibri_t30.c       |   9 +-
 board/toradex/colibri_vf/Kconfig              |  14 +
 board/toradex/colibri_vf/colibri_vf.c         |  24 +-
 board/toradex/common/Kconfig                  |  85 ++++
 board/toradex/common/Makefile                 |  11 +
 board/toradex/common/tdx-cfg-block.c          | 544 ++++++++++++++++++++++++++
 board/toradex/common/tdx-cfg-block.h          |  68 ++++
 board/toradex/common/tdx-common.c             | 180 +++++++++
 board/toradex/common/tdx-common.h             |  13 +
 include/configs/apalis_t30.h                  |  12 +-
 include/configs/colibri_imx7.h                |   6 +-
 include/configs/colibri_pxa270.h              |   7 +-
 include/configs/colibri_t20.h                 |   3 +-
 include/configs/colibri_t30.h                 |  12 +-
 include/configs/colibri_vf.h                  |  14 +-
 scripts/config_whitelist.txt                  |   5 -
 25 files changed, 1066 insertions(+), 54 deletions(-)
 create mode 100644 board/toradex/common/Kconfig
 create mode 100644 board/toradex/common/Makefile
 create mode 100644 board/toradex/common/tdx-cfg-block.c
 create mode 100644 board/toradex/common/tdx-cfg-block.h
 create mode 100644 board/toradex/common/tdx-common.c
 create mode 100644 board/toradex/common/tdx-common.h

-- 
2.5.5

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [U-Boot] [PATCH v2 1/6] colibri_imx7/vf: move to custom checkboard_fallback()
  2016-09-28  9:35 [U-Boot] [PATCH v2 0/6] toradex: config block handling Marcel Ziswiler
@ 2016-09-28  9:35 ` Marcel Ziswiler
  2016-09-28  9:35 ` [U-Boot] [PATCH v2 2/6] apalis/colibri_t20/t30: deactivate displaying board info Marcel Ziswiler
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 18+ messages in thread
From: Marcel Ziswiler @ 2016-09-28  9:35 UTC (permalink / raw)
  To: u-boot

Rename checkboard() to checkboard_fallback() in order to avoid a
name clash with our upcoming common implementation thereof.

Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
---

Changes in v2: None

 board/toradex/colibri_imx7/colibri_imx7.c | 6 +++---
 board/toradex/colibri_vf/colibri_vf.c     | 8 ++++----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/board/toradex/colibri_imx7/colibri_imx7.c b/board/toradex/colibri_imx7/colibri_imx7.c
index 8eedd65..73cd89c 100644
--- a/board/toradex/colibri_imx7/colibri_imx7.c
+++ b/board/toradex/colibri_imx7/colibri_imx7.c
@@ -377,10 +377,10 @@ int board_late_init(void)
 	return 0;
 }
 
-int checkboard(void)
+int checkboard_fallback(void)
 {
-	printf("Model: Toradex Colibri iMX7%c\n",
-	       is_cpu_type(MXC_CPU_MX7D) ? 'D' : 'S');
+	printf("Model: Toradex Colibri iMX7%s\n",
+	       is_cpu_type(MXC_CPU_MX7D) ? "D 512MB" : "S 256MB");
 
 	return 0;
 }
diff --git a/board/toradex/colibri_vf/colibri_vf.c b/board/toradex/colibri_vf/colibri_vf.c
index c65ccb3..c636a8e 100644
--- a/board/toradex/colibri_vf/colibri_vf.c
+++ b/board/toradex/colibri_vf/colibri_vf.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015 Toradex, Inc.
+ * Copyright 2015-2016 Toradex, Inc.
  *
  * Based on vf610twr.c:
  * Copyright 2013 Freescale Semiconductor, Inc.
@@ -518,12 +518,12 @@ int board_init(void)
 	return 0;
 }
 
-int checkboard(void)
+int checkboard_fallback(void)
 {
 	if (is_colibri_vf61())
-		puts("Board: Colibri VF61\n");
+		puts("Model: Toradex Colibri VF61 256MB\n");
 	else
-		puts("Board: Colibri VF50\n");
+		puts("Model: Toradex Colibri VF50 128MB\n");
 
 	return 0;
 }
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [U-Boot] [PATCH v2 2/6] apalis/colibri_t20/t30: deactivate displaying board info
  2016-09-28  9:35 [U-Boot] [PATCH v2 0/6] toradex: config block handling Marcel Ziswiler
  2016-09-28  9:35 ` [U-Boot] [PATCH v2 1/6] colibri_imx7/vf: move to custom checkboard_fallback() Marcel Ziswiler
@ 2016-09-28  9:35 ` Marcel Ziswiler
  2016-09-28 18:00   ` Stephen Warren
  2016-09-28  9:35 ` [U-Boot] [PATCH v2 3/6] toradex: config block handling Marcel Ziswiler
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 18+ messages in thread
From: Marcel Ziswiler @ 2016-09-28  9:35 UTC (permalink / raw)
  To: u-boot

Avoid a checkboard() name clash with our upcoming custom implementation
thereof.

Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
---

Changes in v2: None

 include/configs/apalis_t30.h  | 1 +
 include/configs/colibri_t20.h | 1 +
 include/configs/colibri_t30.h | 1 +
 3 files changed, 3 insertions(+)

diff --git a/include/configs/apalis_t30.h b/include/configs/apalis_t30.h
index 3fc1779..dc17733 100644
--- a/include/configs/apalis_t30.h
+++ b/include/configs/apalis_t30.h
@@ -17,6 +17,7 @@
 
 /* High-level configuration options */
 #define CONFIG_TEGRA_BOARD_STRING	"Toradex Apalis T30"
+#undef CONFIG_DISPLAY_BOARDINFO		/* As defined in tegra-common */
 
 /* Board-specific serial config */
 #define CONFIG_TEGRA_ENABLE_UARTA
diff --git a/include/configs/colibri_t20.h b/include/configs/colibri_t20.h
index b299e15..431fec0 100644
--- a/include/configs/colibri_t20.h
+++ b/include/configs/colibri_t20.h
@@ -15,6 +15,7 @@
 
 /* High-level configuration options */
 #define CONFIG_TEGRA_BOARD_STRING	"Toradex Colibri T20"
+#undef CONFIG_DISPLAY_BOARDINFO		/* As defined in tegra-common */
 
 /* Board-specific serial config */
 #define CONFIG_TEGRA_ENABLE_UARTA
diff --git a/include/configs/colibri_t30.h b/include/configs/colibri_t30.h
index e2a2549..d83c5a0 100644
--- a/include/configs/colibri_t30.h
+++ b/include/configs/colibri_t30.h
@@ -17,6 +17,7 @@
 
 /* High-level configuration options */
 #define CONFIG_TEGRA_BOARD_STRING	"Toradex Colibri T30"
+#undef CONFIG_DISPLAY_BOARDINFO		/* As defined in tegra-common */
 
 /* Board-specific serial config */
 #define CONFIG_TEGRA_ENABLE_UARTA
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [U-Boot] [PATCH v2 3/6] toradex: config block handling
  2016-09-28  9:35 [U-Boot] [PATCH v2 0/6] toradex: config block handling Marcel Ziswiler
  2016-09-28  9:35 ` [U-Boot] [PATCH v2 1/6] colibri_imx7/vf: move to custom checkboard_fallback() Marcel Ziswiler
  2016-09-28  9:35 ` [U-Boot] [PATCH v2 2/6] apalis/colibri_t20/t30: deactivate displaying board info Marcel Ziswiler
@ 2016-09-28  9:35 ` Marcel Ziswiler
  2016-09-30 22:28   ` Stefan Agner
  2016-09-28  9:35 ` [U-Boot] [PATCH v2 4/6] apalis/colibri_imx7/pxa270/t20/t30/vf: integrate " Marcel Ziswiler
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 18+ messages in thread
From: Marcel Ziswiler @ 2016-09-28  9:35 UTC (permalink / raw)
  To: u-boot

Add Toradex factory configuration block handling. The config block is a
data structure which gets stored to flash during production testing. The
structure holds such information as board resp. hardware revision,
product ID and serial number which is used as the NIC part of the
Ethernet MAC address as well. The config block will be read upon boot by
the checkboard() function, displayed as part of the board information
and passed to Linux via device tree or ATAGs.

Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
---

Changes in v2: None

 board/toradex/common/Kconfig         |  80 ++++++
 board/toradex/common/Makefile        |  11 +
 board/toradex/common/tdx-cfg-block.c | 544 +++++++++++++++++++++++++++++++++++
 board/toradex/common/tdx-cfg-block.h |  68 +++++
 board/toradex/common/tdx-common.c    | 180 ++++++++++++
 board/toradex/common/tdx-common.h    |  13 +
 6 files changed, 896 insertions(+)
 create mode 100644 board/toradex/common/Kconfig
 create mode 100644 board/toradex/common/Makefile
 create mode 100644 board/toradex/common/tdx-cfg-block.c
 create mode 100644 board/toradex/common/tdx-cfg-block.h
 create mode 100644 board/toradex/common/tdx-common.c
 create mode 100644 board/toradex/common/tdx-common.h

diff --git a/board/toradex/common/Kconfig b/board/toradex/common/Kconfig
new file mode 100644
index 0000000..e269875
--- /dev/null
+++ b/board/toradex/common/Kconfig
@@ -0,0 +1,80 @@
+# Copyright (c) 2016 Toradex, Inc.
+# SPDX-License-Identifier:	GPL-2.0+
+
+# Not from device tree model node
+config CUSTOM_BOARDINFO
+	bool
+
+menuconfig TDX_CFG_BLOCK
+	bool "Enable Toradex config block support"
+	select OF_BOARD_SETUP
+	help
+	  The Toradex config block stored production data on the on-module
+	  flash device (NAND, NOR or eMMC). The area is normally preserved by
+	  software and contains the serial number (out of which the MAC
+	  address is generated) and the exact module type.
+
+# Helper config to determine the correct default location of the cfg block
+config TDX_HAVE_MMC
+	bool
+
+config TDX_HAVE_NAND
+	bool
+
+config TDX_HAVE_NOR
+	bool
+
+if TDX_CFG_BLOCK
+
+choice TDX_CFG_BLOCK_LOCATION
+	prompt "Toradex config block location"
+	depends on TDX_CFG_BLOCK
+	default TDX_CFG_BLOCK_IS_IN_MMC if TDX_HAVE_MMC
+	default TDX_CFG_BLOCK_IS_IN_NAND if TDX_HAVE_NAND
+	default TDX_CFG_BLOCK_IS_IN_NOR if TDX_HAVE_NOR
+	help
+	  Configure the location of the Toradex config block. By default, the
+	  factory version of the Toradex config block is on the NAND, NOR or
+	  eMMC flash device on the module.
+
+config TDX_CFG_BLOCK_IS_IN_MMC
+	bool "Location of the config block is in eMMC"
+
+config TDX_CFG_BLOCK_IS_IN_NAND
+	bool "Location of the config block is in NAND"
+
+config TDX_CFG_BLOCK_IS_IN_NOR
+	bool "Location of the config block is in NOR"
+
+endchoice
+
+config TDX_CFG_BLOCK_DEV
+	int "Toradex config block eMMC device ID"
+	depends on TDX_CFG_BLOCK_IS_IN_MMC
+
+config TDX_CFG_BLOCK_PART
+	int "Toradex config block eMMC partition ID"
+	depends on TDX_CFG_BLOCK_IS_IN_MMC
+
+config TDX_CFG_BLOCK_OFFSET
+	int "Toradex config block offset"
+	help
+	  Specify the byte offset of the Toradex config block within the flash
+	  device the config block is stored on.
+
+config TDX_CFG_BLOCK_OFFSET2
+	int "Toradex config block offset, second instance"
+	default 0
+	help
+	  Specify the byte offset of the 2nd instance of the Toradex config block
+	  within the flash device the config block is stored on.
+	  Set to 0 on modules which have no 2nd instance.
+
+config TDX_CFG_BLOCK_2ND_ETHADDR
+	bool "Set the second Ethernet address"
+	help
+	  For each serial number two Ethernet addresses are available for dual
+	  Ethernet carrier boards. This options enables the code to set the
+	  second Ethernet address as environment variable (eth1addr).
+
+endif
diff --git a/board/toradex/common/Makefile b/board/toradex/common/Makefile
new file mode 100644
index 0000000..d645f5a
--- /dev/null
+++ b/board/toradex/common/Makefile
@@ -0,0 +1,11 @@
+# Copyright (c) 2016 Toradex, Inc.
+# SPDX-License-Identifier:	GPL-2.0+
+
+# Common for all Toradex modules
+ifeq ($(CONFIG_SPL_BUILD),y)
+# Necessary to create built-in.o
+obj- := __dummy__.o
+else
+obj-$(CONFIG_TDX_CFG_BLOCK) += tdx-cfg-block.o
+obj-y += tdx-common.o
+endif
diff --git a/board/toradex/common/tdx-cfg-block.c b/board/toradex/common/tdx-cfg-block.c
new file mode 100644
index 0000000..0014ce8
--- /dev/null
+++ b/board/toradex/common/tdx-cfg-block.c
@@ -0,0 +1,544 @@
+/*
+ * Copyright (c) 2016 Toradex, Inc.
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include "tdx-cfg-block.h"
+
+#if defined(CONFIG_TARGET_APALIS_IMX6) || defined(CONFIG_TARGET_COLIBRI_IMX6)
+#include <asm/arch/sys_proto.h>
+#else
+#define is_cpu_type(cpu) (0)
+#endif
+#if defined(CONFIG_CPU_PXA27X)
+#include <asm/arch-pxa/pxa.h>
+#else
+#define cpu_is_pxa27x(cpu) (0)
+#endif
+#include <cli.h>
+#include <console.h>
+#include <flash.h>
+#include <malloc.h>
+#include <mmc.h>
+#include <nand.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define TAG_VALID	0xcf01
+#define TAG_MAC		0x0000
+#define TAG_HW		0x0008
+#define TAG_INVALID	0xffff
+
+#define TAG_FLAG_VALID	0x1
+
+#if defined(CONFIG_TDX_CFG_BLOCK_IS_IN_MMC)
+#define TDX_CFG_BLOCK_MAX_SIZE 512
+#elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NAND)
+#define TDX_CFG_BLOCK_MAX_SIZE 64
+#elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NOR)
+#define TDX_CFG_BLOCK_MAX_SIZE 64
+#else
+#error Toradex config block location not set
+#endif
+
+struct toradex_tag {
+	u32 len:14;
+	u32 flags:2;
+	u32 id:16;
+};
+
+bool valid_cfgblock;
+struct toradex_hw tdx_hw_tag;
+struct toradex_eth_addr tdx_eth_addr;
+u32 tdx_serial;
+
+const char * const toradex_modules[] = {
+	 [0] = "UNKNOWN MODULE",
+	 [1] = "Colibri PXA270 312MHz",
+	 [2] = "Colibri PXA270 520MHz",
+	 [3] = "Colibri PXA320 806MHz",
+	 [4] = "Colibri PXA300 208MHz",
+	 [5] = "Colibri PXA310 624MHz",
+	 [6] = "Colibri PXA320 806MHz IT",
+	 [7] = "Colibri PXA300 208MHz XT",
+	 [8] = "Colibri PXA270 312MHz",
+	 [9] = "Colibri PXA270 520MHz",
+	[10] = "Colibri VF50 128MB", /* not currently on sale */
+	[11] = "Colibri VF61 256MB",
+	[12] = "Colibri VF61 256MB IT",
+	[13] = "Colibri VF50 128MB IT",
+	[14] = "Colibri iMX6 Solo 256MB",
+	[15] = "Colibri iMX6 DualLite 512MB",
+	[16] = "Colibri iMX6 Solo 256MB IT",
+	[17] = "Colibri iMX6 DualLite 512MB IT",
+	[18] = "UNKNOWN MODULE",
+	[19] = "UNKNOWN MODULE",
+	[20] = "Colibri T20 256MB",
+	[21] = "Colibri T20 512MB",
+	[22] = "Colibri T20 512MB IT",
+	[23] = "Colibri T30 1GB",
+	[24] = "Colibri T20 256MB IT",
+	[25] = "Apalis T30 2GB",
+	[26] = "Apalis T30 1GB",
+	[27] = "Apalis iMX6 Quad 1GB",
+	[28] = "Apalis iMX6 Quad 2GB IT",
+	[29] = "Apalis iMX6 Dual 512MB",
+	[30] = "Colibri T30 1GB IT",
+	[31] = "Apalis T30 1GB IT",
+	[32] = "Colibri iMX7 Solo 256MB",
+	[33] = "Colibri iMX7 Dual 512MB",
+	[34] = "Apalis TK1 2GB",
+	[35] = "Apalis iMX6 Dual 1GB IT",
+};
+
+#ifdef CONFIG_TDX_CFG_BLOCK_IS_IN_MMC
+static int tdx_cfg_block_mmc_storage(u8 *config_block, int write)
+{
+	struct mmc *mmc;
+	int dev = CONFIG_TDX_CFG_BLOCK_DEV;
+	int offset = CONFIG_TDX_CFG_BLOCK_OFFSET;
+	uint part = CONFIG_TDX_CFG_BLOCK_PART;
+	uint blk_start;
+	int ret = 0;
+
+	/* Read production parameter config block from eMMC */
+	mmc = find_mmc_device(dev);
+	if (!mmc) {
+		puts("No MMC card found\n");
+		ret = -ENODEV;
+		goto out;
+	}
+	if (part != mmc->block_dev.hwpart) {
+		if (blk_select_hwpart_devnum(IF_TYPE_MMC, dev, part)) {
+			puts("MMC partition switch failed\n");
+			ret = -ENODEV;
+			goto out;
+		}
+	}
+	if (offset < 0)
+		offset += mmc->capacity;
+	blk_start = ALIGN(offset, mmc->write_bl_len) / mmc->write_bl_len;
+
+	if (!write) {
+		/* Careful reads a whole block of 512 bytes into config_block */
+		if (blk_dread(mmc_get_blk_desc(mmc), blk_start, 1,
+			      (unsigned char *)config_block) != 1) {
+			ret = -EIO;
+			goto out;
+		}
+		/* Flush cache after read */
+		flush_cache((ulong)(unsigned char *)config_block, 512);
+	} else {
+		/* Just writing one 512 byte block */
+		if (blk_dwrite(mmc_get_blk_desc(mmc), blk_start, 1,
+			       (unsigned char *)config_block) != 1) {
+			ret = -EIO;
+			goto out;
+		}
+	}
+
+out:
+	/* Switch back to regular eMMC user partition */
+	blk_select_hwpart_devnum(IF_TYPE_MMC, 0, 0);
+
+	return ret;
+}
+#endif
+
+#ifdef CONFIG_TDX_CFG_BLOCK_IS_IN_NAND
+static int read_tdx_cfg_block_from_nand(unsigned char *config_block)
+{
+	size_t size = TDX_CFG_BLOCK_MAX_SIZE;
+
+	/* Read production parameter config block from NAND page */
+	return nand_read_skip_bad(nand_info[0], CONFIG_TDX_CFG_BLOCK_OFFSET,
+			 &size, NULL, TDX_CFG_BLOCK_MAX_SIZE, config_block);
+}
+
+static int write_tdx_cfg_block_to_nand(unsigned char *config_block)
+{
+	size_t size = TDX_CFG_BLOCK_MAX_SIZE;
+
+	/* Write production parameter config block to NAND page */
+	return nand_write_skip_bad(nand_info[0], CONFIG_TDX_CFG_BLOCK_OFFSET,
+				   &size, NULL, TDX_CFG_BLOCK_MAX_SIZE,
+				   config_block, WITH_WR_VERIFY);
+}
+#endif
+
+#ifdef CONFIG_TDX_CFG_BLOCK_IS_IN_NOR
+static int read_tdx_cfg_block_from_nor(unsigned char *config_block)
+{
+	/* Read production parameter config block from NOR flash */
+	memcpy(config_block, (void *)CONFIG_TDX_CFG_BLOCK_OFFSET,
+	       TDX_CFG_BLOCK_MAX_SIZE);
+	return 0;
+}
+
+static int write_tdx_cfg_block_to_nor(unsigned char *config_block)
+{
+	/* Write production parameter config block to NOR flash */
+	return flash_write((void *)config_block, CONFIG_TDX_CFG_BLOCK_OFFSET,
+			   TDX_CFG_BLOCK_MAX_SIZE);
+}
+#endif
+
+int read_tdx_cfg_block(void)
+{
+	int ret = 0;
+	u8 *config_block = NULL;
+	struct toradex_tag *tag;
+	size_t size = TDX_CFG_BLOCK_MAX_SIZE;
+	int offset;
+
+	/* Allocate RAM area for config block */
+	config_block = memalign(ARCH_DMA_MINALIGN, size);
+	if (!config_block) {
+		printf("Not enough malloc space available!\n");
+		return -ENOMEM;
+	}
+
+	memset(config_block, 0, size);
+
+#if defined(CONFIG_TDX_CFG_BLOCK_IS_IN_MMC)
+	ret = tdx_cfg_block_mmc_storage(config_block, 0);
+#elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NAND)
+	ret = read_tdx_cfg_block_from_nand(config_block);
+#elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NOR)
+	ret = read_tdx_cfg_block_from_nor(config_block);
+#else
+	ret = -EINVAL;
+#endif
+	if (ret)
+		goto out;
+
+	/* Expect a valid tag first */
+	tag = (struct toradex_tag *)config_block;
+	if (tag->flags != TAG_FLAG_VALID || tag->id != TAG_VALID) {
+		valid_cfgblock = false;
+		ret = -EINVAL;
+		goto out;
+	}
+	valid_cfgblock = true;
+	offset = 4;
+
+	while (offset < TDX_CFG_BLOCK_MAX_SIZE) {
+		tag = (struct toradex_tag *)(config_block + offset);
+		offset += 4;
+		if (tag->id == TAG_INVALID)
+			break;
+
+		if (tag->flags == TAG_FLAG_VALID) {
+			switch (tag->id) {
+			case TAG_MAC:
+				memcpy(&tdx_eth_addr, config_block + offset,
+				       6);
+
+				/* NIC part of MAC address is serial number */
+				tdx_serial = ntohl(tdx_eth_addr.nic) >> 8;
+				break;
+			case TAG_HW:
+				memcpy(&tdx_hw_tag, config_block + offset, 8);
+				break;
+			}
+		}
+
+		/* Get to next tag according to current tags length */
+		offset += tag->len * 4;
+	}
+
+	/* Cap product id to avoid issues with a yet unknown one */
+	if (tdx_hw_tag.prodid > (sizeof(toradex_modules) /
+				  sizeof(toradex_modules[0])))
+		tdx_hw_tag.prodid = 0;
+
+out:
+	free(config_block);
+	return ret;
+}
+
+static int get_cfgblock_interactive(void)
+{
+	char message[CONFIG_SYS_CBSIZE];
+	char *soc;
+	char it = 'n';
+	int len;
+
+	if (cpu_is_pxa27x())
+		sprintf(message, "Is the module the 312 MHz version? [y/N] ");
+	else
+		sprintf(message, "Is the module an IT version? [y/N] ");
+
+	len = cli_readline(message);
+	it = console_buffer[0];
+
+	soc = getenv("soc");
+	if (!strcmp("mx6", soc)) {
+#ifdef CONFIG_MACH_TYPE
+		if (it == 'y' || it == 'Y')
+			if (is_cpu_type(MXC_CPU_MX6Q))
+				tdx_hw_tag.prodid = APALIS_IMX6Q_IT;
+			else
+				tdx_hw_tag.prodid = APALIS_IMX6D_IT;
+		else
+			if (is_cpu_type(MXC_CPU_MX6Q))
+				tdx_hw_tag.prodid = APALIS_IMX6Q;
+			else
+				tdx_hw_tag.prodid = APALIS_IMX6D;
+#else
+		if (it == 'y' || it == 'Y')
+			if (is_cpu_type(MXC_CPU_MX6DL))
+				tdx_hw_tag.prodid = COLIBRI_IMX6DL_IT;
+			else
+				tdx_hw_tag.prodid = COLIBRI_IMX6S_IT;
+		else
+			if (is_cpu_type(MXC_CPU_MX6DL))
+				tdx_hw_tag.prodid = COLIBRI_IMX6DL;
+			else
+				tdx_hw_tag.prodid = COLIBRI_IMX6S;
+#endif /* CONFIG_MACH_TYPE */
+	} else if (!strcmp("imx7d", soc)) {
+		tdx_hw_tag.prodid = COLIBRI_IMX7D;
+	} else if (!strcmp("imx7s", soc)) {
+		tdx_hw_tag.prodid = COLIBRI_IMX7S;
+	} else if (!strcmp("tegra20", soc)) {
+		if (it == 'y' || it == 'Y')
+			if (gd->ram_size == 0x10000000)
+				tdx_hw_tag.prodid = COLIBRI_T20_256MB_IT;
+			else
+				tdx_hw_tag.prodid = COLIBRI_T20_512MB_IT;
+		else
+			if (gd->ram_size == 0x10000000)
+				tdx_hw_tag.prodid = COLIBRI_T20_256MB;
+			else
+				tdx_hw_tag.prodid = COLIBRI_T20_512MB;
+	} else if (cpu_is_pxa27x()) {
+		if (it == 'y' || it == 'Y')
+			tdx_hw_tag.prodid = COLIBRI_PXA270_312MHZ;
+		else
+			tdx_hw_tag.prodid = COLIBRI_PXA270_520MHZ;
+#ifdef CONFIG_MACH_TYPE
+	} else if (!strcmp("tegra30", soc)) {
+		if (CONFIG_MACH_TYPE == MACH_TYPE_APALIS_T30) {
+			if (it == 'y' || it == 'Y')
+				tdx_hw_tag.prodid = APALIS_T30_IT;
+			else
+				if (gd->ram_size == 0x40000000)
+					tdx_hw_tag.prodid = APALIS_T30_1GB;
+				else
+					tdx_hw_tag.prodid = APALIS_T30_2GB;
+		} else {
+			if (it == 'y' || it == 'Y')
+				tdx_hw_tag.prodid = COLIBRI_T30_IT;
+			else
+				tdx_hw_tag.prodid = COLIBRI_T30;
+		}
+#endif /* CONFIG_MACH_TYPE */
+	} else if (!strcmp("tegra124", soc)) {
+		tdx_hw_tag.prodid = APALIS_TK1_2GB;
+	} else if (!strcmp("vf500", soc)) {
+		if (it == 'y' || it == 'Y')
+			tdx_hw_tag.prodid = COLIBRI_VF50_IT;
+		else
+			tdx_hw_tag.prodid = COLIBRI_VF50;
+	} else if (!strcmp("vf610", soc)) {
+		if (it == 'y' || it == 'Y')
+			tdx_hw_tag.prodid = COLIBRI_VF61_IT;
+		else
+			tdx_hw_tag.prodid = COLIBRI_VF61;
+	} else {
+		printf("Module type not detectable due to unknown SoC\n");
+		return -1;
+	}
+
+	while (len < 4) {
+		sprintf(message, "Enter the module version (e.g. V1.1B): V");
+		len = cli_readline(message);
+	}
+
+	tdx_hw_tag.ver_major = console_buffer[0] - '0';
+	tdx_hw_tag.ver_minor = console_buffer[2] - '0';
+	tdx_hw_tag.ver_assembly = console_buffer[3] - 'A';
+
+	if (cpu_is_pxa27x() && (tdx_hw_tag.ver_major == 1))
+		tdx_hw_tag.prodid -= (COLIBRI_PXA270_312MHZ -
+				       COLIBRI_PXA270_V1_312MHZ);
+
+	while (len < 8) {
+		sprintf(message, "Enter module serial number: ");
+		len = cli_readline(message);
+	}
+
+	tdx_serial = simple_strtoul(console_buffer, NULL, 10);
+
+	return 0;
+}
+
+static int get_cfgblock_barcode(char *barcode)
+{
+	if (strlen(barcode) < 16) {
+		printf("Argument too short, barcode is 16 chars long\n");
+		return -1;
+	}
+
+	/* Get hardware information from the first 8 digits */
+	tdx_hw_tag.ver_major = barcode[4] - '0';
+	tdx_hw_tag.ver_minor = barcode[5] - '0';
+	tdx_hw_tag.ver_assembly = barcode[7] - '0';
+
+	barcode[4] = '\0';
+	tdx_hw_tag.prodid = simple_strtoul(barcode, NULL, 10);
+
+	/* Parse second part of the barcode (serial number */
+	barcode += 8;
+	tdx_serial = simple_strtoul(barcode, NULL, 10);
+
+	return 0;
+}
+
+static int do_cfgblock_create(cmd_tbl_t *cmdtp, int flag, int argc,
+			      char * const argv[])
+{
+	u8 *config_block;
+	struct toradex_tag *tag;
+	size_t size = TDX_CFG_BLOCK_MAX_SIZE;
+	int offset = 0;
+	int ret = CMD_RET_SUCCESS;
+	int err;
+
+	/* Allocate RAM area for config block */
+	config_block = memalign(ARCH_DMA_MINALIGN, size);
+	if (!config_block) {
+		printf("Not enough malloc space available!\n");
+		return CMD_RET_FAILURE;
+	}
+
+	memset(config_block, 0xff, size);
+
+	read_tdx_cfg_block();
+	if (valid_cfgblock) {
+#if defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NAND)
+		/*
+		 * On NAND devices, recreation is only allowed if the page is
+		 * empty (config block invalid...)
+		 */
+		printf("NAND erase block %d need to be erased before creating a Toradex config block\n",
+		       CONFIG_TDX_CFG_BLOCK_OFFSET / nand_info[0]->erasesize);
+		goto out;
+#elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NOR)
+		/*
+		 * On NOR devices, recreation is only allowed if the sector is
+		 * empty and write protection is off (config block invalid...)
+		 */
+		printf("NOR sector at offset 0x%02x need to be erased and unprotected before creating a Toradex config block\n",
+		       CONFIG_TDX_CFG_BLOCK_OFFSET);
+		goto out;
+#else
+		char message[CONFIG_SYS_CBSIZE];
+		sprintf(message,
+			"A valid Toradex config block is present, still recreate? [y/N] ");
+
+		if (!cli_readline(message))
+			goto out;
+
+		if (console_buffer[0] != 'y' && console_buffer[0] != 'Y')
+			goto out;
+#endif
+	}
+
+	/* Parse new Toradex config block data... */
+	if (argc < 3)
+		err = get_cfgblock_interactive();
+	else
+		err = get_cfgblock_barcode(argv[2]);
+
+	if (err) {
+		ret = CMD_RET_FAILURE;
+		goto out;
+	}
+
+	/* Convert serial number to MAC address (the storage format) */
+	tdx_eth_addr.oui = htonl(0x00142dUL << 8);
+	tdx_eth_addr.nic = htonl(tdx_serial << 8);
+
+	/* Valid Tag */
+	tag = (struct toradex_tag *)config_block;
+	tag->id = TAG_VALID;
+	tag->flags = TAG_FLAG_VALID;
+	tag->len = 0;
+	offset += 4;
+
+	/* Product Tag */
+	tag = (struct toradex_tag *)(config_block + offset);
+	tag->id = TAG_HW;
+	tag->flags = TAG_FLAG_VALID;
+	tag->len = 2;
+	offset += 4;
+
+	memcpy(config_block + offset, &tdx_hw_tag, 8);
+	offset += 8;
+
+	/* MAC Tag */
+	tag = (struct toradex_tag *)(config_block + offset);
+	tag->id = TAG_MAC;
+	tag->flags = TAG_FLAG_VALID;
+	tag->len = 2;
+	offset += 4;
+
+	memcpy(config_block + offset, &tdx_eth_addr, 6);
+	offset += 6;
+	memset(config_block + offset, 0, 32 - offset);
+
+#if defined(CONFIG_TDX_CFG_BLOCK_IS_IN_MMC)
+	err = tdx_cfg_block_mmc_storage(config_block, 1);
+#elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NAND)
+	err = write_tdx_cfg_block_to_nand(config_block);
+#elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NOR)
+	err = write_tdx_cfg_block_to_nor(config_block);
+#else
+	err = -EINVAL;
+#endif
+	if (err) {
+		printf("Failed to write Toradex config block: %d\n", ret);
+		ret = CMD_RET_FAILURE;
+		goto out;
+	}
+
+	printf("Toradex config block successfully written\n");
+
+out:
+	free(config_block);
+	return ret;
+}
+
+static int do_cfgblock(cmd_tbl_t *cmdtp, int flag, int argc,
+		       char * const argv[])
+{
+	int ret;
+
+	if (argc < 2)
+		return CMD_RET_USAGE;
+
+	if (!strcmp(argv[1], "create")) {
+		return do_cfgblock_create(cmdtp, flag, argc, argv);
+	} else if (!strcmp(argv[1], "reload")) {
+		ret = read_tdx_cfg_block();
+		if (ret) {
+			printf("Failed to reload Toradex config block: %d\n",
+			       ret);
+			return CMD_RET_FAILURE;
+		}
+		return CMD_RET_SUCCESS;
+	}
+
+	return CMD_RET_USAGE;
+}
+
+U_BOOT_CMD(
+	cfgblock, 3, 0, do_cfgblock,
+	"Toradex config block handling commands",
+	"create [barcode] - (Re-)create Toradex config block\n"
+	"cfgblock reload - Reload Toradex config block from flash"
+);
diff --git a/board/toradex/common/tdx-cfg-block.h b/board/toradex/common/tdx-cfg-block.h
new file mode 100644
index 0000000..fd7c362
--- /dev/null
+++ b/board/toradex/common/tdx-cfg-block.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2016 Toradex, Inc.
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef _TDX_CFG_BLOCK_H
+#define _TDX_CFG_BLOCK_H
+
+#include "tdx-common.h"
+
+struct toradex_hw {
+	u16 ver_major;
+	u16 ver_minor;
+	u16 ver_assembly;
+	u16 prodid;
+};
+
+struct toradex_eth_addr {
+	u32 oui:24;
+	u32 nic:24;
+} __attribute__((__packed__));
+
+enum {
+	COLIBRI_PXA270_V1_312MHZ = 1,
+	COLIBRI_PXA270_V1_520MHZ,
+	COLIBRI_PXA320,
+	COLIBRI_PXA300,
+	COLIBRI_PXA310,
+	COLIBRI_PXA320_IT,
+	COLIBRI_PXA300_XT,
+	COLIBRI_PXA270_312MHZ,
+	COLIBRI_PXA270_520MHZ,
+	COLIBRI_VF50, /* not currently on sale */
+	COLIBRI_VF61,
+	COLIBRI_VF61_IT,
+	COLIBRI_VF50_IT,
+	COLIBRI_IMX6S,
+	COLIBRI_IMX6DL,
+	COLIBRI_IMX6S_IT,
+	COLIBRI_IMX6DL_IT,
+	COLIBRI_T20_256MB = 20,
+	COLIBRI_T20_512MB,
+	COLIBRI_T20_512MB_IT,
+	COLIBRI_T30,
+	COLIBRI_T20_256MB_IT,
+	APALIS_T30_2GB,
+	APALIS_T30_1GB,
+	APALIS_IMX6Q,
+	APALIS_IMX6Q_IT,
+	APALIS_IMX6D,
+	COLIBRI_T30_IT,
+	APALIS_T30_IT,
+	COLIBRI_IMX7S,
+	COLIBRI_IMX7D,
+	APALIS_TK1_2GB,
+	APALIS_IMX6D_IT,
+};
+
+extern const char * const toradex_modules[];
+extern bool valid_cfgblock;
+extern struct toradex_hw tdx_hw_tag;
+extern struct toradex_eth_addr tdx_eth_addr;
+extern u32 tdx_serial;
+
+int read_tdx_cfg_block(void);
+
+#endif /* _TDX_CFG_BLOCK_H */
diff --git a/board/toradex/common/tdx-common.c b/board/toradex/common/tdx-common.c
new file mode 100644
index 0000000..e1a81cb
--- /dev/null
+++ b/board/toradex/common/tdx-common.c
@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 2016 Toradex, Inc.
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <g_dnl.h>
+#include <libfdt.h>
+
+#include "tdx-cfg-block.h"
+#include "tdx-common.h"
+
+__weak int checkboard_fallback(void)
+{
+	return 0;
+}
+
+#ifdef CONFIG_TDX_CFG_BLOCK
+static char tdx_serial_str[9];
+static char tdx_board_rev_str[6];
+
+#ifdef CONFIG_REVISION_TAG
+u32 get_board_rev(void)
+{
+	/* Check validity */
+	if (!tdx_hw_tag.ver_major)
+		return 0;
+
+	return ((tdx_hw_tag.ver_major & 0xff) << 8) |
+		((tdx_hw_tag.ver_minor & 0xf) << 4) |
+		((tdx_hw_tag.ver_assembly & 0xf) + 0xa);
+}
+#endif /* CONFIG_TDX_CFG_BLOCK */
+
+#ifdef CONFIG_SERIAL_TAG
+void get_board_serial(struct tag_serialnr *serialnr)
+{
+	int array[8];
+	unsigned int serial = tdx_serial;
+	int i;
+
+	serialnr->low = 0;
+	serialnr->high = 0;
+
+	/* Check validity */
+	if (serial) {
+		/*
+		 * Convert to Linux serial number format (hexadecimal coded
+		 * decimal)
+		 */
+		i = 7;
+		while (serial) {
+			array[i--] = serial % 10;
+			serial /= 10;
+		}
+		while (i >= 0)
+			array[i--] = 0;
+		serial = array[0];
+		for (i = 1; i < 8; i++) {
+			serial *= 16;
+			serial += array[i];
+		}
+
+		serialnr->low = serial;
+	}
+}
+#endif /* CONFIG_SERIAL_TAG */
+
+int checkboard(void)
+{
+	unsigned char ethaddr[6];
+
+	if (read_tdx_cfg_block()) {
+		printf("Missing Toradex config block\n");
+		checkboard_fallback();
+		return 0;
+	}
+
+	/* board serial-number */
+	sprintf(tdx_serial_str, "%08u", tdx_serial);
+	sprintf(tdx_board_rev_str, "V%1d.%1d%c",
+		tdx_hw_tag.ver_major,
+		tdx_hw_tag.ver_minor,
+		(char)tdx_hw_tag.ver_assembly + 'A');
+
+	setenv("serial#", tdx_serial_str);
+
+	/*
+	 * Check if environment contains a valid MAC address,
+	 * set the one from config block if not
+	 */
+	if (!eth_getenv_enetaddr("ethaddr", ethaddr))
+		eth_setenv_enetaddr("ethaddr", (u8 *)&tdx_eth_addr);
+
+#ifdef CONFIG_TDX_CFG_BLOCK_2ND_ETHADDR
+	if (!eth_getenv_enetaddr("eth1addr", ethaddr)) {
+		/*
+		 * Secondary MAC address is allocated from block
+		 * 0x100000 higher then the first MAC address
+		 */
+		memcpy(ethaddr, &tdx_eth_addr, 6);
+		ethaddr[3] += 0x10;
+		eth_setenv_enetaddr("eth1addr", ethaddr);
+	}
+#endif
+
+	printf("Model: Toradex %s %s, Serial# %s\n",
+	       toradex_modules[tdx_hw_tag.prodid],
+	       tdx_board_rev_str,
+	       tdx_serial_str);
+
+	return 0;
+}
+
+#ifdef CONFIG_USBDOWNLOAD_GADGET
+int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
+{
+	unsigned short usb_pid;
+
+	usb_pid = TORADEX_USB_PRODUCT_NUM_OFFSET + tdx_hw_tag.prodid;
+	put_unaligned(usb_pid, &dev->idProduct);
+
+	return 0;
+}
+#endif /* CONFIG_USBDOWNLOAD_GADGET */
+
+#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
+int ft_board_setup(void *blob, bd_t *bd)
+{
+	if (tdx_serial) {
+		fdt_setprop(blob, 0, "serial-number", tdx_serial_str,
+			    strlen(tdx_serial_str) + 1);
+	}
+
+	if (tdx_hw_tag.ver_major) {
+		char prod_id[5];
+
+		sprintf(prod_id, "%04u", tdx_hw_tag.prodid);
+		fdt_setprop(blob, 0, "toradex,product-id", prod_id, 5);
+
+		fdt_setprop(blob, 0, "toradex,board-rev", tdx_board_rev_str,
+			    strlen(tdx_board_rev_str) + 1);
+	}
+
+	return 0;
+}
+#endif
+
+#else /* CONFIG_TDX_CFG_BLOCK */
+
+#ifdef CONFIG_REVISION_TAG
+u32 get_board_rev(void)
+{
+	return 0;
+}
+#endif /* CONFIG_REVISION_TAG */
+
+#ifdef CONFIG_SERIAL_TAG
+u32 get_board_serial(void)
+{
+	return 0;
+}
+#endif /* CONFIG_SERIAL_TAG */
+
+int checkboard(void)
+{
+	checkboard_fallback();
+
+	return 0;
+}
+
+#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
+int ft_board_setup(void *blob, bd_t *bd)
+{
+	return 0;
+}
+#endif
+
+#endif /* CONFIG_TDX_CFG_BLOCK */
diff --git a/board/toradex/common/tdx-common.h b/board/toradex/common/tdx-common.h
new file mode 100644
index 0000000..f308ebd
--- /dev/null
+++ b/board/toradex/common/tdx-common.h
@@ -0,0 +1,13 @@
+/*
+ * Copyright (c) 2016 Toradex, Inc.
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef _TDX_COMMON_H
+#define _TDX_COMMON_H
+
+#define TORADEX_USB_PRODUCT_NUM_OFFSET	0x4000
+#define TDX_USB_VID			0x1B67
+
+#endif /* _TDX_COMMON_H */
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [U-Boot] [PATCH v2 4/6] apalis/colibri_imx7/pxa270/t20/t30/vf: integrate config block handling
  2016-09-28  9:35 [U-Boot] [PATCH v2 0/6] toradex: config block handling Marcel Ziswiler
                   ` (2 preceding siblings ...)
  2016-09-28  9:35 ` [U-Boot] [PATCH v2 3/6] toradex: config block handling Marcel Ziswiler
@ 2016-09-28  9:35 ` Marcel Ziswiler
  2016-09-28  9:35 ` [U-Boot] [PATCH v2 5/6] apalis/colibri_t30: move environment location Marcel Ziswiler
  2016-09-28  9:35 ` [U-Boot] [PATCH v2 6/6] colibri_vf: usb gadget: toradex pid is now set generically Marcel Ziswiler
  5 siblings, 0 replies; 18+ messages in thread
From: Marcel Ziswiler @ 2016-09-28  9:35 UTC (permalink / raw)
  To: u-boot

With our common code in place actually make use of it across all our
modules.

Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
---

Changes in v2: None

 board/toradex/apalis_t30/Kconfig              | 18 ++++++++++++++++++
 board/toradex/apalis_t30/apalis_t30.c         | 12 +++++++++++-
 board/toradex/colibri_imx7/Kconfig            | 16 ++++++++++++++++
 board/toradex/colibri_pxa270/Kconfig          | 11 +++++++++++
 board/toradex/colibri_pxa270/colibri_pxa270.c |  8 ++++++++
 board/toradex/colibri_t20/Kconfig             | 11 +++++++++++
 board/toradex/colibri_t20/colibri_t20.c       | 13 +++++++++++++
 board/toradex/colibri_t30/Kconfig             | 18 ++++++++++++++++++
 board/toradex/colibri_t30/colibri_t30.c       |  9 ++++++++-
 board/toradex/colibri_vf/Kconfig              | 14 ++++++++++++++
 board/toradex/common/Kconfig                  |  5 +++++
 include/configs/apalis_t30.h                  |  4 ++--
 include/configs/colibri_imx7.h                |  6 +++++-
 include/configs/colibri_pxa270.h              |  7 +++++--
 include/configs/colibri_t20.h                 |  2 +-
 include/configs/colibri_t30.h                 |  4 ++--
 include/configs/colibri_vf.h                  |  7 ++++---
 17 files changed, 152 insertions(+), 13 deletions(-)

diff --git a/board/toradex/apalis_t30/Kconfig b/board/toradex/apalis_t30/Kconfig
index f1dcda5..16224da 100644
--- a/board/toradex/apalis_t30/Kconfig
+++ b/board/toradex/apalis_t30/Kconfig
@@ -9,4 +9,22 @@ config SYS_VENDOR
 config SYS_CONFIG_NAME
 	default "apalis_t30"
 
+config TDX_CFG_BLOCK
+	default y
+
+config TDX_HAVE_MMC
+	default y
+
+config TDX_CFG_BLOCK_DEV
+	default "0"
+
+config TDX_CFG_BLOCK_PART
+	default "1"
+
+# Toradex config block in eMMC, at the end of 1st "boot sector"
+config TDX_CFG_BLOCK_OFFSET
+	default "-512"
+
+source "board/toradex/common/Kconfig"
+
 endif
diff --git a/board/toradex/apalis_t30/apalis_t30.c b/board/toradex/apalis_t30/apalis_t30.c
index 3f56971..bf13053 100644
--- a/board/toradex/apalis_t30/apalis_t30.c
+++ b/board/toradex/apalis_t30/apalis_t30.c
@@ -1,5 +1,5 @@
 /*
- *  (C) Copyright 2014
+ *  (C) Copyright 2014-2016
  *  Marcel Ziswiler <marcel@ziswiler.com>
  *
  * SPDX-License-Identifier:	GPL-2.0+
@@ -17,6 +17,8 @@
 
 #include "pinmux-config-apalis_t30.h"
 
+DECLARE_GLOBAL_DATA_PTR;
+
 #define PMU_I2C_ADDRESS		0x2D
 #define MAX_I2C_RETRY		3
 
@@ -29,6 +31,14 @@ int arch_misc_init(void)
 	return 0;
 }
 
+int checkboard_fallback(void)
+{
+	printf("Model: Toradex Apalis T30 %dGB\n",
+	       (gd->ram_size == 0x40000000) ? 1 : 2);
+
+	return 0;
+}
+
 /*
  * Routine: pinmux_init
  * Description: Do individual peripheral pinmux configs
diff --git a/board/toradex/colibri_imx7/Kconfig b/board/toradex/colibri_imx7/Kconfig
index 7bba26b..414a600 100644
--- a/board/toradex/colibri_imx7/Kconfig
+++ b/board/toradex/colibri_imx7/Kconfig
@@ -16,5 +16,21 @@ config COLIBRI_IMX7_EXT_PHYCLK
 	  clock source.
 	default y
 
+config TDX_CFG_BLOCK
+	default y
+
+config TDX_HAVE_NAND
+	default y
+
+config TDX_CFG_BLOCK_OFFSET
+	default "2048"
+
+config TDX_CFG_BLOCK_OFFSET2
+	default "133120"
+
+config TDX_CFG_BLOCK_2ND_ETHADDR
+	default y
+
+source "board/toradex/common/Kconfig"
 
 endif
diff --git a/board/toradex/colibri_pxa270/Kconfig b/board/toradex/colibri_pxa270/Kconfig
index 949407a..f646baa 100644
--- a/board/toradex/colibri_pxa270/Kconfig
+++ b/board/toradex/colibri_pxa270/Kconfig
@@ -9,4 +9,15 @@ config SYS_VENDOR
 config SYS_CONFIG_NAME
 	default "colibri_pxa270"
 
+config TDX_CFG_BLOCK
+	default y
+
+config TDX_HAVE_NOR
+	default y
+
+config TDX_CFG_BLOCK_OFFSET
+	default "262144"
+
+source "board/toradex/common/Kconfig"
+
 endif
diff --git a/board/toradex/colibri_pxa270/colibri_pxa270.c b/board/toradex/colibri_pxa270/colibri_pxa270.c
index 3def0a6..5737363 100644
--- a/board/toradex/colibri_pxa270/colibri_pxa270.c
+++ b/board/toradex/colibri_pxa270/colibri_pxa270.c
@@ -2,6 +2,7 @@
  * Toradex Colibri PXA270 Support
  *
  * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
+ * Copyright (C) 2016 Marcel Ziswiler <marcel.ziswiler@toradex.com>
  *
  * SPDX-License-Identifier:	GPL-2.0+
  */
@@ -32,6 +33,13 @@ int board_init(void)
 	return 0;
 }
 
+int checkboard_fallback(void)
+{
+	puts("Model: Toradex Colibri PXA270\n");
+
+	return 0;
+}
+
 int dram_init(void)
 {
 	pxa2xx_dram_init();
diff --git a/board/toradex/colibri_t20/Kconfig b/board/toradex/colibri_t20/Kconfig
index 7f373b2..a43acdd 100644
--- a/board/toradex/colibri_t20/Kconfig
+++ b/board/toradex/colibri_t20/Kconfig
@@ -9,4 +9,15 @@ config SYS_VENDOR
 config SYS_CONFIG_NAME
 	default "colibri_t20"
 
+config TDX_CFG_BLOCK
+	default y
+
+config TDX_HAVE_NAND
+	default y
+
+config TDX_CFG_BLOCK_OFFSET
+	default "3145728"
+
+source "board/toradex/common/Kconfig"
+
 endif
diff --git a/board/toradex/colibri_t20/colibri_t20.c b/board/toradex/colibri_t20/colibri_t20.c
index 68fbf49..24988eb 100644
--- a/board/toradex/colibri_t20/colibri_t20.c
+++ b/board/toradex/colibri_t20/colibri_t20.c
@@ -14,6 +14,9 @@
 #include <asm/gpio.h>
 #include <asm/io.h>
 #include <i2c.h>
+#include <nand.h>
+
+DECLARE_GLOBAL_DATA_PTR;
 
 #define PMU_I2C_ADDRESS		0x34
 #define MAX_I2C_RETRY		3
@@ -61,6 +64,16 @@ int arch_misc_init(void)
 	return 0;
 }
 
+int checkboard_fallback(void)
+{
+	printf("Model: Toradex Colibri T20 %dMB V%s\n",
+	       (gd->ram_size == 0x10000000) ? 256 : 512,
+	       (nand_info[0]->erasesize >> 10 == 512) ?
+	       ((gd->ram_size == 0x10000000) ? "1.1B" : "1.1C") : "1.2A");
+
+	return 0;
+}
+
 #ifdef CONFIG_TEGRA_MMC
 /*
  * Routine: pin_mux_mmc
diff --git a/board/toradex/colibri_t30/Kconfig b/board/toradex/colibri_t30/Kconfig
index 3e436a2..68ef82b 100644
--- a/board/toradex/colibri_t30/Kconfig
+++ b/board/toradex/colibri_t30/Kconfig
@@ -9,4 +9,22 @@ config SYS_VENDOR
 config SYS_CONFIG_NAME
 	default "colibri_t30"
 
+config TDX_CFG_BLOCK
+	default y
+
+config TDX_HAVE_MMC
+	default y
+
+config TDX_CFG_BLOCK_DEV
+	default "0"
+
+config TDX_CFG_BLOCK_PART
+	default "1"
+
+# Toradex config block in eMMC, at the end of 1st "boot sector"
+config TDX_CFG_BLOCK_OFFSET
+	default "-512"
+
+source "board/toradex/common/Kconfig"
+
 endif
diff --git a/board/toradex/colibri_t30/colibri_t30.c b/board/toradex/colibri_t30/colibri_t30.c
index e32362a..0c8ca5f 100644
--- a/board/toradex/colibri_t30/colibri_t30.c
+++ b/board/toradex/colibri_t30/colibri_t30.c
@@ -1,5 +1,5 @@
 /*
- *  (C) Copyright 2014
+ *  (C) Copyright 2014-2016
  *  Stefan Agner <stefan@agner.ch>
  *
  * SPDX-License-Identifier:	GPL-2.0+
@@ -24,6 +24,13 @@ int arch_misc_init(void)
 	return 0;
 }
 
+int checkboard_fallback(void)
+{
+	puts("Model: Toradex Colibri T30 1GB\n");
+
+	return 0;
+}
+
 /*
  * Routine: pinmux_init
  * Description: Do individual peripheral pinmux configs
diff --git a/board/toradex/colibri_vf/Kconfig b/board/toradex/colibri_vf/Kconfig
index 2c3cb30..bf9bb01 100644
--- a/board/toradex/colibri_vf/Kconfig
+++ b/board/toradex/colibri_vf/Kconfig
@@ -15,4 +15,18 @@ config SYS_SOC
 config SYS_CONFIG_NAME
 	default "colibri_vf"
 
+config TDX_CFG_BLOCK
+	default y
+
+config TDX_HAVE_NAND
+	default y
+
+config TDX_CFG_BLOCK_OFFSET
+	default "2048"
+
+config TDX_CFG_BLOCK_2ND_ETHADDR
+	default y
+
+source "board/toradex/common/Kconfig"
+
 endif
diff --git a/board/toradex/common/Kconfig b/board/toradex/common/Kconfig
index e269875..6278bcc 100644
--- a/board/toradex/common/Kconfig
+++ b/board/toradex/common/Kconfig
@@ -8,12 +8,17 @@ config CUSTOM_BOARDINFO
 menuconfig TDX_CFG_BLOCK
 	bool "Enable Toradex config block support"
 	select OF_BOARD_SETUP
+	select CUSTOM_BOARDINFO
 	help
 	  The Toradex config block stored production data on the on-module
 	  flash device (NAND, NOR or eMMC). The area is normally preserved by
 	  software and contains the serial number (out of which the MAC
 	  address is generated) and the exact module type.
 
+# Not from device tree model node
+config CUSTOM_BOARDINFO
+	bool
+
 # Helper config to determine the correct default location of the cfg block
 config TDX_HAVE_MMC
 	bool
diff --git a/include/configs/apalis_t30.h b/include/configs/apalis_t30.h
index dc17733..1a22973 100644
--- a/include/configs/apalis_t30.h
+++ b/include/configs/apalis_t30.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2015 Marcel Ziswiler
+ * Copyright (c) 2014-2016 Marcel Ziswiler
  *
  * Configuration settings for the Toradex Apalis T30 modules.
  *
@@ -16,8 +16,8 @@
 #define CONFIG_ARCH_MISC_INIT
 
 /* High-level configuration options */
-#define CONFIG_TEGRA_BOARD_STRING	"Toradex Apalis T30"
 #undef CONFIG_DISPLAY_BOARDINFO		/* As defined in tegra-common */
+#define CONFIG_DISPLAY_BOARDINFO_LATE	/* Calls checkboard() */
 
 /* Board-specific serial config */
 #define CONFIG_TEGRA_ENABLE_UARTA
diff --git a/include/configs/colibri_imx7.h b/include/configs/colibri_imx7.h
index 16ae952..b659d53 100644
--- a/include/configs/colibri_imx7.h
+++ b/include/configs/colibri_imx7.h
@@ -21,10 +21,14 @@
 /*#define CONFIG_DBG_MONITOR*/
 #define PHYS_SDRAM_SIZE			SZ_512M
 
+#define CONFIG_ARCH_MISC_INIT
 #define CONFIG_BOARD_EARLY_INIT_F
 #define CONFIG_BOARD_LATE_INIT
 
-#define CONFIG_DISPLAY_BOARDINFO_LATE
+#define CONFIG_DISPLAY_BOARDINFO_LATE	/* Calls checkboard() */
+
+#define CONFIG_ENV_VARS_UBOOT_CONFIG
+#define CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 
 /* Size of malloc() pool */
 #define CONFIG_SYS_MALLOC_LEN		(32 * SZ_1M)
diff --git a/include/configs/colibri_pxa270.h b/include/configs/colibri_pxa270.h
index ba8d93c..7a100de 100644
--- a/include/configs/colibri_pxa270.h
+++ b/include/configs/colibri_pxa270.h
@@ -2,7 +2,7 @@
  * Toradex Colibri PXA270 configuration file
  *
  * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
- * Copyright (C) 2015 Marcel Ziswiler <marcel@ziswiler.com>
+ * Copyright (C) 2015-2016 Marcel Ziswiler <marcel@ziswiler.com>
  *
  * SPDX-License-Identifier:	GPL-2.0+
  */
@@ -21,10 +21,14 @@
 /* We will never enable dcache because we have to setup MMU first */
 #define CONFIG_SYS_DCACHE_OFF
 
+#define CONFIG_DISPLAY_BOARDINFO_LATE	/* Calls checkboard() */
+
 /*
  * Environment settings
  */
 #define	CONFIG_ENV_OVERWRITE
+#define CONFIG_ENV_VARS_UBOOT_CONFIG
+#define CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 #define	CONFIG_SYS_MALLOC_LEN		(128 * 1024)
 #define	CONFIG_ARCH_CPU_INIT
 #define	CONFIG_BOOTCOMMAND						\
@@ -39,7 +43,6 @@
 #define	CONFIG_TIMESTAMP
 #define	CONFIG_CMDLINE_TAG
 #define	CONFIG_SETUP_MEMORY_TAGS
-#define	CONFIG_LZMA			/* LZMA compression support */
 
 /*
  * Serial Console Configuration
diff --git a/include/configs/colibri_t20.h b/include/configs/colibri_t20.h
index 431fec0..ee5762e 100644
--- a/include/configs/colibri_t20.h
+++ b/include/configs/colibri_t20.h
@@ -14,8 +14,8 @@
 #define CONFIG_ARCH_MISC_INIT
 
 /* High-level configuration options */
-#define CONFIG_TEGRA_BOARD_STRING	"Toradex Colibri T20"
 #undef CONFIG_DISPLAY_BOARDINFO		/* As defined in tegra-common */
+#define CONFIG_DISPLAY_BOARDINFO_LATE	/* Calls checkboard() */
 
 /* Board-specific serial config */
 #define CONFIG_TEGRA_ENABLE_UARTA
diff --git a/include/configs/colibri_t30.h b/include/configs/colibri_t30.h
index d83c5a0..6b6496b 100644
--- a/include/configs/colibri_t30.h
+++ b/include/configs/colibri_t30.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2015 Stefan Agner
+ * Copyright (c) 2013-2016 Stefan Agner
  *
  * Configuration settings for the Toradex Colibri T30 modules.
  *
@@ -16,8 +16,8 @@
 #define CONFIG_ARCH_MISC_INIT
 
 /* High-level configuration options */
-#define CONFIG_TEGRA_BOARD_STRING	"Toradex Colibri T30"
 #undef CONFIG_DISPLAY_BOARDINFO		/* As defined in tegra-common */
+#define CONFIG_DISPLAY_BOARDINFO_LATE	/* Calls checkboard() */
 
 /* Board-specific serial config */
 #define CONFIG_TEGRA_ENABLE_UARTA
diff --git a/include/configs/colibri_vf.h b/include/configs/colibri_vf.h
index 597eb2c..38dbf35 100644
--- a/include/configs/colibri_vf.h
+++ b/include/configs/colibri_vf.h
@@ -1,7 +1,7 @@
 /*
- * Copyright 2015 Toradex, Inc.
+ * Copyright 2015-2016 Toradex, Inc.
  *
- * Configuration settings for the Toradex VF50/VF61 module.
+ * Configuration settings for the Toradex VF50/VF61 modules.
  *
  * Based on vf610twr.h:
  * Copyright 2013 Freescale Semiconductor, Inc.
@@ -21,8 +21,8 @@
 #define CONFIG_SYS_FSL_CLK
 
 #define CONFIG_ARCH_MISC_INIT
+#define CONFIG_DISPLAY_BOARDINFO_LATE	/* Calls checkboard() */
 #define CONFIG_DISPLAY_CPUINFO
-#define CONFIG_DISPLAY_BOARDINFO
 
 #define CONFIG_SKIP_LOWLEVEL_INIT
 
@@ -38,6 +38,7 @@
 
 /* Allow to overwrite serial and ethaddr */
 #define CONFIG_ENV_OVERWRITE
+#define CONFIG_ENV_VARS_UBOOT_CONFIG
 #define CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 #define CONFIG_BAUDRATE			115200
 
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [U-Boot] [PATCH v2 5/6] apalis/colibri_t30: move environment location
  2016-09-28  9:35 [U-Boot] [PATCH v2 0/6] toradex: config block handling Marcel Ziswiler
                   ` (3 preceding siblings ...)
  2016-09-28  9:35 ` [U-Boot] [PATCH v2 4/6] apalis/colibri_imx7/pxa270/t20/t30/vf: integrate " Marcel Ziswiler
@ 2016-09-28  9:35 ` Marcel Ziswiler
  2016-09-28 18:11   ` Stephen Warren
  2016-09-28  9:35 ` [U-Boot] [PATCH v2 6/6] colibri_vf: usb gadget: toradex pid is now set generically Marcel Ziswiler
  5 siblings, 1 reply; 18+ messages in thread
From: Marcel Ziswiler @ 2016-09-28  9:35 UTC (permalink / raw)
  To: u-boot

Now with the config block handling in place move the U-Boot environment
location before the config block at the end of 1st "boot sector" as
deployed during production using our downstream BSP.

Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>

---

Changes in v2:
- fixed common.h include mess in board/toradex/common by renaming
  common* to tdx-common
- renamed TRDX to TDX and trdx to tdx as in common use internally
- consolidated makefiles and changed copyright message
- renamed configblock* to tdx-cfg-block* analogous to Kconfig symbols
- moved board/toradex/common/Kconfig sourcing from arch/arm/Kconfig
  into our own board Kconfig files
- use a named choice for the config block location for above to work
  without issuing any warnings (undocumented kbuild feature curtsey
  Arnaud Lacombe)
- added CUSTOM_BOARDINFO into our common Kconfig to avoid recent
  no_new_adhoc_configs_check error
- add Max' patch
  colibri_vf: usb gadget: toradex pid is now set generically

 include/configs/apalis_t30.h  | 7 ++++---
 include/configs/colibri_t30.h | 7 ++++---
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/include/configs/apalis_t30.h b/include/configs/apalis_t30.h
index 1a22973..5be770c 100644
--- a/include/configs/apalis_t30.h
+++ b/include/configs/apalis_t30.h
@@ -33,11 +33,12 @@
 #define CONFIG_GENERIC_MMC
 #define CONFIG_TEGRA_MMC
 
-/* Environment in eMMC, at the end of 2nd "boot sector" */
+/* Environment in eMMC, before config block at the end of 1st "boot sector" */
 #define CONFIG_ENV_IS_IN_MMC
-#define CONFIG_ENV_OFFSET		(-CONFIG_ENV_SIZE)
+#define CONFIG_ENV_OFFSET		(-CONFIG_ENV_SIZE + \
+					 CONFIG_TDX_CFG_BLOCK_OFFSET)
 #define CONFIG_SYS_MMC_ENV_DEV		0
-#define CONFIG_SYS_MMC_ENV_PART		2
+#define CONFIG_SYS_MMC_ENV_PART		1
 
 /* USB host support */
 #define CONFIG_USB_EHCI
diff --git a/include/configs/colibri_t30.h b/include/configs/colibri_t30.h
index 6b6496b..95cba12 100644
--- a/include/configs/colibri_t30.h
+++ b/include/configs/colibri_t30.h
@@ -33,11 +33,12 @@
 #define CONFIG_GENERIC_MMC
 #define CONFIG_TEGRA_MMC
 
-/* Environment in eMMC, at the end of 2nd "boot sector" */
+/* Environment in eMMC, before config block at the end of 1st "boot sector" */
 #define CONFIG_ENV_IS_IN_MMC
-#define CONFIG_ENV_OFFSET		(-CONFIG_ENV_SIZE)
+#define CONFIG_ENV_OFFSET		(-CONFIG_ENV_SIZE + \
+					 CONFIG_TDX_CFG_BLOCK_OFFSET)
 #define CONFIG_SYS_MMC_ENV_DEV		0
-#define CONFIG_SYS_MMC_ENV_PART		2
+#define CONFIG_SYS_MMC_ENV_PART		1
 
 /* USB host support */
 #define CONFIG_USB_EHCI
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [U-Boot] [PATCH v2 6/6] colibri_vf: usb gadget: toradex pid is now set generically
  2016-09-28  9:35 [U-Boot] [PATCH v2 0/6] toradex: config block handling Marcel Ziswiler
                   ` (4 preceding siblings ...)
  2016-09-28  9:35 ` [U-Boot] [PATCH v2 5/6] apalis/colibri_t30: move environment location Marcel Ziswiler
@ 2016-09-28  9:35 ` Marcel Ziswiler
  5 siblings, 0 replies; 18+ messages in thread
From: Marcel Ziswiler @ 2016-09-28  9:35 UTC (permalink / raw)
  To: u-boot

From: Max Krummenacher <max.krummenacher@toradex.com>

remove now unused CONFIG_TRDX_PID_XXX

Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
Acked-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
---

Changes in v2: None

 board/toradex/colibri_vf/colibri_vf.c | 16 ----------------
 include/configs/colibri_vf.h          |  7 -------
 scripts/config_whitelist.txt          |  5 -----
 3 files changed, 28 deletions(-)

diff --git a/board/toradex/colibri_vf/colibri_vf.c b/board/toradex/colibri_vf/colibri_vf.c
index c636a8e..535d6d8 100644
--- a/board/toradex/colibri_vf/colibri_vf.c
+++ b/board/toradex/colibri_vf/colibri_vf.c
@@ -528,22 +528,6 @@ int checkboard_fallback(void)
 	return 0;
 }
 
-int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
-{
-	unsigned short usb_pid;
-
-	put_unaligned(CONFIG_TRDX_VID, &dev->idVendor);
-
-	if (is_colibri_vf61())
-		usb_pid = CONFIG_TRDX_PID_COLIBRI_VF61IT;
-	else
-		usb_pid = CONFIG_TRDX_PID_COLIBRI_VF50IT;
-
-	put_unaligned(usb_pid, &dev->idProduct);
-
-	return 0;
-}
-
 #ifdef CONFIG_USB_EHCI_VF
 int board_ehci_hcd_init(int port)
 {
diff --git a/include/configs/colibri_vf.h b/include/configs/colibri_vf.h
index 38dbf35..78790f1 100644
--- a/include/configs/colibri_vf.h
+++ b/include/configs/colibri_vf.h
@@ -209,13 +209,6 @@
 #define CONFIG_USB_MAX_CONTROLLER_COUNT 2
 #define CONFIG_EHCI_HCD_INIT_AFTER_RESET
 
-/* USB Client Support */
-#define CONFIG_TRDX_VID                  0x1B67
-#define CONFIG_TRDX_PID_COLIBRI_VF50     0x0016
-#define CONFIG_TRDX_PID_COLIBRI_VF61     0x0017
-#define CONFIG_TRDX_PID_COLIBRI_VF61IT   0x0018
-#define CONFIG_TRDX_PID_COLIBRI_VF50IT   0x0019
-
 /* USB DFU */
 #define CONFIG_SYS_DFU_DATA_BUF_SIZE (1024 * 1024)
 
diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt
index efa95f0..f302ab8 100644
--- a/scripts/config_whitelist.txt
+++ b/scripts/config_whitelist.txt
@@ -8023,11 +8023,6 @@ CONFIG_TRACE_EARLY_ADDR
 CONFIG_TRACE_EARLY_SIZE
 CONFIG_TRAILBLAZER
 CONFIG_TRATS
-CONFIG_TRDX_PID_COLIBRI_VF50
-CONFIG_TRDX_PID_COLIBRI_VF50IT
-CONFIG_TRDX_PID_COLIBRI_VF61
-CONFIG_TRDX_PID_COLIBRI_VF61IT
-CONFIG_TRDX_VID
 CONFIG_TSEC
 CONFIG_TSEC1
 CONFIG_TSEC1_NAME
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [U-Boot] [PATCH v2 2/6] apalis/colibri_t20/t30: deactivate displaying board info
  2016-09-28  9:35 ` [U-Boot] [PATCH v2 2/6] apalis/colibri_t20/t30: deactivate displaying board info Marcel Ziswiler
@ 2016-09-28 18:00   ` Stephen Warren
  2016-09-30 10:00     ` Marcel Ziswiler
  0 siblings, 1 reply; 18+ messages in thread
From: Stephen Warren @ 2016-09-28 18:00 UTC (permalink / raw)
  To: u-boot

On 09/28/2016 03:35 AM, Marcel Ziswiler wrote:
> Avoid a checkboard() name clash with our upcoming custom implementation
> thereof.

If you want to avoid naming conflicts, please simply name your new 
function something that doesn't conflict. That way it will avoid 
confusion is someone actually wants to enable the 
CONFIG_DISPLAY_BOARDINFO option themselves, plus it avoids taking the 
current feature set away.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [U-Boot] [PATCH v2 5/6] apalis/colibri_t30: move environment location
  2016-09-28  9:35 ` [U-Boot] [PATCH v2 5/6] apalis/colibri_t30: move environment location Marcel Ziswiler
@ 2016-09-28 18:11   ` Stephen Warren
  2016-09-30 11:44     ` Marcel Ziswiler
  0 siblings, 1 reply; 18+ messages in thread
From: Stephen Warren @ 2016-09-28 18:11 UTC (permalink / raw)
  To: u-boot

On 09/28/2016 03:35 AM, Marcel Ziswiler wrote:
> Now with the config block handling in place move the U-Boot environment
> location before the config block at the end of 1st "boot sector" as
> deployed during production using our downstream BSP.

> diff --git a/include/configs/apalis_t30.h b/include/configs/apalis_t30.h

> -/* Environment in eMMC, at the end of 2nd "boot sector" */
> +/* Environment in eMMC, before config block at the end of 1st "boot sector" */
>  #define CONFIG_ENV_IS_IN_MMC
> -#define CONFIG_ENV_OFFSET		(-CONFIG_ENV_SIZE)
> +#define CONFIG_ENV_OFFSET		(-CONFIG_ENV_SIZE + \
> +					 CONFIG_TDX_CFG_BLOCK_OFFSET)

I'm not convinced that ENV_OFFSET actually points where the description 
says it does. (-CONFIG_ENV_SIZE + CONFIG_TDX_CFG_BLOCK_OFFSET) is (-8192 
+ -512). The original comment states that an ENV_OFFSET of -8192 locates 
the environment at the end of a sector, so shifting it 512 bytes earlier 
in the flash can't possible now align it with a different sector? Should 
ENV_OFFSET be shifted down by a whole sector size by this patch, i.e. 
should +CONFIG_TXT_CFG_BLOCK_OFFSET be rounded up to a sector size to 
match the comment?

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [U-Boot] [PATCH v2 2/6] apalis/colibri_t20/t30: deactivate displaying board info
  2016-09-28 18:00   ` Stephen Warren
@ 2016-09-30 10:00     ` Marcel Ziswiler
  2016-10-03 17:28       ` Stephen Warren
  0 siblings, 1 reply; 18+ messages in thread
From: Marcel Ziswiler @ 2016-09-30 10:00 UTC (permalink / raw)
  To: u-boot

On Wed, 2016-09-28 at 12:00 -0600, Stephen Warren wrote:
> On 09/28/2016 03:35 AM, Marcel Ziswiler wrote:
> > 
> > Avoid a checkboard() name clash with our upcoming custom
> > implementation
> > thereof.
> If you want to avoid naming conflicts, please simply name your new?
> function something that doesn't conflict. That way it will avoid?
> confusion is someone actually wants to enable the?
> CONFIG_DISPLAY_BOARDINFO option themselves, plus it avoids taking
> the?
> current feature set away.

No, it is not just any function. We do want our custom checkboard() to
be called upon boot and not the Tegra generic one just printing a hard
coded string.

I guess alternatively we could gate the checkboard() call
in?arch/arm/mach-tegra/board2.c with a

#if !defined(CONFIG_CUSTOM_BOARDINFO)

just as introduced a while ago in?common/board_info.c

http://git.denx.de/?p=u-boot.git;a=blob;f=common/board_info.c;h=bd5dcfa
066358c2cc44ce5d19fcc3e77d555cd09;hb=HEAD#l20

in order to not print the hard coded name from the device tree.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [U-Boot] [PATCH v2 5/6] apalis/colibri_t30: move environment location
  2016-09-28 18:11   ` Stephen Warren
@ 2016-09-30 11:44     ` Marcel Ziswiler
  2016-10-03 17:31       ` Stephen Warren
  0 siblings, 1 reply; 18+ messages in thread
From: Marcel Ziswiler @ 2016-09-30 11:44 UTC (permalink / raw)
  To: u-boot

On Wed, 2016-09-28 at 12:11 -0600, Stephen Warren wrote:
> On 09/28/2016 03:35 AM, Marcel Ziswiler wrote:
> > 
> > Now with the config block handling in place move the U-Boot
> > environment
> > location before the config block at the end of 1st "boot sector" as
> > deployed during production using our downstream BSP.
> > 
> > diff --git a/include/configs/apalis_t30.h
> > b/include/configs/apalis_t30.h
> > 
> > -/* Environment in eMMC, at the end of 2nd "boot sector" */
> > +/* Environment in eMMC, before config block at the end of 1st
> > "boot sector" */
> > ?#define CONFIG_ENV_IS_IN_MMC
> > -#define CONFIG_ENV_OFFSET		(-CONFIG_ENV_SIZE)
> > +#define CONFIG_ENV_OFFSET		(-CONFIG_ENV_SIZE + \
> > +					?CONFIG_TDX_CFG_BLOCK_OFFS
> > ET)
> I'm not convinced that ENV_OFFSET actually points where the
> description?
> says it does. (-CONFIG_ENV_SIZE + CONFIG_TDX_CFG_BLOCK_OFFSET) is (-
> 8192?
> + -512). The original comment states that an ENV_OFFSET of -8192
> locates?
> the environment at the end of a sector, so shifting it 512 bytes
> earlier?
> in the flash can't possible now align it with a different sector? 

Why not?

> Should?
> ENV_OFFSET be shifted down by a whole sector size by this patch,
> i.e.?
> should +CONFIG_TXT_CFG_BLOCK_OFFSET be rounded up to a sector size
> to?
> match the comment?

Yes, a block, sector or whatever you wana call it is actually 512 bytes
in size on all eMMCs or even MMC/SD cards that I have seen so far.

I guess while it would be kind of nice having this enforced to some
intrinsic size in software ultimately this is a board configuration
option concerning our Toradex factory configuration block as programmed
during production. We just want to make sure that one is preserved and
the environment is stored right before.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [U-Boot] [PATCH v2 3/6] toradex: config block handling
  2016-09-28  9:35 ` [U-Boot] [PATCH v2 3/6] toradex: config block handling Marcel Ziswiler
@ 2016-09-30 22:28   ` Stefan Agner
  0 siblings, 0 replies; 18+ messages in thread
From: Stefan Agner @ 2016-09-30 22:28 UTC (permalink / raw)
  To: u-boot



On 28.09.2016 02:35, Marcel Ziswiler wrote:
> Add Toradex factory configuration block handling. The config block is a
> data structure which gets stored to flash during production testing. The
> structure holds such information as board resp. hardware revision,
> product ID and serial number which is used as the NIC part of the
> Ethernet MAC address as well. The config block will be read upon boot by
> the checkboard() function, displayed as part of the board information
> and passed to Linux via device tree or ATAGs.
>
> Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
> ---
>
> Changes in v2: None
>
>  board/toradex/common/Kconfig         |  80 ++++++
>  board/toradex/common/Makefile        |  11 +
>  board/toradex/common/tdx-cfg-block.c | 544 +++++++++++++++++++++++++++++++++++
>  board/toradex/common/tdx-cfg-block.h |  68 +++++
>  board/toradex/common/tdx-common.c    | 180 ++++++++++++
>  board/toradex/common/tdx-common.h    |  13 +
>  6 files changed, 896 insertions(+)
>  create mode 100644 board/toradex/common/Kconfig
>  create mode 100644 board/toradex/common/Makefile
>  create mode 100644 board/toradex/common/tdx-cfg-block.c
>  create mode 100644 board/toradex/common/tdx-cfg-block.h
>  create mode 100644 board/toradex/common/tdx-common.c
>  create mode 100644 board/toradex/common/tdx-common.h
>
> diff --git a/board/toradex/common/Kconfig b/board/toradex/common/Kconfig
> new file mode 100644
> index 0000000..e269875
> --- /dev/null
> +++ b/board/toradex/common/Kconfig
> @@ -0,0 +1,80 @@
> +# Copyright (c) 2016 Toradex, Inc.
> +# SPDX-License-Identifier:	GPL-2.0+
> +
> +# Not from device tree model node
> +config CUSTOM_BOARDINFO
> +	bool

This Kconfig option seems to be hardly at the right place: We make use
of that config in common/board_info.c

But I have a completely different proposal, why don't we remove a config
option for once:
First, drop CONFIG_CUSTOM_BOARDINFO, it does not have widespread use
yet, so it shouldn't be a problem... Also it ifdefs almost the whole
function so not that much value. Then convert show_board_info to a weak
function instead... The implementer of show_board_info can then decide
whether checkboard should be called or not.

That way we can leave the checkboard() functions in all our boards as
is, and simply reimplement show_board_info in tdx-cfg-block.c (with a
call to checkboard only if the config block is corrupt/missing)...

Thoughts?

--
Stefan


> +
> +menuconfig TDX_CFG_BLOCK
> +	bool "Enable Toradex config block support"
> +	select OF_BOARD_SETUP
> +	help
> +	  The Toradex config block stored production data on the on-module
> +	  flash device (NAND, NOR or eMMC). The area is normally preserved by
> +	  software and contains the serial number (out of which the MAC
> +	  address is generated) and the exact module type.
> +
> +# Helper config to determine the correct default location of the cfg block
> +config TDX_HAVE_MMC
> +	bool
> +
> +config TDX_HAVE_NAND
> +	bool
> +
> +config TDX_HAVE_NOR
> +	bool
> +
> +if TDX_CFG_BLOCK
> +
> +choice TDX_CFG_BLOCK_LOCATION
> +	prompt "Toradex config block location"
> +	depends on TDX_CFG_BLOCK
> +	default TDX_CFG_BLOCK_IS_IN_MMC if TDX_HAVE_MMC
> +	default TDX_CFG_BLOCK_IS_IN_NAND if TDX_HAVE_NAND
> +	default TDX_CFG_BLOCK_IS_IN_NOR if TDX_HAVE_NOR
> +	help
> +	  Configure the location of the Toradex config block. By default, the
> +	  factory version of the Toradex config block is on the NAND, NOR or
> +	  eMMC flash device on the module.
> +
> +config TDX_CFG_BLOCK_IS_IN_MMC
> +	bool "Location of the config block is in eMMC"
> +
> +config TDX_CFG_BLOCK_IS_IN_NAND
> +	bool "Location of the config block is in NAND"
> +
> +config TDX_CFG_BLOCK_IS_IN_NOR
> +	bool "Location of the config block is in NOR"
> +
> +endchoice
> +
> +config TDX_CFG_BLOCK_DEV
> +	int "Toradex config block eMMC device ID"
> +	depends on TDX_CFG_BLOCK_IS_IN_MMC
> +
> +config TDX_CFG_BLOCK_PART
> +	int "Toradex config block eMMC partition ID"
> +	depends on TDX_CFG_BLOCK_IS_IN_MMC
> +
> +config TDX_CFG_BLOCK_OFFSET
> +	int "Toradex config block offset"
> +	help
> +	  Specify the byte offset of the Toradex config block within the flash
> +	  device the config block is stored on.
> +
> +config TDX_CFG_BLOCK_OFFSET2
> +	int "Toradex config block offset, second instance"
> +	default 0
> +	help
> +	  Specify the byte offset of the 2nd instance of the Toradex config block
> +	  within the flash device the config block is stored on.
> +	  Set to 0 on modules which have no 2nd instance.
> +
> +config TDX_CFG_BLOCK_2ND_ETHADDR
> +	bool "Set the second Ethernet address"
> +	help
> +	  For each serial number two Ethernet addresses are available for dual
> +	  Ethernet carrier boards. This options enables the code to set the
> +	  second Ethernet address as environment variable (eth1addr).
> +
> +endif
> diff --git a/board/toradex/common/Makefile b/board/toradex/common/Makefile
> new file mode 100644
> index 0000000..d645f5a
> --- /dev/null
> +++ b/board/toradex/common/Makefile
> @@ -0,0 +1,11 @@
> +# Copyright (c) 2016 Toradex, Inc.
> +# SPDX-License-Identifier:	GPL-2.0+
> +
> +# Common for all Toradex modules
> +ifeq ($(CONFIG_SPL_BUILD),y)
> +# Necessary to create built-in.o
> +obj- := __dummy__.o
> +else
> +obj-$(CONFIG_TDX_CFG_BLOCK) += tdx-cfg-block.o
> +obj-y += tdx-common.o
> +endif
> diff --git a/board/toradex/common/tdx-cfg-block.c b/board/toradex/common/tdx-cfg-block.c
> new file mode 100644
> index 0000000..0014ce8
> --- /dev/null
> +++ b/board/toradex/common/tdx-cfg-block.c
> @@ -0,0 +1,544 @@
> +/*
> + * Copyright (c) 2016 Toradex, Inc.
> + *
> + * SPDX-License-Identifier:	GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include "tdx-cfg-block.h"
> +
> +#if defined(CONFIG_TARGET_APALIS_IMX6) || defined(CONFIG_TARGET_COLIBRI_IMX6)
> +#include <asm/arch/sys_proto.h>
> +#else
> +#define is_cpu_type(cpu) (0)
> +#endif
> +#if defined(CONFIG_CPU_PXA27X)
> +#include <asm/arch-pxa/pxa.h>
> +#else
> +#define cpu_is_pxa27x(cpu) (0)
> +#endif
> +#include <cli.h>
> +#include <console.h>
> +#include <flash.h>
> +#include <malloc.h>
> +#include <mmc.h>
> +#include <nand.h>
> +
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +#define TAG_VALID	0xcf01
> +#define TAG_MAC		0x0000
> +#define TAG_HW		0x0008
> +#define TAG_INVALID	0xffff
> +
> +#define TAG_FLAG_VALID	0x1
> +
> +#if defined(CONFIG_TDX_CFG_BLOCK_IS_IN_MMC)
> +#define TDX_CFG_BLOCK_MAX_SIZE 512
> +#elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NAND)
> +#define TDX_CFG_BLOCK_MAX_SIZE 64
> +#elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NOR)
> +#define TDX_CFG_BLOCK_MAX_SIZE 64
> +#else
> +#error Toradex config block location not set
> +#endif
> +
> +struct toradex_tag {
> +	u32 len:14;
> +	u32 flags:2;
> +	u32 id:16;
> +};
> +
> +bool valid_cfgblock;
> +struct toradex_hw tdx_hw_tag;
> +struct toradex_eth_addr tdx_eth_addr;
> +u32 tdx_serial;
> +
> +const char * const toradex_modules[] = {
> +	 [0] = "UNKNOWN MODULE",
> +	 [1] = "Colibri PXA270 312MHz",
> +	 [2] = "Colibri PXA270 520MHz",
> +	 [3] = "Colibri PXA320 806MHz",
> +	 [4] = "Colibri PXA300 208MHz",
> +	 [5] = "Colibri PXA310 624MHz",
> +	 [6] = "Colibri PXA320 806MHz IT",
> +	 [7] = "Colibri PXA300 208MHz XT",
> +	 [8] = "Colibri PXA270 312MHz",
> +	 [9] = "Colibri PXA270 520MHz",
> +	[10] = "Colibri VF50 128MB", /* not currently on sale */
> +	[11] = "Colibri VF61 256MB",
> +	[12] = "Colibri VF61 256MB IT",
> +	[13] = "Colibri VF50 128MB IT",
> +	[14] = "Colibri iMX6 Solo 256MB",
> +	[15] = "Colibri iMX6 DualLite 512MB",
> +	[16] = "Colibri iMX6 Solo 256MB IT",
> +	[17] = "Colibri iMX6 DualLite 512MB IT",
> +	[18] = "UNKNOWN MODULE",
> +	[19] = "UNKNOWN MODULE",
> +	[20] = "Colibri T20 256MB",
> +	[21] = "Colibri T20 512MB",
> +	[22] = "Colibri T20 512MB IT",
> +	[23] = "Colibri T30 1GB",
> +	[24] = "Colibri T20 256MB IT",
> +	[25] = "Apalis T30 2GB",
> +	[26] = "Apalis T30 1GB",
> +	[27] = "Apalis iMX6 Quad 1GB",
> +	[28] = "Apalis iMX6 Quad 2GB IT",
> +	[29] = "Apalis iMX6 Dual 512MB",
> +	[30] = "Colibri T30 1GB IT",
> +	[31] = "Apalis T30 1GB IT",
> +	[32] = "Colibri iMX7 Solo 256MB",
> +	[33] = "Colibri iMX7 Dual 512MB",
> +	[34] = "Apalis TK1 2GB",
> +	[35] = "Apalis iMX6 Dual 1GB IT",
> +};
> +
> +#ifdef CONFIG_TDX_CFG_BLOCK_IS_IN_MMC
> +static int tdx_cfg_block_mmc_storage(u8 *config_block, int write)
> +{
> +	struct mmc *mmc;
> +	int dev = CONFIG_TDX_CFG_BLOCK_DEV;
> +	int offset = CONFIG_TDX_CFG_BLOCK_OFFSET;
> +	uint part = CONFIG_TDX_CFG_BLOCK_PART;
> +	uint blk_start;
> +	int ret = 0;
> +
> +	/* Read production parameter config block from eMMC */
> +	mmc = find_mmc_device(dev);
> +	if (!mmc) {
> +		puts("No MMC card found\n");
> +		ret = -ENODEV;
> +		goto out;
> +	}
> +	if (part != mmc->block_dev.hwpart) {
> +		if (blk_select_hwpart_devnum(IF_TYPE_MMC, dev, part)) {
> +			puts("MMC partition switch failed\n");
> +			ret = -ENODEV;
> +			goto out;
> +		}
> +	}
> +	if (offset < 0)
> +		offset += mmc->capacity;
> +	blk_start = ALIGN(offset, mmc->write_bl_len) / mmc->write_bl_len;
> +
> +	if (!write) {
> +		/* Careful reads a whole block of 512 bytes into config_block */
> +		if (blk_dread(mmc_get_blk_desc(mmc), blk_start, 1,
> +			      (unsigned char *)config_block) != 1) {
> +			ret = -EIO;
> +			goto out;
> +		}
> +		/* Flush cache after read */
> +		flush_cache((ulong)(unsigned char *)config_block, 512);
> +	} else {
> +		/* Just writing one 512 byte block */
> +		if (blk_dwrite(mmc_get_blk_desc(mmc), blk_start, 1,
> +			       (unsigned char *)config_block) != 1) {
> +			ret = -EIO;
> +			goto out;
> +		}
> +	}
> +
> +out:
> +	/* Switch back to regular eMMC user partition */
> +	blk_select_hwpart_devnum(IF_TYPE_MMC, 0, 0);
> +
> +	return ret;
> +}
> +#endif
> +
> +#ifdef CONFIG_TDX_CFG_BLOCK_IS_IN_NAND
> +static int read_tdx_cfg_block_from_nand(unsigned char *config_block)
> +{
> +	size_t size = TDX_CFG_BLOCK_MAX_SIZE;
> +
> +	/* Read production parameter config block from NAND page */
> +	return nand_read_skip_bad(nand_info[0], CONFIG_TDX_CFG_BLOCK_OFFSET,
> +			 &size, NULL, TDX_CFG_BLOCK_MAX_SIZE, config_block);
> +}
> +
> +static int write_tdx_cfg_block_to_nand(unsigned char *config_block)
> +{
> +	size_t size = TDX_CFG_BLOCK_MAX_SIZE;
> +
> +	/* Write production parameter config block to NAND page */
> +	return nand_write_skip_bad(nand_info[0], CONFIG_TDX_CFG_BLOCK_OFFSET,
> +				   &size, NULL, TDX_CFG_BLOCK_MAX_SIZE,
> +				   config_block, WITH_WR_VERIFY);
> +}
> +#endif
> +
> +#ifdef CONFIG_TDX_CFG_BLOCK_IS_IN_NOR
> +static int read_tdx_cfg_block_from_nor(unsigned char *config_block)
> +{
> +	/* Read production parameter config block from NOR flash */
> +	memcpy(config_block, (void *)CONFIG_TDX_CFG_BLOCK_OFFSET,
> +	       TDX_CFG_BLOCK_MAX_SIZE);
> +	return 0;
> +}
> +
> +static int write_tdx_cfg_block_to_nor(unsigned char *config_block)
> +{
> +	/* Write production parameter config block to NOR flash */
> +	return flash_write((void *)config_block, CONFIG_TDX_CFG_BLOCK_OFFSET,
> +			   TDX_CFG_BLOCK_MAX_SIZE);
> +}
> +#endif
> +
> +int read_tdx_cfg_block(void)
> +{
> +	int ret = 0;
> +	u8 *config_block = NULL;
> +	struct toradex_tag *tag;
> +	size_t size = TDX_CFG_BLOCK_MAX_SIZE;
> +	int offset;
> +
> +	/* Allocate RAM area for config block */
> +	config_block = memalign(ARCH_DMA_MINALIGN, size);
> +	if (!config_block) {
> +		printf("Not enough malloc space available!\n");
> +		return -ENOMEM;
> +	}
> +
> +	memset(config_block, 0, size);
> +
> +#if defined(CONFIG_TDX_CFG_BLOCK_IS_IN_MMC)
> +	ret = tdx_cfg_block_mmc_storage(config_block, 0);
> +#elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NAND)
> +	ret = read_tdx_cfg_block_from_nand(config_block);
> +#elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NOR)
> +	ret = read_tdx_cfg_block_from_nor(config_block);
> +#else
> +	ret = -EINVAL;
> +#endif
> +	if (ret)
> +		goto out;
> +
> +	/* Expect a valid tag first */
> +	tag = (struct toradex_tag *)config_block;
> +	if (tag->flags != TAG_FLAG_VALID || tag->id != TAG_VALID) {
> +		valid_cfgblock = false;
> +		ret = -EINVAL;
> +		goto out;
> +	}
> +	valid_cfgblock = true;
> +	offset = 4;
> +
> +	while (offset < TDX_CFG_BLOCK_MAX_SIZE) {
> +		tag = (struct toradex_tag *)(config_block + offset);
> +		offset += 4;
> +		if (tag->id == TAG_INVALID)
> +			break;
> +
> +		if (tag->flags == TAG_FLAG_VALID) {
> +			switch (tag->id) {
> +			case TAG_MAC:
> +				memcpy(&tdx_eth_addr, config_block + offset,
> +				       6);
> +
> +				/* NIC part of MAC address is serial number */
> +				tdx_serial = ntohl(tdx_eth_addr.nic) >> 8;
> +				break;
> +			case TAG_HW:
> +				memcpy(&tdx_hw_tag, config_block + offset, 8);
> +				break;
> +			}
> +		}
> +
> +		/* Get to next tag according to current tags length */
> +		offset += tag->len * 4;
> +	}
> +
> +	/* Cap product id to avoid issues with a yet unknown one */
> +	if (tdx_hw_tag.prodid > (sizeof(toradex_modules) /
> +				  sizeof(toradex_modules[0])))
> +		tdx_hw_tag.prodid = 0;
> +
> +out:
> +	free(config_block);
> +	return ret;
> +}
> +
> +static int get_cfgblock_interactive(void)
> +{
> +	char message[CONFIG_SYS_CBSIZE];
> +	char *soc;
> +	char it = 'n';
> +	int len;
> +
> +	if (cpu_is_pxa27x())
> +		sprintf(message, "Is the module the 312 MHz version? [y/N] ");
> +	else
> +		sprintf(message, "Is the module an IT version? [y/N] ");
> +
> +	len = cli_readline(message);
> +	it = console_buffer[0];
> +
> +	soc = getenv("soc");
> +	if (!strcmp("mx6", soc)) {
> +#ifdef CONFIG_MACH_TYPE
> +		if (it == 'y' || it == 'Y')
> +			if (is_cpu_type(MXC_CPU_MX6Q))
> +				tdx_hw_tag.prodid = APALIS_IMX6Q_IT;
> +			else
> +				tdx_hw_tag.prodid = APALIS_IMX6D_IT;
> +		else
> +			if (is_cpu_type(MXC_CPU_MX6Q))
> +				tdx_hw_tag.prodid = APALIS_IMX6Q;
> +			else
> +				tdx_hw_tag.prodid = APALIS_IMX6D;
> +#else
> +		if (it == 'y' || it == 'Y')
> +			if (is_cpu_type(MXC_CPU_MX6DL))
> +				tdx_hw_tag.prodid = COLIBRI_IMX6DL_IT;
> +			else
> +				tdx_hw_tag.prodid = COLIBRI_IMX6S_IT;
> +		else
> +			if (is_cpu_type(MXC_CPU_MX6DL))
> +				tdx_hw_tag.prodid = COLIBRI_IMX6DL;
> +			else
> +				tdx_hw_tag.prodid = COLIBRI_IMX6S;
> +#endif /* CONFIG_MACH_TYPE */
> +	} else if (!strcmp("imx7d", soc)) {
> +		tdx_hw_tag.prodid = COLIBRI_IMX7D;
> +	} else if (!strcmp("imx7s", soc)) {
> +		tdx_hw_tag.prodid = COLIBRI_IMX7S;
> +	} else if (!strcmp("tegra20", soc)) {
> +		if (it == 'y' || it == 'Y')
> +			if (gd->ram_size == 0x10000000)
> +				tdx_hw_tag.prodid = COLIBRI_T20_256MB_IT;
> +			else
> +				tdx_hw_tag.prodid = COLIBRI_T20_512MB_IT;
> +		else
> +			if (gd->ram_size == 0x10000000)
> +				tdx_hw_tag.prodid = COLIBRI_T20_256MB;
> +			else
> +				tdx_hw_tag.prodid = COLIBRI_T20_512MB;
> +	} else if (cpu_is_pxa27x()) {
> +		if (it == 'y' || it == 'Y')
> +			tdx_hw_tag.prodid = COLIBRI_PXA270_312MHZ;
> +		else
> +			tdx_hw_tag.prodid = COLIBRI_PXA270_520MHZ;
> +#ifdef CONFIG_MACH_TYPE
> +	} else if (!strcmp("tegra30", soc)) {
> +		if (CONFIG_MACH_TYPE == MACH_TYPE_APALIS_T30) {
> +			if (it == 'y' || it == 'Y')
> +				tdx_hw_tag.prodid = APALIS_T30_IT;
> +			else
> +				if (gd->ram_size == 0x40000000)
> +					tdx_hw_tag.prodid = APALIS_T30_1GB;
> +				else
> +					tdx_hw_tag.prodid = APALIS_T30_2GB;
> +		} else {
> +			if (it == 'y' || it == 'Y')
> +				tdx_hw_tag.prodid = COLIBRI_T30_IT;
> +			else
> +				tdx_hw_tag.prodid = COLIBRI_T30;
> +		}
> +#endif /* CONFIG_MACH_TYPE */
> +	} else if (!strcmp("tegra124", soc)) {
> +		tdx_hw_tag.prodid = APALIS_TK1_2GB;
> +	} else if (!strcmp("vf500", soc)) {
> +		if (it == 'y' || it == 'Y')
> +			tdx_hw_tag.prodid = COLIBRI_VF50_IT;
> +		else
> +			tdx_hw_tag.prodid = COLIBRI_VF50;
> +	} else if (!strcmp("vf610", soc)) {
> +		if (it == 'y' || it == 'Y')
> +			tdx_hw_tag.prodid = COLIBRI_VF61_IT;
> +		else
> +			tdx_hw_tag.prodid = COLIBRI_VF61;
> +	} else {
> +		printf("Module type not detectable due to unknown SoC\n");
> +		return -1;
> +	}
> +
> +	while (len < 4) {
> +		sprintf(message, "Enter the module version (e.g. V1.1B): V");
> +		len = cli_readline(message);
> +	}
> +
> +	tdx_hw_tag.ver_major = console_buffer[0] - '0';
> +	tdx_hw_tag.ver_minor = console_buffer[2] - '0';
> +	tdx_hw_tag.ver_assembly = console_buffer[3] - 'A';
> +
> +	if (cpu_is_pxa27x() && (tdx_hw_tag.ver_major == 1))
> +		tdx_hw_tag.prodid -= (COLIBRI_PXA270_312MHZ -
> +				       COLIBRI_PXA270_V1_312MHZ);
> +
> +	while (len < 8) {
> +		sprintf(message, "Enter module serial number: ");
> +		len = cli_readline(message);
> +	}
> +
> +	tdx_serial = simple_strtoul(console_buffer, NULL, 10);
> +
> +	return 0;
> +}
> +
> +static int get_cfgblock_barcode(char *barcode)
> +{
> +	if (strlen(barcode) < 16) {
> +		printf("Argument too short, barcode is 16 chars long\n");
> +		return -1;
> +	}
> +
> +	/* Get hardware information from the first 8 digits */
> +	tdx_hw_tag.ver_major = barcode[4] - '0';
> +	tdx_hw_tag.ver_minor = barcode[5] - '0';
> +	tdx_hw_tag.ver_assembly = barcode[7] - '0';
> +
> +	barcode[4] = '\0';
> +	tdx_hw_tag.prodid = simple_strtoul(barcode, NULL, 10);
> +
> +	/* Parse second part of the barcode (serial number */
> +	barcode += 8;
> +	tdx_serial = simple_strtoul(barcode, NULL, 10);
> +
> +	return 0;
> +}
> +
> +static int do_cfgblock_create(cmd_tbl_t *cmdtp, int flag, int argc,
> +			      char * const argv[])
> +{
> +	u8 *config_block;
> +	struct toradex_tag *tag;
> +	size_t size = TDX_CFG_BLOCK_MAX_SIZE;
> +	int offset = 0;
> +	int ret = CMD_RET_SUCCESS;
> +	int err;
> +
> +	/* Allocate RAM area for config block */
> +	config_block = memalign(ARCH_DMA_MINALIGN, size);
> +	if (!config_block) {
> +		printf("Not enough malloc space available!\n");
> +		return CMD_RET_FAILURE;
> +	}
> +
> +	memset(config_block, 0xff, size);
> +
> +	read_tdx_cfg_block();
> +	if (valid_cfgblock) {
> +#if defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NAND)
> +		/*
> +		 * On NAND devices, recreation is only allowed if the page is
> +		 * empty (config block invalid...)
> +		 */
> +		printf("NAND erase block %d need to be erased before creating a Toradex config block\n",
> +		       CONFIG_TDX_CFG_BLOCK_OFFSET / nand_info[0]->erasesize);
> +		goto out;
> +#elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NOR)
> +		/*
> +		 * On NOR devices, recreation is only allowed if the sector is
> +		 * empty and write protection is off (config block invalid...)
> +		 */
> +		printf("NOR sector at offset 0x%02x need to be erased and unprotected before creating a Toradex config block\n",
> +		       CONFIG_TDX_CFG_BLOCK_OFFSET);
> +		goto out;
> +#else
> +		char message[CONFIG_SYS_CBSIZE];
> +		sprintf(message,
> +			"A valid Toradex config block is present, still recreate? [y/N] ");
> +
> +		if (!cli_readline(message))
> +			goto out;
> +
> +		if (console_buffer[0] != 'y' && console_buffer[0] != 'Y')
> +			goto out;
> +#endif
> +	}
> +
> +	/* Parse new Toradex config block data... */
> +	if (argc < 3)
> +		err = get_cfgblock_interactive();
> +	else
> +		err = get_cfgblock_barcode(argv[2]);
> +
> +	if (err) {
> +		ret = CMD_RET_FAILURE;
> +		goto out;
> +	}
> +
> +	/* Convert serial number to MAC address (the storage format) */
> +	tdx_eth_addr.oui = htonl(0x00142dUL << 8);
> +	tdx_eth_addr.nic = htonl(tdx_serial << 8);
> +
> +	/* Valid Tag */
> +	tag = (struct toradex_tag *)config_block;
> +	tag->id = TAG_VALID;
> +	tag->flags = TAG_FLAG_VALID;
> +	tag->len = 0;
> +	offset += 4;
> +
> +	/* Product Tag */
> +	tag = (struct toradex_tag *)(config_block + offset);
> +	tag->id = TAG_HW;
> +	tag->flags = TAG_FLAG_VALID;
> +	tag->len = 2;
> +	offset += 4;
> +
> +	memcpy(config_block + offset, &tdx_hw_tag, 8);
> +	offset += 8;
> +
> +	/* MAC Tag */
> +	tag = (struct toradex_tag *)(config_block + offset);
> +	tag->id = TAG_MAC;
> +	tag->flags = TAG_FLAG_VALID;
> +	tag->len = 2;
> +	offset += 4;
> +
> +	memcpy(config_block + offset, &tdx_eth_addr, 6);
> +	offset += 6;
> +	memset(config_block + offset, 0, 32 - offset);
> +
> +#if defined(CONFIG_TDX_CFG_BLOCK_IS_IN_MMC)
> +	err = tdx_cfg_block_mmc_storage(config_block, 1);
> +#elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NAND)
> +	err = write_tdx_cfg_block_to_nand(config_block);
> +#elif defined(CONFIG_TDX_CFG_BLOCK_IS_IN_NOR)
> +	err = write_tdx_cfg_block_to_nor(config_block);
> +#else
> +	err = -EINVAL;
> +#endif
> +	if (err) {
> +		printf("Failed to write Toradex config block: %d\n", ret);
> +		ret = CMD_RET_FAILURE;
> +		goto out;
> +	}
> +
> +	printf("Toradex config block successfully written\n");
> +
> +out:
> +	free(config_block);
> +	return ret;
> +}
> +
> +static int do_cfgblock(cmd_tbl_t *cmdtp, int flag, int argc,
> +		       char * const argv[])
> +{
> +	int ret;
> +
> +	if (argc < 2)
> +		return CMD_RET_USAGE;
> +
> +	if (!strcmp(argv[1], "create")) {
> +		return do_cfgblock_create(cmdtp, flag, argc, argv);
> +	} else if (!strcmp(argv[1], "reload")) {
> +		ret = read_tdx_cfg_block();
> +		if (ret) {
> +			printf("Failed to reload Toradex config block: %d\n",
> +			       ret);
> +			return CMD_RET_FAILURE;
> +		}
> +		return CMD_RET_SUCCESS;
> +	}
> +
> +	return CMD_RET_USAGE;
> +}
> +
> +U_BOOT_CMD(
> +	cfgblock, 3, 0, do_cfgblock,
> +	"Toradex config block handling commands",
> +	"create [barcode] - (Re-)create Toradex config block\n"
> +	"cfgblock reload - Reload Toradex config block from flash"
> +);
> diff --git a/board/toradex/common/tdx-cfg-block.h b/board/toradex/common/tdx-cfg-block.h
> new file mode 100644
> index 0000000..fd7c362
> --- /dev/null
> +++ b/board/toradex/common/tdx-cfg-block.h
> @@ -0,0 +1,68 @@
> +/*
> + * Copyright (c) 2016 Toradex, Inc.
> + *
> + * SPDX-License-Identifier:	GPL-2.0+
> + */
> +
> +#ifndef _TDX_CFG_BLOCK_H
> +#define _TDX_CFG_BLOCK_H
> +
> +#include "tdx-common.h"
> +
> +struct toradex_hw {
> +	u16 ver_major;
> +	u16 ver_minor;
> +	u16 ver_assembly;
> +	u16 prodid;
> +};
> +
> +struct toradex_eth_addr {
> +	u32 oui:24;
> +	u32 nic:24;
> +} __attribute__((__packed__));
> +
> +enum {
> +	COLIBRI_PXA270_V1_312MHZ = 1,
> +	COLIBRI_PXA270_V1_520MHZ,
> +	COLIBRI_PXA320,
> +	COLIBRI_PXA300,
> +	COLIBRI_PXA310,
> +	COLIBRI_PXA320_IT,
> +	COLIBRI_PXA300_XT,
> +	COLIBRI_PXA270_312MHZ,
> +	COLIBRI_PXA270_520MHZ,
> +	COLIBRI_VF50, /* not currently on sale */
> +	COLIBRI_VF61,
> +	COLIBRI_VF61_IT,
> +	COLIBRI_VF50_IT,
> +	COLIBRI_IMX6S,
> +	COLIBRI_IMX6DL,
> +	COLIBRI_IMX6S_IT,
> +	COLIBRI_IMX6DL_IT,
> +	COLIBRI_T20_256MB = 20,
> +	COLIBRI_T20_512MB,
> +	COLIBRI_T20_512MB_IT,
> +	COLIBRI_T30,
> +	COLIBRI_T20_256MB_IT,
> +	APALIS_T30_2GB,
> +	APALIS_T30_1GB,
> +	APALIS_IMX6Q,
> +	APALIS_IMX6Q_IT,
> +	APALIS_IMX6D,
> +	COLIBRI_T30_IT,
> +	APALIS_T30_IT,
> +	COLIBRI_IMX7S,
> +	COLIBRI_IMX7D,
> +	APALIS_TK1_2GB,
> +	APALIS_IMX6D_IT,
> +};
> +
> +extern const char * const toradex_modules[];
> +extern bool valid_cfgblock;
> +extern struct toradex_hw tdx_hw_tag;
> +extern struct toradex_eth_addr tdx_eth_addr;
> +extern u32 tdx_serial;
> +
> +int read_tdx_cfg_block(void);
> +
> +#endif /* _TDX_CFG_BLOCK_H */
> diff --git a/board/toradex/common/tdx-common.c b/board/toradex/common/tdx-common.c
> new file mode 100644
> index 0000000..e1a81cb
> --- /dev/null
> +++ b/board/toradex/common/tdx-common.c
> @@ -0,0 +1,180 @@
> +/*
> + * Copyright (c) 2016 Toradex, Inc.
> + *
> + * SPDX-License-Identifier:	GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <g_dnl.h>
> +#include <libfdt.h>
> +
> +#include "tdx-cfg-block.h"
> +#include "tdx-common.h"
> +
> +__weak int checkboard_fallback(void)
> +{
> +	return 0;
> +}
> +
> +#ifdef CONFIG_TDX_CFG_BLOCK
> +static char tdx_serial_str[9];
> +static char tdx_board_rev_str[6];
> +
> +#ifdef CONFIG_REVISION_TAG
> +u32 get_board_rev(void)
> +{
> +	/* Check validity */
> +	if (!tdx_hw_tag.ver_major)
> +		return 0;
> +
> +	return ((tdx_hw_tag.ver_major & 0xff) << 8) |
> +		((tdx_hw_tag.ver_minor & 0xf) << 4) |
> +		((tdx_hw_tag.ver_assembly & 0xf) + 0xa);
> +}
> +#endif /* CONFIG_TDX_CFG_BLOCK */
> +
> +#ifdef CONFIG_SERIAL_TAG
> +void get_board_serial(struct tag_serialnr *serialnr)
> +{
> +	int array[8];
> +	unsigned int serial = tdx_serial;
> +	int i;
> +
> +	serialnr->low = 0;
> +	serialnr->high = 0;
> +
> +	/* Check validity */
> +	if (serial) {
> +		/*
> +		 * Convert to Linux serial number format (hexadecimal coded
> +		 * decimal)
> +		 */
> +		i = 7;
> +		while (serial) {
> +			array[i--] = serial % 10;
> +			serial /= 10;
> +		}
> +		while (i >= 0)
> +			array[i--] = 0;
> +		serial = array[0];
> +		for (i = 1; i < 8; i++) {
> +			serial *= 16;
> +			serial += array[i];
> +		}
> +
> +		serialnr->low = serial;
> +	}
> +}
> +#endif /* CONFIG_SERIAL_TAG */
> +
> +int checkboard(void)
> +{
> +	unsigned char ethaddr[6];
> +
> +	if (read_tdx_cfg_block()) {
> +		printf("Missing Toradex config block\n");
> +		checkboard_fallback();
> +		return 0;
> +	}
> +
> +	/* board serial-number */
> +	sprintf(tdx_serial_str, "%08u", tdx_serial);
> +	sprintf(tdx_board_rev_str, "V%1d.%1d%c",
> +		tdx_hw_tag.ver_major,
> +		tdx_hw_tag.ver_minor,
> +		(char)tdx_hw_tag.ver_assembly + 'A');
> +
> +	setenv("serial#", tdx_serial_str);
> +
> +	/*
> +	 * Check if environment contains a valid MAC address,
> +	 * set the one from config block if not
> +	 */
> +	if (!eth_getenv_enetaddr("ethaddr", ethaddr))
> +		eth_setenv_enetaddr("ethaddr", (u8 *)&tdx_eth_addr);
> +
> +#ifdef CONFIG_TDX_CFG_BLOCK_2ND_ETHADDR
> +	if (!eth_getenv_enetaddr("eth1addr", ethaddr)) {
> +		/*
> +		 * Secondary MAC address is allocated from block
> +		 * 0x100000 higher then the first MAC address
> +		 */
> +		memcpy(ethaddr, &tdx_eth_addr, 6);
> +		ethaddr[3] += 0x10;
> +		eth_setenv_enetaddr("eth1addr", ethaddr);
> +	}
> +#endif
> +
> +	printf("Model: Toradex %s %s, Serial# %s\n",
> +	       toradex_modules[tdx_hw_tag.prodid],
> +	       tdx_board_rev_str,
> +	       tdx_serial_str);
> +
> +	return 0;
> +}
> +
> +#ifdef CONFIG_USBDOWNLOAD_GADGET
> +int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
> +{
> +	unsigned short usb_pid;
> +
> +	usb_pid = TORADEX_USB_PRODUCT_NUM_OFFSET + tdx_hw_tag.prodid;
> +	put_unaligned(usb_pid, &dev->idProduct);
> +
> +	return 0;
> +}
> +#endif /* CONFIG_USBDOWNLOAD_GADGET */
> +
> +#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
> +int ft_board_setup(void *blob, bd_t *bd)
> +{
> +	if (tdx_serial) {
> +		fdt_setprop(blob, 0, "serial-number", tdx_serial_str,
> +			    strlen(tdx_serial_str) + 1);
> +	}
> +
> +	if (tdx_hw_tag.ver_major) {
> +		char prod_id[5];
> +
> +		sprintf(prod_id, "%04u", tdx_hw_tag.prodid);
> +		fdt_setprop(blob, 0, "toradex,product-id", prod_id, 5);
> +
> +		fdt_setprop(blob, 0, "toradex,board-rev", tdx_board_rev_str,
> +			    strlen(tdx_board_rev_str) + 1);
> +	}
> +
> +	return 0;
> +}
> +#endif
> +
> +#else /* CONFIG_TDX_CFG_BLOCK */
> +
> +#ifdef CONFIG_REVISION_TAG
> +u32 get_board_rev(void)
> +{
> +	return 0;
> +}
> +#endif /* CONFIG_REVISION_TAG */
> +
> +#ifdef CONFIG_SERIAL_TAG
> +u32 get_board_serial(void)
> +{
> +	return 0;
> +}
> +#endif /* CONFIG_SERIAL_TAG */
> +
> +int checkboard(void)
> +{
> +	checkboard_fallback();
> +
> +	return 0;
> +}
> +
> +#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
> +int ft_board_setup(void *blob, bd_t *bd)
> +{
> +	return 0;
> +}
> +#endif
> +
> +#endif /* CONFIG_TDX_CFG_BLOCK */
> diff --git a/board/toradex/common/tdx-common.h b/board/toradex/common/tdx-common.h
> new file mode 100644
> index 0000000..f308ebd
> --- /dev/null
> +++ b/board/toradex/common/tdx-common.h
> @@ -0,0 +1,13 @@
> +/*
> + * Copyright (c) 2016 Toradex, Inc.
> + *
> + * SPDX-License-Identifier:	GPL-2.0+
> + */
> +
> +#ifndef _TDX_COMMON_H
> +#define _TDX_COMMON_H
> +
> +#define TORADEX_USB_PRODUCT_NUM_OFFSET	0x4000
> +#define TDX_USB_VID			0x1B67
> +
> +#endif /* _TDX_COMMON_H */

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [U-Boot] [PATCH v2 2/6] apalis/colibri_t20/t30: deactivate displaying board info
  2016-09-30 10:00     ` Marcel Ziswiler
@ 2016-10-03 17:28       ` Stephen Warren
  2016-10-03 20:27         ` Stefan Agner
  0 siblings, 1 reply; 18+ messages in thread
From: Stephen Warren @ 2016-10-03 17:28 UTC (permalink / raw)
  To: u-boot

On 09/30/2016 04:00 AM, Marcel Ziswiler wrote:
> On Wed, 2016-09-28 at 12:00 -0600, Stephen Warren wrote:
>> On 09/28/2016 03:35 AM, Marcel Ziswiler wrote:
>>>
>>> Avoid a checkboard() name clash with our upcoming custom
>>> implementation
>>> thereof.
>> If you want to avoid naming conflicts, please simply name your new
>> function something that doesn't conflict. That way it will avoid
>> confusion is someone actually wants to enable the
>> CONFIG_DISPLAY_BOARDINFO option themselves, plus it avoids taking
>> the
>> current feature set away.
>
> No, it is not just any function. We do want our custom checkboard() to
> be called upon boot and not the Tegra generic one just printing a hard
> coded string.
>
> I guess alternatively we could gate the checkboard() call
> in arch/arm/mach-tegra/board2.c with a
>
> #if !defined(CONFIG_CUSTOM_BOARDINFO)
>
> just as introduced a while ago in common/board_info.c
>
> http://git.denx.de/?p=u-boot.git;a=blob;f=common/board_info.c;h=bd5dcfa
> 066358c2cc44ce5d19fcc3e77d555cd09;hb=HEAD#l20
>
> in order to not print the hard coded name from the device tree.

I'd prefer to keep the behaviour standard across all Tegra boards. If 
you want to do additional actions in the checkboard() function, I 
suggest making it call an optional additional function:

__weak int tegra_checkboard(void)
{
         return 0;
}

int checkboard(void)
{
     ...
     return tegra_checkboard();
}

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [U-Boot] [PATCH v2 5/6] apalis/colibri_t30: move environment location
  2016-09-30 11:44     ` Marcel Ziswiler
@ 2016-10-03 17:31       ` Stephen Warren
  0 siblings, 0 replies; 18+ messages in thread
From: Stephen Warren @ 2016-10-03 17:31 UTC (permalink / raw)
  To: u-boot

On 09/30/2016 05:44 AM, Marcel Ziswiler wrote:
> On Wed, 2016-09-28 at 12:11 -0600, Stephen Warren wrote:
>> On 09/28/2016 03:35 AM, Marcel Ziswiler wrote:
>>>
>>> Now with the config block handling in place move the U-Boot
>>> environment
>>> location before the config block at the end of 1st "boot sector" as
>>> deployed during production using our downstream BSP.
>>>
>>> diff --git a/include/configs/apalis_t30.h b/include/configs/apalis_t30.h
>>>
>>> -/* Environment in eMMC, at the end of 2nd "boot sector" */
>>> +/* Environment in eMMC, before config block at the end of 1st "boot sector" */
>>>  #define CONFIG_ENV_IS_IN_MMC
>>> -#define CONFIG_ENV_OFFSET		(-CONFIG_ENV_SIZE)
>>> +#define CONFIG_ENV_OFFSET		(-CONFIG_ENV_SIZE + \
>>> +					 CONFIG_TDX_CFG_BLOCK_OFFSET)
>> I'm not convinced that ENV_OFFSET actually points where the description
>> says it does. (-CONFIG_ENV_SIZE + CONFIG_TDX_CFG_BLOCK_OFFSET) is (-8192
>> + -512). The original comment states that an ENV_OFFSET of -8192 locates
>> the environment at the end of a sector, so shifting it 512 bytes earlier
>> in the flash can't possible now align it with a different sector?
>
> Why not?

If -8192 is aligned to the last sector boundary, the sectors must be 
8192 bytes in size (or the last sector isn't a whole sector, which is 
highly unlikely). If so, then 512 bytes away from that isn't also at a 
sector boundary.

>> Should  ENV_OFFSET be shifted down by a whole sector size by this patch, i.e. should
>> +CONFIG_TXT_CFG_BLOCK_OFFSET be rounded up to a sector size to  match the comment?
>
> Yes, a block, sector or whatever you wana call it is actually 512 bytes
> in size on all eMMCs or even MMC/SD cards that I have seen so far.
>
> I guess while it would be kind of nice having this enforced to some
> intrinsic size in software ultimately this is a board configuration
> option concerning our Toradex factory configuration block as programmed
> during production. We just want to make sure that one is preserved and
> the environment is stored right before.

Ah, I see. the existing comment uses the term "sector" incorrectly, 
which is where the confusion arises. eMMC do indeed have 512-byte 
sectors. I suppose the old (and new) comments should refer to HW boot 
partitions, not "sectors"?

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [U-Boot] [PATCH v2 2/6] apalis/colibri_t20/t30: deactivate displaying board info
  2016-10-03 17:28       ` Stephen Warren
@ 2016-10-03 20:27         ` Stefan Agner
  2016-10-05 15:53           ` Stephen Warren
  0 siblings, 1 reply; 18+ messages in thread
From: Stefan Agner @ 2016-10-03 20:27 UTC (permalink / raw)
  To: u-boot

On 03.10.2016 10:28, Stephen Warren wrote:
> On 09/30/2016 04:00 AM, Marcel Ziswiler wrote:
>> On Wed, 2016-09-28 at 12:00 -0600, Stephen Warren wrote:
>>> On 09/28/2016 03:35 AM, Marcel Ziswiler wrote:
>>>>
>>>> Avoid a checkboard() name clash with our upcoming custom
>>>> implementation
>>>> thereof.
>>> If you want to avoid naming conflicts, please simply name your new
>>> function something that doesn't conflict. That way it will avoid
>>> confusion is someone actually wants to enable the
>>> CONFIG_DISPLAY_BOARDINFO option themselves, plus it avoids taking
>>> the
>>> current feature set away.
>>
>> No, it is not just any function. We do want our custom checkboard() to
>> be called upon boot and not the Tegra generic one just printing a hard
>> coded string.
>>
>> I guess alternatively we could gate the checkboard() call
>> in arch/arm/mach-tegra/board2.c with a
>>
>> #if !defined(CONFIG_CUSTOM_BOARDINFO)
>>
>> just as introduced a while ago in common/board_info.c
>>
>> http://git.denx.de/?p=u-boot.git;a=blob;f=common/board_info.c;h=bd5dcfa
>> 066358c2cc44ce5d19fcc3e77d555cd09;hb=HEAD#l20
>>
>> in order to not print the hard coded name from the device tree.
>
> I'd prefer to keep the behaviour standard across all Tegra boards. If
> you want to do additional actions in the checkboard() function, I
> suggest making it call an optional additional function:
>
> __weak int tegra_checkboard(void)
> {
>         return 0;
> }
>
> int checkboard(void)
> {
>     ...
>     return tegra_checkboard();
> }
Well that would print a message "Board: " ... twice, which is rather
strange.

What do you think of my idea?

--
Stefan

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [U-Boot] [PATCH v2 2/6] apalis/colibri_t20/t30: deactivate displaying board info
  2016-10-03 20:27         ` Stefan Agner
@ 2016-10-05 15:53           ` Stephen Warren
  2016-10-05 16:12             ` Stefan Agner
  0 siblings, 1 reply; 18+ messages in thread
From: Stephen Warren @ 2016-10-05 15:53 UTC (permalink / raw)
  To: u-boot

On 10/03/2016 02:27 PM, Stefan Agner wrote:
> On 03.10.2016 10:28, Stephen Warren wrote:
>> On 09/30/2016 04:00 AM, Marcel Ziswiler wrote:
>>> On Wed, 2016-09-28 at 12:00 -0600, Stephen Warren wrote:
>>>> On 09/28/2016 03:35 AM, Marcel Ziswiler wrote:
>>>>>
>>>>> Avoid a checkboard() name clash with our upcoming custom
>>>>> implementation
>>>>> thereof.
>>>> If you want to avoid naming conflicts, please simply name your new
>>>> function something that doesn't conflict. That way it will avoid
>>>> confusion is someone actually wants to enable the
>>>> CONFIG_DISPLAY_BOARDINFO option themselves, plus it avoids taking
>>>> the
>>>> current feature set away.
>>>
>>> No, it is not just any function. We do want our custom checkboard() to
>>> be called upon boot and not the Tegra generic one just printing a hard
>>> coded string.
>>>
>>> I guess alternatively we could gate the checkboard() call
>>> in arch/arm/mach-tegra/board2.c with a
>>>
>>> #if !defined(CONFIG_CUSTOM_BOARDINFO)
>>>
>>> just as introduced a while ago in common/board_info.c
>>>
>>> http://git.denx.de/?p=u-boot.git;a=blob;f=common/board_info.c;h=bd5dcfa
>>> 066358c2cc44ce5d19fcc3e77d555cd09;hb=HEAD#l20
>>>
>>> in order to not print the hard coded name from the device tree.
>>
>> I'd prefer to keep the behaviour standard across all Tegra boards. If
>> you want to do additional actions in the checkboard() function, I
>> suggest making it call an optional additional function:
>>
>> __weak int tegra_checkboard(void)
>> {
>>         return 0;
>> }
>>
>> int checkboard(void)
>> {
>>     ...
>>     return tegra_checkboard();
>> }
 >
> Well that would print a message "Board: " ... twice, which is rather
> strange.

Surely you simply make tegra_checkboard() not contain duplicate code?

> What do you think of my idea?

I'd rather not introduce any more ifdefs, but instead have a single path 
through the code-base.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [U-Boot] [PATCH v2 2/6] apalis/colibri_t20/t30: deactivate displaying board info
  2016-10-05 15:53           ` Stephen Warren
@ 2016-10-05 16:12             ` Stefan Agner
  2016-10-10 19:27               ` Stephen Warren
  0 siblings, 1 reply; 18+ messages in thread
From: Stefan Agner @ 2016-10-05 16:12 UTC (permalink / raw)
  To: u-boot

On 2016-10-05 08:53, Stephen Warren wrote:
> On 10/03/2016 02:27 PM, Stefan Agner wrote:
>> On 03.10.2016 10:28, Stephen Warren wrote:
>>> On 09/30/2016 04:00 AM, Marcel Ziswiler wrote:
>>>> On Wed, 2016-09-28 at 12:00 -0600, Stephen Warren wrote:
>>>>> On 09/28/2016 03:35 AM, Marcel Ziswiler wrote:
>>>>>>
>>>>>> Avoid a checkboard() name clash with our upcoming custom
>>>>>> implementation
>>>>>> thereof.
>>>>> If you want to avoid naming conflicts, please simply name your new
>>>>> function something that doesn't conflict. That way it will avoid
>>>>> confusion is someone actually wants to enable the
>>>>> CONFIG_DISPLAY_BOARDINFO option themselves, plus it avoids taking
>>>>> the
>>>>> current feature set away.
>>>>
>>>> No, it is not just any function. We do want our custom checkboard() to
>>>> be called upon boot and not the Tegra generic one just printing a hard
>>>> coded string.
>>>>
>>>> I guess alternatively we could gate the checkboard() call
>>>> in arch/arm/mach-tegra/board2.c with a
>>>>
>>>> #if !defined(CONFIG_CUSTOM_BOARDINFO)
>>>>
>>>> just as introduced a while ago in common/board_info.c
>>>>
>>>> http://git.denx.de/?p=u-boot.git;a=blob;f=common/board_info.c;h=bd5dcfa
>>>> 066358c2cc44ce5d19fcc3e77d555cd09;hb=HEAD#l20
>>>>
>>>> in order to not print the hard coded name from the device tree.
>>>
>>> I'd prefer to keep the behaviour standard across all Tegra boards. If
>>> you want to do additional actions in the checkboard() function, I
>>> suggest making it call an optional additional function:
>>>
>>> __weak int tegra_checkboard(void)
>>> {
>>>         return 0;
>>> }
>>>
>>> int checkboard(void)
>>> {
>>>     ...
>>>     return tegra_checkboard();
>>> }
>>
>> Well that would print a message "Board: " ... twice, which is rather
>> strange.
> 
> Surely you simply make tegra_checkboard() not contain duplicate code?
> 
>> What do you think of my idea?
> 
> I'd rather not introduce any more ifdefs, but instead have a single
> path through the code-base.

Sorry, I was a bit unclear, with my other idea I meant the answer I sent
to patch 3/6 of this patchset:
http://lists.denx.de/pipermail/u-boot/2016-October/268669.html

It does remove a ifdef...

--
Stefan

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [U-Boot] [PATCH v2 2/6] apalis/colibri_t20/t30: deactivate displaying board info
  2016-10-05 16:12             ` Stefan Agner
@ 2016-10-10 19:27               ` Stephen Warren
  0 siblings, 0 replies; 18+ messages in thread
From: Stephen Warren @ 2016-10-10 19:27 UTC (permalink / raw)
  To: u-boot

On 10/05/2016 10:12 AM, Stefan Agner wrote:
> On 2016-10-05 08:53, Stephen Warren wrote:
>> On 10/03/2016 02:27 PM, Stefan Agner wrote:
>>> On 03.10.2016 10:28, Stephen Warren wrote:
>>>> On 09/30/2016 04:00 AM, Marcel Ziswiler wrote:
>>>>> On Wed, 2016-09-28 at 12:00 -0600, Stephen Warren wrote:
>>>>>> On 09/28/2016 03:35 AM, Marcel Ziswiler wrote:
>>>>>>>
>>>>>>> Avoid a checkboard() name clash with our upcoming custom
>>>>>>> implementation
>>>>>>> thereof.
>>>>>> If you want to avoid naming conflicts, please simply name your new
>>>>>> function something that doesn't conflict. That way it will avoid
>>>>>> confusion is someone actually wants to enable the
>>>>>> CONFIG_DISPLAY_BOARDINFO option themselves, plus it avoids taking
>>>>>> the
>>>>>> current feature set away.
>>>>>
>>>>> No, it is not just any function. We do want our custom checkboard() to
>>>>> be called upon boot and not the Tegra generic one just printing a hard
>>>>> coded string.
>>>>>
>>>>> I guess alternatively we could gate the checkboard() call
>>>>> in arch/arm/mach-tegra/board2.c with a
>>>>>
>>>>> #if !defined(CONFIG_CUSTOM_BOARDINFO)
>>>>>
>>>>> just as introduced a while ago in common/board_info.c
>>>>>
>>>>> http://git.denx.de/?p=u-boot.git;a=blob;f=common/board_info.c;h=bd5dcfa
>>>>> 066358c2cc44ce5d19fcc3e77d555cd09;hb=HEAD#l20
>>>>>
>>>>> in order to not print the hard coded name from the device tree.
>>>>
>>>> I'd prefer to keep the behaviour standard across all Tegra boards. If
>>>> you want to do additional actions in the checkboard() function, I
>>>> suggest making it call an optional additional function:
>>>>
>>>> __weak int tegra_checkboard(void)
>>>> {
>>>>         return 0;
>>>> }
>>>>
>>>> int checkboard(void)
>>>> {
>>>>     ...
>>>>     return tegra_checkboard();
>>>> }
>>>
>>> Well that would print a message "Board: " ... twice, which is rather
>>> strange.
>>
>> Surely you simply make tegra_checkboard() not contain duplicate code?
>>
>>> What do you think of my idea?
>>
>> I'd rather not introduce any more ifdefs, but instead have a single
>> path through the code-base.
>
> Sorry, I was a bit unclear, with my other idea I meant the answer I sent
> to patch 3/6 of this patchset:
> http://lists.denx.de/pipermail/u-boot/2016-October/268669.html
>
> It does remove a ifdef...

That's probably better than adding more ifdefs. It does have the 
disadvantage of not using the common show_board_info() or Tegra-wide 
checkboard() implementations though, which means that anything added 
there won't execute on all Tegras, which could potentially be confusing.

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2016-10-10 19:27 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-28  9:35 [U-Boot] [PATCH v2 0/6] toradex: config block handling Marcel Ziswiler
2016-09-28  9:35 ` [U-Boot] [PATCH v2 1/6] colibri_imx7/vf: move to custom checkboard_fallback() Marcel Ziswiler
2016-09-28  9:35 ` [U-Boot] [PATCH v2 2/6] apalis/colibri_t20/t30: deactivate displaying board info Marcel Ziswiler
2016-09-28 18:00   ` Stephen Warren
2016-09-30 10:00     ` Marcel Ziswiler
2016-10-03 17:28       ` Stephen Warren
2016-10-03 20:27         ` Stefan Agner
2016-10-05 15:53           ` Stephen Warren
2016-10-05 16:12             ` Stefan Agner
2016-10-10 19:27               ` Stephen Warren
2016-09-28  9:35 ` [U-Boot] [PATCH v2 3/6] toradex: config block handling Marcel Ziswiler
2016-09-30 22:28   ` Stefan Agner
2016-09-28  9:35 ` [U-Boot] [PATCH v2 4/6] apalis/colibri_imx7/pxa270/t20/t30/vf: integrate " Marcel Ziswiler
2016-09-28  9:35 ` [U-Boot] [PATCH v2 5/6] apalis/colibri_t30: move environment location Marcel Ziswiler
2016-09-28 18:11   ` Stephen Warren
2016-09-30 11:44     ` Marcel Ziswiler
2016-10-03 17:31       ` Stephen Warren
2016-09-28  9:35 ` [U-Boot] [PATCH v2 6/6] colibri_vf: usb gadget: toradex pid is now set generically Marcel Ziswiler

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.