Skip to contentSkip to conversation

GPMI NAND xload for i.MX6

PATCH Superseded Andrej Picej 3 participants 17 messages Jan 20, 2021 – Jan 26, 2021

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover GPMI NAND xload for i.MX6

Hi all,

these patches implement GPMI NAND xload mechanism for i.MX6 SoCs. The xload from GPMI NAND is needed in case board wants to boot from internal SRAM (limited in size) and then load remaining barebox image from NAND.

The usual use-case for xload mechanism is board DRAM size auto-detection and runtime configuration without the need for separate DCD tables for each SoM variant.

In our case patches were required to support DRAM size auto-detection on Phytec's phycard-imx6 SoM with 1GiB and 2GiB DRAM variants. Thus we decided to submit example implementation on the mentioned board as RFC patch that will follow these patch series.

Nonetheless, the majority of work was already provided by Sascha Hauer, but his patches were in WIP stage and not found in the mainline. We added missing parts for detecting NAND's page and oob size necessary for initial FCB page reading, etc.

We hope patches spawn ideas for future implementations and work!

Best regards,
Andrej Picej

Andrej Picej (1):
ARM: i.MX: xload-gpmi-nand: apply errata 007117

Primoz Fiser (1):
ARM: i.MX: move BCB structures to header file

Sascha Hauer (1):
ARM: i.MX: implement GPMI NAND xload

 arch/arm/mach-imx/Makefile                    |    2 +-
 arch/arm/mach-imx/include/mach/imx-nand-bcb.h |   80 ++
 arch/arm/mach-imx/include/mach/xload.h        |    1 +
 arch/arm/mach-imx/xload-gpmi-nand.c           | 1225 +++++++++++++++++
 common/imx-bbu-nand-fcb.c                     |   69 +-
 5 files changed, 1308 insertions(+), 69 deletions(-)
 create mode 100644 arch/arm/mach-imx/include/mach/imx-nand-bcb.h
 create mode 100644 arch/arm/mach-imx/xload-gpmi-nand.c
Signature · 7 lines
2.25.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 1/3 ARM: i.MX: move BCB structures to header file

From: Primoz Fiser <[email protected]>

Move i.MX BCB related structures to header file so they can be used by others.

---
 arch/arm/mach-imx/include/mach/imx-nand-bcb.h | 80 +++++++++++++++++++
 common/imx-bbu-nand-fcb.c                     | 69 +---------------
 2 files changed, 81 insertions(+), 68 deletions(-)
 create mode 100644 arch/arm/mach-imx/include/mach/imx-nand-bcb.h
arch/arm/mach-imx/include/mach/imx-nand-bcb.h new file +80 -0
new file mode 100644
index 000000000..b60205bd5
@@ -0,0 +1,80 @@
+#ifndef __MACH_IMX_NAND_BCB_H
+#define __MACH_IMX_NAND_BCB_H
+
+#define	FCB_FINGERPRINT		0x20424346	/* 'FCB' */
+#define	FCB_VERSION_1		0x01000000
+#define	FCB_FINGERPRINT_OFF	0x4		/* FCB fingerprint offset*/
+
+#define	DBBT_FINGERPRINT	0x54424244	/* 'DBBT' */
+#define	DBBT_VERSION_1		0x01000000
+#define	DBBT_FINGERPRINT_OFF	0x4		/* DBBT fingerprint offset*/
+
+struct dbbt_block {
+	uint32_t Checksum;
+	uint32_t FingerPrint;
+	uint32_t Version;
+	uint32_t numberBB; /* reserved on i.MX6 */
+	uint32_t DBBTNumOfPages;
+};
+
+struct fcb_block {
+	uint32_t Checksum;		/* First fingerprint in first byte */
+	uint32_t FingerPrint;		/* 2nd fingerprint at byte 4 */
+	uint32_t Version;		/* 3rd fingerprint at byte 8 */
+	uint8_t DataSetup;
+	uint8_t DataHold;
+	uint8_t AddressSetup;
+	uint8_t DSAMPLE_TIME;
+	/* These are for application use only and not for ROM. */
+	uint8_t NandTimingState;
+	uint8_t REA;
+	uint8_t RLOH;
+	uint8_t RHOH;
+	uint32_t PageDataSize;		/* 2048 for 2K pages, 4096 for 4K pages */
+	uint32_t TotalPageSize;		/* 2112 for 2K pages, 4314 for 4K pages */
+	uint32_t SectorsPerBlock;	/* Number of 2K sections per block */
+	uint32_t NumberOfNANDs;		/* Total Number of NANDs - not used by ROM */
+	uint32_t TotalInternalDie;	/* Number of separate chips in this NAND */
+	uint32_t CellType;		/* MLC or SLC */
+	uint32_t EccBlockNEccType;	/* Type of ECC, can be one of BCH-0-20 */
+	uint32_t EccBlock0Size;		/* Number of bytes for Block0 - BCH */
+	uint32_t EccBlockNSize;		/* Block size in bytes for all blocks other than Block0 - BCH */
+	uint32_t EccBlock0EccType;	/* Ecc level for Block 0 - BCH */
+	uint32_t MetadataBytes;		/* Metadata size - BCH */
+	uint32_t NumEccBlocksPerPage;	/* Number of blocks per page for ROM use - BCH */
+	uint32_t EccBlockNEccLevelSDK;	/* Type of ECC, can be one of BCH-0-20 */
+	uint32_t EccBlock0SizeSDK;	/* Number of bytes for Block0 - BCH */
+	uint32_t EccBlockNSizeSDK;	/* Block size in bytes for all blocks other than Block0 - BCH */
+	uint32_t EccBlock0EccLevelSDK;	/* Ecc level for Block 0 - BCH */
+	uint32_t NumEccBlocksPerPageSDK;/* Number of blocks per page for SDK use - BCH */
+	uint32_t MetadataBytesSDK;	/* Metadata size - BCH */
+	uint32_t EraseThreshold;	/* To set into BCH_MODE register */
+	uint32_t BootPatch;		/* 0 for normal boot and 1 to load patch starting next to FCB */
+	uint32_t PatchSectors;		/* Size of patch in sectors */
+	uint32_t Firmware1_startingPage;/* Firmware image starts on this sector */
+	uint32_t Firmware2_startingPage;/* Secondary FW Image starting Sector */
+	uint32_t PagesInFirmware1;	/* Number of sectors in firmware image */
+	uint32_t PagesInFirmware2;	/* Number of sector in secondary FW image */
+	uint32_t DBBTSearchAreaStartAddress; /* Page address where dbbt search area begins */
+	uint32_t BadBlockMarkerByte;	/* Byte in page data that have manufacturer marked bad block marker, */
+					/* this will be swapped with metadata[0] to complete page data. */
+	uint32_t BadBlockMarkerStartBit;/* For BCH ECC sizes other than 8 and 16 the bad block marker does not */
+					/* start at 0th bit of BadBlockMarkerByte. This field is used to get to */
+					/* the start bit of bad block marker byte with in BadBlockMarkerByte */
+	uint32_t BBMarkerPhysicalOffset;/* FCB value that gives byte offset for bad block marker on physical NAND page */
+	uint32_t BCHType;
+
+	uint32_t TMTiming2_ReadLatency;
+	uint32_t TMTiming2_PreambleDelay;
+	uint32_t TMTiming2_CEDelay;
+	uint32_t TMTiming2_PostambleDelay;
+	uint32_t TMTiming2_CmdAddPause;
+	uint32_t TMTiming2_DataPause;
+	uint32_t TMSpeed;
+	uint32_t TMTiming1_BusyTimeout;
+
+	uint32_t DISBBM;	/* the flag to enable (1)/disable(0) bi swap */
+	uint32_t BBMarkerPhysicalOffsetInSpareData; /* The swap position of main area in spare area */
+};
+
+#endif /* __MACH_IMX_NAND_BCB_H */
common/imx-bbu-nand-fcb.c +1 -68

