[PATCH V2 3/4] arm: mach-imx: cmd_nandbcb fix bad block handling
Michael Nazzareno Trimarchi
michael at amarulasolutions.com
Wed May 11 08:49:25 CEST 2022
Hi Tim
Do you have an alternative board to test?
Michael
On Fri, May 6, 2022 at 4:41 PM Han Xu <han.xu at nxp.com> wrote:
>
> On 22/04/27 07:50AM, Michael Trimarchi wrote:
> > The badblock should be skipped properly in reading and writing.
> > Fix the logic. The bcb struct is written, skipping the bad block,
> > so we need to read using the same logic. This was tested create
> > bad block in the area and then flash it and read it back.
> >
> > Cc: Han Xu <han.xu at nxp.com>
> > Cc: Fabio Estevam <festevam at gmail.com>
> > Signed-off-by: Michael Trimarchi <michael at amarulasolutions.com>
>
> Acked-by: Han Xu <han.xu at nxp.com>
>
> > ---
> > V1->V2:
> > - Adjust the commit message
> > - Add Cc Han Xu and Fabio
> > - move out from RFC
> > ---
> > arch/arm/mach-imx/cmd_nandbcb.c | 21 +++++++--------------
> > 1 file changed, 7 insertions(+), 14 deletions(-)
> >
> > diff --git a/arch/arm/mach-imx/cmd_nandbcb.c b/arch/arm/mach-imx/cmd_nandbcb.c
> > index f119e9f88d..c54f52b343 100644
> > --- a/arch/arm/mach-imx/cmd_nandbcb.c
> > +++ b/arch/arm/mach-imx/cmd_nandbcb.c
> > @@ -506,10 +506,6 @@ static int read_fcb(struct boot_config *boot_cfg, struct fcb_block *fcb,
> > int ret = 0;
> >
> > mtd = boot_cfg->mtd;
> > - if (mtd_block_isbad(mtd, off)) {
> > - printf("Block %d is bad, skipped\n", (int)CONV_TO_BLOCKS(off));
> > - return 1;
> > - }
> >
> > fcb_raw_page = kzalloc(mtd->writesize + mtd->oobsize, GFP_KERNEL);
> > if (!fcb_raw_page) {
> > @@ -530,7 +526,7 @@ static int read_fcb(struct boot_config *boot_cfg, struct fcb_block *fcb,
> > else if (plat_config.misc_flags & FCB_ENCODE_BCH_40b)
> > mxs_nand_mode_fcb_40bit(mtd);
> >
> > - ret = nand_read(mtd, off, &size, (u_char *)fcb);
> > + ret = nand_read_skip_bad(mtd, off, &size, NULL, mtd->size, (u_char *)fcb);
> >
> > /* switch BCH back */
> > mxs_nand_mode_normal(mtd);
> > @@ -617,6 +613,7 @@ static int write_fcb(struct boot_config *boot_cfg, struct fcb_block *fcb)
> > for (i = 0; i < g_boot_search_count; i++) {
> > if (mtd_block_isbad(mtd, off)) {
> > printf("Block %d is bad, skipped\n", i);
> > + off += mtd->erasesize;
> > continue;
> > }
> >
> > @@ -676,20 +673,15 @@ static int read_dbbt(struct boot_config *boot_cfg, struct dbbt_block *dbbt,
> > void *dbbt_data_page, loff_t off)
> > {
> > size_t size;
> > + size_t actual_size;
> > struct mtd_info *mtd;
> > loff_t to;
> > int ret;
> >
> > mtd = boot_cfg->mtd;
> >
> > - if (mtd_block_isbad(mtd, off)) {
> > - printf("Block %d is bad, skipped\n",
> > - (int)CONV_TO_BLOCKS(off));
> > - return 1;
> > - }
> > -
> > size = sizeof(struct dbbt_block);
> > - ret = nand_read(mtd, off, &size, (u_char *)dbbt);
> > + ret = nand_read_skip_bad(mtd, off, &size, &actual_size, mtd->size, (u_char *)dbbt);
> > printf("NAND DBBT read from 0x%llx offset 0x%zx read: %s\n",
> > off, size, ret ? "ERROR" : "OK");
> > if (ret)
> > @@ -697,9 +689,9 @@ static int read_dbbt(struct boot_config *boot_cfg, struct dbbt_block *dbbt,
> >
> > /* dbbtpages == 0 if no bad blocks */
> > if (dbbt->dbbtpages > 0) {
> > - to = off + 4 * mtd->writesize;
> > + to = off + 4 * mtd->writesize + actual_size - size;
> > size = mtd->writesize;
> > - ret = nand_read(mtd, to, &size, dbbt_data_page);
> > + ret = nand_read_skip_bad(mtd, to, &size, NULL, mtd->size, dbbt_data_page);
> > printf("DBBT data read from 0x%llx offset 0x%zx read: %s\n",
> > to, size, ret ? "ERROR" : "OK");
> >
> > @@ -729,6 +721,7 @@ static int write_dbbt(struct boot_config *boot_cfg, struct dbbt_block *dbbt,
> > if (mtd_block_isbad(mtd, off)) {
> > printf("Block %d is bad, skipped\n",
> > (int)(i + CONV_TO_BLOCKS(off)));
> > + off += mtd->erasesize;
> > continue;
> > }
> >
> > --
> > 2.25.1
> >
--
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
michael at amarulasolutions.com
__________________________________
Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
info at amarulasolutions.com
www.amarulasolutions.com
More information about the U-Boot
mailing list