public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH][MTD-UTILS] flashcp.c: Add new option -f/--full
@ 2006-12-04  8:58 Andreas Engel
  0 siblings, 0 replies; only message in thread
From: Andreas Engel @ 2006-12-04  8:58 UTC (permalink / raw)
  To: linux-mtd

[-- Attachment #1: Type: text/plain, Size: 254 bytes --]

This patch adds the option -f/--full which erases the whole flash
partition instead of just the sectors necessary for writing the file.
This might come in handy when copying filesystem images.

Signed-off-by: Andreas Engel <andreas.engel@ericsson.com>



[-- Attachment #2: flashcp.patch --]
[-- Type: text/x-patch, Size: 2061 bytes --]

diff --git a/flashcp.c b/flashcp.c
index 64b2eca..ef51d37 100644
--- a/flashcp.c
+++ b/flashcp.c
@@ -71,6 +71,7 @@ typedef int bool;
 #define FLAG_HELP		0x02
 #define FLAG_FILENAME	0x04
 #define FLAG_DEVICE		0x08
+#define FLAG_FULLERASE	0x10
 
 /* error levels */
 #define LOG_NORMAL	1
@@ -99,6 +100,7 @@ static void showusage (const char *progn
 			"\n"
 			"   -h | --help      Show this help message\n"
 			"   -v | --verbose   Show progress reports\n"
+                        "   -f | --full      Erase whole partition\n"
 			"   <filename>       File which you want to copy to flash\n"
 			"   <device>         Flash device to write to (e.g. /dev/mtd0, /dev/mtd1, etc.)\n"
 			"\n",
@@ -184,10 +186,11 @@ int main (int argc,char *argv[])
 
 	for (;;) {
 		int option_index = 0;
-		static const char *short_options = "hv";
+		static const char *short_options = "hvf";
 		static const struct option long_options[] = {
 			{"help", no_argument, 0, 'h'},
 			{"verbose", no_argument, 0, 'v'},
+                        {"full", no_argument, 0, 'f'},
 			{0, 0, 0, 0},
 		};
 
@@ -206,6 +209,10 @@ int main (int argc,char *argv[])
 				flags |= FLAG_VERBOSE;
 				DEBUG("Got FLAG_VERBOSE\n");
 				break;
+			case 'f':
+				flags |= FLAG_FULLERASE;
+				DEBUG("Got FLAG_FULLERASE\n");
+				break;
 			default:
 				DEBUG("Unknown parameter: %s\n",argv[option_index]);
 				showusage (progname,true);
@@ -257,8 +264,10 @@ int main (int argc,char *argv[])
 #warning "Check for smaller erase regions"
 
 	erase.start = 0;
-	erase.length = filestat.st_size & ~(mtd.erasesize - 1);
-	if (filestat.st_size % mtd.erasesize) erase.length += mtd.erasesize;
+	erase.length = (flags & FLAG_FULLERASE) ? mtd.size : filestat.st_size;
+        if (erase.length % mtd.erasesize)
+        	erase.length = (erase.length & ~(mtd.erasesize - 1)) + mtd.erasesize;
+
 	if (flags & FLAG_VERBOSE)
 	{
 		/* if the user wants verbose output, erase 1 block at a time and show him/her what's going on */
@@ -388,4 +397,3 @@ int main (int argc,char *argv[])
 
 	exit (EXIT_SUCCESS);
 }
-

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2006-12-04  8:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-04  8:58 [PATCH][MTD-UTILS] flashcp.c: Add new option -f/--full Andreas Engel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox