[U-Boot] [PATCH 2/4 v2] cmd: mtd: Don't abort erase operation when a bad block is detected

Boris Brezillon boris.brezillon at bootlin.com
Tue Aug 7 13:05:21 UTC 2018


On Tue,  7 Aug 2018 14:16:53 +0200
Stefan Roese <sr at denx.de> wrote:

> It was noticed, that the erase command (mtd erase spi-nand0) aborts upon
> the first bad block. With this change, bad blocks are now skipped and
> the erase operation will continue.
> 
> Signed-off-by: Stefan Roese <sr at denx.de>
> Cc: Miquel Raynal <miquel.raynal at bootlin.com>
> Cc: Boris Brezillon <boris.brezillon at bootlin.com>
> Cc: Jagan Teki <jagan at openedev.com>
> ---
> v2: 
> - Use an U-Boot "mtd" command specific option to skip the bad block
>   upon erase so that other MTD users are not affected by this change
> 
>  cmd/mtd.c               | 1 +
>  drivers/mtd/nand/core.c | 6 ++++++
>  include/linux/mtd/mtd.h | 1 +
>  3 files changed, 8 insertions(+)
> 
> diff --git a/cmd/mtd.c b/cmd/mtd.c
> index 221b12500f..999d686e66 100644
> --- a/cmd/mtd.c
> +++ b/cmd/mtd.c
> @@ -359,6 +359,7 @@ static int do_mtd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
>  		erase_op.addr = off;
>  		erase_op.len = len;
>  		erase_op.scrub = scrub;
> +		erase_op.skipbad = true;
>  
>  		ret = mtd_erase(mtd, &erase_op);
>  	} else {
> diff --git a/drivers/mtd/nand/core.c b/drivers/mtd/nand/core.c
> index 0b793695cc..c9d7a646f6 100644
> --- a/drivers/mtd/nand/core.c
> +++ b/drivers/mtd/nand/core.c
> @@ -163,6 +163,12 @@ int nanddev_mtd_erase(struct mtd_info *mtd, struct erase_info *einfo)
>  	while (nanddev_pos_cmp(&pos, &last) <= 0) {
>  		ret = nanddev_erase(nand, &pos);
>  		if (ret) {
> +			/* U-Boot special: Allow the users to skip bad blocks */
> +			if ((ret == -EIO) && einfo->skipbad) {
> +				nanddev_pos_next_eraseblock(nand, &pos);
> +				continue;
> +			}
> +

If you choose this approach you'll have to patch rawnand and onenand
code to do the same (maybe others too), because we want mtd erase to
work the same way on all MTD devices.

To be honest, I'd prefer to see that handled in cmd/mtd.c. If you don't
like the idea of erasing one block at a time, you can always check the
->fail_addr info when mtd_erase() returns an error, and start over
from ->fail_addr + mtd->erasesize. 

>  			einfo->fail_addr = nanddev_pos_to_offs(nand, &pos);
>  
>  			return ret;
> diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
> index 4ca5d764d7..3a09dbab95 100644
> --- a/include/linux/mtd/mtd.h
> +++ b/include/linux/mtd/mtd.h
> @@ -53,6 +53,7 @@ struct erase_info {
>  	u_char state;
>  	struct erase_info *next;
>  	int scrub;
> +	bool skipbad;
>  };
>  
>  struct mtd_erase_region_info {



More information about the U-Boot mailing list