Skip to contentSkip to conversation

imx: nandbcb update

PATCH New Peng Fan 2 participants 13 messages May 5, 2020 – May 11, 2020

Subsystems (3)
lore
Share & tools
lore

Peng Fan

author
#0 lore raw

cover imx: nandbcb update

i.MX nandbcb update to support i.MX8M, add dump command, restructure, fix gf_14, add boot search count for i.MX8

Alice Guo (3):
nandbcb: support i.MX8M
nandbcb: add nandbcb dump command for i.MX8MM
nandbcb: add nandbcb dump command for i.MX6

Han Xu (3):
nandbcb: fix the issue cannot support gf_14 NAND boot
cmd: nandbcb: Reconstruct the nandbcb tool for all platforms
nandbcb: read boot search count from fuse for imx8qxp

 arch/arm/include/asm/mach-imx/imx-nandbcb.h |    4 +-
 arch/arm/mach-imx/Kconfig                   |    2 +-
 arch/arm/mach-imx/cmd_nandbcb.c             | 1241 +++++++++++++++++++++++----
 3 files changed, 1094 insertions(+), 153 deletions(-)
Signature · 1 line
2.16.4
author
#1 lore raw

PATCH 1/6 nandbcb: fix the issue cannot support gf_14 NAND boot

From: Han Xu <[email protected]>

bchtype in FCB should be associated to the gf_13/14 settings in BCH, fix the issue and test on Micron 29F64G08CBABB, it can boot after the change.

---
 arch/arm/mach-imx/cmd_nandbcb.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm/mach-imx/cmd_nandbcb.c +1 -0