81 lines not on this page · raw message

Signature · 7 lines
2.25.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 2/3 ARM: i.MX: implement GPMI NAND xload

In reply to Andrej Picej

From: Sascha Hauer <[email protected]>

Commit is based on initial Sascha Hauer's work. It implements PBL xload mechanism to load image from GPMI NAND flash.

Additional work was done, so that the NAND's size, page size and OOB's size are autodetected and not hardcoded. Detection method follows the same methods as used in NAND driver, meaning NAND ONFI support is probed and if NAND supports ONFI, NAND memory organization is read from ONFI parameter page otherwise "READ ID" is used.

Currently only implemented for i.MX6 familly of SoCs.

---
 arch/arm/mach-imx/Makefile             |    2 +-
 arch/arm/mach-imx/include/mach/xload.h |    1 +
 arch/arm/mach-imx/xload-gpmi-nand.c    | 1163 ++++++++++++++++++++++++
 3 files changed, 1165 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/mach-imx/xload-gpmi-nand.c
arch/arm/mach-imx/Makefile +1 -1
index e45f758e9..d94c846a1 100644
@@ -26,4 +26,4 @@ obj-$(CONFIG_BAREBOX_UPDATE) += imx-bbu-internal.o
 obj-$(CONFIG_BAREBOX_UPDATE_IMX_EXTERNAL_NAND) += imx-bbu-external-nand.o
 obj-$(CONFIG_RESET_IMX_SRC) += src.o
 lwl-y += cpu_init.o
-pbl-y += xload-spi.o xload-common.o xload-imx-nand.o
+pbl-y += xload-spi.o xload-common.o xload-imx-nand.o xload-gpmi-nand.o
arch/arm/mach-imx/include/mach/xload.h +1 -0
index 94b2f3761..7187787f5 100644
@@ -5,6 +5,7 @@ int imx53_nand_start_image(void);
 int imx6_spi_load_image(int instance, unsigned int flash_offset, void *buf, int len);
 int imx6_spi_start_image(int instance);
 int imx6_esdhc_start_image(int instance);
+int imx6_nand_start_image(void);
 int imx7_esdhc_start_image(int instance);
 int imx8m_esdhc_load_image(int instance, bool start);
 int imx8mp_esdhc_load_image(int instance, bool start);
arch/arm/mach-imx/xload-gpmi-nand.c new file +1163 -0

1,163 lines not on this page · raw message

Signature · 7 lines
2.25.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

Re: [PATCH 2/3] ARM: i.MX: implement GPMI NAND xload

Quoted 11 lines · Andrej Picej

From: Sascha Hauer <[email protected]>

Commit is based on initial Sascha Hauer's work. It implements PBL xload mechanism to load image from GPMI NAND flash.

Additional work was done, so that the NAND's size, page size and OOB's size are autodetected and not hardcoded. Detection method follows the same methods as used in NAND driver, meaning NAND ONFI support is probed and if NAND supports ONFI, NAND memory organization is read from ONFI parameter page otherwise "READ ID" is used.

Quoted 5 lines

Currently only implemented for i.MX6 familly of SoCs.

I did not look at the code, but I appreciate how those names line up nicely :-)

- Roland

Signature · 9 lines
Roland Hieber, Pengutronix e.K.          | [email protected]     |
Steuerwalder Str. 21                     | https://www.pengutronix.de/ |
31137 Hildesheim, Germany                | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686         | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

Re: [PATCH 2/3] ARM: i.MX: implement GPMI NAND xload

In reply to Andrej Picej

Hi Andrej,

Some comments inline.

Quoted 27 lines · Andrej Picej

From: Sascha Hauer <[email protected]>

Commit is based on initial Sascha Hauer's work. It implements PBL xload mechanism to load image from GPMI NAND flash.

Additional work was done, so that the NAND's size, page size and OOB's size are autodetected and not hardcoded. Detection method follows the same methods as used in NAND driver, meaning NAND ONFI support is probed and if NAND supports ONFI, NAND memory organization is read from ONFI parameter page otherwise "READ ID" is used.

Currently only implemented for i.MX6 familly of SoCs.

---
 arch/arm/mach-imx/Makefile             |    2 +-
 arch/arm/mach-imx/include/mach/xload.h |    1 +
 arch/arm/mach-imx/xload-gpmi-nand.c    | 1163 ++++++++++++++++++++++++
 3 files changed, 1165 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/mach-imx/xload-gpmi-nand.c
arch/arm/mach-imx/Makefile +0 -0
index e45f758e9..d94c846a1 100644

arch/arm/mach-imx/Makefile

