flashcp.c: Add new option -f/--full
PATCH 1/1 flashcp.c: Add new option -f/--full
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 <[email protected]>
flashcp.c +12 -4
@@ -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 ); } -