All of lore.kernel.org
 help / color / mirror / Atom feed
From: Scott Wood <scottwood@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2] nand: Add torture feature
Date: Fri, 16 Nov 2012 17:54:10 -0600	[thread overview]
Message-ID: <1353110050.13910.6@snotra> (raw)
In-Reply-To: <1752254295.1495778.1353093654020.JavaMail.root@advansee.com> (from benoit.thebaudeau@advansee.com on Fri Nov 16 13:20:54 2012)

On 11/16/2012 01:20:54 PM, Beno?t Th?baudeau wrote:
> +int nand_torture(nand_info_t *nand, loff_t offset)
> +{
> +	u_char patterns[] = {0xa5, 0x5a, 0x00};
> +	struct erase_info instr = {
> +		.mtd = nand,
> +		.addr = offset,
> +		.len = nand->erasesize,
> +	};
> +	size_t retlen;
> +	int err, ret = -1, i, patt_count;
> +	u_char *buf;
> +
> +	if ((offset & (nand->erasesize - 1)) != 0) {
> +		puts("Attempt to torture a block at a non block-aligned  
> "
> +				"offset\n");
> +		return -EINVAL;
> +	}
> +
> +	if (offset + nand->erasesize > nand->size) {
> +		puts("Attempt to torture a block outside the flash  
> area\n");
> +		return -EINVAL;
> +	}

I won't hold up the patch for this, since I think it works out OK due  
to type promotion rules (and in any case there are easier ways for a  
hostile user to do bad things in U-Boot) with nand->size being  
uint64_t, but loff_t is signed.  An explicit cast would be nice.

> +	patt_count = ARRAY_SIZE(patterns);
> +
> +	buf = malloc(nand->erasesize);
> +	if (buf == NULL) {
> +		puts("Out of memory for erase block buffer\n");
> +		return -ENOMEM;
> +	}
> +
> +	for (i = 0; i < patt_count; i++) {
> +		err = nand->erase(nand, &instr);
> +		if (err) {
> +			printf("%s: erase() failed for block at 0x%llx:  
> %d\n",
> +				nand->name, instr.addr, err);
> +			goto out;
> +		}
> +
> +		/* Make sure the block contains only 0xff bytes */
> +		err = nand->read(nand, offset, nand->erasesize,  
> &retlen, buf);
> +		if ((err && err != -EUCLEAN) || retlen !=  
> nand->erasesize) {
> +			printf("%s: read() failed for block at 0x%llx:  
> %d\n",
> +				nand->name, instr.addr, err);
> +			goto out;
> +		}
> +
> +		err = check_pattern(buf, 0xff, nand->erasesize);
> +		if (!err) {
> +			printf("Erased block at 0x%llx, but a non-0xff  
> byte "
> +					"was found\n", offset);
> +			ret = -EIO;
> +			goto out;
> +		}

Strings should not be wrapped (to improve greppability of errors), even  
if it would put the line over 80 columns.  I'll fix this when applying.

> diff --git u-boot-nand-flash-9c60e75.orig/include/nand.h  
> u-boot-nand-flash-9c60e75/include/nand.h
> index bbe28b2..c4530b0 100644
> --- u-boot-nand-flash-9c60e75.orig/include/nand.h
> +++ u-boot-nand-flash-9c60e75/include/nand.h
> @@ -139,6 +139,9 @@ int nand_read_skip_bad(nand_info_t *nand, loff_t  
> offset, size_t *length,
>  int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t  
> *length,
>  			u_char *buffer, int flags);
>  int nand_erase_opts(nand_info_t *meminfo, const nand_erase_options_t  
> *opts);
> +#ifdef CONFIG_CMD_NAND_TORTURE
> +int nand_torture(nand_info_t *nand, loff_t offset);
> +#endif

Prototypes should not be ifdeffed.  Will fix when applying.

Applied to u-boot-nand-flash.

-Scott

  reply	other threads:[~2012-11-16 23:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-05 20:15 [U-Boot] [PATCH 1/3] nand: Clean up nand_util Benoît Thébaudeau
2012-11-05 20:16 ` [U-Boot] [PATCH 2/3] nand: Fix nand_erase_opts() offset check Benoît Thébaudeau
2012-11-16  0:23   ` [U-Boot] [U-Boot,2/3] " Scott Wood
2012-11-19 20:40     ` Benoît Thébaudeau
2012-11-19 20:51       ` Scott Wood
2012-11-05 20:16 ` [U-Boot] [PATCH 3/3] nand: Add torture feature Benoît Thébaudeau
2012-11-06  0:03   ` Scott Wood
2012-11-16 19:20   ` [U-Boot] [PATCH v2] " Benoît Thébaudeau
2012-11-16 23:54     ` Scott Wood [this message]
2012-11-16  0:22 ` [U-Boot] [U-Boot,1/3] nand: Clean up nand_util Scott Wood
2012-11-16  0:29   ` Scott Wood
2012-11-16  7:20     ` Andreas Bießmann
2012-11-19 20:54       ` Tom Rini

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=1353110050.13910.6@snotra \
    --to=scottwood@freescale.com \
    --cc=u-boot@lists.denx.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.