public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] nand: fix buffer alignment in new verification feature
@ 2015-04-13 18:55 Stephen Warren
  2015-04-13 19:53 ` Scott Wood
  0 siblings, 1 reply; 2+ messages in thread
From: Stephen Warren @ 2015-04-13 18:55 UTC (permalink / raw)
  To: u-boot

From: Stephen Warren <swarren@nvidia.com>

On systems with caches enabled, NAND I/O may need to flush/invalidate
the cache during read/write operations. For this to work correctly, all
buffers must be cache-aligned. Fix nand_verify*() to allocate aligned
buffers.

This prevents cache alignment warnings from being spewed when using
U-Boot to write an updated version of itself to flash on NVIDIA Tegra
Seaboard (after perturbation of stack/data layout in current
u-boot-dm/next branch).

I have validatd (executed) nand_verify(), but I don't think I've executed
nand_verify_page_oob(); testing of that would be useful.

Cc: Peter Tyser <ptyser@xes-inc.com>
Cc: Heiko Schocher <hs@denx.de>
Cc: Scott Wood <scottwood@freescale.com>
Fixes: 59b5a2ad83df ("nand: Add verification functions")
Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
 drivers/mtd/nand/nand_util.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/drivers/mtd/nand/nand_util.c b/drivers/mtd/nand/nand_util.c
index 12dd26a33fac..4e40952bf363 100644
--- a/drivers/mtd/nand/nand_util.c
+++ b/drivers/mtd/nand/nand_util.c
@@ -480,13 +480,11 @@ int nand_verify_page_oob(nand_info_t *nand, struct mtd_oob_ops *ops, loff_t ofs)
 	int rval;
 	struct mtd_oob_ops vops;
 	size_t verlen = nand->writesize + nand->oobsize;
+	ALLOC_CACHE_ALIGN_BUFFER(uint8_t, verbuf, verlen);
 
 	memcpy(&vops, ops, sizeof(vops));
 
-	vops.datbuf = malloc(verlen);
-
-	if (!vops.datbuf)
-		return -ENOMEM;
+	vops.datbuf = verbuf;
 
 	vops.oobbuf = vops.datbuf + nand->writesize;
 
@@ -496,8 +494,6 @@ int nand_verify_page_oob(nand_info_t *nand, struct mtd_oob_ops *ops, loff_t ofs)
 	if (!rval)
 		rval = memcmp(ops->oobbuf, vops.oobbuf, vops.ooblen);
 
-	free(vops.datbuf);
-
 	return rval ? -EIO : 0;
 }
 
@@ -520,10 +516,7 @@ int nand_verify(nand_info_t *nand, loff_t ofs, size_t len, u_char *buf)
 	int rval = 0;
 	size_t verofs;
 	size_t verlen = nand->writesize;
-	uint8_t *verbuf = malloc(verlen);
-
-	if (!verbuf)
-		return -ENOMEM;
+	ALLOC_CACHE_ALIGN_BUFFER(uint8_t, verbuf, verlen);
 
 	/* Read the NAND back in page-size groups to limit malloc size */
 	for (verofs = ofs; verofs < ofs + len;
@@ -537,8 +530,6 @@ int nand_verify(nand_info_t *nand, loff_t ofs, size_t len, u_char *buf)
 			break;
 	}
 
-	free(verbuf);
-
 	return rval ? -EIO : 0;
 }
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [U-Boot] [PATCH] nand: fix buffer alignment in new verification feature
  2015-04-13 18:55 [U-Boot] [PATCH] nand: fix buffer alignment in new verification feature Stephen Warren
@ 2015-04-13 19:53 ` Scott Wood
  0 siblings, 0 replies; 2+ messages in thread
From: Scott Wood @ 2015-04-13 19:53 UTC (permalink / raw)
  To: u-boot

On Mon, 2015-04-13 at 12:55 -0600, Stephen Warren wrote:
> From: Stephen Warren <swarren@nvidia.com>
> 
> On systems with caches enabled, NAND I/O may need to flush/invalidate
> the cache during read/write operations. For this to work correctly, all
> buffers must be cache-aligned. Fix nand_verify*() to allocate aligned
> buffers.
> 
> This prevents cache alignment warnings from being spewed when using
> U-Boot to write an updated version of itself to flash on NVIDIA Tegra
> Seaboard (after perturbation of stack/data layout in current
> u-boot-dm/next branch).
> 
> I have validatd (executed) nand_verify(), but I don't think I've executed
> nand_verify_page_oob(); testing of that would be useful.
> 
> Cc: Peter Tyser <ptyser@xes-inc.com>
> Cc: Heiko Schocher <hs@denx.de>
> Cc: Scott Wood <scottwood@freescale.com>
> Fixes: 59b5a2ad83df ("nand: Add verification functions")
> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> ---
>  drivers/mtd/nand/nand_util.c | 15 +++------------
>  1 file changed, 3 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/mtd/nand/nand_util.c b/drivers/mtd/nand/nand_util.c
> index 12dd26a33fac..4e40952bf363 100644
> --- a/drivers/mtd/nand/nand_util.c
> +++ b/drivers/mtd/nand/nand_util.c
> @@ -480,13 +480,11 @@ int nand_verify_page_oob(nand_info_t *nand, struct mtd_oob_ops *ops, loff_t ofs)
>  	int rval;
>  	struct mtd_oob_ops vops;
>  	size_t verlen = nand->writesize + nand->oobsize;
> +	ALLOC_CACHE_ALIGN_BUFFER(uint8_t, verbuf, verlen);

Isn't this a bit big for the stack?  Especially if NAND page sizes
continue to grow.  Can you use memalign() instead?

-Scott

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-04-13 19:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-13 18:55 [U-Boot] [PATCH] nand: fix buffer alignment in new verification feature Stephen Warren
2015-04-13 19:53 ` Scott Wood

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox