* [PATCH v2] flashcp: Add option -A/--erase-all
@ 2019-10-21 10:10 drolevar
2019-10-28 7:13 ` David Oberhollenzer
0 siblings, 1 reply; 3+ messages in thread
From: drolevar @ 2019-10-21 10:10 UTC (permalink / raw)
To: linux-mtd; +Cc: Andrij Abyzov
From: Andrij Abyzov <drolevar@gmail.com>
Sometimes there's a need to erase the whole device when
programming an image, and not just the area under the
image itself.
Therefore, option -A/--erase-all has been added which
erases the whole device before writing the image.
Signed-off-by: Andrij Abyzov <drolevar@gmail.com>
---
misc-utils/flashcp.c | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/misc-utils/flashcp.c b/misc-utils/flashcp.c
index c46a5b4..b6ad2f9 100644
--- a/misc-utils/flashcp.c
+++ b/misc-utils/flashcp.c
@@ -66,6 +66,7 @@
#define FLAG_HELP 0x02
#define FLAG_FILENAME 0x04
#define FLAG_DEVICE 0x08
+#define FLAG_ERASE_ALL 0x10
/* error levels */
#define LOG_NORMAL 1
@@ -89,12 +90,13 @@ static NORETURN void showusage(bool error)
"\n"
"Flash Copy - Written by Abraham van der Merwe <abraham@2d3d.co.za>\n"
"\n"
- "usage: %1$s [ -v | --verbose ] <filename> <device>\n"
+ "usage: %1$s [ -v | --verbose | -A | --erase-all ] <filename> <device>\n"
" %1$s -h | --help\n"
" %1$s -V | --version\n"
"\n"
" -h | --help Show this help message\n"
" -v | --verbose Show progress reports\n"
+ " -A | --erase-all Erases the whole device regardless of the image size\n"
" -V | --version Show version information and exit\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"
@@ -179,10 +181,11 @@ int main (int argc,char *argv[])
for (;;) {
int option_index = 0;
- static const char *short_options = "hvV";
+ static const char *short_options = "hvAV";
static const struct option long_options[] = {
{"help", no_argument, 0, 'h'},
{"verbose", no_argument, 0, 'v'},
+ {"erase-all", no_argument, 0, 'A'},
{"version", no_argument, 0, 'V'},
{0, 0, 0, 0},
};
@@ -202,6 +205,10 @@ int main (int argc,char *argv[])
flags |= FLAG_VERBOSE;
DEBUG("Got FLAG_VERBOSE\n");
break;
+ case 'A':
+ flags |= FLAG_ERASE_ALL;
+ DEBUG("Got FLAG_ERASE_ALL\n");
+ break;
case 'V':
common_print_version();
exit(EXIT_SUCCESS);
@@ -257,8 +264,16 @@ int main (int argc,char *argv[])
#warning "Check for smaller erase regions"
erase.start = 0;
- erase.length = (filestat.st_size + mtd.erasesize - 1) / mtd.erasesize;
- erase.length *= mtd.erasesize;
+
+ if (flags & FLAG_ERASE_ALL)
+ {
+ erase.length = mtd.size;
+ }
+ else
+ {
+ erase.length = (filestat.st_size + mtd.erasesize - 1) / mtd.erasesize;
+ erase.length *= mtd.erasesize;
+ }
if (flags & FLAG_VERBOSE)
{
--
2.20.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] flashcp: Add option -A/--erase-all
2019-10-21 10:10 [PATCH v2] flashcp: Add option -A/--erase-all drolevar
@ 2019-10-28 7:13 ` David Oberhollenzer
0 siblings, 0 replies; 3+ messages in thread
From: David Oberhollenzer @ 2019-10-28 7:13 UTC (permalink / raw)
To: drolevar; +Cc: linux-mtd
Applied to mtd-utils.git master.
Thanks,
David
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2] flashcp: Add option -A/--erase-all
@ 2019-10-22 8:18 aabyzov
0 siblings, 0 replies; 3+ messages in thread
From: aabyzov @ 2019-10-22 8:18 UTC (permalink / raw)
To: linux-mtd; +Cc: Andrij Abyzov
From: Andrij Abyzov <drolevar@gmail.com>
Sometimes there's a need to erase the whole device when
programming an image, and not just the area under the
image itself.
Therefore, option -A/--erase-all has been added which
erases the whole device before writing the image.
Signed-off-by: Andrij Abyzov <drolevar@gmail.com>
---
misc-utils/flashcp.c | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/misc-utils/flashcp.c b/misc-utils/flashcp.c
index c46a5b4..b6ad2f9 100644
--- a/misc-utils/flashcp.c
+++ b/misc-utils/flashcp.c
@@ -66,6 +66,7 @@
#define FLAG_HELP 0x02
#define FLAG_FILENAME 0x04
#define FLAG_DEVICE 0x08
+#define FLAG_ERASE_ALL 0x10
/* error levels */
#define LOG_NORMAL 1
@@ -89,12 +90,13 @@ static NORETURN void showusage(bool error)
"\n"
"Flash Copy - Written by Abraham van der Merwe <abraham@2d3d.co.za>\n"
"\n"
- "usage: %1$s [ -v | --verbose ] <filename> <device>\n"
+ "usage: %1$s [ -v | --verbose | -A | --erase-all ] <filename> <device>\n"
" %1$s -h | --help\n"
" %1$s -V | --version\n"
"\n"
" -h | --help Show this help message\n"
" -v | --verbose Show progress reports\n"
+ " -A | --erase-all Erases the whole device regardless of the image size\n"
" -V | --version Show version information and exit\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"
@@ -179,10 +181,11 @@ int main (int argc,char *argv[])
for (;;) {
int option_index = 0;
- static const char *short_options = "hvV";
+ static const char *short_options = "hvAV";
static const struct option long_options[] = {
{"help", no_argument, 0, 'h'},
{"verbose", no_argument, 0, 'v'},
+ {"erase-all", no_argument, 0, 'A'},
{"version", no_argument, 0, 'V'},
{0, 0, 0, 0},
};
@@ -202,6 +205,10 @@ int main (int argc,char *argv[])
flags |= FLAG_VERBOSE;
DEBUG("Got FLAG_VERBOSE\n");
break;
+ case 'A':
+ flags |= FLAG_ERASE_ALL;
+ DEBUG("Got FLAG_ERASE_ALL\n");
+ break;
case 'V':
common_print_version();
exit(EXIT_SUCCESS);
@@ -257,8 +264,16 @@ int main (int argc,char *argv[])
#warning "Check for smaller erase regions"
erase.start = 0;
- erase.length = (filestat.st_size + mtd.erasesize - 1) / mtd.erasesize;
- erase.length *= mtd.erasesize;
+
+ if (flags & FLAG_ERASE_ALL)
+ {
+ erase.length = mtd.size;
+ }
+ else
+ {
+ erase.length = (filestat.st_size + mtd.erasesize - 1) / mtd.erasesize;
+ erase.length *= mtd.erasesize;
+ }
if (flags & FLAG_VERBOSE)
{
--
2.20.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-10-28 7:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-21 10:10 [PATCH v2] flashcp: Add option -A/--erase-all drolevar
2019-10-28 7:13 ` David Oberhollenzer
2019-10-22 8:18 aabyzov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).