[U-Boot] [RFC 05/11] mtd/nand: take nand_ecc_ctrl initialization out of nand_scan_tail

Boris Brezillon boris.brezillon at free-electrons.com
Sun Jun 14 13:50:32 CEST 2015


On Fri,  5 Jun 2015 13:52:38 +0200
Roy Spliet <r.spliet at ultimaker.com> wrote:

Ditto (work not mainlined yet, so we'd better either get rid of it).
BTW, a commit message would help understanding what you're doing in
this patch (even if I'm probably the one who omit the commit message in
the first place, that doesn't mean you should do the same ;-))

> From: yassin <yassinjaffer at gmail.com>
> 
> Signed-off-by: Roy Spliet <r.spliet at ultimaker.com>
> ---
>  drivers/mtd/nand/nand_base.c | 101 ++++++++++++++++++++++++++-----------------
>  1 file changed, 61 insertions(+), 40 deletions(-)
> 
> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
> index 1c514a0..83586cc 100644
> --- a/drivers/mtd/nand/nand_base.c
> +++ b/drivers/mtd/nand/nand_base.c
> @@ -4114,47 +4114,15 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
>  }
>  EXPORT_SYMBOL(nand_scan_ident);
>  
> -
> -/**
> - * nand_scan_tail - [NAND Interface] Scan for the NAND device
> - * @mtd: MTD device structure
> - *
> - * This is the second phase of the normal nand_scan() function. It fills out
> - * all the uninitialized function pointers with the defaults and scans for a
> - * bad block table if appropriate.
> +/*
> + * Initialize ECC struct:
> + *  - fill ECC struct with default function/values when these ones are undefined
> + *  - fill ECC infos based on MTD device
>   */
> -int nand_scan_tail(struct mtd_info *mtd)
> +static int nand_ecc_ctrl_init(struct mtd_info *mtd, struct nand_ecc_ctrl *ecc)
>  {
>  	int i;
> -	struct nand_chip *chip = mtd->priv;
> -	struct nand_ecc_ctrl *ecc = &chip->ecc;
> -	struct nand_buffers *nbuf;
>  
> -	/* New bad blocks should be marked in OOB, flash-based BBT, or both */
> -	BUG_ON((chip->bbt_options & NAND_BBT_NO_OOB_BBM) &&
> -			!(chip->bbt_options & NAND_BBT_USE_FLASH));
> -
> -	if (!(chip->options & NAND_OWN_BUFFERS)) {
> -#ifndef __UBOOT__
> -		nbuf = kzalloc(sizeof(*nbuf) + mtd->writesize
> -				+ mtd->oobsize * 3, GFP_KERNEL);
> -		if (!nbuf)
> -			return -ENOMEM;
> -		nbuf->ecccalc = (uint8_t *)(nbuf + 1);
> -		nbuf->ecccode = nbuf->ecccalc + mtd->oobsize;
> -		nbuf->databuf = nbuf->ecccode + mtd->oobsize;
> -#else
> -		nbuf = kzalloc(sizeof(struct nand_buffers), GFP_KERNEL);
> -#endif
> -
> -		chip->buffers = nbuf;
> -	} else {
> -		if (!chip->buffers)
> -			return -ENOMEM;
> -	}
> -
> -	/* Set the internal oob buffer location, just after the page data */
> -	chip->oob_poi = chip->buffers->databuf + mtd->writesize;
>  
>  	/*
>  	 * If no default placement scheme is given, select an appropriate one.
> @@ -4180,9 +4148,6 @@ int nand_scan_tail(struct mtd_info *mtd)
>  		}
>  	}
>  
> -	if (!chip->write_page)
> -		chip->write_page = nand_write_page;
> -
>  	/*
>  	 * Check ECC mode, default to software if 3byte/512byte hardware ECC is
>  	 * selected and we have 256 byte pagesize fallback to software ECC
> @@ -4349,6 +4314,62 @@ int nand_scan_tail(struct mtd_info *mtd)
>  	}
>  	ecc->total = ecc->steps * ecc->bytes;
>  
> +	return 0;
> +}
> +
> +/**
> + * nand_scan_tail - [NAND Interface] Scan for the NAND device
> + * @mtd: MTD device structure
> + *
> + * This is the second phase of the normal nand_scan() function. It fills out
> + * all the uninitialized function pointers with the defaults and scans for a
> + * bad block table if appropriate.
> + */
> +int nand_scan_tail(struct mtd_info *mtd)
> +{
> +	int ret;
> +	struct nand_chip *chip = mtd->priv;
> +	struct nand_ecc_ctrl *ecc = &chip->ecc;
> +	struct nand_buffers *nbuf;
> +
> +	/* New bad blocks should be marked in OOB, flash-based BBT, or both */
> +	BUG_ON((chip->bbt_options & NAND_BBT_NO_OOB_BBM) &&
> +			!(chip->bbt_options & NAND_BBT_USE_FLASH));
> +
> +	if (!(chip->options & NAND_OWN_BUFFERS)) {
> +#ifndef __UBOOT__
> +		nbuf = kzalloc(sizeof(*nbuf) + mtd->writesize
> +				+ mtd->oobsize * 3, GFP_KERNEL);
> +		if (!nbuf)
> +			return -ENOMEM;
> +		nbuf->ecccalc = (uint8_t *)(nbuf + 1);
> +		nbuf->ecccode = nbuf->ecccalc + mtd->oobsize;
> +		nbuf->databuf = nbuf->ecccode + mtd->oobsize;
> +#else
> +		nbuf = kzalloc(sizeof(struct nand_buffers), GFP_KERNEL);
> +#endif
> +
> +		chip->buffers = nbuf;
> +	} else {
> +		if (!chip->buffers)
> +			return -ENOMEM;
> +	}
> +
> +	/* Set the internal oob buffer location, just after the page data */
> +	chip->oob_poi = chip->buffers->databuf + mtd->writesize;
> +
> +	if (!chip->write_page)
> +		chip->write_page = nand_write_page;
> +
> +	/* Initialize ECC struct */
> +	ret = nand_ecc_ctrl_init(mtd, ecc);
> +	if (ret) {
> +		if (!(chip->options & NAND_OWN_BUFFERS))
> +			kfree(chip->buffers);
> +
> +		return ret;
> +	}
> +
>  	/* Allow subpage writes up to ecc.steps. Not possible for MLC flash */
>  	if (!(chip->options & NAND_NO_SUBPAGE_WRITE) && nand_is_slc(chip)) {
>  		switch (ecc->steps) {



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com


More information about the U-Boot mailing list