From: Andrej Picej <andrej.picej@norik.com> To: barebox@lists.infradead.org Subject: [PATCH 1/2] ARM: i.MX: xload-gpmi-nand: fix bad block mark swapping Date: Mon, 7 Jun 2021 11:09:50 +0200 [thread overview] Message-ID: <20210607090951.107269-1-andrej.picej@norik.com> (raw) 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
next reply other threads:[~2021-06-07 9:32 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-06-07 9:09 Andrej Picej [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210607090951.107269-1-andrej.picej@norik.com \ --to=andrej.picej@norik.com \ --cc=barebox@lists.infradead.org \ --subject='Re: [PATCH 1/2] ARM: i.MX: xload-gpmi-nand: fix bad block mark swapping' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox