mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] ARM: i.MX: xload-gpmi-nand: fix bad block mark swapping
@ 2021-06-07  9:09 Andrej Picej
  2021-06-07  9:09 ` [PATCH 2/2] ARM: i.MX: xload: consider ECC strength when reading page Andrej Picej
  0 siblings, 1 reply; 11+ messages in thread
From: Andrej Picej @ 2021-06-07  9:09 UTC (permalink / raw)
  To: barebox

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@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


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

end of thread, other threads:[~2021-06-16  7:50 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-07  9:09 [PATCH 1/2] ARM: i.MX: xload-gpmi-nand: fix bad block mark swapping Andrej Picej
2021-06-07  9:09 ` [PATCH 2/2] ARM: i.MX: xload: consider ECC strength when reading page Andrej Picej
2021-06-07 20:03   ` Trent Piepho
2021-06-08  6:28     ` Sascha Hauer
2021-06-08  7:23     ` Andrej Picej
2021-06-08 12:38       ` Trent Piepho
2021-06-09  6:34         ` Andrej Picej
2021-06-14 22:14           ` Trent Piepho
2021-06-15 14:35             ` Sascha Hauer
2021-06-15 20:25               ` Trent Piepho
2021-06-16  7:48                 ` Andrej Picej

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox