All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 2/2] mtd core: call driver write function with complete buffer
Date: Wed, 5 Dec 2012 17:53:37 +0100	[thread overview]
Message-ID: <20121205165337.GJ8327@game.jcrosoft.org> (raw)
In-Reply-To: <1354215786-25615-2-git-send-email-s.hauer@pengutronix.de>

On 20:03 Thu 29 Nov     , Sascha Hauer wrote:
> mtd->write is supposed to loop around pages internally, no need
> to do this in mtd_write. This fixes a huge write performance drop
> with the m25p80 driver when it was converted to a mtd driver recently.
> Since mtd->writesize is 1 for this driver mtd_write ended up doing
> single byte writes on the flash.
this is the right patch for the flash

but this break my nand on 9x5

## Total Size      = 0x0002948e = 169102 Bytes

erasing partition /dev/nand0.barebox.bb


flashing barebox.bin to /dev/nand0.barebox.bb

	[#################################################################]
nand_write: Attempt to write not page aligned data
CRC32 for barebox.bin 0x00000000 ... 0x0002948d ==> 0x4cfca554
CRC32 for /dev/nand0.barebox.bb 0x00000000 ... 0x0002948d ==> 0x61dca32f != 0x61dca32f ** ERROR **

Best Regards,
J.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  drivers/mtd/core.c |   56 +++-------------------------------------------------
>  1 file changed, 3 insertions(+), 53 deletions(-)
> 
> diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
> index 8601787..b5916da 100644
> --- a/drivers/mtd/core.c
> +++ b/drivers/mtd/core.c
> @@ -62,65 +62,15 @@ static 	ssize_t mtd_read(struct cdev *cdev, void* buf, size_t count,
>  #define MTDPGALG(x) ((x) & ~(mtd->writesize - 1))
>  
>  #ifdef CONFIG_MTD_WRITE
> -static int all_ff(const void *buf, int len)
> -{
> -	int i;
> -	const uint8_t *p = buf;
> -
> -	for (i = 0; i < len; i++)
> -		if (p[i] != 0xFF)
> -			return 0;
> -	return 1;
> -}
> -
>  static ssize_t mtd_write(struct cdev* cdev, const void *buf, size_t _count,
>  			  loff_t _offset, ulong flags)
>  {
>  	struct mtd_info *mtd = cdev->priv;
> -	size_t retlen, now;
> -	int ret = 0;
> -	void *wrbuf = NULL;
> -	size_t count = _count;
> -	unsigned long offset = _offset;
> -
> -	if (NOTALIGNED(offset)) {
> -		printf("offset 0x%0lx not page aligned\n", offset);
> -		return -EINVAL;
> -	}
> -
> -	dev_dbg(cdev->dev, "write: offset: 0x%08lx count: 0x%zx\n", offset, count);
> -	while (count) {
> -		now = count > mtd->writesize ? mtd->writesize : count;
> -
> -		if (NOTALIGNED(now)) {
> -			dev_dbg(cdev->dev, "not aligned: %d %ld\n",
> -				mtd->writesize,
> -				(offset % mtd->writesize));
> -			wrbuf = xmalloc(mtd->writesize);
> -			memset(wrbuf, 0xff, mtd->writesize);
> -			memcpy(wrbuf + (offset % mtd->writesize), buf, now);
> -			if (!all_ff(wrbuf, mtd->writesize))
> -				ret = mtd->write(mtd, MTDPGALG(offset),
> -						  mtd->writesize, &retlen,
> -						  wrbuf);
> -			free(wrbuf);
> -		} else {
> -			if (!all_ff(buf, mtd->writesize))
> -				ret = mtd->write(mtd, offset, now, &retlen,
> -						  buf);
> -			dev_dbg(cdev->dev,
> -				"offset: 0x%08lx now: 0x%zx retlen: 0x%zx\n",
> -				offset, now, retlen);
> -		}
> -		if (ret)
> -			goto out;
> +	size_t retlen;
> +	int ret;
>  
> -		offset += now;
> -		count -= now;
> -		buf += now;
> -	}
> +	ret = mtd->write(mtd, _offset, _count, &retlen, buf);
>  
> -out:
>  	return ret ? ret : _count;
>  }
>  #endif
> -- 
> 1.7.10.4
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

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

  parent reply	other threads:[~2012-12-05 16:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-29 19:03 [PATCH 1/2] mtd oob: do not register oob device for devices without oob Sascha Hauer
2012-11-29 19:03 ` [PATCH 2/2] mtd core: call driver write function with complete buffer Sascha Hauer
2012-12-03 19:10   ` Robert Jarzmik
2012-12-05 16:53   ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2012-12-05 17:15     ` [PATCH 1/1] mtd: nand: fix unaligned write support Jean-Christophe PLAGNIOL-VILLARD
2012-12-05 18:28       ` Sascha Hauer
2012-12-07 13:17         ` Jean-Christophe PLAGNIOL-VILLARD

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=20121205165337.GJ8327@game.jcrosoft.org \
    --to=plagnioj@jcrosoft.com \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.