]> www.infradead.org Git - mtd-utils.git/commitdiff
nanddump: Add Support for Quiet Option
authorGrant Erickson <gerickson@nuovations.com>
Sun, 7 Sep 2008 20:45:57 +0000 (20:45 +0000)
committerJosh Boyer <jwboyer@gmail.com>
Mon, 8 Sep 2008 14:28:57 +0000 (10:28 -0400)
Added support for the '-q,--quiet' option to suppress diagnostic output.
 Made the new option mutually-exclusive with the pretty print option.

Signed-off-by: Grant Erickson <gerickson@nuovations.com>
Acked-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: Josh Boyer <jwboyer@gmail.com>
nanddump.c

index b8332f994acce0a67e746a2adb289060c7713e4a..678d6847a9dd707d246a11cdff697ec89513eda2 100644 (file)
@@ -52,6 +52,7 @@ static void display_help (void)
 "-o         --omitoob            Omit oob data\n"
 "-b         --omitbad            Omit bad blocks from the dump\n"
 "-p         --prettyprint        Print nice (hexdump)\n"
+"-q         --quiet              Don't display progress and status messages\n"
 "-s addr    --startaddress=addr  Start address\n"
        );
        exit(EXIT_SUCCESS);
@@ -81,6 +82,7 @@ static unsigned long  length;                 // dump length
 static const char      *mtddev;                // mtd device name
 static const char      *dumpfile;              // dump file name
 static bool            omitbad = false;
+static bool            quiet = false;          // suppress diagnostic output
 
 static void process_options (int argc, char * const argv[])
 {
@@ -88,7 +90,7 @@ static void process_options (int argc, char * const argv[])
 
        for (;;) {
                int option_index = 0;
-               static const char *short_options = "bs:f:il:opn";
+               static const char *short_options = "bs:f:il:opqn";
                static const struct option long_options[] = {
                        {"help", no_argument, 0, 0},
                        {"version", no_argument, 0, 0},
@@ -100,6 +102,7 @@ static void process_options (int argc, char * const argv[])
                        {"startaddress", required_argument, 0, 's'},
                        {"length", required_argument, 0, 'l'},
                        {"noecc", no_argument, 0, 'n'},
+                       {"quiet", no_argument, 0, 'q'},
                        {0, 0, 0, 0},
                };
 
@@ -144,6 +147,9 @@ static void process_options (int argc, char * const argv[])
                        case 'p':
                                pretty_print = true;
                                break;
+                       case 'q':
+                               quiet = true;
+                               break;
                        case 'n':
                                noecc = true;
                                break;
@@ -153,6 +159,12 @@ static void process_options (int argc, char * const argv[])
                }
        }
 
+       if (quiet && pretty_print) {
+               fprintf(stderr, "The quiet and pretty print options are mutually-\n"
+                               "exclusive. Choose one or the other.\n");
+               exit(EXIT_FAILURE);
+       }
+
        if ((argc - optind) != 1 || error)
                display_help ();
 
@@ -239,10 +251,12 @@ int main(int argc, char * const argv[])
                /* check if we can read ecc stats */
                if (!ioctl(fd, ECCGETSTATS, &stat1)) {
                        eccstats = true;
-                       fprintf(stderr, "ECC failed: %d\n", stat1.failed);
-                       fprintf(stderr, "ECC corrected: %d\n", stat1.corrected);    
-                       fprintf(stderr, "Number of bad blocks: %d\n", stat1.badblocks);    
-                       fprintf(stderr, "Number of bbt blocks: %d\n", stat1.bbtblocks);    
+                       if (!quiet) {
+                               fprintf(stderr, "ECC failed: %d\n", stat1.failed);
+                               fprintf(stderr, "ECC corrected: %d\n", stat1.corrected);    
+                               fprintf(stderr, "Number of bad blocks: %d\n", stat1.badblocks);    
+                               fprintf(stderr, "Number of bbt blocks: %d\n", stat1.bbtblocks);    
+                       }
                } else
                        perror("No ECC status information available");
        }
@@ -266,12 +280,14 @@ int main(int argc, char * const argv[])
        bs = meminfo.writesize;
 
        /* Print informative message */
-       fprintf(stderr, "Block size %u, page size %u, OOB size %u\n",
-                       meminfo.erasesize, meminfo.writesize, meminfo.oobsize);
-       fprintf(stderr,
-                       "Dumping data starting at 0x%08x and ending at 0x%08x...\n",
-                       (unsigned int) start_addr, (unsigned int) end_addr);
 
+       if (!quiet) {
+               fprintf(stderr, "Block size %u, page size %u, OOB size %u\n",
+                               meminfo.erasesize, meminfo.writesize, meminfo.oobsize);
+               fprintf(stderr,
+                               "Dumping data starting at 0x%08x and ending at 0x%08x...\n",
+                               (unsigned int) start_addr, (unsigned int) end_addr);
+       }
        /* Dump the flash contents */
        for (ofs = start_addr; ofs < end_addr ; ofs+=bs) {