index b3e59b1b00..103c3d6a08 100644
@@ -154,6 +154,7 @@ static void fill_fcb(struct fcb_block *fcb, struct mtd_info *mtd,
 	fcb->ecc_level = l.ecc0;
 	fcb->ecc_size = l.datan_size;
 	fcb->ecc_type = l.eccn;
+	fcb->bchtype = l.gf_len;
 
 	/* Also hardcoded in kobs-ng */
 	if (is_mx6()) {
Signature · 1 line
2.16.4
#2 lore raw

PATCH 1/6 nandbcb: fix the issue cannot support gf_14 NAND boot

Quoted 6 lines

From: Han Xu <[email protected]>
bchtype in FCB should be associated to the gf_13/14 settings in BCH, fix the issue and test on Micron 29F64G08CBABB, it can boot after the change.

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

Best regards,
Stefano Babic

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

PATCH 2/6 nandbcb: support i.MX8M

In reply to Peng Fan

From: Alice Guo <[email protected]>

Tested on i.MX8MM EVK, imx8mm evk uses BCH encoding and randomizer
modify macro and print size_t with %zx
use CONFIG_IMX8M because it should apply to imx8mq/mm/mn

---
 arch/arm/mach-imx/Kconfig       |  2 +-
 arch/arm/mach-imx/cmd_nandbcb.c | 88 +++++++++++++++++++++++++++++++----------
 2 files changed, 68 insertions(+), 22 deletions(-)
arch/arm/mach-imx/Kconfig +1 -1
index 2b97208445..6c3fedf665 100644
@@ -89,7 +89,7 @@ config CMD_NANDBCB
 	bool "i.MX6 NAND Boot Control Block(BCB) command"
 	depends on MTD_RAW_NAND && CMD_MTDPARTS
 	select BCH if MX6UL || MX6ULL
-	default y if (ARCH_MX6 && NAND_MXS) || (ARCH_MX7 && NAND_MXS)
+	default y if ((ARCH_MX6 || ARCH_MX7 || ARCH_IMX8M) && NAND_MXS)
 	help
 	  Unlike normal 'nand write/erase' commands, this command update
 	  Boot Control Block(BCB) for i.MX6 platform NAND IP's.
arch/arm/mach-imx/cmd_nandbcb.c +67 -21

140 lines not on this page · raw message

Signature · 1 line
2.16.4
#4 lore raw

PATCH 2/6 nandbcb: support i.MX8M

Quoted 7 lines

From: Alice Guo <[email protected]>
Tested on i.MX8MM EVK, imx8mm evk uses BCH encoding and randomizer
modify macro and print size_t with %zx
use CONFIG_IMX8M because it should apply to imx8mq/mm/mn

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

Best regards,
Stefano Babic

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

PATCH 3/6 nandbcb: add nandbcb dump command for i.MX8MM

In reply to Peng Fan

From: Alice Guo <[email protected]>

Verify/dump boot structures written to NAND Flash chip.

---
 arch/arm/mach-imx/cmd_nandbcb.c | 266 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 258 insertions(+), 8 deletions(-)
arch/arm/mach-imx/cmd_nandbcb.c +258 -8
index 682f5064e6..02a65ffd43 100644
@@ -25,6 +25,7 @@
 #include <mxs_nand.h>
 #include <linux/mtd/mtd.h>
 #include <nand.h>
+#include <div64.h>
 
 #include "../../../cmd/legacy-mtd-utils.h"
 
@@ -32,6 +33,16 @@
 #define GETBIT(v, n)		(((v) >> (n)) & 0x1)
 #define IMX8MQ_SPL_SZ 0x3e000
 #define IMX8MQ_HDMI_FW_SZ 0x19c00
+#define BOOT_SEARCH_COUNT 2
+
+struct mtd_info *dump_mtd;
+static loff_t dump_nandboot_size;
+static struct fcb_block dump_fill_fcb;
+static struct dbbt_block dump_fill_dbbt;
+static struct fcb_block dump_nand_fcb[BOOT_SEARCH_COUNT];
+static struct dbbt_block dump_nand_dbbt[BOOT_SEARCH_COUNT];
+static u32 dump_fcb_off[BOOT_SEARCH_COUNT];
+static u32 dump_dbbt_off[BOOT_SEARCH_COUNT];
 
 #if defined(CONFIG_MX6UL) || defined(CONFIG_MX6ULL)
 static uint8_t reverse_bit(uint8_t b)
@@ -212,9 +223,10 @@ static int dbbt_fill_data(struct mtd_info *mtd, void *buf, int num_blocks)
 	return n_bad_blocks;
 }
 
-static int write_fcb_dbbt(struct mtd_info *mtd, struct fcb_block *fcb,
-			  struct dbbt_block *dbbt, void *dbbt_data_page,
-			  loff_t off)
+static int write_fcb_dbbt_and_readback(struct mtd_info *mtd,
+				       struct fcb_block *fcb,
+				       struct dbbt_block *dbbt,
+				       void *dbbt_data_page, loff_t off)
 {
 	void *fcb_raw_page = 0;
 	int i, ret;
@@ -272,6 +284,11 @@ static int write_fcb_dbbt(struct mtd_info *mtd, struct fcb_block *fcb,
 			mxs_nand_mode_fcb(mtd);
 			ret = nand_write(mtd, off, &rwsize,
 					 (unsigned char *)fcb);
+
+			dump_fcb_off[i] = off;
+			nand_read(mtd, off, &rwsize,
+				  (unsigned char *)(dump_nand_fcb + i));
+
 			mxs_nand_mode_normal(mtd);
 
 			printf("%s\n", ret ? "ERROR" : "OK");
@@ -302,6 +319,12 @@ static int write_fcb_dbbt(struct mtd_info *mtd, struct fcb_block *fcb,
 		      mtd->erasesize * i + mtd->writesize, dummy,
 		      ret ? "ERROR" : "OK");
 
+		dump_dbbt_off[i] = mtd->erasesize * i + mtd->writesize;
+		size_t rwsize = sizeof(*dbbt);
+
+		nand_read(mtd, dump_dbbt_off[i], &rwsize,
+			  (unsigned char *)(dump_nand_dbbt + i));
+
 		/* dbbtpages == 0 if no bad blocks */
 		if (dbbt->dbbtpages > 0) {
 			loff_t to = (mtd->erasesize * i + mtd->writesize * 5);
@@ -366,7 +389,7 @@ static int nandbcb_update(struct mtd_info *mtd, loff_t off, size_t size,
 	 * - rest split in half for primary and secondary firmware
 	 * - same firmware will write two times
 	 */
-	nr_blks_fcb = 2;
+	nr_blks_fcb = BOOT_SEARCH_COUNT;
 	nr_blks = maxsize / mtd->erasesize;
 	fw1_blk = nr_blks_fcb;
 
@@ -442,6 +465,8 @@ static int nandbcb_update(struct mtd_info *mtd, loff_t off, size_t size,
 		fw1_pages = (IMX8MQ_SPL_SZ + (mtd->writesize - 1)) / mtd->writesize;
 	fill_fcb(fcb, mtd, fw1_start, 0, fw1_pages);
 
+	dump_fill_fcb = *fcb;
+
 	/* fill dbbt */
 	dbbt_page = kzalloc(mtd->writesize, GFP_KERNEL);
 	if (!dbbt_page) {
@@ -467,8 +492,10 @@ static int nandbcb_update(struct mtd_info *mtd, loff_t off, size_t size,
 	else if (ret > 0)
 		dbbt->dbbtpages = 1;
 
+	dump_fill_dbbt = *dbbt;
+
 	/* write fcb and dbbt to nand */
-	ret = write_fcb_dbbt(mtd, fcb, dbbt, dbbt_data_page, off);
+	ret = write_fcb_dbbt_and_readback(mtd, fcb, dbbt, dbbt_data_page, off);
 	if (ret < 0)
 		printf("failed to write FCB/DBBT\n");
 
@@ -550,7 +577,7 @@ static int do_nandbcb_bcbonly(int argc, char * const argv[])
 		dbbt->dbbtpages = 1;
 
 	/* write fcb and dbbt to nand */
-	ret = write_fcb_dbbt(mtd, fcb, dbbt, dbbt_data_page, 0);
+	ret = write_fcb_dbbt_and_readback(mtd, fcb, dbbt, dbbt_data_page, 0);
 dbbt_data_page_err:
 	kfree(dbbt_data_page);
 dbbt_page_err:
@@ -566,6 +593,218 @@ fcb_err:
 	return CMD_RET_SUCCESS;
 }
 
+/* dump data which is planned to be encoded and written to NAND chip */
+void mtd_cfg_dump(void)
+{
+	u64 blocks;
+
+	printf("MTD CONFIG:\n");
+	printf("  %s = %d\n", "data_setup_time", dump_fill_fcb.datasetup);
+	printf("  %s = %d\n", "data_hold_time", dump_fill_fcb.datahold);
+	printf("  %s = %d\n", "address_setup_time", dump_fill_fcb.addr_setup);
+	printf("  %s = %d\n", "data_sample_time", dump_fill_fcb.dsample_time);
+
+	printf("NFC geometry :\n");
+	printf("\tECC Strength       : %d\n", dump_mtd->ecc_strength);
+	printf("\tPage Size in Bytes : %d\n", dump_fill_fcb.oob_pagesize);
+	printf("\tMetadata size      : %d\n", dump_fill_fcb.meta_size);
+	printf("\tECC Chunk Size in byte : %d\n", dump_fill_fcb.ecc_size);
+	printf("\tECC Chunk count        : %d\n", dump_fill_fcb.nr_blocks + 1);
+	printf("\tBlock Mark Byte Offset : %d\n", dump_fill_fcb.bb_byte);
+	printf("\tBlock Mark Bit Offset  : %d\n", dump_fill_fcb.bb_start_bit);
+	printf("====================================================\n");
+
+	printf("mtd: partition #0\n");
+	printf("  %s = %d\n", "type", dump_mtd->type);
+	printf("  %s = %d\n", "flags", dump_mtd->flags);
+	printf("  %s = %llu\n", "size", dump_nandboot_size);
+	printf("  %s = %d\n", "erasesize", dump_mtd->erasesize);
+	printf("  %s = %d\n", "writesize", dump_mtd->writesize);
+	printf("  %s = %d\n", "oobsize", dump_mtd->oobsize);
+	blocks = dump_nandboot_size;
+	do_div(blocks, dump_mtd->erasesize);
+	printf("  %s = %llu\n", "blocks", blocks);
+}
+
+/* dump data which is read from NAND chip */
+void mtd_dump_structure(int i)
+{
+	#define P1(x) printf("  %s = 0x%08x\n", #x, dump_nand_fcb[i].x)
+		printf("FCB %d:\n", i);
+		P1(checksum);
+		P1(fingerprint);
+		P1(version);
+	#undef P1
+	#define P1(x)	printf("  %s = %d\n", #x, dump_nand_fcb[i].x)
+		P1(datasetup);
+		P1(datahold);
+		P1(addr_setup);
+		P1(dsample_time);
+		P1(pagesize);
+		P1(oob_pagesize);
+		P1(sectors);
+		P1(nr_nand);
+		P1(nr_die);
+		P1(celltype);
+		P1(ecc_type);
+		P1(ecc_nr);
+		P1(ecc_size);
+		P1(ecc_level);
+		P1(meta_size);
+		P1(nr_blocks);
+		P1(ecc_type_sdk);
+		P1(ecc_nr_sdk);
+		P1(ecc_size_sdk);
+		P1(ecc_level_sdk);
+		P1(nr_blocks_sdk);
+		P1(meta_size_sdk);
+		P1(erase_th);
+		P1(bootpatch);
+		P1(patch_size);
+		P1(fw1_start);
+		P1(fw2_start);
+		P1(fw1_pages);
+		P1(fw2_pages);
+		P1(dbbt_start);
+		P1(bb_byte);
+		P1(bb_start_bit);
+		P1(phy_offset);
+		P1(bchtype);
+		P1(readlatency);
+		P1(predelay);
+		P1(cedelay);
+		P1(postdelay);
+		P1(cmdaddpause);
+		P1(datapause);
+		P1(tmspeed);
+		P1(busytimeout);
+		P1(disbbm);
+		P1(spare_offset);
+		P1(onfi_sync_enable);
+		P1(onfi_sync_speed);
+		P1(onfi_sync_nand_data);
+		P1(disbbm_search);
+		P1(disbbm_search_limit);
+		P1(read_retry_enable);
+	#undef P1
+	#define P1(x)	printf("  %s = 0x%08x\n", #x, dump_nand_dbbt[i].x)
+		printf("DBBT %d:\n", i);
+		P1(checksum);
+		P1(fingerprint);
+		P1(version);
+	#undef P1
+	#define P1(x)	printf("  %s = %d\n", #x, dump_nand_dbbt[i].x)
+		P1(numberbb);
+	#undef P1
+
+	printf("Firmware: image #0 @ 0x%x size 0x%x - available 0x%llx\n",
+	       dump_nand_fcb[i].fw1_start * dump_nand_fcb[i].pagesize,
+	       dump_nand_fcb[i].fw1_pages * dump_nand_fcb[i].pagesize,
+	       dump_nandboot_size - dump_nand_fcb[i].fw1_start *
+	       dump_nand_fcb[i].pagesize);
+	if (is_imx8m()) {
+		printf("Extra Firmware: image #0 @ 0x%x size 0x%x - available 0x%llx\n",
+		       dump_nand_fcb[i].fw1_start *
+		       dump_nand_fcb[i].pagesize + dump_mtd->erasesize *
+		       ((IMX8MQ_SPL_SZ + dump_mtd->erasesize - 1) /
+			dump_mtd->erasesize),
+		       dump_nand_fcb[i].fw1_pages * dump_nand_fcb[i].pagesize,
+		       dump_nandboot_size -
+		       (dump_nand_fcb[i].fw1_start *
+			dump_nand_fcb[i].pagesize + dump_mtd->erasesize *
+			((IMX8MQ_SPL_SZ + dump_mtd->erasesize - 1) /
+			 dump_mtd->erasesize)));
+	}
+}
+
+static int do_nandbcb_dump(int argc, char * const argv[])
+{
+	int num;
+	int stride;
+	int search_area_sz;
+	bool bab_block_table[BOOT_SEARCH_COUNT];
+	int bab_block_flag;
+
+	if (argc != 2)
+		return CMD_RET_USAGE;
+
+	switch (argv[1][0]) {
+	case '0':
+		num = 0;
+		break;
+	case '1':
+		num = 1;
+		break;
+	default:
+		return CMD_RET_USAGE;
+	}
+
+	/* dump data which is planned to be encoded and written to NAND chip */
+	mtd_cfg_dump();
+
+	stride = dump_mtd->erasesize;
+	search_area_sz = BOOT_SEARCH_COUNT * stride;
+	printf("stride: %x, search_area_sz: %x\n", stride, search_area_sz);
+
+	bab_block_flag = 0;
+	for (int i = 0; i < BOOT_SEARCH_COUNT; i++) {
+		if (mtd_block_isbad(dump_mtd,
+				    (loff_t)(dump_mtd->erasesize * i))) {
+			bab_block_table[i] = 1;
+			bab_block_flag = 1;
+			continue;
+		}
+		bab_block_table[i] = 0;
+		if (!memcmp(dump_nand_fcb + i, &dump_fill_fcb,
+			    sizeof(dump_fill_fcb))) {
+			printf("mtd: found FCB%d candidate version %08x @%d:0x%x\n",
+			       i, dump_nand_fcb[i].version, i, dump_fcb_off[i]);
+		} else {
+			printf("mtd: FCB%d not found\n", i);
+		}
+	}
+
+	for (int i = 0; i < BOOT_SEARCH_COUNT; i++) {
+		if (mtd_block_isbad(dump_mtd,
+				    (loff_t)(dump_mtd->erasesize * i)))
+			continue;
+
+		if (!memcmp(dump_nand_dbbt + i, &dump_fill_dbbt,
+			    sizeof(dump_fill_dbbt))) {
+			printf("mtd: DBBT%d found\n", i);
+			printf("mtd: Valid DBBT%d found @%d:0x%x\n",
+			       i, i, dump_dbbt_off[i]);
+
+		} else {
+			printf("mtd: DBBT%d not found\n", i);
+		}
+	}
+	if (bab_block_flag == 0) {
+		printf("no bad block found, dbbt: %08x\n",
+		       dump_fill_dbbt.fingerprint);
+	} else {
+		for (int i = 0; i < BOOT_SEARCH_COUNT; i++) {
+			if (bab_block_table[i] == 1)
+				printf("mtd: bad block @ 0x%llx\n",
+				       (loff_t)(dump_mtd->erasesize * i));
+		}
+	}
+
+	/* dump data which is read from NAND chip */
+	if (num > (BOOT_SEARCH_COUNT - 1))
+		return CMD_RET_USAGE;
+
+	if (bab_block_table[num] == 1) {
+		printf("mtd: bad block @ 0x%llx (FCB - DBBT)\n",
+		       (loff_t)(dump_mtd->erasesize * num));
+		return CMD_RET_USAGE;
+	}
+
+	mtd_dump_structure(num);
+
+	return 0;
+}
+
 static int do_nandbcb_update(int argc, char * const argv[])
 {
 	struct mtd_info *mtd;
@@ -593,6 +832,10 @@ static int do_nandbcb_update(int argc, char * const argv[])
 			     &maxsize, MTD_DEV_TYPE_NAND, mtd->size))
 		return CMD_RET_FAILURE;
 
+	/* dump_mtd and dump_nandboot_size are used for "nandbcb dump [-v]" */
+	dump_mtd = mtd;
+	dump_nandboot_size = maxsize;
+
 	buf = map_physmem(addr, size, MAP_WRBACK);
 	if (!buf) {
 		puts("failed to map physical memory\n");
@@ -610,7 +853,7 @@ static int do_nandbcb(cmd_tbl_t *cmdtp, int flag, int argc,
 	const char *cmd;
 	int ret = 0;
 
-	if (argc < 5)
+	if (argc < 3)
 		goto usage;
 
 	cmd = argv[1];
@@ -622,6 +865,11 @@ static int do_nandbcb(cmd_tbl_t *cmdtp, int flag, int argc,
 		goto done;
 	}
 
+	if (strcmp(cmd, "dump") == 0) {
+		ret = do_nandbcb_dump(argc, argv);
+		goto done;
+	}
+
 	if (strcmp(cmd, "bcbonly") == 0) {
 		ret = do_nandbcb_bcbonly(argc, argv);
 		goto done;
@@ -643,7 +891,9 @@ static char nandbcb_help_text[] =
 	"       and `fw2-off` - firmware offsets\n"
 	"       FIY, BCB isn't erased automatically, so mtd erase should\n"
 	"       be called in advance before writing new BCB:\n"
-	"           > mtd erase mx7-bcb";
+	"           > mtd erase mx7-bcb\n"
+	"nandbcb dump num - verify/dump boot structures\n"
+	"	'num' can be set to 0 and 1";
 #endif
 
 U_BOOT_CMD(nandbcb, 5, 1, do_nandbcb,
Signature · 1 line
2.16.4
#6 lore raw

PATCH 3/6 nandbcb: add nandbcb dump command for i.MX8MM

Quoted 4 lines

From: Alice Guo <[email protected]> Verify/dump boot structures written to NAND Flash chip.

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

Best regards,
Stefano Babic

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

PATCH 4/6 nandbcb: add nandbcb dump command for i.MX6

In reply to Peng Fan

From: Alice Guo <[email protected]>

Verify/dump boot structures.

---
 arch/arm/mach-imx/cmd_nandbcb.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm/mach-imx/cmd_nandbcb.c +4 -0
index 02a65ffd43..a8531def35 100644
@@ -309,6 +309,10 @@ static int write_fcb_dbbt_and_readback(struct mtd_info *mtd,
 			debug("NAND fcb write: 0x%x offset 0x%zx written: %s\n",
 			      mtd->erasesize * i, ops.len, ret ?
 			      "ERROR" : "OK");
+
+			ops.datbuf = (u8 *)(dump_nand_fcb + i);
+			ops.oobbuf = ((u8 *)(dump_nand_fcb + i)) + mtd->writesize;
+			mtd_read_oob(mtd, mtd->erasesize * i, &ops);
 		}
 
 		ret = mtd_write(mtd, mtd->erasesize * i + mtd->writesize,
Signature · 1 line
2.16.4
#8 lore raw

PATCH 4/6 nandbcb: add nandbcb dump command for i.MX6

Quoted 4 lines

From: Alice Guo <[email protected]>
Verify/dump boot structures.

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

Best regards,
Stefano Babic

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

PATCH 5/6 cmd: nandbcb: Reconstruct the nandbcb tool for all platforms

In reply to Peng Fan

From: Han Xu <[email protected]>

The original nandbcb tool was designed for imx6 only, when trying to leverage it to replace the kobs-ng tool, we found the design is not friendly for supporting all platforms. To support all iMX6/7/8 platforms and for easy further maintain, I reconstruct the structure of the tool.

The main changes including:

1. Use platform_data to determine the logic branches rather than simply use SOC name.
2. More data structures as parameter for functions.
3. Global variables to define the FCB/DBBT/FW locations.
4. Implement the kobs-ng default 4 FCB/4 DBBT/2 FW layout.
5. Support Hamming coding/ 40bit BCH/ 62bit BCH coding FCB.
6. Dump and compare all written FCB/DBBT to verify data integrity.

The tool has been verified on iMX6Q/DL, 6SX, 7D, 6ULL, iMX8QX, iMX8MM.

---
 arch/arm/include/asm/mach-imx/imx-nandbcb.h |    4 +-
 arch/arm/mach-imx/cmd_nandbcb.c             | 1303 +++++++++++++++++++--------
 2 files changed, 955 insertions(+), 352 deletions(-)
arch/arm/include/asm/mach-imx/imx-nandbcb.h +3 -1
index 907e7ed8f9..74c9031d4e 100644
@@ -9,9 +9,11 @@
 
 #define FCB_FINGERPRINT		0x20424346      /* 'FCB' */
 #define FCB_VERSION_1		0x01000000
+#define FCB_FINGERPRINT_OFF	0x4		/* FCB fingerprint offset*/
 
-#define DBBT_FINGERPRINT2	0x54424244	/* 'DBBT' */
+#define DBBT_FINGERPRINT	0x54424244	/* 'DBBT' */
 #define DBBT_VERSION_1		0x01000000
+#define DBBT_FINGERPRINT_OFF	0x4		/* DBBT fingerprint offset*/
 
 struct dbbt_block {
 	u32 checksum;	/* reserved on i.MX6 */
arch/arm/mach-imx/cmd_nandbcb.c +952 -351

1,591 lines not on this page · raw message

Signature · 1 line
2.16.4
#10 lore raw

PATCH 5/6 cmd: nandbcb: Reconstruct the nandbcb tool for all platforms

Quoted 14 lines

From: Han Xu <[email protected]>
The original nandbcb tool was designed for imx6 only, when trying to leverage it to replace the kobs-ng tool, we found the design is not friendly for supporting all platforms. To support all iMX6/7/8 platforms and for easy further maintain, I reconstruct the structure of the tool. The main changes including:
1. Use platform_data to determine the logic branches rather than simply use SOC name.
2. More data structures as parameter for functions.
3. Global variables to define the FCB/DBBT/FW locations.
4. Implement the kobs-ng default 4 FCB/4 DBBT/2 FW layout.
5. Support Hamming coding/ 40bit BCH/ 62bit BCH coding FCB.
6. Dump and compare all written FCB/DBBT to verify data integrity. The tool has been verified on iMX6Q/DL, 6SX, 7D, 6ULL, iMX8QX, iMX8MM.

Quoted 2 lines

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

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================
author
#11 lore raw

PATCH 6/6 nandbcb: read boot search count from fuse for imx8qxp

In reply to Peng Fan

From: Han Xu <[email protected]>

add support for imx8qxp to read boot search count from fuse in nandbcb

---
 arch/arm/mach-imx/cmd_nandbcb.c | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)
arch/arm/mach-imx/cmd_nandbcb.c +38 -1
index ab12b1f1cf..94cae146ce 100644
@@ -27,6 +27,7 @@
 #include <mxs_nand.h>
 #include <linux/mtd/mtd.h>
 #include <nand.h>
+#include <fuse.h>
 
 #include "../../../cmd/legacy-mtd-utils.h"
 
@@ -1260,6 +1261,35 @@ static bool check_fingerprint(void *data, int fingerprint)
 	return (*(int *)(data + off) == fingerprint);
 }
 
+static int fuse_to_search_count(u32 bank, u32 word, u32 mask, u32 off)
+{
+	int err;
+	u32 val;
+	int ret;
+
+	/* by default, the boot search count from fuse should be 2 */
+	err = fuse_read(bank, word, &val);
+	if (err)
+		return 2;
+
+	val = (val & mask) >> off;
+
+	switch (val) {
+		case 0:
+			ret = 2;
+			break;
+		case 1:
+		case 2:
+		case 3:
+			ret = 1 << val;
+			break;
+		default:
+			ret = 2;
+	}
+
+	return ret;
+}
+
 static int nandbcb_dump(struct boot_config *boot_cfg)
 {
 	int i;
@@ -1459,7 +1489,14 @@ static int do_nandbcb(cmd_tbl_t *cmdtp, int flag, int argc,
 		return CMD_RET_FAILURE;
 	}
 
-	/* TODO: set the boot search count if need to read from fuse */
+	if (plat_config.misc_flags & BT_SEARCH_CNT_FROM_FUSE) {
+		if (is_imx8qxp()) {
+			g_boot_search_count = fuse_to_search_count(0, 720,
+								   0xc0, 6);
+			printf("search count set to %d from fuse\n",
+			       g_boot_search_count);
+		}
+	}
 
 	cmd = argv[1];
 	--argc;
Signature · 1 line
2.16.4
#12 lore raw

PATCH 6/6 nandbcb: read boot search count from fuse for imx8qxp

Quoted 4 lines

From: Han Xu <[email protected]>
add support for imx8qxp to read boot search count from fuse in nandbcb

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

Best regards,
Stefano Babic

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