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
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to