aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2014-01-14 12:29:55 +1100
committerLorenz Meier <lm@inf.ethz.ch>2014-01-14 07:32:34 +0100
commitf30ae8c9f3b2f97322f5f4b2f6dcebb6277cd9c0 (patch)
treeb1299a5ba7a6a8c0f362c16bafe8d7552b5f5ae2
parent7b38c576e9720881dcb04d9d7f3f3df1e7c160fb (diff)
downloadpx4-firmware-f30ae8c9f3b2f97322f5f4b2f6dcebb6277cd9c0.tar.gz
px4-firmware-f30ae8c9f3b2f97322f5f4b2f6dcebb6277cd9c0.tar.bz2
px4-firmware-f30ae8c9f3b2f97322f5f4b2f6dcebb6277cd9c0.zip
Added MTD erase command
-rw-r--r--src/systemcmds/mtd/mtd.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/systemcmds/mtd/mtd.c b/src/systemcmds/mtd/mtd.c
index c9a9ea97a..590c1fb30 100644
--- a/src/systemcmds/mtd/mtd.c
+++ b/src/systemcmds/mtd/mtd.c
@@ -77,6 +77,7 @@ int mtd_main(int argc, char *argv[])
static void mtd_attach(void);
static void mtd_start(char *partition_names[], unsigned n_partitions);
static void mtd_test(void);
+static void mtd_erase(char *partition_names[], unsigned n_partitions);
static bool attached = false;
static bool started = false;
@@ -102,9 +103,16 @@ int mtd_main(int argc, char *argv[])
if (!strcmp(argv[1], "test"))
mtd_test();
+
+ if (!strcmp(argv[1], "erase")) {
+ if (argc < 3) {
+ errx(1, "usage: mtd erase <PARTITION_PATH..>");
+ }
+ mtd_erase(argv + 2, argc - 2);
+ }
}
- errx(1, "expected a command, try 'start' or 'test'");
+ errx(1, "expected a command, try 'start', 'erase' or 'test'");
}
struct mtd_dev_s *ramtron_initialize(FAR struct spi_dev_s *dev);
@@ -247,4 +255,25 @@ mtd_test(void)
exit(1);
}
+static void
+mtd_erase(char *partition_names[], unsigned n_partitions)
+{
+ uint8_t v[64];
+ memset(v, 0xFF, sizeof(v));
+ for (uint8_t i = 0; i < n_partitions; i++) {
+ uint32_t count = 0;
+ printf("Erasing %s\n", partition_names[i]);
+ int fd = open(partition_names[i], O_WRONLY);
+ if (fd == -1) {
+ errx(1, "Failed to open partition");
+ }
+ while (write(fd, &v, sizeof(v)) == sizeof(v)) {
+ count += sizeof(v);
+ }
+ printf("Erased %lu bytes\n", (unsigned long)count);
+ close(fd);
+ }
+ exit(0);
+}
+
#endif