[PATCH 1/2] ARM: i.MX: xload-gpmi-nand: fix bad block mark swapping

Andrej Picej andrej.picej at norik.com
Mon Jun 7 02:09:50 PDT 2021


Until now GPMI NAND xloader assumed NAND bad block marker start bit was
always 0! This is not true for every NAND chip out there. Thus make
xloader more robust and port NAND bad block marker swapping
functionality from the nand_mxs driver and make use of it in PBL.

This patch was tested on a PHYTEC phyCARD i.MX6Q board with next NANDs:
 - Spansion S34ML08G201FI00,
 - Samsung K9K8G08U0E and
 - Winbond W29N08GVSIAA.

Signed-off-by: Andrej Picej <andrej.picej at norik.com>
---
 arch/arm/mach-imx/xload-gpmi-nand.c | 41 +++++++++++++++++++++++++++--
 1 file changed, 39 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-imx/xload-gpmi-nand.c b/arch/arm/mach-imx/xload-gpmi-nand.c
index b3fd479cb..661302762 100644
--- a/arch/arm/mach-imx/xload-gpmi-nand.c
+++ b/arch/arm/mach-imx/xload-gpmi-nand.c
@@ -1086,6 +1086,43 @@ static int block_is_bad(struct mxs_nand_info *info, int blocknum)
 	return 0;
 }
 
+/* Function ported from nand_mxs driver -> mxs_nand_swap_block_mark() */
+static void bad_block_marker_swap(struct mxs_nand_info *info,
+		uint8_t *data_buf, uint8_t *oob_buf)
+{
+	struct fcb_block *fcb = &info->fcb;
+
+	uint32_t bit_offset;
+	uint32_t buf_offset;
+
+	uint32_t src;
+	uint32_t dst;
+
+	/* Location of bad block marker is specified in FCB. */
+	bit_offset = fcb->BadBlockMarkerStartBit;
+	buf_offset = fcb->BadBlockMarkerByte;
+
+	/*
+	 * Get the byte from the data area that overlays the block mark. Since
+	 * the ECC engine applies its own view to the bits in the page, the
+	 * physical block mark won't (in general) appear on a byte boundary in
+	 * the data.
+	 */
+
+	src = data_buf[buf_offset] >> bit_offset;
+	src |= data_buf[buf_offset + 1] << (8 - bit_offset);
+
+	dst = oob_buf[0];
+
+	oob_buf[0] = src;
+
+	data_buf[buf_offset] &= ~(0xff << bit_offset);
+	data_buf[buf_offset + 1] &= 0xff << bit_offset;
+
+	data_buf[buf_offset] |= dst << bit_offset;
+	data_buf[buf_offset + 1] |= dst >> (8 - bit_offset);
+}
+
 static int read_firmware(struct mxs_nand_info *info, int startpage,
 	void *dest, int len)
 {
@@ -1121,8 +1158,8 @@ static int read_firmware(struct mxs_nand_info *info, int startpage,
 			return ret;
 		}
 
-		*((u8 *)dest + fcb->BadBlockMarkerByte) =
-			*(u8 *)(dest + pagesize);
+		/* Read DMA completed, now swap the bad block marker. */
+		bad_block_marker_swap(info, dest, dest + pagesize);
 
 		numpages--;
 		dest += pagesize;
-- 
2.25.1




More information about the barebox mailing list