--- ./nandtest.c.bad 2012-02-19 11:15:39 +0100 +++ ./nandtest.c 2012-02-19 11:23:37 +0100 @@ -28,6 +28,7 @@ " -o, --offset Start offset on flash\n" " -l, --length Length of flash to test\n" - " -k, --keep Restore existing contents after test\n", + " -k, --keep Restore existing contents after test\n" + " -B, --badblock Mark this block as bad (use 0x prefix)\n", PROGRAM_NAME); exit(1); } @@ -35,6 +36,7 @@ struct mtd_info_user meminfo; struct mtd_ecc_stats oldstats, newstats; int fd; +loff_t badblock=0; int markbad=0; int markeccbad=0; int seed; @@ -149,7 +151,7 @@ uint32_t length = -1; for (;;) { - static const char *short_options="hkl:mMo:p:s:"; + static const char *short_options="hkl:mMo:p:s:B:"; static const struct option long_options[] = { { "help", no_argument, 0, 'h' }, { "markbad", no_argument, 0, 'm' }, @@ -159,6 +161,7 @@ { "offset", required_argument, 0, 'o' }, { "length", required_argument, 0, 'l' }, { "keep", no_argument, 0, 'k' }, + { "badblock", required_argument, 0, 'B' }, {0, 0, 0, 0}, }; int option_index = 0; @@ -199,7 +202,10 @@ case 'l': length = strtol(optarg, NULL, 0); break; - + + case 'B': + badblock = strtol(optarg, NULL, 0); + break; } } if (argc - optind != 1) @@ -256,6 +262,25 @@ printf("Bad blocks : %d\n", oldstats.badblocks); printf("BBT blocks : %d\n", oldstats.bbtblocks); + if (badblock) { + printf("Mark block bad at %08lx\n", (long)badblock); + ioctl(fd, MEMSETBADBLOCK, &badblock); + + if (ioctl(fd, ECCGETSTATS, &oldstats)) { + perror("ECCGETSTATS"); + close(fd); + exit(1); + } + + printf("ECC corrections: %d\n", oldstats.corrected); + printf("ECC failures : %d\n", oldstats.failed); + printf("Bad blocks : %d\n", oldstats.badblocks); + printf("BBT blocks : %d\n", oldstats.bbtblocks); + + printf("Exiting after marking block bad\n"); + exit(0); + } + for (pass = 0; pass < nr_passes; pass++) { loff_t test_ofs;