From 7d2839b8dede3ae368780364b4a07473d2303219 Mon Sep 17 00:00:00 2001 From: Ezequiel Garcia Date: Mon, 28 Apr 2014 10:14:18 -0300 Subject: nandtest: Move the "read and compare" code to a function This commit makes no functionality change, and simply moves the read and compare code into a separate read_and_compare() function. Signed-off-by: Ezequiel Garcia Signed-off-by: Artem Bityutskiy --- nandtest.c | 79 ++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 36 deletions(-) diff --git a/nandtest.c b/nandtest.c index fd78b95..31301d6 100644 --- a/nandtest.c +++ b/nandtest.c @@ -37,46 +37,11 @@ int fd; int markbad=0; int seed; -int erase_and_write(loff_t ofs, unsigned char *data, unsigned char *rbuf) +void read_and_compare(loff_t ofs, unsigned char *data, unsigned char *rbuf) { - struct erase_info_user er; ssize_t len; int i; - printf("\r%08x: erasing... ", (unsigned)ofs); - fflush(stdout); - - er.start = ofs; - er.length = meminfo.erasesize; - - if (ioctl(fd, MEMERASE, &er)) { - perror("MEMERASE"); - if (markbad) { - printf("Mark block bad at %08lx\n", (long)ofs); - ioctl(fd, MEMSETBADBLOCK, &ofs); - } - return 1; - } - - printf("\r%08x: writing...", (unsigned)ofs); - fflush(stdout); - - len = pwrite(fd, data, meminfo.erasesize, ofs); - if (len < 0) { - printf("\n"); - perror("write"); - if (markbad) { - printf("Mark block bad at %08lx\n", (long)ofs); - ioctl(fd, MEMSETBADBLOCK, &ofs); - } - return 1; - } - if (len < meminfo.erasesize) { - printf("\n"); - fprintf(stderr, "Short write (%zd bytes)\n", len); - exit(1); - } - printf("\r%08x: reading...", (unsigned)ofs); fflush(stdout); @@ -121,6 +86,48 @@ int erase_and_write(loff_t ofs, unsigned char *data, unsigned char *rbuf) } exit(1); } +} + +int erase_and_write(loff_t ofs, unsigned char *data, unsigned char *rbuf) +{ + struct erase_info_user er; + ssize_t len; + + printf("\r%08x: erasing... ", (unsigned)ofs); + fflush(stdout); + + er.start = ofs; + er.length = meminfo.erasesize; + + if (ioctl(fd, MEMERASE, &er)) { + perror("MEMERASE"); + if (markbad) { + printf("Mark block bad at %08lx\n", (long)ofs); + ioctl(fd, MEMSETBADBLOCK, &ofs); + } + return 1; + } + + printf("\r%08x: writing...", (unsigned)ofs); + fflush(stdout); + + len = pwrite(fd, data, meminfo.erasesize, ofs); + if (len < 0) { + printf("\n"); + perror("write"); + if (markbad) { + printf("Mark block bad at %08lx\n", (long)ofs); + ioctl(fd, MEMSETBADBLOCK, &ofs); + } + return 1; + } + if (len < meminfo.erasesize) { + printf("\n"); + fprintf(stderr, "Short write (%zd bytes)\n", len); + exit(1); + } + + read_and_compare(ofs, data, rbuf); return 0; } -- cgit v1.2.3