diff mbox

nanddump: Add Support for Quiet Option

Message ID 1220856357-22854-1-git-send-email-gerickson@nuovations.com
State Accepted
Commit 41c53b6f2d756ae995c3ffa4455576515427c5e0
Headers show

Commit Message

Grant Erickson Sept. 8, 2008, 6:45 a.m. UTC
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>
diff mbox

Patch

diff --git a/nanddump.c b/nanddump.c
index b8332f9..678d684 100644
--- a/nanddump.c
+++ b/nanddump.c
@@ -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) {