Quoted 9 lines
arch/arm/mach-imx/Makefile +9 -0
+static int mxs_nand_get_info(struct mxs_nand_info *info, void *databuf)
+{
+	int ret, i;
+
+	ret = mxs_nand_check_onfi(info, databuf);
+	if (ret) {
+		if (ret != 1)
+			return ret;
+		pr_warn("ONFI not supported, try \"READ ID\"...\n");

You already printed a "ONFI not supported\n" message. Printing it once is enough. Also this message appears with every non-ONFI nand, right? In that case it should rather be pr_info()

Quoted 9 lines
arch/arm/mach-imx/Makefile +9 -0
+	/*
+	 * If ONFI is not supported or if it fails try to get NAND's info from
+	 * "READ ID" command.
+	 */
+	pr_debug("Trying \"READ ID\" command...\n");
+	ret = mxs_nand_get_readid(info, databuf);
+	if (ret) {
+		if (ret != -EOVERFLOW)
+			return ret;

arch/arm/mach-imx/Makefile

Quoted 10 lines
arch/arm/mach-imx/Makefile +10 -0
+
+		/*
+		 * If NAND's "READ ID" returns bad values, try to set them to
+		 * default (most common NAND memory org.) and continue.
+		 */
+		pr_warn("NANDs READ ID command returned bad values" \
+			" set them to default and try to continue!\n");
+		info->organization.pagesize = 2048;
+		info->organization.oobsize = 64;
+		info->nand_size = SZ_1G;

Is this worth it? READ ID is the most basic command, when this doesn't work I don't think there's a point in continuing.

Quoted 37 lines
arch/arm/mach-imx/Makefile +37 -0
+	}
+succ:
+	pr_debug("NAND page_size: %d\n", info->organization.pagesize);
+	pr_debug("NAND block_size: %d\n",
+		info->organization.pages_per_eraseblock
+		* info->organization.pagesize);
+	pr_debug("NAND oob_size: %d\n", info->organization.oobsize);
+	pr_debug("NAND nand_size: %lu\n", info->nand_size);
+	pr_debug("NAND bits_per_cell: %d\n", info->organization.bits_per_cell);
+	pr_debug("NAND planes_per_lun: %d\n",
+		info->organization.planes_per_lun);
+	pr_debug("NAND luns_per_target: %d\n",
+		info->organization.luns_per_target);
+	pr_debug("NAND eraseblocks_per_lun: %d\n",
+		info->organization.eraseblocks_per_lun);
+	pr_debug("NAND ntargets: %d\n", info->organization.ntargets);
+
+
+	return 0;
+}
+
+/* ---------------------------- BCB handling part -------------------------- */
+
+static uint32_t calc_chksum(void *buf, size_t size)
+{
+	u32 chksum = 0;
+	u8 *bp = buf;
+	size_t i;
+
+	for (i = 0; i < size; i++)
+		chksum += bp[i];
+
+	return ~chksum;
+}
+
+static int get_fcb(struct mxs_nand_info *info, void *databuf)
+{

arch/arm/mach-imx/Makefile

Quoted 10 lines
arch/arm/mach-imx/Makefile +10 -0
+	int i, pagenum, ret;
+	uint32_t checksum;
+	struct fcb_block *fcb = &info->fcb;
+
+	/* First page read fails, this shouldn't be necessary */
+	mxs_nand_read_page(info, info->organization.pagesize,
+		info->organization.oobsize, 0, databuf, 1);
+
+	for (i = 0; i < 4; i++) {
+		pagenum = 64 * i;

I haven't looked at the documentation, but the '64' should probably be pages per block, so better info->organization.pages_per_eraseblock?

Quoted 40 lines
arch/arm/mach-imx/Makefile +40 -0
+
+		ret = mxs_nand_read_page(info, info->organization.pagesize,
+			info->organization.oobsize, pagenum, databuf, 1);
+		if (ret)
+			continue;
+
+		memcpy(fcb, databuf + mxs_nand_aux_status_offset(),
+			sizeof(*fcb));
+
+		if (fcb->FingerPrint != FCB_FINGERPRINT) {
+			pr_err("No FCB found on page %d\n", pagenum);
+			continue;
+		}
+
+		checksum = calc_chksum((void *)fcb +
+			sizeof(uint32_t), sizeof(*fcb) - sizeof(uint32_t));
+
+		if (checksum != fcb->Checksum) {
+			pr_err("FCB on page %d has invalid checksum. " \
+				"Expected: 0x%08x, calculated: 0x%08x",
+				pagenum, fcb->Checksum, checksum);
+			continue;
+		}
+
+		pr_debug("Found FCB:\n");
+		pr_debug("PageDataSize:     0x%08x\n", fcb->PageDataSize);
+		pr_debug("TotalPageSize:    0x%08x\n", fcb->TotalPageSize);
+		pr_debug("SectorsPerBlock:  0x%08x\n", fcb->SectorsPerBlock);
+		pr_debug("FW1_startingPage: 0x%08x\n",
+			fcb->Firmware1_startingPage);
+		pr_debug("PagesInFW1:       0x%08x\n", fcb->PagesInFirmware1);
+		pr_debug("FW2_startingPage: 0x%08x\n",
+			fcb->Firmware2_startingPage);
+		pr_debug("PagesInFW2:       0x%08x\n", fcb->PagesInFirmware2);
+
+		return 0;
+	}
+
+	return -EINVAL;
+}

arch/arm/mach-imx/Makefile

Quoted 10 lines
arch/arm/mach-imx/Makefile +10 -0
+
+static int get_dbbt(struct mxs_nand_info *info, void *databuf)
+{
+	int i, ret;
+	int page;
+	int startpage = info->fcb.DBBTSearchAreaStartAddress;
+	struct dbbt_block dbbt;
+
+	for (i = 0; i < 4; i++) {
+		page = startpage + i * 64;

Same here.

Regards,
Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

Re: [PATCH 2/3] ARM: i.MX: implement GPMI NAND xload

Hi Sascha,

thanks for your comments.

Responses inline.

Quoted 37 lines · Sascha Hauer

Hi Andrej,

Some comments inline.

Quoted 32 lines · Andrej Picej

From: Sascha Hauer <[email protected]>

Commit is based on initial Sascha Hauer's work. It implements PBL xload mechanism to load image from GPMI NAND flash.

Additional work was done, so that the NAND's size, page size and OOB's size are autodetected and not hardcoded. Detection method follows the same methods as used in NAND driver, meaning NAND ONFI support is probed and if NAND supports ONFI, NAND memory organization is read from ONFI parameter page otherwise "READ ID" is used.

Currently only implemented for i.MX6 familly of SoCs.

---
  arch/arm/mach-imx/Makefile             |    2 +-
  arch/arm/mach-imx/include/mach/xload.h |    1 +
  arch/arm/mach-imx/xload-gpmi-nand.c    | 1163 ++++++++++++++++++++++++
  3 files changed, 1165 insertions(+), 1 deletion(-)

create mode 100644 arch/arm/mach-imx/xload-gpmi-nand.c

arch/arm/mach-imx/Makefile +5 -0
index e45f758e9..d94c846a1 100644
+static int mxs_nand_get_info(struct mxs_nand_info *info, void *databuf)
+{
+	int ret, i;
+
+	ret = mxs_nand_check_onfi(info, databuf);
Quoted 8 lines

arch/arm/mach-imx/Makefile

Quoted 4 lines
arch/arm/mach-imx/Makefile +4 -0
+	if (ret) {
+		if (ret != 1)
+			return ret;
+		pr_warn("ONFI not supported, try \"READ ID\"...\n");

You already printed a "ONFI not supported\n" message. Printing it once is enough. Also this message appears with every non-ONFI nand, right? In that case it should rather be pr_info()

OK, I agree, will fix it in v2.

Quoted 15 lines
Quoted 15 lines
arch/arm/mach-imx/Makefile +14 -0
+	/*
+	 * If ONFI is not supported or if it fails try to get NAND's info from
+	 * "READ ID" command.
+	 */
+	pr_debug("Trying \"READ ID\" command...\n");
+	ret = mxs_nand_get_readid(info, databuf);
+	if (ret) {
+		if (ret != -EOVERFLOW)
+			return ret;
+
+		/*
+		 * If NAND's "READ ID" returns bad values, try to set them to
+		 * default (most common NAND memory org.) and continue.
+		 */
Quoted 8 lines

arch/arm/mach-imx/Makefile

Quoted 5 lines
arch/arm/mach-imx/Makefile +5 -0
+		pr_warn("NANDs READ ID command returned bad values" \
+			" set them to default and try to continue!\n");
+		info->organization.pagesize = 2048;
+		info->organization.oobsize = 64;
+		info->nand_size = SZ_1G;

Is this worth it? READ ID is the most basic command, when this doesn't work I don't think there's a point in continuing.

We had a case with Samsung K9K8G08U0E when sometimes (reasons not known) the 5th byte returned 0xff instead of correct values, all other returned values were correct. In this case the device booted successfully because of this hook. Maybe a better solution would be to check only the 5th byte for 0xff value (5th byte is not supported from all NAND vendors), if this is the case set the NAND size to 1GB. Would that make more sense?

Quoted 43 lines
Quoted 43 lines
arch/arm/mach-imx/Makefile +42 -0
+	}
+succ:
+	pr_debug("NAND page_size: %d\n", info->organization.pagesize);
+	pr_debug("NAND block_size: %d\n",
+		info->organization.pages_per_eraseblock
+		* info->organization.pagesize);
+	pr_debug("NAND oob_size: %d\n", info->organization.oobsize);
+	pr_debug("NAND nand_size: %lu\n", info->nand_size);
+	pr_debug("NAND bits_per_cell: %d\n", info->organization.bits_per_cell);
+	pr_debug("NAND planes_per_lun: %d\n",
+		info->organization.planes_per_lun);
+	pr_debug("NAND luns_per_target: %d\n",
+		info->organization.luns_per_target);
+	pr_debug("NAND eraseblocks_per_lun: %d\n",
+		info->organization.eraseblocks_per_lun);
+	pr_debug("NAND ntargets: %d\n", info->organization.ntargets);
+
+
+	return 0;
+}
+
+/* ---------------------------- BCB handling part -------------------------- */
+
+static uint32_t calc_chksum(void *buf, size_t size)
+{
+	u32 chksum = 0;
+	u8 *bp = buf;
+	size_t i;
+
+	for (i = 0; i < size; i++)
+		chksum += bp[i];
+
+	return ~chksum;
+}
+
+static int get_fcb(struct mxs_nand_info *info, void *databuf)
+{
+	int i, pagenum, ret;
+	uint32_t checksum;
+	struct fcb_block *fcb = &info->fcb;
+
+	/* First page read fails, this shouldn't be necessary */
Quoted 8 lines

arch/arm/mach-imx/Makefile

Quoted 5 lines
arch/arm/mach-imx/Makefile +5 -0
+	mxs_nand_read_page(info, info->organization.pagesize,
+		info->organization.oobsize, 0, databuf, 1);
+
+	for (i = 0; i < 4; i++) {
+		pagenum = 64 * i;

I haven't looked at the documentation, but the '64' should probably be pages per block, so better info->organization.pages_per_eraseblock.

Yes, I agree, will fix it in v2.

Quoted 45 lines
Quoted 45 lines
arch/arm/mach-imx/Makefile +44 -0
+
+		ret = mxs_nand_read_page(info, info->organization.pagesize,
+			info->organization.oobsize, pagenum, databuf, 1);
+		if (ret)
+			continue;
+
+		memcpy(fcb, databuf + mxs_nand_aux_status_offset(),
+			sizeof(*fcb));
+
+		if (fcb->FingerPrint != FCB_FINGERPRINT) {
+			pr_err("No FCB found on page %d\n", pagenum);
+			continue;
+		}
+
+		checksum = calc_chksum((void *)fcb +
+			sizeof(uint32_t), sizeof(*fcb) - sizeof(uint32_t));
+
+		if (checksum != fcb->Checksum) {
+			pr_err("FCB on page %d has invalid checksum. " \
+				"Expected: 0x%08x, calculated: 0x%08x",
+				pagenum, fcb->Checksum, checksum);
+			continue;
+		}
+
+		pr_debug("Found FCB:\n");
+		pr_debug("PageDataSize:     0x%08x\n", fcb->PageDataSize);
+		pr_debug("TotalPageSize:    0x%08x\n", fcb->TotalPageSize);
+		pr_debug("SectorsPerBlock:  0x%08x\n", fcb->SectorsPerBlock);
+		pr_debug("FW1_startingPage: 0x%08x\n",
+			fcb->Firmware1_startingPage);
+		pr_debug("PagesInFW1:       0x%08x\n", fcb->PagesInFirmware1);
+		pr_debug("FW2_startingPage: 0x%08x\n",
+			fcb->Firmware2_startingPage);
+		pr_debug("PagesInFW2:       0x%08x\n", fcb->PagesInFirmware2);
+
+		return 0;
+	}
+
+	return -EINVAL;
+}
+
+static int get_dbbt(struct mxs_nand_info *info, void *databuf)
+{
+	int i, ret;
Quoted 8 lines

arch/arm/mach-imx/Makefile

Quoted 6 lines
arch/arm/mach-imx/Makefile +6 -0
+	int page;
+	int startpage = info->fcb.DBBTSearchAreaStartAddress;
+	struct dbbt_block dbbt;
+
+	for (i = 0; i < 4; i++) {
+		page = startpage + i * 64;

Same here.

Again, will fix it in v2.

Quoted 4 lines

Regards,
Sascha

Thank you for your comments and review.

Best regards,
Andrej Picej

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#6 lore raw

Re: [PATCH 2/3] ARM: i.MX: implement GPMI NAND xload

Quoted 79 lines · Andrej Picej

Hi Sascha,

thanks for your comments.

Responses inline.

Quoted 37 lines · Sascha Hauer

Hi Andrej,

Some comments inline.

Quoted 32 lines · Andrej Picej

From: Sascha Hauer <[email protected]>

Commit is based on initial Sascha Hauer's work. It implements PBL xload mechanism to load image from GPMI NAND flash.

Additional work was done, so that the NAND's size, page size and OOB's size are autodetected and not hardcoded. Detection method follows the same methods as used in NAND driver, meaning NAND ONFI support is probed and if NAND supports ONFI, NAND memory organization is read from ONFI parameter page otherwise "READ ID" is used.

Currently only implemented for i.MX6 familly of SoCs.

---
  arch/arm/mach-imx/Makefile             |    2 +-
  arch/arm/mach-imx/include/mach/xload.h |    1 +
  arch/arm/mach-imx/xload-gpmi-nand.c    | 1163 ++++++++++++++++++++++++
  3 files changed, 1165 insertions(+), 1 deletion(-)

create mode 100644 arch/arm/mach-imx/xload-gpmi-nand.c

arch/arm/mach-imx/Makefile +5 -0
index e45f758e9..d94c846a1 100644
+static int mxs_nand_get_info(struct mxs_nand_info *info, void *databuf)
+{
+	int ret, i;
+
+	ret = mxs_nand_check_onfi(info, databuf);
Quoted 8 lines

arch/arm/mach-imx/Makefile

Quoted 4 lines
arch/arm/mach-imx/Makefile +4 -0
+	if (ret) {
+		if (ret != 1)
+			return ret;
+		pr_warn("ONFI not supported, try \"READ ID\"...\n");

You already printed a "ONFI not supported\n" message. Printing it once is enough. Also this message appears with every non-ONFI nand, right? In that case it should rather be pr_info()

OK, I agree, will fix it in v2.

Quoted 15 lines
Quoted 15 lines
arch/arm/mach-imx/Makefile +14 -0
+	/*
+	 * If ONFI is not supported or if it fails try to get NAND's info from
+	 * "READ ID" command.
+	 */
+	pr_debug("Trying \"READ ID\" command...\n");
+	ret = mxs_nand_get_readid(info, databuf);
+	if (ret) {
+		if (ret != -EOVERFLOW)
+			return ret;
+
+		/*
+		 * If NAND's "READ ID" returns bad values, try to set them to
+		 * default (most common NAND memory org.) and continue.
+		 */
Quoted 8 lines

arch/arm/mach-imx/Makefile

Quoted 5 lines
arch/arm/mach-imx/Makefile +5 -0
+		pr_warn("NANDs READ ID command returned bad values" \
+			" set them to default and try to continue!\n");
+		info->organization.pagesize = 2048;
+		info->organization.oobsize = 64;
+		info->nand_size = SZ_1G;

Is this worth it? READ ID is the most basic command, when this doesn't work I don't think there's a point in continuing.

Quoted 7 lines

We had a case with Samsung K9K8G08U0E when sometimes (reasons not known) the 5th byte returned 0xff instead of correct values, all other returned values were correct. In this case the device booted successfully because of this hook. Maybe a better solution would be to check only the 5th byte for 0xff value (5th byte is not supported from all NAND vendors), if this is the case set the NAND size to 1GB.
Would that make more sense?

The best would be to track the issue down and to fix it ;) It's not very nice to assume it in case of read id failures it's exactly that NAND type you have troubles with.
Does it help to reset the NAND chip before reading the ID?

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw

Re: [PATCH 2/3] ARM: i.MX: implement GPMI NAND xload

Quoted 88 lines · Sascha Hauer
Quoted 79 lines · Andrej Picej

Hi Sascha,

thanks for your comments.

Responses inline.

Quoted 37 lines · Sascha Hauer

Hi Andrej,

Some comments inline.

Quoted 32 lines · Andrej Picej

From: Sascha Hauer <[email protected]>

Commit is based on initial Sascha Hauer's work. It implements PBL xload mechanism to load image from GPMI NAND flash.

Additional work was done, so that the NAND's size, page size and OOB's size are autodetected and not hardcoded. Detection method follows the same methods as used in NAND driver, meaning NAND ONFI support is probed and if NAND supports ONFI, NAND memory organization is read from ONFI parameter page otherwise "READ ID" is used.

Currently only implemented for i.MX6 familly of SoCs.

---
   arch/arm/mach-imx/Makefile             |    2 +-
   arch/arm/mach-imx/include/mach/xload.h |    1 +
   arch/arm/mach-imx/xload-gpmi-nand.c    | 1163 ++++++++++++++++++++++++
   3 files changed, 1165 insertions(+), 1 deletion(-)

create mode 100644 arch/arm/mach-imx/xload-gpmi-nand.c

arch/arm/mach-imx/Makefile +5 -0
index e45f758e9..d94c846a1 100644
+static int mxs_nand_get_info(struct mxs_nand_info *info, void *databuf)
+{
+	int ret, i;
+
+	ret = mxs_nand_check_onfi(info, databuf);
Quoted 8 lines

arch/arm/mach-imx/Makefile

Quoted 4 lines
arch/arm/mach-imx/Makefile +4 -0
+	if (ret) {
+		if (ret != 1)
+			return ret;
+		pr_warn("ONFI not supported, try \"READ ID\"...\n");

You already printed a "ONFI not supported\n" message. Printing it once is enough. Also this message appears with every non-ONFI nand, right? In that case it should rather be pr_info()

OK, I agree, will fix it in v2.

Quoted 15 lines
Quoted 15 lines
arch/arm/mach-imx/Makefile +14 -0
+	/*
+	 * If ONFI is not supported or if it fails try to get NAND's info from
+	 * "READ ID" command.
+	 */
+	pr_debug("Trying \"READ ID\" command...\n");
+	ret = mxs_nand_get_readid(info, databuf);
+	if (ret) {
+		if (ret != -EOVERFLOW)
+			return ret;
+
+		/*
+		 * If NAND's "READ ID" returns bad values, try to set them to
+		 * default (most common NAND memory org.) and continue.
+		 */
Quoted 8 lines

arch/arm/mach-imx/Makefile

Quoted 5 lines
arch/arm/mach-imx/Makefile +5 -0
+		pr_warn("NANDs READ ID command returned bad values" \
+			" set them to default and try to continue!\n");
+		info->organization.pagesize = 2048;
+		info->organization.oobsize = 64;
+		info->nand_size = SZ_1G;

Is this worth it? READ ID is the most basic command, when this doesn't work I don't think there's a point in continuing.

Quoted 7 lines

We had a case with Samsung K9K8G08U0E when sometimes (reasons not known) the 5th byte returned 0xff instead of correct values, all other returned values were correct. In this case the device booted successfully because of this hook. Maybe a better solution would be to check only the 5th byte for 0xff value (5th byte is not supported from all NAND vendors), if this is the case set the NAND size to 1GB.
Would that make more sense?

Quoted 7 lines

The best would be to track the issue down and to fix it ;) It's not very nice to assume it in case of read id failures it's exactly that NAND type you have troubles with.
Does it help to reset the NAND chip before reading the ID?

Sascha

I totally agree with fixing the issue and will look into it a bit more.
I will reset the NAND before reading the ID in the same way as it is done before reading parameter page. I will leave the testing on over night (reading the ID failed in about 1 out of 500 boots) and report the results tomorrow.

BR,
Andrej

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#8 lore raw

Re: [PATCH 2/3] ARM: i.MX: implement GPMI NAND xload

Quoted 97 lines · Andrej Picej
Quoted 96 lines · Sascha Hauer
Quoted 82 lines · Andrej Picej

Hi Sascha,

thanks for your comments.

Responses inline.

Quoted 39 lines · Sascha Hauer

Hi Andrej,

Some comments inline.

Quoted 34 lines · Andrej Picej

From: Sascha Hauer <[email protected]>

Commit is based on initial Sascha Hauer's work. It implements PBL xload mechanism to load image from GPMI NAND flash.

Additional work was done, so that the NAND's size, page size and OOB's size are autodetected and not hardcoded. Detection method follows the same methods as used in NAND driver, meaning NAND ONFI support is probed and if NAND supports ONFI, NAND memory organization is read from ONFI parameter page otherwise "READ ID" is used.

Currently only implemented for i.MX6 familly of SoCs.

---
   arch/arm/mach-imx/Makefile             |    2 +- arch/arm/mach-imx/include/mach/xload.h |    1 + arch/arm/mach-imx/xload-gpmi-nand.c    | 1163
++++++++++++++++++++++++

   3 files changed, 1165 insertions(+), 1 deletion(-)

   create mode 100644 arch/arm/mach-imx/xload-gpmi-nand.c

arch/arm/mach-imx/Makefile +1 -0
index e45f758e9..d94c846a1 100644
+static int mxs_nand_get_info(struct mxs_nand_info *info, void 

*databuf)

arch/arm/mach-imx/Makefile +4 -0
+{
+    int ret, i;
+
+    ret = mxs_nand_check_onfi(info, databuf);
Quoted 8 lines
Quoted 4 lines

+    if (ret) {
+        if (ret != 1)
+            return ret;
+        pr_warn("ONFI not supported, try \"READ ID\"...\n");

You already printed a "ONFI not supported\n" message. Printing it once is enough. Also this message appears with every non-ONFI nand, right? In that case it should rather be pr_info()

OK, I agree, will fix it in v2.

Quoted 22 lines
Quoted 13 lines

+    /*
+     * If ONFI is not supported or if it fails try to get NAND's info from
+     * "READ ID" command.
+     */
+    pr_debug("Trying \"READ ID\" command...\n");
+    ret = mxs_nand_get_readid(info, databuf);
+    if (ret) {
+        if (ret != -EOVERFLOW)
+            return ret;
+
+        /*

Quoted 8 lines

+         * If NAND's "READ ID" returns bad values, try to set them to +         * default (most common NAND memory org.) and continue. +         */
+        pr_warn("NANDs READ ID command returned bad values" \
+            " set them to default and try to continue!\n"); +        info->organization.pagesize = 2048;
+        info->organization.oobsize = 64;
+        info->nand_size = SZ_1G;

Quoted 2 lines

Is this worth it? READ ID is the most basic command, when this doesn't work I don't think there's a point in continuing.

Quoted 7 lines

We had a case with Samsung K9K8G08U0E when sometimes (reasons not known) the 5th byte returned 0xff instead of correct values, all other returned values were correct. In this case the device booted successfully because of this hook. Maybe a better solution would be to check only the 5th byte for 0xff value (5th byte is not supported from all NAND vendors), if this is the case set the NAND size to 1GB.
Would that make more sense?

The best would be to track the issue down and to fix it ;) It's not very nice to assume it in case of read id failures it's exactly that NAND type you have troubles with.
Does it help to reset the NAND chip before reading the ID?

Quoted 6 lines
Quoted 2 lines

Sascha

I totally agree with fixing the issue and will look into it a bit more.
I will reset the NAND before reading the ID in the same way as it is done before reading parameter page. I will leave the testing on over night (reading the ID failed in about 1 out of 500 boots) and report the results tomorrow.

I guess resetting fixed this problem, I got 50.000 boots without any problems. Will fix this in v2 :).

Should I now completely abandon setting the NANDs memory to default values and just return error on failure? Something like this:

Quoted 6 lines
	/*
	 * If ONFI is not supported or if it fails try to get NAND's info from
	 * "READ ID" command.
	 */
	ret = mxs_nand_reset(info, databuf);
	if (ret)
Quoted 8 lines
		return ret;
	pr_debug("Trying \"READ ID\" command...\n");
	ret = mxs_nand_get_readid(info, databuf);
	if (ret) {
		pr_err("xloader supports only ONFI and generic \"READ ID\" " \
			"supported NANDs\n");
		return -1;
	}

I'm asking this because NANDs ID command is manufacturer specific, some manufacturers follow generic values and other unfortunately don't. In barebox NAND driver decoding is done based on manufacturer. I guess we could do the same here but I don't want to expand the PBL part too much just for reading FCB, where all NAND's memory parameters are decoded from.

BR,
Andrej

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#9 lore raw

Re: [PATCH 2/3] ARM: i.MX: implement GPMI NAND xload

Quoted 117 lines · Andrej Picej
Quoted 105 lines · Andrej Picej
Quoted 104 lines · Sascha Hauer
Quoted 85 lines · Andrej Picej

Hi Sascha,

thanks for your comments.

Responses inline.

Quoted 42 lines · Sascha Hauer

Hi Andrej,

Some comments inline.

Quoted 37 lines · Andrej Picej

From: Sascha Hauer <[email protected]>

Commit is based on initial Sascha Hauer's work. It implements PBL xload
mechanism to load image from GPMI NAND flash.

Additional work was done, so that the NAND's size, page size and OOB's size are autodetected and not hardcoded. Detection method follows the same methods as used in NAND driver, meaning NAND ONFI support is probed
and if NAND supports ONFI, NAND memory organization is read from ONFI parameter page otherwise "READ ID" is used.

Currently only implemented for i.MX6 familly of SoCs.

---
   arch/arm/mach-imx/Makefile             |    2 +- arch/arm/mach-imx/include/mach/xload.h |    1 + arch/arm/mach-imx/xload-gpmi-nand.c    | 1163
++++++++++++++++++++++++

   3 files changed, 1165 insertions(+), 1 deletion(-)

   create mode 100644 arch/arm/mach-imx/xload-gpmi-nand.c

arch/arm/mach-imx/Makefile +1 -0
index e45f758e9..d94c846a1 100644
+static int mxs_nand_get_info(struct mxs_nand_info

*info, void *databuf)

arch/arm/mach-imx/Makefile +5 -0
+{
+    int ret, i;
+
+    ret = mxs_nand_check_onfi(info, databuf);
+    if (ret) {
Quoted 8 lines
Quoted 3 lines

+        if (ret != 1)
+            return ret;
+        pr_warn("ONFI not supported, try \"READ ID\"...\n");

You already printed a "ONFI not supported\n" message. Printing it once is enough. Also this message appears with every non-ONFI nand, right? In
that case it should rather be pr_info()

OK, I agree, will fix it in v2.

Quoted 22 lines
Quoted 13 lines

+    /*
+     * If ONFI is not supported or if it fails try to get NAND's info from
+     * "READ ID" command.
+     */
+    pr_debug("Trying \"READ ID\" command...\n"); +    ret = mxs_nand_get_readid(info, databuf); +    if (ret) {
+        if (ret != -EOVERFLOW)
+            return ret;
+
+        /*

Quoted 8 lines

+         * If NAND's "READ ID" returns bad values, try to set them to +         * default (most common NAND memory org.) and continue. +         */
+        pr_warn("NANDs READ ID command returned bad values" \
+            " set them to default and try to continue!\n"); +        info->organization.pagesize = 2048;
+        info->organization.oobsize = 64;
+        info->nand_size = SZ_1G;

Quoted 2 lines

Is this worth it? READ ID is the most basic command, when this doesn't work I don't think there's a point in continuing.

Quoted 12 lines

We had a case with Samsung K9K8G08U0E when sometimes (reasons not known) the
5th byte returned 0xff instead of correct values, all other returned values
were correct. In this case the device booted successfully because of this
hook. Maybe a better solution would be to check only the 5th byte for 0xff
value (5th byte is not supported from all NAND vendors), if this is the case
set the NAND size to 1GB.
Would that make more sense?

The best would be to track the issue down and to fix it ;) It's not very nice to assume it in case of read id failures it's exactly that NAND type you have troubles with.
Does it help to reset the NAND chip before reading the ID?

Quoted 9 lines
Quoted 2 lines

Sascha

I totally agree with fixing the issue and will look into it a bit more. I will reset the NAND before reading the ID in the same way as it is done before reading parameter page. I will leave the testing on over night (reading the ID failed in about 1 out of 500 boots) and report the results tomorrow.

Quoted 5 lines

I guess resetting fixed this problem, I got 50.000 boots without any problems. Will fix this in v2 :).

Should I now completely abandon setting the NANDs memory to default values and just return error on failure?

Yes please.

Quoted 17 lines

Something like this:

Quoted 6 lines
	/*
	 * If ONFI is not supported or if it fails try to get NAND's info from
	 * "READ ID" command.
	 */
	ret = mxs_nand_reset(info, databuf);
	if (ret)
Quoted 8 lines
		return ret;
	pr_debug("Trying \"READ ID\" command...\n");
	ret = mxs_nand_get_readid(info, databuf);
	if (ret) {
		pr_err("xloader supports only ONFI and generic \"READ ID\" " \
			"supported NANDs\n");
		return -1;
	}
Quoted 5 lines

I'm asking this because NANDs ID command is manufacturer specific, some manufacturers follow generic values and other unfortunately don't. In barebox NAND driver decoding is done based on manufacturer. I guess we could do the same here but I don't want to expand the PBL part too much just for reading FCB, where all NAND's memory parameters are decoded from.

We can do that once we have to later. Decoding the ID into page/block sizes should also be done generically and not part of the i.MX6 NAND loader. Maybe we could also utilize parts of the NAND layer instead of adding new code.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#10 lore raw

Re: [PATCH 2/3] ARM: i.MX: implement GPMI NAND xload

Quoted 149 lines · Sascha Hauer
Quoted 117 lines · Andrej Picej
Quoted 105 lines · Andrej Picej
Quoted 104 lines · Sascha Hauer
Quoted 85 lines · Andrej Picej

Hi Sascha,

thanks for your comments.

Responses inline.

Quoted 42 lines · Sascha Hauer

Hi Andrej,

Some comments inline.

Quoted 37 lines · Andrej Picej

From: Sascha Hauer <[email protected]>

Commit is based on initial Sascha Hauer's work. It implements PBL xload
mechanism to load image from GPMI NAND flash.

Additional work was done, so that the NAND's size, page size and OOB's size are autodetected and not hardcoded. Detection method follows the same methods as used in NAND driver, meaning NAND ONFI support is probed
and if NAND supports ONFI, NAND memory organization is read from ONFI parameter page otherwise "READ ID" is used.

Currently only implemented for i.MX6 familly of SoCs.

---
    arch/arm/mach-imx/Makefile             |    2 +-
    arch/arm/mach-imx/include/mach/xload.h |    1 +
    arch/arm/mach-imx/xload-gpmi-nand.c    | 1163
++++++++++++++++++++++++
    3 files changed, 1165 insertions(+), 1 deletion(-)

   create mode 100644 arch/arm/mach-imx/xload-gpmi-nand.c

arch/arm/mach-imx/Makefile +1 -0
index e45f758e9..d94c846a1 100644
+static int mxs_nand_get_info(struct mxs_nand_info

*info, void *databuf)

arch/arm/mach-imx/Makefile +5 -0
+{
+    int ret, i;
+
+    ret = mxs_nand_check_onfi(info, databuf);
+    if (ret) {
Quoted 8 lines
Quoted 3 lines

+        if (ret != 1)
+            return ret;
+        pr_warn("ONFI not supported, try \"READ ID\"...\n");

You already printed a "ONFI not supported\n" message. Printing it once is enough. Also this message appears with every non-ONFI nand, right? In
that case it should rather be pr_info()

OK, I agree, will fix it in v2.

Quoted 22 lines
Quoted 13 lines

+    /*
+     * If ONFI is not supported or if it fails try to get NAND's info from
+     * "READ ID" command.
+     */
+    pr_debug("Trying \"READ ID\" command...\n"); +    ret = mxs_nand_get_readid(info, databuf); +    if (ret) {
+        if (ret != -EOVERFLOW)
+            return ret;
+
+        /*

Quoted 8 lines

+         * If NAND's "READ ID" returns bad values, try to set them to +         * default (most common NAND memory org.) and continue. +         */
+        pr_warn("NANDs READ ID command returned bad values" \
+            " set them to default and try to continue!\n"); +        info->organization.pagesize = 2048;
+        info->organization.oobsize = 64;
+        info->nand_size = SZ_1G;

Quoted 2 lines

Is this worth it? READ ID is the most basic command, when this doesn't work I don't think there's a point in continuing.

Quoted 12 lines

We had a case with Samsung K9K8G08U0E when sometimes (reasons not known) the
5th byte returned 0xff instead of correct values, all other returned values
were correct. In this case the device booted successfully because of this
hook. Maybe a better solution would be to check only the 5th byte for 0xff
value (5th byte is not supported from all NAND vendors), if this is the case
set the NAND size to 1GB.
Would that make more sense?

The best would be to track the issue down and to fix it ;) It's not very nice to assume it in case of read id failures it's exactly that NAND type you have troubles with.
Does it help to reset the NAND chip before reading the ID?

Quoted 9 lines
Quoted 2 lines

Sascha

I totally agree with fixing the issue and will look into it a bit more. I will reset the NAND before reading the ID in the same way as it is done before reading parameter page. I will leave the testing on over night (reading the ID failed in about 1 out of 500 boots) and report the results tomorrow.

Quoted 5 lines

I guess resetting fixed this problem, I got 50.000 boots without any problems. Will fix this in v2 :).

Should I now completely abandon setting the NANDs memory to default values and just return error on failure?

Yes please.

Quoted 17 lines

Something like this:

Quoted 6 lines
	/*
	 * If ONFI is not supported or if it fails try to get NAND's info from
	 * "READ ID" command.
	 */
	ret = mxs_nand_reset(info, databuf);
	if (ret)
Quoted 8 lines
		return ret;
	pr_debug("Trying \"READ ID\" command...\n");
	ret = mxs_nand_get_readid(info, databuf);
	if (ret) {
		pr_err("xloader supports only ONFI and generic \"READ ID\" " \
			"supported NANDs\n");
		return -1;
	}
Quoted 5 lines

I'm asking this because NANDs ID command is manufacturer specific, some manufacturers follow generic values and other unfortunately don't. In barebox NAND driver decoding is done based on manufacturer. I guess we could do the same here but I don't want to expand the PBL part too much just for reading FCB, where all NAND's memory parameters are decoded from.

Quoted 5 lines

We can do that once we have to later. Decoding the ID into page/block sizes should also be done generically and not part of the i.MX6 NAND loader. Maybe we could also utilize parts of the NAND layer instead of adding new code.

Ok, will prepare v2 and submit it when done. Thank you for your kind comments and guidance so far.

BR,
Andrej

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#11 lore raw

PATCH 3/3 ARM: i.MX: xload-gpmi-nand: apply errata 007117

In reply to Andrej Picej

During raw NAND booting, GPMI/BCH clock generation might fail due to improper clock gating conditions and consequently booting from NAND will fail. This is caused by silicon errata ERR007117. Apply errata fix workaround before GPMI NAND xload to prevent this from occurring.

---
 arch/arm/mach-imx/xload-gpmi-nand.c | 62 +++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
arch/arm/mach-imx/xload-gpmi-nand.c +62 -0
index 04f799604..4be6d1890 100644
@@ -20,6 +20,8 @@
 #include <mach/xload.h>
 #include <mach/imx-nand-bcb.h>
 #include <linux/mtd/rawnand.h>
+#include <mach/imx6-regs.h>
+#include <mach/clock-imx6.h>
 
 /*
  * MXS DMA hardware command.
@@ -256,6 +258,63 @@ struct mxs_nand_info {
 	unsigned long nand_size;
 };
 
+/**
+ * It was discovered that xloading barebox from NAND sometimes fails. Observed
+ * behaviour is similar to silicon errata ERR007117 for i.MX6.
+ *
+ * ERR007117 description:
+ * For raw NAND boot, ROM switches the source of enfc_clk_root from PLL2_PFD2
+ * to PLL3. The root clock is required to be gated before switching the source
+ * clock. If the root clock is not gated, clock glitches might be passed to the
+ * divider that follows the clock mux, and the divider might behave
+ * unpredictably. This can cause the clock generation to fail and the chip will
+ * not boot successfully.
+ *
+ * Workaround solution for this errata:
+ * 1) gate all GPMI/BCH related clocks (CG15, G14, CG13, CG12 and CG6)
+ * 2) reconfigure clocks
+ * 3) ungate all GPMI/BCH related clocks
+ *
+ */
+static inline void imx6_errata_007117_enable(void)
+{
+	u32 reg;
+
+	/* Gate (disable) the GPMI/BCH clocks in CCM_CCGR4 */
+	reg = readl(MXC_CCM_CCGR4);
+	reg &= ~(0xFF003000);
+	writel(reg, MXC_CCM_CCGR4);
+
+	/**
+	 * Gate (disable) the enfc_clk_root before changing the enfc_clk_root
+	 * source or dividers by clearing CCM_CCGR2[CG7] to 2'b00. This
+	 * disables the iomux_ipt_clk_io_clk.
+	 */
+	reg = readl(MXC_CCM_CCGR2);
+	reg &= ~(0x3 << 14);
+	writel(reg, MXC_CCM_CCGR2);
+
+	/* Configure CCM_CS2CDR for the new clock source configuration */
+	reg = readl(MXC_CCM_CS2CDR);
+	reg &= ~(0x7FF0000);
+	writel(reg, MXC_CCM_CS2CDR);
+	reg |= 0xF0000;
+	writel(reg, MXC_CCM_CS2CDR);
+
+	/**
+	 * Enable enfc_clk_root by setting CCM_CCGR2[CG7] to 2'b11. This
+	 * enables the iomux_ipt_clk_io_clk.
+	 */
+	reg = readl(MXC_CCM_CCGR2);
+	reg |= 0x3 << 14;
+	writel(reg, MXC_CCM_CCGR2);
+
+	/* Ungate (enable) the GPMI/BCH clocks in CCM_CCGR4 */
+	reg = readl(MXC_CCM_CCGR4);
+	reg |= 0xFF003000;
+	writel(reg, MXC_CCM_CCGR4);
+}
+
 static uint32_t mxs_nand_aux_status_offset(void)
 {
 	return (MXS_NAND_METADATA_SIZE + 0x3) & ~0x3;
@@ -1147,6 +1206,9 @@ int imx6_nand_start_image(void)
 		sizeof(struct mxs_dma_cmd) * MXS_NAND_DMA_DESCRIPTOR_COUNT;
 	bb = (void *)PAGE_ALIGN((unsigned long)databuf + SZ_8K);
 
+	/* Apply ERR007117 workaround */
+	imx6_errata_007117_enable();
+
 	ret = imx6_nand_load_image(cmdbuf, descs, databuf,
 		bb, imx_image_size());
 	if (ret) {
Signature · 7 lines
2.25.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#12 lore raw

Re: [PATCH 3/3] ARM: i.MX: xload-gpmi-nand: apply errata 007117

Quoted 25 lines · Andrej Picej

During raw NAND booting, GPMI/BCH clock generation might fail due to improper clock gating conditions and consequently booting from NAND will fail. This is caused by silicon errata ERR007117. Apply errata fix workaround before GPMI NAND xload to prevent this from occurring.

---
 arch/arm/mach-imx/xload-gpmi-nand.c | 62 +++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
arch/arm/mach-imx/xload-gpmi-nand.c +2 -0
index 04f799604..4be6d1890 100644
@@ -20,6 +20,8 @@
 #include <mach/xload.h>
 #include <mach/imx-nand-bcb.h>
 #include <linux/mtd/rawnand.h>
+#include <mach/imx6-regs.h>
+#include <mach/clock-imx6.h>
 
 /*
  * MXS DMA hardware command.

arch/arm/mach-imx/xload-gpmi-nand.c struct mxs_nand_info { · line 263

Quoted 6 lines
arch/arm/mach-imx/xload-gpmi-nand.c +3 -0
@@ -256,6 +258,63 @@ struct mxs_nand_info {
 	unsigned long nand_size;
 };
 
+/**
+ * It was discovered that xloading barebox from NAND sometimes fails. Observed
+ * behaviour is similar to silicon errata ERR007117 for i.MX6.

Have you really seen this behaviour? I wonder because the ROM has already loaded the initial code that is just running from NAND, so it surprises me that we still have to apply clock fixes.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#13 lore raw

Re: [PATCH 3/3] ARM: i.MX: xload-gpmi-nand: apply errata 007117

Hi Sascha,

yes, unfortunately we have. We applied this just because we experienced hangs in device booting tests. After this patch the NAND booting problems went away. The booting failed during DMA page reading. I just tested this again and after excluding the changes in this patch the device fails at executing DMA commands. The boot fails in approximately one out of 10 boots.

Best regards,
Andrej

Quoted 37 lines · Sascha Hauer
Quoted 25 lines · Andrej Picej

During raw NAND booting, GPMI/BCH clock generation might fail due to improper clock gating conditions and consequently booting from NAND will fail. This is caused by silicon errata ERR007117. Apply errata fix workaround before GPMI NAND xload to prevent this from occurring.

---
  arch/arm/mach-imx/xload-gpmi-nand.c | 62 +++++++++++++++++++++++++++++
  1 file changed, 62 insertions(+)
arch/arm/mach-imx/xload-gpmi-nand.c +2 -0
index 04f799604..4be6d1890 100644
@@ -20,6 +20,8 @@
  #include <mach/xload.h>
  #include <mach/imx-nand-bcb.h>
  #include <linux/mtd/rawnand.h>
+#include <mach/imx6-regs.h>
+#include <mach/clock-imx6.h>
 
  /*
   * MXS DMA hardware command.

arch/arm/mach-imx/xload-gpmi-nand.c struct mxs_nand_info { · line 263

Quoted 6 lines
arch/arm/mach-imx/xload-gpmi-nand.c +3 -0
@@ -256,6 +258,63 @@ struct mxs_nand_info {
  	unsigned long nand_size;
  };
 
+/**
+ * It was discovered that xloading barebox from NAND sometimes fails. Observed
+ * behaviour is similar to silicon errata ERR007117 for i.MX6.

Have you really seen this behaviour? I wonder because the ROM has already loaded the initial code that is just running from NAND, so it surprises me that we still have to apply clock fixes.

Quoted 2 lines

Sascha

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#14 lore raw

Re: [PATCH 3/3] ARM: i.MX: xload-gpmi-nand: apply errata 007117

Quoted 8 lines · Andrej Picej

Hi Sascha,

yes, unfortunately we have. We applied this just because we experienced hangs in device booting tests. After this patch the NAND booting problems went away. The booting failed during DMA page reading.
I just tested this again and after excluding the changes in this patch the device fails at executing DMA commands. The boot fails in approximately one out of 10 boots.

Where exactly did it hang? In the xloader or later in the real barebox driver?
You probably mean that it hangs in the xloader. Sorry to ask, but I'm still trying to understand. That would mean the ROM leaves the GPMI in an unusable state and I really wonder how this can happen.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#15 lore raw

Re: [PATCH 3/3] ARM: i.MX: xload-gpmi-nand: apply errata 007117

Quoted 10 lines · Sascha Hauer
Quoted 8 lines · Andrej Picej

Hi Sascha,

yes, unfortunately we have. We applied this just because we experienced hangs in device booting tests. After this patch the NAND booting problems went away. The booting failed during DMA page reading.
I just tested this again and after excluding the changes in this patch the device fails at executing DMA commands. The boot fails in approximately one out of 10 boots.

Quoted 8 lines

Where exactly did it hang? In the xloader or later in the real barebox driver?
You probably mean that it hangs in the xloader. Sorry to ask, but I'm still trying to understand. That would mean the ROM leaves the GPMI in an unusable state and I really wonder how this can happen.

Sascha

Sorry for not being clear enough the first time. You are correct, it hangs in xloader.

Maybe some additional information that may be relevant. When we boot barebox without PBL support barebox boots without problem and NAND behaves normal, so i guess the ROM sets the GPMI in usable state. Just a thought: could it be that the problem is in xloader and we somehow repair or reset the GPMI with this errata fix, so it works with xloader?

Andrej

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#16 lore raw

Re: [PATCH 3/3] ARM: i.MX: xload-gpmi-nand: apply errata 007117

Quoted 22 lines · Andrej Picej
Quoted 10 lines · Sascha Hauer
Quoted 8 lines · Andrej Picej

Hi Sascha,

yes, unfortunately we have. We applied this just because we experienced hangs in device booting tests. After this patch the NAND booting problems went away. The booting failed during DMA page reading.
I just tested this again and after excluding the changes in this patch the device fails at executing DMA commands. The boot fails in approximately one out of 10 boots.

Quoted 8 lines

Where exactly did it hang? In the xloader or later in the real barebox driver?
You probably mean that it hangs in the xloader. Sorry to ask, but I'm still trying to understand. That would mean the ROM leaves the GPMI in an unusable state and I really wonder how this can happen.

Sascha

Quoted 8 lines

Sorry for not being clear enough the first time. You are correct, it hangs in xloader.

Maybe some additional information that may be relevant. When we boot barebox without PBL support barebox boots without problem and NAND behaves normal, so i guess the ROM sets the GPMI in usable state.
Just a thought: could it be that the problem is in xloader and we somehow repair or reset the GPMI with this errata fix, so it works with xloader?

It could be that the ROM changes parts of the clock tree after having loaded the image from NAND and before it jumps to the payload. It might be that we would have the same problem in the real barebox driver if we wouldn't reconfigure the clocks anyway in the clock driver.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox