aboutsummaryrefslogtreecommitdiffstats
path: root/package/mtd/src/mtd.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2007-08-19 21:53:44 +0000
committerFelix Fietkau <nbd@openwrt.org>2007-08-19 21:53:44 +0000
commit5307d511aa974d2aaca2e7f6402d683077283d84 (patch)
treefb0490fbc937a600d3876162c58d481a16c98266 /package/mtd/src/mtd.c
parent4460bbca4731a3521e30b742b2cc1c3252ab0be5 (diff)
downloadupstream-5307d511aa974d2aaca2e7f6402d683077283d84.tar.gz
upstream-5307d511aa974d2aaca2e7f6402d683077283d84.tar.bz2
upstream-5307d511aa974d2aaca2e7f6402d683077283d84.zip
add 'mtd refresh' command
SVN-Revision: 8439
Diffstat (limited to 'package/mtd/src/mtd.c')
-rw-r--r--package/mtd/src/mtd.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/package/mtd/src/mtd.c b/package/mtd/src/mtd.c
index 9025240e1e..85b069f813 100644
--- a/package/mtd/src/mtd.c
+++ b/package/mtd/src/mtd.c
@@ -242,6 +242,25 @@ mtd_erase(const char *mtd)
}
int
+mtd_refresh(const char *mtd)
+{
+ int fd;
+
+ fd = mtd_open(mtd, O_RDWR | O_SYNC);
+ if(fd < 0) {
+ fprintf(stderr, "Could not open mtd device: %s\n", mtd);
+ exit(1);
+ }
+ if (ioctl(fd, MTDREFRESH, NULL)) {
+ fprintf(stderr, "Failed to refresh the MTD device\n");
+ close(fd);
+ exit(1);
+ }
+ close(fd);
+ return 0;
+}
+
+int
mtd_write(int imagefd, const char *mtd)
{
int fd, i, result;
@@ -318,6 +337,7 @@ void usage(void)
"The device is in the format of mtdX (eg: mtd4) or its label.\n"
"mtd recognizes these commands:\n"
" unlock unlock the device\n"
+ " refresh refresh mtd partition\n"
" erase erase all data on device\n"
" write <imagefile>|- write <imagefile> (use - for stdin) to device\n"
"Following options are available:\n"
@@ -338,7 +358,8 @@ int main (int argc, char **argv)
enum {
CMD_ERASE,
CMD_WRITE,
- CMD_UNLOCK
+ CMD_UNLOCK,
+ CMD_REFRESH
} cmd;
erase[0] = NULL;
@@ -380,6 +401,9 @@ int main (int argc, char **argv)
if ((strcmp(argv[0], "unlock") == 0) && (argc == 2)) {
cmd = CMD_UNLOCK;
device = argv[1];
+ } else if ((strcmp(argv[0], "refresh") == 0) && (argc == 2)) {
+ cmd = CMD_REFRESH;
+ device = argv[1];
} else if ((strcmp(argv[0], "erase") == 0) && (argc == 2)) {
cmd = CMD_ERASE;
device = argv[1];
@@ -451,6 +475,13 @@ int main (int argc, char **argv)
if (quiet < 2)
fprintf(stderr, "\n");
break;
+ case CMD_REFRESH:
+ if (quiet < 2)
+ fprintf(stderr, "Refreshing mtd partition %s ... ");
+ mtd_refresh(device);
+ if (quiet < 2)
+ fprintf(stderr, "\n");
+ break;
}
sync();