* [PATCH 1/4] libmtd: add lock/unlock helpers
@ 2010-09-24 1:53 Mike Frysinger
2010-09-24 1:53 ` [PATCH 2/4] mtd-utils: new bareverbose() helper Mike Frysinger
` (3 more replies)
0 siblings, 4 replies; 30+ messages in thread
From: Mike Frysinger @ 2010-09-24 1:53 UTC (permalink / raw)
To: linux-mtd
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
include/libmtd.h | 24 ++++++++++++++++++++++++
lib/libmtd.c | 32 ++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 0 deletions(-)
diff --git a/include/libmtd.h b/include/libmtd.h
index afaba42..f73af4c 100644
--- a/include/libmtd.h
+++ b/include/libmtd.h
@@ -138,6 +138,30 @@ int mtd_get_dev_info(libmtd_t desc, const char *node, struct mtd_dev_info *mtd);
int mtd_get_dev_info1(libmtd_t desc, int mtd_num, struct mtd_dev_info *mtd);
/**
+ * mtd_lock - lock eraseblocks
+ * @desc: MTD library descriptor
+ * @mtd: MTD device description object
+ * @fd: MTD device node file descriptor
+ * @eb: eraseblock to lock
+ *
+ * This function locks eraseblock @eb. Returns %0 in case of success and %-1
+ * in case of failure.
+ */
+int mtd_lock(const struct mtd_dev_info *mtd, int fd, int eb);
+
+/**
+ * mtd_unlock - unlock eraseblocks
+ * @desc: MTD library descriptor
+ * @mtd: MTD device description object
+ * @fd: MTD device node file descriptor
+ * @eb: eraseblock to lock
+ *
+ * This function unlocks eraseblock @eb. Returns %0 in case of success and %-1
+ * in case of failure.
+ */
+int mtd_unlock(const struct mtd_dev_info *mtd, int fd, int eb);
+
+/**
* mtd_erase - erase an eraseblock.
* @desc: MTD library descriptor
* @mtd: MTD device description object
diff --git a/lib/libmtd.c b/lib/libmtd.c
index d57ae8f..1b3d597 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -802,6 +802,38 @@ static int mtd_valid_erase_block(const struct mtd_dev_info *mtd, int eb)
return 0;
}
+static int mtd_xlock(const struct mtd_dev_info *mtd, int fd, int eb, int req,
+ const char *sreq)
+{
+ int ret;
+ struct erase_info_user ei;
+
+ ret = mtd_valid_erase_block(mtd, eb);
+ if (ret)
+ return ret;
+
+ ei.start = eb * mtd->eb_size;
+ ei.length = mtd->eb_size;
+
+ ret = ioctl(fd, req, &ei);
+ if (ret < 0)
+ return sys_errmsg("%s ioctl failed for eraseblock %d "
+ "(mtd%d)", sreq, eb, mtd->mtd_num);
+
+ return 0;
+}
+#define mtd_xlock(mtd, fd, eb, req) mtd_xlock(mtd, fd, eb, req, #req)
+
+int mtd_lock(const struct mtd_dev_info *mtd, int fd, int eb)
+{
+ return mtd_xlock(mtd, fd, eb, MEMLOCK);
+}
+
+int mtd_unlock(const struct mtd_dev_info *mtd, int fd, int eb)
+{
+ return mtd_xlock(mtd, fd, eb, MEMUNLOCK);
+}
+
int mtd_erase(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb)
{
int ret;
--
1.7.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 2/4] mtd-utils: new bareverbose() helper
2010-09-24 1:53 [PATCH 1/4] libmtd: add lock/unlock helpers Mike Frysinger
@ 2010-09-24 1:53 ` Mike Frysinger
2010-09-24 4:24 ` Jon Povey
2010-09-25 6:05 ` [PATCH 2/4 v2] " Mike Frysinger
2010-09-24 1:53 ` [PATCH 3/4] mtd-utils: new strtoX helpers Mike Frysinger
` (2 subsequent siblings)
3 siblings, 2 replies; 30+ messages in thread
From: Mike Frysinger @ 2010-09-24 1:53 UTC (permalink / raw)
To: linux-mtd
Add a new helper that let's people do simple verbose output without any
implicit strings added around it. Good for progress bars and such.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
include/common.h | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/include/common.h b/include/common.h
index e87b215..11b0cf6 100644
--- a/include/common.h
+++ b/include/common.h
@@ -38,10 +38,12 @@ extern "C" {
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
/* Verbose messages */
-#define verbose(verbose, fmt, ...) do { \
+#define bareverbose(verbose, fmt, ...) do { \
if (verbose) \
- printf(PROGRAM_NAME ": " fmt "\n", ##__VA_ARGS__); \
+ printf(fmt, ##__VA_ARGS__); \
} while(0)
+#define verbose(verbose, fmt, ...) \
+ bareverbose(verbose, PROGRAM_NAME ": " fmt "\n", ##__VA_ARGS__)
/* Normal messages */
#define normsg(fmt, ...) do { \
--
1.7.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 3/4] mtd-utils: new strtoX helpers
2010-09-24 1:53 [PATCH 1/4] libmtd: add lock/unlock helpers Mike Frysinger
2010-09-24 1:53 ` [PATCH 2/4] mtd-utils: new bareverbose() helper Mike Frysinger
@ 2010-09-24 1:53 ` Mike Frysinger
2010-09-24 4:31 ` Jon Povey
2010-09-25 6:06 ` [PATCH 3/4 v2] " Mike Frysinger
2010-09-24 1:53 ` [PATCH 4/4] mtd-utils: unify flash_erase and flash_eraseall Mike Frysinger
2010-09-25 10:50 ` [PATCH 1/4] libmtd: add lock/unlock helpers Artem Bityutskiy
3 siblings, 2 replies; 30+ messages in thread
From: Mike Frysinger @ 2010-09-24 1:53 UTC (permalink / raw)
To: linux-mtd
Simply usage of converting strings to numbers by adding some wrappers
around the standard strtoX functions. These helpers support both hex
and dec numbers transparently, and the caller need only provide a ptr
to an error integer if they want to be notified of problems.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
include/strtox.h | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 63 insertions(+), 0 deletions(-)
create mode 100644 include/strtox.h
diff --git a/include/strtox.h b/include/strtox.h
new file mode 100644
index 0000000..f7ae824
--- /dev/null
+++ b/include/strtox.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) Artem Bityutskiy, 2007, 2008
+ * Copyright (c) Mike Frysinger, 2010
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __MTD_UTILS_STRTOX_H__
+#define __MTD_UTILS_STRTOX_H__
+
+#include "common.h"
+#include <stdlib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * simple_strtoX - convert a hex/dec string into a number
+ * @snum: buffer to convert
+ * @error: set to 1 when buffer isn't fully consumed
+ */
+#define simple_strtoX(func, type) \
+static inline type simple_##func(const char *snum, int *error) \
+{ \
+ type ret; \
+ char *endptr; \
+ \
+ if (snum[0] == '0' && snum[1] == 'x') \
+ ret = func(snum, &endptr, 16); \
+ else \
+ ret = func(snum, &endptr, 10); \
+ \
+ if (!*snum || *endptr) { \
+ errmsg("%s: unable to parse the number '%s'", #func, snum); \
+ if (error) \
+ *error = 1; \
+ } \
+ \
+ return ret; \
+}
+simple_strtoX(strtol, long int)
+simple_strtoX(strtoll, long int)
+simple_strtoX(strtoul, unsigned long int)
+simple_strtoX(strtoull, unsigned long int)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !__MTD_UTILS_STRTOX_H__ */
--
1.7.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 4/4] mtd-utils: unify flash_erase and flash_eraseall
2010-09-24 1:53 [PATCH 1/4] libmtd: add lock/unlock helpers Mike Frysinger
2010-09-24 1:53 ` [PATCH 2/4] mtd-utils: new bareverbose() helper Mike Frysinger
2010-09-24 1:53 ` [PATCH 3/4] mtd-utils: new strtoX helpers Mike Frysinger
@ 2010-09-24 1:53 ` Mike Frysinger
2010-09-24 4:35 ` Jon Povey
` (2 more replies)
2010-09-25 10:50 ` [PATCH 1/4] libmtd: add lock/unlock helpers Artem Bityutskiy
3 siblings, 3 replies; 30+ messages in thread
From: Mike Frysinger @ 2010-09-24 1:53 UTC (permalink / raw)
To: linux-mtd
These have overlapping functionality, and while flash_eraseall supports
newer 64bit ioctls, flash_erase does not. So rather than graft support
onto flash_erase, merge the functionality of two into flash_erase so we
only have to support one util from now on.
A simple wrapper is provided to ease old flash_eraseall users into the
new combined flash_erase util.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
.gitignore | 1 -
Makefile | 2 +-
flash_erase.c | 418 ++++++++++++++++++++++++++++++++++--------------------
flash_eraseall | 4 +
flash_eraseall.c | 276 -----------------------------------
5 files changed, 266 insertions(+), 435 deletions(-)
create mode 100755 flash_eraseall
delete mode 100644 flash_eraseall.c
diff --git a/.gitignore b/.gitignore
index defbd57..2dbf198 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,7 +20,6 @@
/doc_loadbios
/docfdisk
/flash_erase
-/flash_eraseall
/flash_info
/flash_lock
/flash_otp_dump
diff --git a/Makefile b/Makefile
index d315f39..6151fb2 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ endif
SUBDIRS = lib ubi-utils mkfs.ubifs
-TARGETS = ftl_format flash_erase flash_eraseall nanddump doc_loadbios \
+TARGETS = ftl_format flash_erase nanddump doc_loadbios \
ftl_check mkfs.jffs2 flash_lock flash_unlock flash_info \
flash_otp_info flash_otp_dump mtd_debug flashcp nandwrite nandtest \
jffs2dump \
diff --git a/flash_erase.c b/flash_erase.c
index fdf9918..2467fff 100644
--- a/flash_erase.c
+++ b/flash_erase.c
@@ -1,189 +1,293 @@
-/*
- * flash_erase.c -- erase parts of a MTD device
- */
+/* flash_erase.c -- erase MTD devices
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <time.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <sys/mount.h>
-#include <mtd/mtd-user.h>
+ Copyright (C) 2000 Arcom Control System Ltd
+ Copyright (C) 2010 Mike Frysinger <vapier@gentoo.org>
-int region_erase(int Fd, int start, int count, int unlock, int regcount)
-{
- int i, j;
- region_info_t * reginfo;
-
- reginfo = calloc(regcount, sizeof(region_info_t));
-
- for(i = 0; i < regcount; i++)
- {
- reginfo[i].regionindex = i;
- if(ioctl(Fd,MEMGETREGIONINFO,&(reginfo[i])) != 0)
- return 8;
- else
- printf("Region %d is at %d of %d sector and with sector "
- "size %x\n", i, reginfo[i].offset, reginfo[i].numblocks,
- reginfo[i].erasesize);
- }
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
- // We have all the information about the chip we need.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- for(i = 0; i < regcount; i++)
- { //Loop through the regions
- region_info_t * r = &(reginfo[i]);
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
- if((start >= reginfo[i].offset) &&
- (start < (r->offset + r->numblocks*r->erasesize)))
- break;
- }
+#define PROGRAM_NAME "flash_erase"
+#define VERSION "2"
- if(i >= regcount)
- {
- printf("Starting offset %x not within chip.\n", start);
- return 8;
- }
+#include <inttypes.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <stdint.h>
+#include <getopt.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
- //We are now positioned within region i of the chip, so start erasing
- //count sectors from there.
+#include <common.h>
+#include <strtox.h>
+#include <crc32.h>
+#include <libmtd.h>
- for(j = 0; (j < count)&&(i < regcount); j++)
- {
- erase_info_t erase;
- region_info_t * r = &(reginfo[i]);
+#include <mtd/mtd-user.h>
+#include <mtd/jffs2-user.h>
- erase.start = start;
- erase.length = r->erasesize;
+static const char *mtd_device;
- if(unlock != 0)
- { //Unlock the sector first.
- if(ioctl(Fd, MEMUNLOCK, &erase) != 0)
- {
- perror("\nMTD Unlock failure");
- close(Fd);
- return 8;
- }
- }
- printf("\rPerforming Flash Erase of length %u at offset 0x%x",
- erase.length, erase.start);
- fflush(stdout);
- if(ioctl(Fd, MEMERASE, &erase) != 0)
- {
- perror("\nMTD Erase failure");
- close(Fd);
- return 8;
- }
+static int quiet; /* true -- don't output progress */
+static int jffs2; /* format for jffs2 usage */
+static int noskipbad; /* do not skip bad blocks */
+static int unlock; /* unlock sectors before erasing */
+static struct jffs2_unknown_node cleanmarker;
+int target_endian = __BYTE_ORDER;
- start += erase.length;
- if(start >= (r->offset + r->numblocks*r->erasesize))
- { //We finished region i so move to region i+1
- printf("\nMoving to region %d\n", i+1);
- i++;
- }
- }
+static void show_progress(struct mtd_dev_info *mtd, uint64_t start, int eb,
+ int eb_start, int eb_cnt)
+{
+ bareverbose(!quiet, "\rErasing %d Kibyte @ %"PRIx64" -- %2i %% complete ",
+ mtd->eb_size / 1024, start, ((eb - eb_start) * 100) / eb_cnt);
+ fflush(stdout);
+}
- printf(" done\n");
+static void display_help (void)
+{
+ printf("Usage: %s [options] MTD_DEVICE <start block> <block count>\n"
+ "Erase blocks of the specified MTD device.\n"
+ "Specify a count of 0 to erase to end of device.\n"
+ "\n"
+ " -j, --jffs2 format the device for jffs2\n"
+ " -N, --noskipbad don't skip bad blocks\n"
+ " -u, --unlock unlock sectors before erasing\n"
+ " -q, --quiet display progress messages\n"
+ " --silent same as --quiet\n"
+ " --help display this help and exit\n"
+ " --version output version information and exit\n",
+ PROGRAM_NAME);
+}
- return 0;
+static void display_version (void)
+{
+ printf(PROGRAM_NAME " version " VERSION "\n"
+ "\n"
+ "Copyright (C) 2000 Arcom Control Systems Ltd\n"
+ "\n"
+ PROGRAM_NAME " comes with NO WARRANTY\n"
+ "to the extent permitted by law.\n"
+ "\n"
+ "You may redistribute copies of " PROGRAM_NAME "\n"
+ "under the terms of the GNU General Public Licence.\n"
+ "See the file `COPYING' for more information.\n");
}
-int non_region_erase(int Fd, int start, int count, int unlock)
+int main(int argc, char *argv[])
{
- mtd_info_t meminfo;
-
- if (ioctl(Fd,MEMGETINFO,&meminfo) == 0)
- {
- erase_info_t erase;
-
- erase.start = start;
-
- erase.length = meminfo.erasesize;
-
- for (; count > 0; count--) {
- printf("\rPerforming Flash Erase of length %u at offset 0x%x",
- erase.length, erase.start);
- fflush(stdout);
-
- if(unlock != 0)
- {
- //Unlock the sector first.
- printf("\rPerforming Flash unlock at offset 0x%x",erase.start);
- if(ioctl(Fd, MEMUNLOCK, &erase) != 0)
- {
- perror("\nMTD Unlock failure");
- close(Fd);
- return 8;
- }
- }
+ libmtd_t mtd_desc;
+ struct mtd_dev_info mtd;
+ int fd, clmpos = 0, clmlen = 8, eb, eb_start, eb_cnt;
+ int isNAND;
+ int error = 0;
+ uint64_t offset = 0;
+
+ /*
+ * Process user arguments
+ */
+ for (;;) {
+ int option_index = 0;
+ static const char *short_options = "jNqu";
+ static const struct option long_options[] = {
+ {"help", no_argument, 0, 0},
+ {"version", no_argument, 0, 0},
+ {"jffs2", no_argument, 0, 'j'},
+ {"noskipbad", no_argument, 0, 'N'},
+ {"quiet", no_argument, 0, 'q'},
+ {"silent", no_argument, 0, 'q'},
+ {"unlock", no_argument, 0, 'u'},
+
+ {0, 0, 0, 0},
+ };
+
+ int c = getopt_long(argc, argv, short_options,
+ long_options, &option_index);
+ if (c == EOF)
+ break;
- if (ioctl(Fd,MEMERASE,&erase) != 0)
- {
- perror("\nMTD Erase failure");
- close(Fd);
- return 8;
+ switch (c) {
+ case 0:
+ switch (option_index) {
+ case 0:
+ display_help();
+ return 0;
+ case 1:
+ display_version();
+ return 0;
}
- erase.start += meminfo.erasesize;
+ break;
+ case 'j':
+ jffs2 = 1;
+ break;
+ case 'N':
+ noskipbad = 1;
+ break;
+ case 'q':
+ quiet = 1;
+ break;
+ case 'u':
+ unlock = 1;
+ break;
+ case '?':
+ error = 1;
+ break;
}
- printf(" done\n");
}
- return 0;
-}
-
-int main(int argc,char *argv[])
-{
- int regcount;
- int Fd;
- int start;
- int count;
- int unlock;
- int res = 0;
-
- if (1 >= argc || !strcmp(argv[1], "-h") || !strcmp (argv[1], "--help") ) {
- printf("Usage: flash_erase MTD-device [start] [cnt (# erase blocks)] [lock]\n"
- " flash_erase -h | --help\n") ;
- return 16 ;
+ switch (argc - optind) {
+ case 3:
+ mtd_device = argv[optind];
+ eb_start = simple_strtoul(argv[optind + 1], &error);
+ eb_cnt = simple_strtoul(argv[optind + 2], &error);
+ break;
+ default:
+ case 0:
+ errmsg("no MTD device specified");
+ case 1:
+ errmsg("no start erase block specified");
+ case 2:
+ errmsg("no erase block count specified");
+ error = 1;
+ break;
+ }
+ if (error)
+ return errmsg("Try `--help' for more information");
+
+ /*
+ * Locate MTD and prepare for erasure
+ */
+ mtd_desc = libmtd_open();
+ if (mtd_desc == NULL)
+ return errmsg("can't initialize libmtd");
+
+ if ((fd = open(mtd_device, O_RDWR)) < 0)
+ return sys_errmsg("%s", mtd_device);
+
+ if (mtd_get_dev_info(mtd_desc, mtd_device, &mtd) < 0)
+ return errmsg("mtd_get_dev_info failed");
+
+ isNAND = mtd.type == MTD_NANDFLASH ? 1 : 0;
+
+ if (jffs2) {
+ cleanmarker.magic = cpu_to_je16 (JFFS2_MAGIC_BITMASK);
+ cleanmarker.nodetype = cpu_to_je16 (JFFS2_NODETYPE_CLEANMARKER);
+ if (!isNAND)
+ cleanmarker.totlen = cpu_to_je32(sizeof(cleanmarker));
+ else {
+ struct nand_oobinfo oobinfo;
+
+ if (ioctl(fd, MEMGETOOBSEL, &oobinfo) != 0)
+ return sys_errmsg("%s: unable to get NAND oobinfo", mtd_device);
+
+ /* Check for autoplacement */
+ if (oobinfo.useecc == MTD_NANDECC_AUTOPLACE) {
+ /* Get the position of the free bytes */
+ if (!oobinfo.oobfree[0][1])
+ return errmsg(" Eeep. Autoplacement selected and no empty space in oob");
+ clmpos = oobinfo.oobfree[0][0];
+ clmlen = oobinfo.oobfree[0][1];
+ if (clmlen > 8)
+ clmlen = 8;
+ } else {
+ /* Legacy mode */
+ switch (mtd.oob_size) {
+ case 8:
+ clmpos = 6;
+ clmlen = 2;
+ break;
+ case 16:
+ clmpos = 8;
+ clmlen = 8;
+ break;
+ case 64:
+ clmpos = 16;
+ clmlen = 8;
+ break;
+ }
+ }
+ cleanmarker.totlen = cpu_to_je32(8);
+ }
+ cleanmarker.hdr_crc = cpu_to_je32(mtd_crc32(0, &cleanmarker, sizeof(cleanmarker) - 4));
}
- if (argc > 2)
- start = strtol(argv[2], NULL, 0);
- else
- start = 0;
-
- if (argc > 3)
- count = strtol(argv[3], NULL, 0);
- else
- count = 1;
+ /*
+ * Now do the actual erasing of the MTD device
+ */
+ if (eb_cnt == 0)
+ eb_cnt = (mtd.size / mtd.eb_size) - eb_start;
+
+ for (eb = eb_start; eb < eb_start + eb_cnt; eb++) {
+ offset = eb * mtd.eb_size;
+
+ if (!noskipbad) {
+ int ret = mtd_is_bad(&mtd, fd, eb);
+ if (ret > 0) {
+ verbose(!quiet, "Skipping bad block at %08"PRIx64, offset);
+ continue;
+ } else if (ret < 0) {
+ if (errno == EOPNOTSUPP) {
+ noskipbad = 1;
+ if (isNAND)
+ return errmsg("%s: Bad block check not available", mtd_device);
+ } else
+ return sys_errmsg("%s: MTD get bad block failed", mtd_device);
+ }
+ }
- if(argc > 4)
- unlock = strtol(argv[4], NULL, 0);
- else
- unlock = 0;
+ show_progress(&mtd, offset, eb, eb_start, eb_cnt);
+ if (unlock) {
+ if (mtd_unlock(&mtd, fd, eb) != 0) {
+ sys_errmsg("%s: MTD unlock failure", mtd_device);
+ continue;
+ }
+ }
- // Open and size the device
- if ((Fd = open(argv[1],O_RDWR)) < 0)
- {
- fprintf(stderr,"File open error\n");
- return 8;
- }
+ if (mtd_erase(mtd_desc, &mtd, fd, eb) != 0) {
+ sys_errmsg("%s: MTD Erase failure", mtd_device);
+ continue;
+ }
- printf("Erase Total %d Units\n", count);
+ /* format for JFFS2 ? */
+ if (!jffs2)
+ continue;
- if (ioctl(Fd,MEMGETREGIONCOUNT,®count) == 0)
- {
- if(regcount == 0)
- {
- res = non_region_erase(Fd, start, count, unlock);
- }
- else
- {
- res = region_erase(Fd, start, count, unlock, regcount);
+ /* write cleanmarker */
+ if (isNAND) {
+ if (mtd_write_oob(mtd_desc, &mtd, fd, offset + clmpos, clmlen, &cleanmarker) != 0) {
+ sys_errmsg("%s: MTD writeoob failure", mtd_device);
+ continue;
+ }
+ } else {
+ if (lseek(fd, (loff_t)offset, SEEK_SET) < 0) {
+ sys_errmsg("%s: MTD lseek failure", mtd_device);
+ continue;
+ }
+ if (write(fd, &cleanmarker, sizeof(cleanmarker)) != sizeof(cleanmarker)) {
+ sys_errmsg("%s: MTD write failure", mtd_device);
+ continue;
+ }
}
+ verbose(!quiet, " Cleanmarker written at %"PRIx64, offset);
}
+ offset += mtd.eb_size;
+ show_progress(&mtd, offset, eb, eb_start, eb_cnt);
+ bareverbose(!quiet, "\n");
- return res;
+ return 0;
}
diff --git a/flash_eraseall b/flash_eraseall
new file mode 100755
index 0000000..c5539b3
--- /dev/null
+++ b/flash_eraseall
@@ -0,0 +1,4 @@
+#!/bin/sh
+echo "${0##*/} has been replaced by \`flash_erase <mtddev> 0 0\`; please use it" 1>&2
+[ $# -ne 0 ] && set -- "$@" 0 0
+exec flash_erase "$@"
diff --git a/flash_eraseall.c b/flash_eraseall.c
deleted file mode 100644
index cb6f632..0000000
--- a/flash_eraseall.c
+++ /dev/null
@@ -1,276 +0,0 @@
-/* eraseall.c -- erase the whole of a MTD device
-
- Copyright (C) 2000 Arcom Control System Ltd
-
- Renamed to flash_eraseall.c
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-#include <sys/types.h>
-#include <stdio.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <stdarg.h>
-#include <stdint.h>
-#include <libgen.h>
-#include <ctype.h>
-#include <time.h>
-#include <getopt.h>
-#include <sys/ioctl.h>
-#include <sys/mount.h>
-#include <crc32.h>
-#include <libmtd.h>
-
-#include <mtd/mtd-user.h>
-#include <mtd/jffs2-user.h>
-
-#define PROGRAM "flash_eraseall"
-#define VERSION "$Revision: 1.22 $"
-
-static const char *exe_name;
-static const char *mtd_device;
-static int quiet; /* true -- don't output progress */
-static int jffs2; /* format for jffs2 usage */
-
-static struct jffs2_unknown_node cleanmarker;
-int target_endian = __BYTE_ORDER;
-
-static void show_progress (struct mtd_dev_info *mtd, uint64_t start)
-{
- printf("\rErasing %d Kibyte @ %llx -- %2llu %% complete.",
- mtd->eb_size / 1024, (unsigned long long)start,
- (unsigned long long) start * 100 / mtd->size);
- fflush(stdout);
-}
-
-static void display_help (void)
-{
- printf("Usage: %s [OPTION] MTD_DEVICE\n"
- "Erases all of the specified MTD device.\n"
- "\n"
- " -j, --jffs2 format the device for jffs2\n"
- " -q, --quiet don't display progress messages\n"
- " --silent same as --quiet\n"
- " --help display this help and exit\n"
- " --version output version information and exit\n",
- exe_name);
-}
-
-
-static void display_version (void)
-{
- printf(PROGRAM " " VERSION "\n"
- "\n"
- "Copyright (C) 2000 Arcom Control Systems Ltd\n"
- "\n"
- PROGRAM " comes with NO WARRANTY\n"
- "to the extent permitted by law.\n"
- "\n"
- "You may redistribute copies of " PROGRAM "\n"
- "under the terms of the GNU General Public Licence.\n"
- "See the file `COPYING' for more information.\n");
-}
-
-int main (int argc, char *argv[])
-{
- libmtd_t mtd_desc;
- struct mtd_dev_info mtd;
- int fd, clmpos = 0, clmlen = 8, eb;
- int isNAND, bbtest = 1;
- int error = 0;
- uint64_t offset = 0;
-
- exe_name = argv[0];
- for (;;) {
- int option_index = 0;
- static const char *short_options = "jq";
- static const struct option long_options[] = {
- {"help", no_argument, 0, 0},
- {"version", no_argument, 0, 0},
- {"jffs2", no_argument, 0, 'j'},
- {"quiet", no_argument, 0, 'q'},
- {"silent", no_argument, 0, 'q'},
-
- {0, 0, 0, 0},
- };
-
- int c = getopt_long(argc, argv, short_options,
- long_options, &option_index);
- if (c == EOF)
- break;
-
- switch (c) {
- case 0:
- switch (option_index) {
- case 0:
- display_help();
- return 0;
- case 1:
- display_version();
- return 0;
- }
- break;
- case 'q':
- quiet = 1;
- break;
- case 'j':
- jffs2 = 1;
- break;
- case '?':
- error = 1;
- break;
- }
- }
- if (optind == argc) {
- fprintf(stderr, "%s: no MTD device specified\n", exe_name);
- error = 1;
- }
- if (error) {
- fprintf(stderr, "Try `%s --help' for more information.\n",
- exe_name);
- return 1;
- }
- mtd_device = argv[optind];
-
- mtd_desc = libmtd_open();
- if (mtd_desc == NULL) {
- fprintf(stderr, "%s: can't initialize libmtd\n", exe_name);
- return 1;
- }
-
- if ((fd = open(mtd_device, O_RDWR)) < 0) {
- fprintf(stderr, "%s: %s: %s\n", exe_name, mtd_device, strerror(errno));
- return 1;
- }
-
- if (mtd_get_dev_info(mtd_desc, mtd_device, &mtd) < 0) {
- fprintf(stderr, "%s: mtd_get_dev_info failed\n", exe_name);
- return 1;
- }
-
- isNAND = mtd.type == MTD_NANDFLASH ? 1 : 0;
-
- if (jffs2) {
- cleanmarker.magic = cpu_to_je16 (JFFS2_MAGIC_BITMASK);
- cleanmarker.nodetype = cpu_to_je16 (JFFS2_NODETYPE_CLEANMARKER);
- if (!isNAND)
- cleanmarker.totlen = cpu_to_je32 (sizeof (struct jffs2_unknown_node));
- else {
- struct nand_oobinfo oobinfo;
-
- if (ioctl(fd, MEMGETOOBSEL, &oobinfo) != 0) {
- fprintf(stderr, "%s: %s: unable to get NAND oobinfo\n", exe_name, mtd_device);
- return 1;
- }
-
- /* Check for autoplacement */
- if (oobinfo.useecc == MTD_NANDECC_AUTOPLACE) {
- /* Get the position of the free bytes */
- if (!oobinfo.oobfree[0][1]) {
- fprintf (stderr, " Eeep. Autoplacement selected and no empty space in oob\n");
- return 1;
- }
- clmpos = oobinfo.oobfree[0][0];
- clmlen = oobinfo.oobfree[0][1];
- if (clmlen > 8)
- clmlen = 8;
- } else {
- /* Legacy mode */
- switch (mtd.oob_size) {
- case 8:
- clmpos = 6;
- clmlen = 2;
- break;
- case 16:
- clmpos = 8;
- clmlen = 8;
- break;
- case 64:
- clmpos = 16;
- clmlen = 8;
- break;
- }
- }
- cleanmarker.totlen = cpu_to_je32(8);
- }
- cleanmarker.hdr_crc = cpu_to_je32 (mtd_crc32 (0, &cleanmarker, sizeof (struct jffs2_unknown_node) - 4));
- }
-
- for (eb = 0; eb < (mtd.size / mtd.eb_size); eb++) {
- offset = eb * mtd.eb_size;
- if (bbtest) {
- int ret = mtd_is_bad(&mtd, fd, eb);
- if (ret > 0) {
- if (!quiet)
- printf ("\nSkipping bad block at 0x%08llx\n", (unsigned long long)offset);
- continue;
- } else if (ret < 0) {
- if (errno == EOPNOTSUPP) {
- bbtest = 0;
- if (isNAND) {
- fprintf(stderr, "%s: %s: Bad block check not available\n", exe_name, mtd_device);
- return 1;
- }
- } else {
- fprintf(stderr, "\n%s: %s: MTD get bad block failed: %s\n", exe_name, mtd_device, strerror(errno));
- return 1;
- }
- }
- }
-
- if (!quiet)
- show_progress(&mtd, offset);
-
- if (mtd_erase(mtd_desc, &mtd, fd, eb) != 0) {
- fprintf(stderr, "\n%s: %s: MTD Erase failure: %s\n", exe_name, mtd_device, strerror(errno));
- continue;
- }
-
- /* format for JFFS2 ? */
- if (!jffs2)
- continue;
-
- /* write cleanmarker */
- if (isNAND) {
- if (mtd_write_oob(mtd_desc, &mtd, fd, offset + clmpos, clmlen, &cleanmarker) != 0) {
- fprintf(stderr, "\n%s: %s: MTD writeoob failure: %s\n", exe_name, mtd_device, strerror(errno));
- continue;
- }
- } else {
- if (lseek (fd, (loff_t)offset, SEEK_SET) < 0) {
- fprintf(stderr, "\n%s: %s: MTD lseek failure: %s\n", exe_name, mtd_device, strerror(errno));
- continue;
- }
- if (write (fd , &cleanmarker, sizeof (cleanmarker)) != sizeof (cleanmarker)) {
- fprintf(stderr, "\n%s: %s: MTD write failure: %s\n", exe_name, mtd_device, strerror(errno));
- continue;
- }
- }
- if (!quiet)
- printf (" Cleanmarker written at %llx.", (unsigned long long)offset);
- }
- if (!quiet) {
- show_progress(&mtd, offset);
- printf("\n");
- }
-
- return 0;
-}
-
--
1.7.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* RE: [PATCH 2/4] mtd-utils: new bareverbose() helper
2010-09-24 1:53 ` [PATCH 2/4] mtd-utils: new bareverbose() helper Mike Frysinger
@ 2010-09-24 4:24 ` Jon Povey
2010-09-25 6:05 ` [PATCH 2/4 v2] " Mike Frysinger
1 sibling, 0 replies; 30+ messages in thread
From: Jon Povey @ 2010-09-24 4:24 UTC (permalink / raw)
To: Mike Frysinger, linux-mtd@lists.infradead.org
linux-mtd-bounces@lists.infradead.org wrote:
> Add a new helper that let's people do simple verbose output
Punctuation nit: "lets"
--
Jon Povey
jon.povey@racelogic.co.uk
Racelogic is a limited company registered in England. Registered number 2743719 .
Registered Office Unit 10, Swan Business Centre, Osier Way, Buckingham, Bucks, MK18 1TB .
The information contained in this electronic mail transmission is intended by Racelogic Ltd for the use of the named individual or entity to which it is directed and may contain information that is confidential or privileged. If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email so that the sender's address records can be corrected. The views expressed by the sender of this communication do not necessarily represent those of Racelogic Ltd. Please note that Racelogic reserves the right to monitor e-mail communications passing through its network
^ permalink raw reply [flat|nested] 30+ messages in thread
* RE: [PATCH 3/4] mtd-utils: new strtoX helpers
2010-09-24 1:53 ` [PATCH 3/4] mtd-utils: new strtoX helpers Mike Frysinger
@ 2010-09-24 4:31 ` Jon Povey
2010-09-24 5:35 ` Mike Frysinger
2010-09-25 6:06 ` [PATCH 3/4 v2] " Mike Frysinger
1 sibling, 1 reply; 30+ messages in thread
From: Jon Povey @ 2010-09-24 4:31 UTC (permalink / raw)
To: Mike Frysinger, linux-mtd@lists.infradead.org
linux-mtd-bounces@lists.infradead.org wrote:
> Simply usage of converting strings to numbers by adding some wrappers
> around the standard strtoX functions. These helpers support both hex
> and dec numbers transparently, and the caller need only provide a ptr
> to an error integer if they want to be notified of problems.
> + */ +#define simple_strtoX(func, type) \
> +static inline type simple_##func(const char *snum, int *error) \ +{ \
Why inline? won't this bloat code, better to remove inline?
> + if (snum[0] == '0' && snum[1] == 'x') \
> + ret = func(snum, &endptr, 16); \
> + else \
> + ret = func(snum, &endptr, 10); \
Can just call strtol etc. with 0 instead of 10 or 16, it will autodetect
0xnnn as base 16.
--
Jon Povey
jon.povey@racelogic.co.uk
Racelogic is a limited company registered in England. Registered number 2743719 .
Registered Office Unit 10, Swan Business Centre, Osier Way, Buckingham, Bucks, MK18 1TB .
The information contained in this electronic mail transmission is intended by Racelogic Ltd for the use of the named individual or entity to which it is directed and may contain information that is confidential or privileged. If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email so that the sender's address records can be corrected. The views expressed by the sender of this communication do not necessarily represent those of Racelogic Ltd. Please note that Racelogic reserves the right to monitor e-mail communications passing through its network
^ permalink raw reply [flat|nested] 30+ messages in thread
* RE: [PATCH 4/4] mtd-utils: unify flash_erase and flash_eraseall
2010-09-24 1:53 ` [PATCH 4/4] mtd-utils: unify flash_erase and flash_eraseall Mike Frysinger
@ 2010-09-24 4:35 ` Jon Povey
2010-09-24 5:36 ` Mike Frysinger
2010-09-25 6:07 ` [PATCH 4/4 v2] " Mike Frysinger
2010-09-28 9:46 ` [PATCH 4/4] " Artem Bityutskiy
2 siblings, 1 reply; 30+ messages in thread
From: Jon Povey @ 2010-09-24 4:35 UTC (permalink / raw)
To: Mike Frysinger, linux-mtd@lists.infradead.org
linux-mtd-bounces@lists.infradead.org wrote:
> These have overlapping functionality, and while
> flash_eraseall supports
> newer 64bit ioctls, flash_erase does not. So rather than
> graft support
> onto flash_erase, merge the functionality of two into
> flash_erase so we
> only have to support one util from now on.
>
> A simple wrapper is provided to ease old flash_eraseall users into the
> new combined flash_erase util.
> -TARGETS = ftl_format flash_erase flash_eraseall nanddump
> doc_loadbios \ +TARGETS = ftl_format flash_erase nanddump
> doc_loadbios \ ftl_check mkfs.jffs2 flash_lock flash_unlock
> flash_info \ flash_otp_info flash_otp_dump mtd_debug flashcp
> nandwrite nandtest \
> jffs2dump \
Wow, my mailer really mangles patches.
But anyway; will the flash_eraseall script still get installed by
make install? it needs to.
--
Jon Povey
jon.povey@racelogic.co.uk
Racelogic is a limited company registered in England. Registered number 2743719 .
Registered Office Unit 10, Swan Business Centre, Osier Way, Buckingham, Bucks, MK18 1TB .
The information contained in this electronic mail transmission is intended by Racelogic Ltd for the use of the named individual or entity to which it is directed and may contain information that is confidential or privileged. If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email so that the sender's address records can be corrected. The views expressed by the sender of this communication do not necessarily represent those of Racelogic Ltd. Please note that Racelogic reserves the right to monitor e-mail communications passing through its network
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 3/4] mtd-utils: new strtoX helpers
2010-09-24 4:31 ` Jon Povey
@ 2010-09-24 5:35 ` Mike Frysinger
2010-09-24 6:13 ` Jon Povey
0 siblings, 1 reply; 30+ messages in thread
From: Mike Frysinger @ 2010-09-24 5:35 UTC (permalink / raw)
To: Jon Povey; +Cc: linux-mtd@lists.infradead.org
On Fri, Sep 24, 2010 at 00:31, Jon Povey wrote:
> linux-mtd-bounces@lists.infradead.org wrote:
>> Simply usage of converting strings to numbers by adding some wrappers
>> around the standard strtoX functions. These helpers support both hex
>> and dec numbers transparently, and the caller need only provide a ptr
>> to an error integer if they want to be notified of problems.
>
>> + */ +#define simple_strtoX(func, type) \
>> +static inline type simple_##func(const char *snum, int *error) \ +{ \
>
> Why inline? won't this bloat code, better to remove inline?
because uninlined static definitions will generate unused warnings
>> + if (snum[0] == '0' && snum[1] == 'x') \
>> + ret = func(snum, &endptr, 16); \
>> + else \
>> + ret = func(snum, &endptr, 10); \
>
> Can just call strtol etc. with 0 instead of 10 or 16, it will autodetect
> 0xnnn as base 16.
true ... i'll fix that up
-mike
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 4/4] mtd-utils: unify flash_erase and flash_eraseall
2010-09-24 4:35 ` Jon Povey
@ 2010-09-24 5:36 ` Mike Frysinger
2010-09-24 5:42 ` Jon Povey
0 siblings, 1 reply; 30+ messages in thread
From: Mike Frysinger @ 2010-09-24 5:36 UTC (permalink / raw)
To: Jon Povey; +Cc: linux-mtd@lists.infradead.org
On Fri, Sep 24, 2010 at 00:35, Jon Povey wrote:
> linux-mtd-bounces@lists.infradead.org wrote:
>> These have overlapping functionality, and while
>> flash_eraseall supports
>> newer 64bit ioctls, flash_erase does not. So rather than
>> graft support
>> onto flash_erase, merge the functionality of two into
>> flash_erase so we
>> only have to support one util from now on.
>>
>> A simple wrapper is provided to ease old flash_eraseall users into the
>> new combined flash_erase util.
>
>> -TARGETS = ftl_format flash_erase flash_eraseall nanddump
>> doc_loadbios \ +TARGETS = ftl_format flash_erase nanddump
>> doc_loadbios \ ftl_check mkfs.jffs2 flash_lock flash_unlock
>> flash_info \ flash_otp_info flash_otp_dump mtd_debug flashcp
>> nandwrite nandtest \
>> jffs2dump \
>
> But anyway; will the flash_eraseall script still get installed by
> make install? it needs to.
it will not, but i didnt think that to be too much of a problem.
people usually dont use `make install` for their embedded system ...
they pluck out the one or two utils they actually need.
-mike
^ permalink raw reply [flat|nested] 30+ messages in thread
* RE: [PATCH 4/4] mtd-utils: unify flash_erase and flash_eraseall
2010-09-24 5:36 ` Mike Frysinger
@ 2010-09-24 5:42 ` Jon Povey
2010-09-24 12:42 ` Mike Frysinger
0 siblings, 1 reply; 30+ messages in thread
From: Jon Povey @ 2010-09-24 5:42 UTC (permalink / raw)
To: Mike Frysinger; +Cc: linux-mtd@lists.infradead.org
Mike Frysinger wrote:
> On Fri, Sep 24, 2010 at 00:35, Jon Povey wrote:
>> But anyway; will the flash_eraseall script still get installed by
>> make install? it needs to.
>
> it will not, but i didnt think that to be too much of a problem.
> people usually dont use `make install` for their embedded system ...
> they pluck out the one or two utils they actually need.
"I suppose" is not much of an argument for breaking make install.
It can be made to work.. I could do this but don't have time right now.
--
Jon Povey
jon.povey@racelogic.co.uk
Racelogic is a limited company registered in England. Registered number 2743719 .
Registered Office Unit 10, Swan Business Centre, Osier Way, Buckingham, Bucks, MK18 1TB .
The information contained in this electronic mail transmission is intended by Racelogic Ltd for the use of the named individual or entity to which it is directed and may contain information that is confidential or privileged. If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email so that the sender's address records can be corrected. The views expressed by the sender of this communication do not necessarily represent those of Racelogic Ltd. Please note that Racelogic reserves the right to monitor e-mail communications passing through its network
^ permalink raw reply [flat|nested] 30+ messages in thread
* RE: [PATCH 3/4] mtd-utils: new strtoX helpers
2010-09-24 5:35 ` Mike Frysinger
@ 2010-09-24 6:13 ` Jon Povey
2010-09-24 12:34 ` Mike Frysinger
0 siblings, 1 reply; 30+ messages in thread
From: Jon Povey @ 2010-09-24 6:13 UTC (permalink / raw)
To: Mike Frysinger; +Cc: linux-mtd@lists.infradead.org
Mike Frysinger wrote:
> On Fri, Sep 24, 2010 at 00:31, Jon Povey wrote:
>> linux-mtd-bounces@lists.infradead.org wrote:
>>> Simply usage of converting strings to numbers by adding some
>>> wrappers around the standard strtoX functions. These helpers
>>> support both hex and dec numbers transparently, and the caller need
>>> only provide a ptr to an error integer if they want to be notified
>>> of problems.
>>
>>> + */ +#define simple_strtoX(func, type) \
>>> +static inline type simple_##func(const char *snum, int *error) \
>>> +{ \
>>
>> Why inline? won't this bloat code, better to remove inline?
>
> because uninlined static definitions will generate unused warnings
you could do
__attribute__((unused)) static type simple_##func(...
I assume the compiler will still optimise them away, not sure.
but with the 0xnn handling going away, does this header now offer
much over just calling strtol et al directly?
I'd argue it just adds complexity and maintainence hassle.
--
Jon Povey
jon.povey@racelogic.co.uk
Racelogic is a limited company registered in England. Registered number 2743719 .
Registered Office Unit 10, Swan Business Centre, Osier Way, Buckingham, Bucks, MK18 1TB .
The information contained in this electronic mail transmission is intended by Racelogic Ltd for the use of the named individual or entity to which it is directed and may contain information that is confidential or privileged. If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email so that the sender's address records can be corrected. The views expressed by the sender of this communication do not necessarily represent those of Racelogic Ltd. Please note that Racelogic reserves the right to monitor e-mail communications passing through its network
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 3/4] mtd-utils: new strtoX helpers
2010-09-24 6:13 ` Jon Povey
@ 2010-09-24 12:34 ` Mike Frysinger
0 siblings, 0 replies; 30+ messages in thread
From: Mike Frysinger @ 2010-09-24 12:34 UTC (permalink / raw)
To: Jon Povey; +Cc: linux-mtd@lists.infradead.org
On Fri, Sep 24, 2010 at 02:13, Jon Povey wrote:
> Mike Frysinger wrote:
>> On Fri, Sep 24, 2010 at 00:31, Jon Povey wrote:
>>> linux-mtd-bounces@lists.infradead.org wrote:
>>>> Simply usage of converting strings to numbers by adding some
>>>> wrappers around the standard strtoX functions. These helpers
>>>> support both hex and dec numbers transparently, and the caller need
>>>> only provide a ptr to an error integer if they want to be notified
>>>> of problems.
>>>
>>>> + */ +#define simple_strtoX(func, type) \
>>>> +static inline type simple_##func(const char *snum, int *error) \
>>>> +{ \
>>>
>>> Why inline? won't this bloat code, better to remove inline?
>>
>> because uninlined static definitions will generate unused warnings
>
> you could do
> __attribute__((unused)) static type simple_##func(...
>
> I assume the compiler will still optimise them away, not sure.
>
> but with the 0xnn handling going away, does this header now offer
> much over just calling strtol et al directly?
that depends on whether you're comfortable breaking out your own
endptr and knowing the exact semantics
-mike
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 4/4] mtd-utils: unify flash_erase and flash_eraseall
2010-09-24 5:42 ` Jon Povey
@ 2010-09-24 12:42 ` Mike Frysinger
0 siblings, 0 replies; 30+ messages in thread
From: Mike Frysinger @ 2010-09-24 12:42 UTC (permalink / raw)
To: Jon Povey; +Cc: linux-mtd@lists.infradead.org
On Fri, Sep 24, 2010 at 01:42, Jon Povey wrote:
> Mike Frysinger wrote:
>> On Fri, Sep 24, 2010 at 00:35, Jon Povey wrote:
>>> But anyway; will the flash_eraseall script still get installed by
>>> make install? it needs to.
>>
>> it will not, but i didnt think that to be too much of a problem.
>> people usually dont use `make install` for their embedded system ...
>> they pluck out the one or two utils they actually need.
>
> "I suppose" is not much of an argument for breaking make install.
> It can be made to work.. I could do this but don't have time right now.
you call it "breakage", i call it "intended behavior"
it's trivial to make it work as a one off:
+install: TARGETS += flash_eraseall
-mike
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH 2/4 v2] mtd-utils: new bareverbose() helper
2010-09-24 1:53 ` [PATCH 2/4] mtd-utils: new bareverbose() helper Mike Frysinger
2010-09-24 4:24 ` Jon Povey
@ 2010-09-25 6:05 ` Mike Frysinger
2010-09-25 10:52 ` Artem Bityutskiy
1 sibling, 1 reply; 30+ messages in thread
From: Mike Frysinger @ 2010-09-25 6:05 UTC (permalink / raw)
To: linux-mtd
Add a new helper that lets people do simple verbose output without any
implicit strings added around it. Good for progress bars and such.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
v2
- fix typo in changelog
include/common.h | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/include/common.h b/include/common.h
index e87b215..11b0cf6 100644
--- a/include/common.h
+++ b/include/common.h
@@ -38,10 +38,12 @@ extern "C" {
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
/* Verbose messages */
-#define verbose(verbose, fmt, ...) do { \
+#define bareverbose(verbose, fmt, ...) do { \
if (verbose) \
- printf(PROGRAM_NAME ": " fmt "\n", ##__VA_ARGS__); \
+ printf(fmt, ##__VA_ARGS__); \
} while(0)
+#define verbose(verbose, fmt, ...) \
+ bareverbose(verbose, PROGRAM_NAME ": " fmt "\n", ##__VA_ARGS__)
/* Normal messages */
#define normsg(fmt, ...) do { \
--
1.7.2.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 3/4 v2] mtd-utils: new strtoX helpers
2010-09-24 1:53 ` [PATCH 3/4] mtd-utils: new strtoX helpers Mike Frysinger
2010-09-24 4:31 ` Jon Povey
@ 2010-09-25 6:06 ` Mike Frysinger
2010-09-25 10:54 ` Artem Bityutskiy
` (3 more replies)
1 sibling, 4 replies; 30+ messages in thread
From: Mike Frysinger @ 2010-09-25 6:06 UTC (permalink / raw)
To: linux-mtd
Simply usage of converting strings to numbers by adding some wrappers
around the standard strtoX functions. These helpers support both hex
and dec numbers transparently, and the caller need only provide a ptr
to an error integer if they want to be notified of problems.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
v2
- drop redundant parsing logic
include/strtox.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 58 insertions(+), 0 deletions(-)
create mode 100644 include/strtox.h
diff --git a/include/strtox.h b/include/strtox.h
new file mode 100644
index 0000000..0dcafc7
--- /dev/null
+++ b/include/strtox.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) Artem Bityutskiy, 2007, 2008
+ * Copyright (c) Mike Frysinger, 2010
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __MTD_UTILS_STRTOX_H__
+#define __MTD_UTILS_STRTOX_H__
+
+#include "common.h"
+#include <stdlib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * simple_strtoX - convert a hex/dec string into a number
+ * @snum: buffer to convert
+ * @error: set to 1 when buffer isn't fully consumed
+ */
+#define simple_strtoX(func, type) \
+static inline type simple_##func(const char *snum, int *error) \
+{ \
+ char *endptr; \
+ type ret = func(snum, &endptr, 0); \
+ \
+ if (!*snum || *endptr) { \
+ errmsg("%s: unable to parse the number '%s'", #func, snum); \
+ if (error) \
+ *error = 1; \
+ } \
+ \
+ return ret; \
+}
+simple_strtoX(strtol, long int)
+simple_strtoX(strtoll, long int)
+simple_strtoX(strtoul, unsigned long int)
+simple_strtoX(strtoull, unsigned long int)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !__MTD_UTILS_STRTOX_H__ */
--
1.7.2.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 4/4 v2] mtd-utils: unify flash_erase and flash_eraseall
2010-09-24 1:53 ` [PATCH 4/4] mtd-utils: unify flash_erase and flash_eraseall Mike Frysinger
2010-09-24 4:35 ` Jon Povey
@ 2010-09-25 6:07 ` Mike Frysinger
2010-09-27 6:50 ` [PATCH v3] " Mike Frysinger
2010-09-28 9:46 ` [PATCH 4/4] " Artem Bityutskiy
2 siblings, 1 reply; 30+ messages in thread
From: Mike Frysinger @ 2010-09-25 6:07 UTC (permalink / raw)
To: linux-mtd
These have overlapping functionality, and while flash_eraseall supports
newer 64bit ioctls, flash_erase does not. So rather than graft support
onto flash_erase, merge the functionality of two into flash_erase so we
only have to support one util from now on.
A simple wrapper is provided to ease old flash_eraseall users into the
new combined flash_erase util.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
v2
- add SCRIPTS var for install
.gitignore | 1 -
Makefile | 7 +-
flash_erase.c | 418 ++++++++++++++++++++++++++++++++++--------------------
flash_eraseall | 4 +
flash_eraseall.c | 276 -----------------------------------
5 files changed, 269 insertions(+), 437 deletions(-)
create mode 100755 flash_eraseall
delete mode 100644 flash_eraseall.c
diff --git a/.gitignore b/.gitignore
index defbd57..2dbf198 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,7 +20,6 @@
/doc_loadbios
/docfdisk
/flash_erase
-/flash_eraseall
/flash_info
/flash_lock
/flash_otp_dump
diff --git a/Makefile b/Makefile
index d315f39..9160fac 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ endif
SUBDIRS = lib ubi-utils mkfs.ubifs
-TARGETS = ftl_format flash_erase flash_eraseall nanddump doc_loadbios \
+TARGETS = ftl_format flash_erase nanddump doc_loadbios \
ftl_check mkfs.jffs2 flash_lock flash_unlock flash_info \
flash_otp_info flash_otp_dump mtd_debug flashcp nandwrite nandtest \
jffs2dump \
@@ -17,6 +17,7 @@ TARGETS = ftl_format flash_erase flash_eraseall nanddump doc_loadbios \
rfddump rfdformat \
serve_image recv_image \
sumtool #jffs2reader
+SCRIPTS = flash_eraseall
SYMLINKS =
@@ -53,8 +54,8 @@ LDLIBS_jffs2reader = -lz -llzo2
$(BUILDDIR)/lib/libmtd.a: subdirs_lib_all ;
-install:: ${TARGETS}
+install:: ${TARGETS} ${SCRIPTS}
mkdir -p ${DESTDIR}/${SBINDIR}
- install -m 0755 ${TARGETS} ${DESTDIR}/${SBINDIR}/
+ install -m 0755 $^ ${DESTDIR}/${SBINDIR}/
mkdir -p ${DESTDIR}/${MANDIR}/man1
gzip -9c mkfs.jffs2.1 > ${DESTDIR}/${MANDIR}/man1/mkfs.jffs2.1.gz
diff --git a/flash_erase.c b/flash_erase.c
index fdf9918..2467fff 100644
--- a/flash_erase.c
+++ b/flash_erase.c
@@ -1,189 +1,293 @@
-/*
- * flash_erase.c -- erase parts of a MTD device
- */
+/* flash_erase.c -- erase MTD devices
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <time.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <sys/mount.h>
-#include <mtd/mtd-user.h>
+ Copyright (C) 2000 Arcom Control System Ltd
+ Copyright (C) 2010 Mike Frysinger <vapier@gentoo.org>
-int region_erase(int Fd, int start, int count, int unlock, int regcount)
-{
- int i, j;
- region_info_t * reginfo;
-
- reginfo = calloc(regcount, sizeof(region_info_t));
-
- for(i = 0; i < regcount; i++)
- {
- reginfo[i].regionindex = i;
- if(ioctl(Fd,MEMGETREGIONINFO,&(reginfo[i])) != 0)
- return 8;
- else
- printf("Region %d is at %d of %d sector and with sector "
- "size %x\n", i, reginfo[i].offset, reginfo[i].numblocks,
- reginfo[i].erasesize);
- }
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
- // We have all the information about the chip we need.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- for(i = 0; i < regcount; i++)
- { //Loop through the regions
- region_info_t * r = &(reginfo[i]);
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
- if((start >= reginfo[i].offset) &&
- (start < (r->offset + r->numblocks*r->erasesize)))
- break;
- }
+#define PROGRAM_NAME "flash_erase"
+#define VERSION "2"
- if(i >= regcount)
- {
- printf("Starting offset %x not within chip.\n", start);
- return 8;
- }
+#include <inttypes.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <stdint.h>
+#include <getopt.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
- //We are now positioned within region i of the chip, so start erasing
- //count sectors from there.
+#include <common.h>
+#include <strtox.h>
+#include <crc32.h>
+#include <libmtd.h>
- for(j = 0; (j < count)&&(i < regcount); j++)
- {
- erase_info_t erase;
- region_info_t * r = &(reginfo[i]);
+#include <mtd/mtd-user.h>
+#include <mtd/jffs2-user.h>
- erase.start = start;
- erase.length = r->erasesize;
+static const char *mtd_device;
- if(unlock != 0)
- { //Unlock the sector first.
- if(ioctl(Fd, MEMUNLOCK, &erase) != 0)
- {
- perror("\nMTD Unlock failure");
- close(Fd);
- return 8;
- }
- }
- printf("\rPerforming Flash Erase of length %u at offset 0x%x",
- erase.length, erase.start);
- fflush(stdout);
- if(ioctl(Fd, MEMERASE, &erase) != 0)
- {
- perror("\nMTD Erase failure");
- close(Fd);
- return 8;
- }
+static int quiet; /* true -- don't output progress */
+static int jffs2; /* format for jffs2 usage */
+static int noskipbad; /* do not skip bad blocks */
+static int unlock; /* unlock sectors before erasing */
+static struct jffs2_unknown_node cleanmarker;
+int target_endian = __BYTE_ORDER;
- start += erase.length;
- if(start >= (r->offset + r->numblocks*r->erasesize))
- { //We finished region i so move to region i+1
- printf("\nMoving to region %d\n", i+1);
- i++;
- }
- }
+static void show_progress(struct mtd_dev_info *mtd, uint64_t start, int eb,
+ int eb_start, int eb_cnt)
+{
+ bareverbose(!quiet, "\rErasing %d Kibyte @ %"PRIx64" -- %2i %% complete ",
+ mtd->eb_size / 1024, start, ((eb - eb_start) * 100) / eb_cnt);
+ fflush(stdout);
+}
- printf(" done\n");
+static void display_help (void)
+{
+ printf("Usage: %s [options] MTD_DEVICE <start block> <block count>\n"
+ "Erase blocks of the specified MTD device.\n"
+ "Specify a count of 0 to erase to end of device.\n"
+ "\n"
+ " -j, --jffs2 format the device for jffs2\n"
+ " -N, --noskipbad don't skip bad blocks\n"
+ " -u, --unlock unlock sectors before erasing\n"
+ " -q, --quiet display progress messages\n"
+ " --silent same as --quiet\n"
+ " --help display this help and exit\n"
+ " --version output version information and exit\n",
+ PROGRAM_NAME);
+}
- return 0;
+static void display_version (void)
+{
+ printf(PROGRAM_NAME " version " VERSION "\n"
+ "\n"
+ "Copyright (C) 2000 Arcom Control Systems Ltd\n"
+ "\n"
+ PROGRAM_NAME " comes with NO WARRANTY\n"
+ "to the extent permitted by law.\n"
+ "\n"
+ "You may redistribute copies of " PROGRAM_NAME "\n"
+ "under the terms of the GNU General Public Licence.\n"
+ "See the file `COPYING' for more information.\n");
}
-int non_region_erase(int Fd, int start, int count, int unlock)
+int main(int argc, char *argv[])
{
- mtd_info_t meminfo;
-
- if (ioctl(Fd,MEMGETINFO,&meminfo) == 0)
- {
- erase_info_t erase;
-
- erase.start = start;
-
- erase.length = meminfo.erasesize;
-
- for (; count > 0; count--) {
- printf("\rPerforming Flash Erase of length %u at offset 0x%x",
- erase.length, erase.start);
- fflush(stdout);
-
- if(unlock != 0)
- {
- //Unlock the sector first.
- printf("\rPerforming Flash unlock at offset 0x%x",erase.start);
- if(ioctl(Fd, MEMUNLOCK, &erase) != 0)
- {
- perror("\nMTD Unlock failure");
- close(Fd);
- return 8;
- }
- }
+ libmtd_t mtd_desc;
+ struct mtd_dev_info mtd;
+ int fd, clmpos = 0, clmlen = 8, eb, eb_start, eb_cnt;
+ int isNAND;
+ int error = 0;
+ uint64_t offset = 0;
+
+ /*
+ * Process user arguments
+ */
+ for (;;) {
+ int option_index = 0;
+ static const char *short_options = "jNqu";
+ static const struct option long_options[] = {
+ {"help", no_argument, 0, 0},
+ {"version", no_argument, 0, 0},
+ {"jffs2", no_argument, 0, 'j'},
+ {"noskipbad", no_argument, 0, 'N'},
+ {"quiet", no_argument, 0, 'q'},
+ {"silent", no_argument, 0, 'q'},
+ {"unlock", no_argument, 0, 'u'},
+
+ {0, 0, 0, 0},
+ };
+
+ int c = getopt_long(argc, argv, short_options,
+ long_options, &option_index);
+ if (c == EOF)
+ break;
- if (ioctl(Fd,MEMERASE,&erase) != 0)
- {
- perror("\nMTD Erase failure");
- close(Fd);
- return 8;
+ switch (c) {
+ case 0:
+ switch (option_index) {
+ case 0:
+ display_help();
+ return 0;
+ case 1:
+ display_version();
+ return 0;
}
- erase.start += meminfo.erasesize;
+ break;
+ case 'j':
+ jffs2 = 1;
+ break;
+ case 'N':
+ noskipbad = 1;
+ break;
+ case 'q':
+ quiet = 1;
+ break;
+ case 'u':
+ unlock = 1;
+ break;
+ case '?':
+ error = 1;
+ break;
}
- printf(" done\n");
}
- return 0;
-}
-
-int main(int argc,char *argv[])
-{
- int regcount;
- int Fd;
- int start;
- int count;
- int unlock;
- int res = 0;
-
- if (1 >= argc || !strcmp(argv[1], "-h") || !strcmp (argv[1], "--help") ) {
- printf("Usage: flash_erase MTD-device [start] [cnt (# erase blocks)] [lock]\n"
- " flash_erase -h | --help\n") ;
- return 16 ;
+ switch (argc - optind) {
+ case 3:
+ mtd_device = argv[optind];
+ eb_start = simple_strtoul(argv[optind + 1], &error);
+ eb_cnt = simple_strtoul(argv[optind + 2], &error);
+ break;
+ default:
+ case 0:
+ errmsg("no MTD device specified");
+ case 1:
+ errmsg("no start erase block specified");
+ case 2:
+ errmsg("no erase block count specified");
+ error = 1;
+ break;
+ }
+ if (error)
+ return errmsg("Try `--help' for more information");
+
+ /*
+ * Locate MTD and prepare for erasure
+ */
+ mtd_desc = libmtd_open();
+ if (mtd_desc == NULL)
+ return errmsg("can't initialize libmtd");
+
+ if ((fd = open(mtd_device, O_RDWR)) < 0)
+ return sys_errmsg("%s", mtd_device);
+
+ if (mtd_get_dev_info(mtd_desc, mtd_device, &mtd) < 0)
+ return errmsg("mtd_get_dev_info failed");
+
+ isNAND = mtd.type == MTD_NANDFLASH ? 1 : 0;
+
+ if (jffs2) {
+ cleanmarker.magic = cpu_to_je16 (JFFS2_MAGIC_BITMASK);
+ cleanmarker.nodetype = cpu_to_je16 (JFFS2_NODETYPE_CLEANMARKER);
+ if (!isNAND)
+ cleanmarker.totlen = cpu_to_je32(sizeof(cleanmarker));
+ else {
+ struct nand_oobinfo oobinfo;
+
+ if (ioctl(fd, MEMGETOOBSEL, &oobinfo) != 0)
+ return sys_errmsg("%s: unable to get NAND oobinfo", mtd_device);
+
+ /* Check for autoplacement */
+ if (oobinfo.useecc == MTD_NANDECC_AUTOPLACE) {
+ /* Get the position of the free bytes */
+ if (!oobinfo.oobfree[0][1])
+ return errmsg(" Eeep. Autoplacement selected and no empty space in oob");
+ clmpos = oobinfo.oobfree[0][0];
+ clmlen = oobinfo.oobfree[0][1];
+ if (clmlen > 8)
+ clmlen = 8;
+ } else {
+ /* Legacy mode */
+ switch (mtd.oob_size) {
+ case 8:
+ clmpos = 6;
+ clmlen = 2;
+ break;
+ case 16:
+ clmpos = 8;
+ clmlen = 8;
+ break;
+ case 64:
+ clmpos = 16;
+ clmlen = 8;
+ break;
+ }
+ }
+ cleanmarker.totlen = cpu_to_je32(8);
+ }
+ cleanmarker.hdr_crc = cpu_to_je32(mtd_crc32(0, &cleanmarker, sizeof(cleanmarker) - 4));
}
- if (argc > 2)
- start = strtol(argv[2], NULL, 0);
- else
- start = 0;
-
- if (argc > 3)
- count = strtol(argv[3], NULL, 0);
- else
- count = 1;
+ /*
+ * Now do the actual erasing of the MTD device
+ */
+ if (eb_cnt == 0)
+ eb_cnt = (mtd.size / mtd.eb_size) - eb_start;
+
+ for (eb = eb_start; eb < eb_start + eb_cnt; eb++) {
+ offset = eb * mtd.eb_size;
+
+ if (!noskipbad) {
+ int ret = mtd_is_bad(&mtd, fd, eb);
+ if (ret > 0) {
+ verbose(!quiet, "Skipping bad block at %08"PRIx64, offset);
+ continue;
+ } else if (ret < 0) {
+ if (errno == EOPNOTSUPP) {
+ noskipbad = 1;
+ if (isNAND)
+ return errmsg("%s: Bad block check not available", mtd_device);
+ } else
+ return sys_errmsg("%s: MTD get bad block failed", mtd_device);
+ }
+ }
- if(argc > 4)
- unlock = strtol(argv[4], NULL, 0);
- else
- unlock = 0;
+ show_progress(&mtd, offset, eb, eb_start, eb_cnt);
+ if (unlock) {
+ if (mtd_unlock(&mtd, fd, eb) != 0) {
+ sys_errmsg("%s: MTD unlock failure", mtd_device);
+ continue;
+ }
+ }
- // Open and size the device
- if ((Fd = open(argv[1],O_RDWR)) < 0)
- {
- fprintf(stderr,"File open error\n");
- return 8;
- }
+ if (mtd_erase(mtd_desc, &mtd, fd, eb) != 0) {
+ sys_errmsg("%s: MTD Erase failure", mtd_device);
+ continue;
+ }
- printf("Erase Total %d Units\n", count);
+ /* format for JFFS2 ? */
+ if (!jffs2)
+ continue;
- if (ioctl(Fd,MEMGETREGIONCOUNT,®count) == 0)
- {
- if(regcount == 0)
- {
- res = non_region_erase(Fd, start, count, unlock);
- }
- else
- {
- res = region_erase(Fd, start, count, unlock, regcount);
+ /* write cleanmarker */
+ if (isNAND) {
+ if (mtd_write_oob(mtd_desc, &mtd, fd, offset + clmpos, clmlen, &cleanmarker) != 0) {
+ sys_errmsg("%s: MTD writeoob failure", mtd_device);
+ continue;
+ }
+ } else {
+ if (lseek(fd, (loff_t)offset, SEEK_SET) < 0) {
+ sys_errmsg("%s: MTD lseek failure", mtd_device);
+ continue;
+ }
+ if (write(fd, &cleanmarker, sizeof(cleanmarker)) != sizeof(cleanmarker)) {
+ sys_errmsg("%s: MTD write failure", mtd_device);
+ continue;
+ }
}
+ verbose(!quiet, " Cleanmarker written at %"PRIx64, offset);
}
+ offset += mtd.eb_size;
+ show_progress(&mtd, offset, eb, eb_start, eb_cnt);
+ bareverbose(!quiet, "\n");
- return res;
+ return 0;
}
diff --git a/flash_eraseall b/flash_eraseall
new file mode 100755
index 0000000..c5539b3
--- /dev/null
+++ b/flash_eraseall
@@ -0,0 +1,4 @@
+#!/bin/sh
+echo "${0##*/} has been replaced by \`flash_erase <mtddev> 0 0\`; please use it" 1>&2
+[ $# -ne 0 ] && set -- "$@" 0 0
+exec flash_erase "$@"
diff --git a/flash_eraseall.c b/flash_eraseall.c
deleted file mode 100644
index cb6f632..0000000
--- a/flash_eraseall.c
+++ /dev/null
@@ -1,276 +0,0 @@
-/* eraseall.c -- erase the whole of a MTD device
-
- Copyright (C) 2000 Arcom Control System Ltd
-
- Renamed to flash_eraseall.c
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-#include <sys/types.h>
-#include <stdio.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <stdarg.h>
-#include <stdint.h>
-#include <libgen.h>
-#include <ctype.h>
-#include <time.h>
-#include <getopt.h>
-#include <sys/ioctl.h>
-#include <sys/mount.h>
-#include <crc32.h>
-#include <libmtd.h>
-
-#include <mtd/mtd-user.h>
-#include <mtd/jffs2-user.h>
-
-#define PROGRAM "flash_eraseall"
-#define VERSION "$Revision: 1.22 $"
-
-static const char *exe_name;
-static const char *mtd_device;
-static int quiet; /* true -- don't output progress */
-static int jffs2; /* format for jffs2 usage */
-
-static struct jffs2_unknown_node cleanmarker;
-int target_endian = __BYTE_ORDER;
-
-static void show_progress (struct mtd_dev_info *mtd, uint64_t start)
-{
- printf("\rErasing %d Kibyte @ %llx -- %2llu %% complete.",
- mtd->eb_size / 1024, (unsigned long long)start,
- (unsigned long long) start * 100 / mtd->size);
- fflush(stdout);
-}
-
-static void display_help (void)
-{
- printf("Usage: %s [OPTION] MTD_DEVICE\n"
- "Erases all of the specified MTD device.\n"
- "\n"
- " -j, --jffs2 format the device for jffs2\n"
- " -q, --quiet don't display progress messages\n"
- " --silent same as --quiet\n"
- " --help display this help and exit\n"
- " --version output version information and exit\n",
- exe_name);
-}
-
-
-static void display_version (void)
-{
- printf(PROGRAM " " VERSION "\n"
- "\n"
- "Copyright (C) 2000 Arcom Control Systems Ltd\n"
- "\n"
- PROGRAM " comes with NO WARRANTY\n"
- "to the extent permitted by law.\n"
- "\n"
- "You may redistribute copies of " PROGRAM "\n"
- "under the terms of the GNU General Public Licence.\n"
- "See the file `COPYING' for more information.\n");
-}
-
-int main (int argc, char *argv[])
-{
- libmtd_t mtd_desc;
- struct mtd_dev_info mtd;
- int fd, clmpos = 0, clmlen = 8, eb;
- int isNAND, bbtest = 1;
- int error = 0;
- uint64_t offset = 0;
-
- exe_name = argv[0];
- for (;;) {
- int option_index = 0;
- static const char *short_options = "jq";
- static const struct option long_options[] = {
- {"help", no_argument, 0, 0},
- {"version", no_argument, 0, 0},
- {"jffs2", no_argument, 0, 'j'},
- {"quiet", no_argument, 0, 'q'},
- {"silent", no_argument, 0, 'q'},
-
- {0, 0, 0, 0},
- };
-
- int c = getopt_long(argc, argv, short_options,
- long_options, &option_index);
- if (c == EOF)
- break;
-
- switch (c) {
- case 0:
- switch (option_index) {
- case 0:
- display_help();
- return 0;
- case 1:
- display_version();
- return 0;
- }
- break;
- case 'q':
- quiet = 1;
- break;
- case 'j':
- jffs2 = 1;
- break;
- case '?':
- error = 1;
- break;
- }
- }
- if (optind == argc) {
- fprintf(stderr, "%s: no MTD device specified\n", exe_name);
- error = 1;
- }
- if (error) {
- fprintf(stderr, "Try `%s --help' for more information.\n",
- exe_name);
- return 1;
- }
- mtd_device = argv[optind];
-
- mtd_desc = libmtd_open();
- if (mtd_desc == NULL) {
- fprintf(stderr, "%s: can't initialize libmtd\n", exe_name);
- return 1;
- }
-
- if ((fd = open(mtd_device, O_RDWR)) < 0) {
- fprintf(stderr, "%s: %s: %s\n", exe_name, mtd_device, strerror(errno));
- return 1;
- }
-
- if (mtd_get_dev_info(mtd_desc, mtd_device, &mtd) < 0) {
- fprintf(stderr, "%s: mtd_get_dev_info failed\n", exe_name);
- return 1;
- }
-
- isNAND = mtd.type == MTD_NANDFLASH ? 1 : 0;
-
- if (jffs2) {
- cleanmarker.magic = cpu_to_je16 (JFFS2_MAGIC_BITMASK);
- cleanmarker.nodetype = cpu_to_je16 (JFFS2_NODETYPE_CLEANMARKER);
- if (!isNAND)
- cleanmarker.totlen = cpu_to_je32 (sizeof (struct jffs2_unknown_node));
- else {
- struct nand_oobinfo oobinfo;
-
- if (ioctl(fd, MEMGETOOBSEL, &oobinfo) != 0) {
- fprintf(stderr, "%s: %s: unable to get NAND oobinfo\n", exe_name, mtd_device);
- return 1;
- }
-
- /* Check for autoplacement */
- if (oobinfo.useecc == MTD_NANDECC_AUTOPLACE) {
- /* Get the position of the free bytes */
- if (!oobinfo.oobfree[0][1]) {
- fprintf (stderr, " Eeep. Autoplacement selected and no empty space in oob\n");
- return 1;
- }
- clmpos = oobinfo.oobfree[0][0];
- clmlen = oobinfo.oobfree[0][1];
- if (clmlen > 8)
- clmlen = 8;
- } else {
- /* Legacy mode */
- switch (mtd.oob_size) {
- case 8:
- clmpos = 6;
- clmlen = 2;
- break;
- case 16:
- clmpos = 8;
- clmlen = 8;
- break;
- case 64:
- clmpos = 16;
- clmlen = 8;
- break;
- }
- }
- cleanmarker.totlen = cpu_to_je32(8);
- }
- cleanmarker.hdr_crc = cpu_to_je32 (mtd_crc32 (0, &cleanmarker, sizeof (struct jffs2_unknown_node) - 4));
- }
-
- for (eb = 0; eb < (mtd.size / mtd.eb_size); eb++) {
- offset = eb * mtd.eb_size;
- if (bbtest) {
- int ret = mtd_is_bad(&mtd, fd, eb);
- if (ret > 0) {
- if (!quiet)
- printf ("\nSkipping bad block at 0x%08llx\n", (unsigned long long)offset);
- continue;
- } else if (ret < 0) {
- if (errno == EOPNOTSUPP) {
- bbtest = 0;
- if (isNAND) {
- fprintf(stderr, "%s: %s: Bad block check not available\n", exe_name, mtd_device);
- return 1;
- }
- } else {
- fprintf(stderr, "\n%s: %s: MTD get bad block failed: %s\n", exe_name, mtd_device, strerror(errno));
- return 1;
- }
- }
- }
-
- if (!quiet)
- show_progress(&mtd, offset);
-
- if (mtd_erase(mtd_desc, &mtd, fd, eb) != 0) {
- fprintf(stderr, "\n%s: %s: MTD Erase failure: %s\n", exe_name, mtd_device, strerror(errno));
- continue;
- }
-
- /* format for JFFS2 ? */
- if (!jffs2)
- continue;
-
- /* write cleanmarker */
- if (isNAND) {
- if (mtd_write_oob(mtd_desc, &mtd, fd, offset + clmpos, clmlen, &cleanmarker) != 0) {
- fprintf(stderr, "\n%s: %s: MTD writeoob failure: %s\n", exe_name, mtd_device, strerror(errno));
- continue;
- }
- } else {
- if (lseek (fd, (loff_t)offset, SEEK_SET) < 0) {
- fprintf(stderr, "\n%s: %s: MTD lseek failure: %s\n", exe_name, mtd_device, strerror(errno));
- continue;
- }
- if (write (fd , &cleanmarker, sizeof (cleanmarker)) != sizeof (cleanmarker)) {
- fprintf(stderr, "\n%s: %s: MTD write failure: %s\n", exe_name, mtd_device, strerror(errno));
- continue;
- }
- }
- if (!quiet)
- printf (" Cleanmarker written at %llx.", (unsigned long long)offset);
- }
- if (!quiet) {
- show_progress(&mtd, offset);
- printf("\n");
- }
-
- return 0;
-}
-
--
1.7.2.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [PATCH 1/4] libmtd: add lock/unlock helpers
2010-09-24 1:53 [PATCH 1/4] libmtd: add lock/unlock helpers Mike Frysinger
` (2 preceding siblings ...)
2010-09-24 1:53 ` [PATCH 4/4] mtd-utils: unify flash_erase and flash_eraseall Mike Frysinger
@ 2010-09-25 10:50 ` Artem Bityutskiy
3 siblings, 0 replies; 30+ messages in thread
From: Artem Bityutskiy @ 2010-09-25 10:50 UTC (permalink / raw)
To: Mike Frysinger; +Cc: linux-mtd
On Thu, 2010-09-23 at 21:53 -0400, Mike Frysinger wrote:
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> ---
> include/libmtd.h | 24 ++++++++++++++++++++++++
> lib/libmtd.c | 32 ++++++++++++++++++++++++++++++++
> 2 files changed, 56 insertions(+), 0 deletions(-)
Pushed with a minor tweak, thanks.
> /**
> + * mtd_lock - lock eraseblocks
Put a dot at the end, for consistency.
> +/**
> + * mtd_unlock - unlock eraseblocks
Ditto.
--
Best Regards,
Artem Bityutskiy (Битюцкий Артём)
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 2/4 v2] mtd-utils: new bareverbose() helper
2010-09-25 6:05 ` [PATCH 2/4 v2] " Mike Frysinger
@ 2010-09-25 10:52 ` Artem Bityutskiy
0 siblings, 0 replies; 30+ messages in thread
From: Artem Bityutskiy @ 2010-09-25 10:52 UTC (permalink / raw)
To: Mike Frysinger; +Cc: linux-mtd
On Sat, 2010-09-25 at 02:05 -0400, Mike Frysinger wrote:
> Add a new helper that lets people do simple verbose output without any
> implicit strings added around it. Good for progress bars and such.
>
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Pushed, thanks.
--
Best Regards,
Artem Bityutskiy (Битюцкий Артём)
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 3/4 v2] mtd-utils: new strtoX helpers
2010-09-25 6:06 ` [PATCH 3/4 v2] " Mike Frysinger
@ 2010-09-25 10:54 ` Artem Bityutskiy
2010-09-25 18:59 ` Mike Frysinger
2010-09-26 11:41 ` Artem Bityutskiy
` (2 subsequent siblings)
3 siblings, 1 reply; 30+ messages in thread
From: Artem Bityutskiy @ 2010-09-25 10:54 UTC (permalink / raw)
To: Mike Frysinger; +Cc: linux-mtd
On Sat, 2010-09-25 at 02:06 -0400, Mike Frysinger wrote:
> Simply usage of converting strings to numbers by adding some wrappers
> around the standard strtoX functions. These helpers support both hex
> and dec numbers transparently, and the caller need only provide a ptr
> to an error integer if they want to be notified of problems.
>
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> ---
> v2
> - drop redundant parsing logic
Why do you need a separate file for this? common.h does not suit this?
--
Best Regards,
Artem Bityutskiy (Битюцкий Артём)
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 3/4 v2] mtd-utils: new strtoX helpers
2010-09-25 10:54 ` Artem Bityutskiy
@ 2010-09-25 18:59 ` Mike Frysinger
2010-09-25 19:31 ` Artem Bityutskiy
0 siblings, 1 reply; 30+ messages in thread
From: Mike Frysinger @ 2010-09-25 18:59 UTC (permalink / raw)
To: dedekind1; +Cc: linux-mtd
On Sat, Sep 25, 2010 at 06:54, Artem Bityutskiy wrote:
> On Sat, 2010-09-25 at 02:06 -0400, Mike Frysinger wrote:
>> Simply usage of converting strings to numbers by adding some wrappers
>> around the standard strtoX functions. These helpers support both hex
>> and dec numbers transparently, and the caller need only provide a ptr
>> to an error integer if they want to be notified of problems.
>
> Why do you need a separate file for this? common.h does not suit this?
the expansion of PROGRAM_NAME causes build errors for programs that do
not define it but include common.h
-mike
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 3/4 v2] mtd-utils: new strtoX helpers
2010-09-25 18:59 ` Mike Frysinger
@ 2010-09-25 19:31 ` Artem Bityutskiy
2010-09-25 19:37 ` Mike Frysinger
0 siblings, 1 reply; 30+ messages in thread
From: Artem Bityutskiy @ 2010-09-25 19:31 UTC (permalink / raw)
To: Mike Frysinger; +Cc: linux-mtd
On Sat, 2010-09-25 at 14:59 -0400, Mike Frysinger wrote:
> On Sat, Sep 25, 2010 at 06:54, Artem Bityutskiy wrote:
> > On Sat, 2010-09-25 at 02:06 -0400, Mike Frysinger wrote:
> >> Simply usage of converting strings to numbers by adding some wrappers
> >> around the standard strtoX functions. These helpers support both hex
> >> and dec numbers transparently, and the caller need only provide a ptr
> >> to an error integer if they want to be notified of problems.
> >
> > Why do you need a separate file for this? common.h does not suit this?
>
> the expansion of PROGRAM_NAME causes build errors for programs that do
> not define it but include common.h
> -mike
May be
#ifndef PROGRAM_NAME
#define PROGRAM_NAME "undefined"
#endif
?
--
Best Regards,
Artem Bityutskiy (Битюцкий Артём)
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 3/4 v2] mtd-utils: new strtoX helpers
2010-09-25 19:31 ` Artem Bityutskiy
@ 2010-09-25 19:37 ` Mike Frysinger
2010-09-26 11:42 ` Artem Bityutskiy
0 siblings, 1 reply; 30+ messages in thread
From: Mike Frysinger @ 2010-09-25 19:37 UTC (permalink / raw)
To: dedekind1; +Cc: linux-mtd
On Sat, Sep 25, 2010 at 15:31, Artem Bityutskiy wrote:
> On Sat, 2010-09-25 at 14:59 -0400, Mike Frysinger wrote:
>> On Sat, Sep 25, 2010 at 06:54, Artem Bityutskiy wrote:
>> > On Sat, 2010-09-25 at 02:06 -0400, Mike Frysinger wrote:
>> >> Simply usage of converting strings to numbers by adding some wrappers
>> >> around the standard strtoX functions. These helpers support both hex
>> >> and dec numbers transparently, and the caller need only provide a ptr
>> >> to an error integer if they want to be notified of problems.
>> >
>> > Why do you need a separate file for this? common.h does not suit this?
>>
>> the expansion of PROGRAM_NAME causes build errors for programs that do
>> not define it but include common.h
>
> May be
>
> #ifndef PROGRAM_NAME
> #define PROGRAM_NAME "undefined"
> #endif
if we're going to go that route, i'd rather just go through the few
files not defining PROGRAM_NAME, add it, and then turn the comment in
common.h about people defining it into an error
-mike
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 3/4 v2] mtd-utils: new strtoX helpers
2010-09-25 6:06 ` [PATCH 3/4 v2] " Mike Frysinger
2010-09-25 10:54 ` Artem Bityutskiy
@ 2010-09-26 11:41 ` Artem Bityutskiy
2010-09-27 6:39 ` Artem Bityutskiy
2010-09-27 6:42 ` [PATCH v3] " Mike Frysinger
3 siblings, 0 replies; 30+ messages in thread
From: Artem Bityutskiy @ 2010-09-26 11:41 UTC (permalink / raw)
To: Mike Frysinger; +Cc: linux-mtd
On Sat, 2010-09-25 at 02:06 -0400, Mike Frysinger wrote:
> +#ifndef __MTD_UTILS_STRTOX_H__
> +#define __MTD_UTILS_STRTOX_H__
> +
> +#include "common.h"
> +#include <stdlib.h>
Hmm, but you include this file here anyway.
--
Best Regards,
Artem Bityutskiy (Битюцкий Артём)
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 3/4 v2] mtd-utils: new strtoX helpers
2010-09-25 19:37 ` Mike Frysinger
@ 2010-09-26 11:42 ` Artem Bityutskiy
0 siblings, 0 replies; 30+ messages in thread
From: Artem Bityutskiy @ 2010-09-26 11:42 UTC (permalink / raw)
To: Mike Frysinger; +Cc: linux-mtd
On Sat, 2010-09-25 at 15:37 -0400, Mike Frysinger wrote:
> On Sat, Sep 25, 2010 at 15:31, Artem Bityutskiy wrote:
> > On Sat, 2010-09-25 at 14:59 -0400, Mike Frysinger wrote:
> >> On Sat, Sep 25, 2010 at 06:54, Artem Bityutskiy wrote:
> >> > On Sat, 2010-09-25 at 02:06 -0400, Mike Frysinger wrote:
> >> >> Simply usage of converting strings to numbers by adding some wrappers
> >> >> around the standard strtoX functions. These helpers support both hex
> >> >> and dec numbers transparently, and the caller need only provide a ptr
> >> >> to an error integer if they want to be notified of problems.
> >> >
> >> > Why do you need a separate file for this? common.h does not suit this?
> >>
> >> the expansion of PROGRAM_NAME causes build errors for programs that do
> >> not define it but include common.h
> >
> > May be
> >
> > #ifndef PROGRAM_NAME
> > #define PROGRAM_NAME "undefined"
> > #endif
>
> if we're going to go that route, i'd rather just go through the few
> files not defining PROGRAM_NAME, add it, and then turn the comment in
> common.h about people defining it into an error
Sounds good as well.
--
Best Regards,
Artem Bityutskiy (Битюцкий Артём)
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 3/4 v2] mtd-utils: new strtoX helpers
2010-09-25 6:06 ` [PATCH 3/4 v2] " Mike Frysinger
2010-09-25 10:54 ` Artem Bityutskiy
2010-09-26 11:41 ` Artem Bityutskiy
@ 2010-09-27 6:39 ` Artem Bityutskiy
2010-09-27 6:42 ` [PATCH v3] " Mike Frysinger
3 siblings, 0 replies; 30+ messages in thread
From: Artem Bityutskiy @ 2010-09-27 6:39 UTC (permalink / raw)
To: Mike Frysinger; +Cc: linux-mtd
On Sat, 2010-09-25 at 02:06 -0400, Mike Frysinger wrote:
> Simply usage of converting strings to numbers by adding some wrappers
> around the standard strtoX functions. These helpers support both hex
> and dec numbers transparently, and the caller need only provide a ptr
> to an error integer if they want to be notified of problems.
>
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> ---
> v2
> - drop redundant parsing logic
>
Mike, so will you move this to common.h or you insist this should be a
separate header file?
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH v3] mtd-utils: new strtoX helpers
2010-09-25 6:06 ` [PATCH 3/4 v2] " Mike Frysinger
` (2 preceding siblings ...)
2010-09-27 6:39 ` Artem Bityutskiy
@ 2010-09-27 6:42 ` Mike Frysinger
2010-09-27 6:44 ` Artem Bityutskiy
3 siblings, 1 reply; 30+ messages in thread
From: Mike Frysinger @ 2010-09-27 6:42 UTC (permalink / raw)
To: linux-mtd
Simply usage of converting strings to numbers by adding some wrappers
around the standard strtoX functions. These helpers simplify the api
of these functions a bit by providing an optional "error" pointer and
automatic error message.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
v3
- merge into common.h now that PROGRAM_NAME has been sorted out
include/common.h | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/include/common.h b/include/common.h
index dce067b..472315e 100644
--- a/include/common.h
+++ b/include/common.h
@@ -20,6 +20,7 @@
#define __MTD_UTILS_COMMON_H__
#include <stdio.h>
+#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
@@ -79,6 +80,29 @@ static inline int is_power_of_2(unsigned long long n)
return (n != 0 && ((n & (n - 1)) == 0));
}
+/**
+ * simple_strtoX - convert a hex/dec/oct string into a number
+ * @snum: buffer to convert
+ * @error: set to 1 when buffer isn't fully consumed
+ */
+#define simple_strtoX(func, type) \
+static inline type simple_##func(const char *snum, int *error) \
+{ \
+ char *endptr; \
+ type ret = func(snum, &endptr, 0); \
+ \
+ if (error && (!*snum || *endptr)) { \
+ errmsg("%s: unable to parse the number '%s'", #func, snum); \
+ *error = 1; \
+ } \
+ \
+ return ret; \
+}
+simple_strtoX(strtol, long int)
+simple_strtoX(strtoll, long int)
+simple_strtoX(strtoul, unsigned long int)
+simple_strtoX(strtoull, unsigned long int)
+
#ifdef __cplusplus
}
#endif
--
1.7.2.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [PATCH v3] mtd-utils: new strtoX helpers
2010-09-27 6:42 ` [PATCH v3] " Mike Frysinger
@ 2010-09-27 6:44 ` Artem Bityutskiy
0 siblings, 0 replies; 30+ messages in thread
From: Artem Bityutskiy @ 2010-09-27 6:44 UTC (permalink / raw)
To: Mike Frysinger; +Cc: linux-mtd
On Mon, 2010-09-27 at 02:42 -0400, Mike Frysinger wrote:
> Simply usage of converting strings to numbers by adding some wrappers
> around the standard strtoX functions. These helpers simplify the api
> of these functions a bit by providing an optional "error" pointer and
> automatic error message.
>
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> ---
> v3
> - merge into common.h now that PROGRAM_NAME has been sorted out
Pushed, thanks!
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH v3] mtd-utils: unify flash_erase and flash_eraseall
2010-09-25 6:07 ` [PATCH 4/4 v2] " Mike Frysinger
@ 2010-09-27 6:50 ` Mike Frysinger
2010-09-27 6:56 ` Artem Bityutskiy
0 siblings, 1 reply; 30+ messages in thread
From: Mike Frysinger @ 2010-09-27 6:50 UTC (permalink / raw)
To: linux-mtd
These have overlapping functionality, and while flash_eraseall supports
newer 64bit ioctls, flash_erase does not. So rather than graft support
onto flash_erase, merge the functionality of two into flash_erase so we
only have to support one util from now on.
A simple wrapper is provided to ease old flash_eraseall users into the
new combined flash_erase util.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
v3
- rebase after recent common.h changes
.gitignore | 1 -
Makefile | 7 +-
flash_erase.c | 418 ++++++++++++++++++++++++++++++++++--------------------
flash_eraseall | 4 +
flash_eraseall.c | 276 -----------------------------------
5 files changed, 269 insertions(+), 437 deletions(-)
create mode 100755 flash_eraseall
delete mode 100644 flash_eraseall.c
diff --git a/.gitignore b/.gitignore
index defbd57..2dbf198 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,7 +20,6 @@
/doc_loadbios
/docfdisk
/flash_erase
-/flash_eraseall
/flash_info
/flash_lock
/flash_otp_dump
diff --git a/Makefile b/Makefile
index d315f39..93661cb 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ endif
SUBDIRS = lib ubi-utils mkfs.ubifs
-TARGETS = ftl_format flash_erase flash_eraseall nanddump doc_loadbios \
+TARGETS = ftl_format flash_erase nanddump doc_loadbios \
ftl_check mkfs.jffs2 flash_lock flash_unlock flash_info \
flash_otp_info flash_otp_dump mtd_debug flashcp nandwrite nandtest \
jffs2dump \
@@ -17,6 +17,7 @@ TARGETS = ftl_format flash_erase flash_eraseall nanddump doc_loadbios \
rfddump rfdformat \
serve_image recv_image \
sumtool #jffs2reader
+SCRIPTS = flash_eraseall
SYMLINKS =
@@ -53,8 +54,8 @@ LDLIBS_jffs2reader = -lz -llzo2
$(BUILDDIR)/lib/libmtd.a: subdirs_lib_all ;
-install:: ${TARGETS}
+install:: ${TARGETS} ${SCRIPTS}
mkdir -p ${DESTDIR}/${SBINDIR}
- install -m 0755 ${TARGETS} ${DESTDIR}/${SBINDIR}/
+ install -m 0755 ${TARGETS} ${SCRIPTS} ${DESTDIR}/${SBINDIR}/
mkdir -p ${DESTDIR}/${MANDIR}/man1
gzip -9c mkfs.jffs2.1 > ${DESTDIR}/${MANDIR}/man1/mkfs.jffs2.1.gz
diff --git a/flash_erase.c b/flash_erase.c
index fdf9918..8929054 100644
--- a/flash_erase.c
+++ b/flash_erase.c
@@ -1,189 +1,293 @@
-/*
- * flash_erase.c -- erase parts of a MTD device
- */
+/* flash_erase.c -- erase MTD devices
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <time.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <sys/mount.h>
-#include <mtd/mtd-user.h>
+ Copyright (C) 2000 Arcom Control System Ltd
+ Copyright (C) 2010 Mike Frysinger <vapier@gentoo.org>
-int region_erase(int Fd, int start, int count, int unlock, int regcount)
-{
- int i, j;
- region_info_t * reginfo;
-
- reginfo = calloc(regcount, sizeof(region_info_t));
-
- for(i = 0; i < regcount; i++)
- {
- reginfo[i].regionindex = i;
- if(ioctl(Fd,MEMGETREGIONINFO,&(reginfo[i])) != 0)
- return 8;
- else
- printf("Region %d is at %d of %d sector and with sector "
- "size %x\n", i, reginfo[i].offset, reginfo[i].numblocks,
- reginfo[i].erasesize);
- }
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
- // We have all the information about the chip we need.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- for(i = 0; i < regcount; i++)
- { //Loop through the regions
- region_info_t * r = &(reginfo[i]);
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
- if((start >= reginfo[i].offset) &&
- (start < (r->offset + r->numblocks*r->erasesize)))
- break;
- }
+#define PROGRAM_NAME "flash_erase"
+#define VERSION "2"
- if(i >= regcount)
- {
- printf("Starting offset %x not within chip.\n", start);
- return 8;
- }
+#include <inttypes.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <stdint.h>
+#include <getopt.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
- //We are now positioned within region i of the chip, so start erasing
- //count sectors from there.
+#include <common.h>
+#include <crc32.h>
+#include <libmtd.h>
- for(j = 0; (j < count)&&(i < regcount); j++)
- {
- erase_info_t erase;
- region_info_t * r = &(reginfo[i]);
+#include <mtd/mtd-user.h>
+#include <mtd/jffs2-user.h>
- erase.start = start;
- erase.length = r->erasesize;
+static const char *mtd_device;
- if(unlock != 0)
- { //Unlock the sector first.
- if(ioctl(Fd, MEMUNLOCK, &erase) != 0)
- {
- perror("\nMTD Unlock failure");
- close(Fd);
- return 8;
- }
- }
- printf("\rPerforming Flash Erase of length %u at offset 0x%x",
- erase.length, erase.start);
- fflush(stdout);
- if(ioctl(Fd, MEMERASE, &erase) != 0)
- {
- perror("\nMTD Erase failure");
- close(Fd);
- return 8;
- }
+static int quiet; /* true -- don't output progress */
+static int jffs2; /* format for jffs2 usage */
+static int noskipbad; /* do not skip bad blocks */
+static int unlock; /* unlock sectors before erasing */
+static struct jffs2_unknown_node cleanmarker;
+int target_endian = __BYTE_ORDER;
- start += erase.length;
- if(start >= (r->offset + r->numblocks*r->erasesize))
- { //We finished region i so move to region i+1
- printf("\nMoving to region %d\n", i+1);
- i++;
- }
- }
+static void show_progress(struct mtd_dev_info *mtd, uint64_t start, int eb,
+ int eb_start, int eb_cnt)
+{
+ bareverbose(!quiet, "\rErasing %d Kibyte @ %"PRIx64" -- %2i %% complete ",
+ mtd->eb_size / 1024, start, ((eb - eb_start) * 100) / eb_cnt);
+ fflush(stdout);
+}
- printf(" done\n");
+static void display_help (void)
+{
+ printf("Usage: %s [options] MTD_DEVICE <start block> <block count>\n"
+ "Erase blocks of the specified MTD device.\n"
+ "Specify a count of 0 to erase to end of device.\n"
+ "\n"
+ " -j, --jffs2 format the device for jffs2\n"
+ " -N, --noskipbad don't skip bad blocks\n"
+ " -u, --unlock unlock sectors before erasing\n"
+ " -q, --quiet display progress messages\n"
+ " --silent same as --quiet\n"
+ " --help display this help and exit\n"
+ " --version output version information and exit\n",
+ PROGRAM_NAME);
+}
- return 0;
+static void display_version (void)
+{
+ printf("%1$s version " VERSION "\n"
+ "\n"
+ "Copyright (C) 2000 Arcom Control Systems Ltd\n"
+ "\n"
+ "%1$s comes with NO WARRANTY\n"
+ "to the extent permitted by law.\n"
+ "\n"
+ "You may redistribute copies of %1$s\n"
+ "under the terms of the GNU General Public Licence.\n"
+ "See the file `COPYING' for more information.\n",
+ PROGRAM_NAME);
}
-int non_region_erase(int Fd, int start, int count, int unlock)
+int main(int argc, char *argv[])
{
- mtd_info_t meminfo;
-
- if (ioctl(Fd,MEMGETINFO,&meminfo) == 0)
- {
- erase_info_t erase;
-
- erase.start = start;
-
- erase.length = meminfo.erasesize;
-
- for (; count > 0; count--) {
- printf("\rPerforming Flash Erase of length %u at offset 0x%x",
- erase.length, erase.start);
- fflush(stdout);
-
- if(unlock != 0)
- {
- //Unlock the sector first.
- printf("\rPerforming Flash unlock at offset 0x%x",erase.start);
- if(ioctl(Fd, MEMUNLOCK, &erase) != 0)
- {
- perror("\nMTD Unlock failure");
- close(Fd);
- return 8;
- }
- }
+ libmtd_t mtd_desc;
+ struct mtd_dev_info mtd;
+ int fd, clmpos = 0, clmlen = 8, eb, eb_start, eb_cnt;
+ int isNAND;
+ int error = 0;
+ uint64_t offset = 0;
+
+ /*
+ * Process user arguments
+ */
+ for (;;) {
+ int option_index = 0;
+ static const char *short_options = "jNqu";
+ static const struct option long_options[] = {
+ {"help", no_argument, 0, 0},
+ {"version", no_argument, 0, 0},
+ {"jffs2", no_argument, 0, 'j'},
+ {"noskipbad", no_argument, 0, 'N'},
+ {"quiet", no_argument, 0, 'q'},
+ {"silent", no_argument, 0, 'q'},
+ {"unlock", no_argument, 0, 'u'},
+
+ {0, 0, 0, 0},
+ };
+
+ int c = getopt_long(argc, argv, short_options,
+ long_options, &option_index);
+ if (c == EOF)
+ break;
- if (ioctl(Fd,MEMERASE,&erase) != 0)
- {
- perror("\nMTD Erase failure");
- close(Fd);
- return 8;
+ switch (c) {
+ case 0:
+ switch (option_index) {
+ case 0:
+ display_help();
+ return 0;
+ case 1:
+ display_version();
+ return 0;
}
- erase.start += meminfo.erasesize;
+ break;
+ case 'j':
+ jffs2 = 1;
+ break;
+ case 'N':
+ noskipbad = 1;
+ break;
+ case 'q':
+ quiet = 1;
+ break;
+ case 'u':
+ unlock = 1;
+ break;
+ case '?':
+ error = 1;
+ break;
}
- printf(" done\n");
}
- return 0;
-}
-
-int main(int argc,char *argv[])
-{
- int regcount;
- int Fd;
- int start;
- int count;
- int unlock;
- int res = 0;
-
- if (1 >= argc || !strcmp(argv[1], "-h") || !strcmp (argv[1], "--help") ) {
- printf("Usage: flash_erase MTD-device [start] [cnt (# erase blocks)] [lock]\n"
- " flash_erase -h | --help\n") ;
- return 16 ;
+ switch (argc - optind) {
+ case 3:
+ mtd_device = argv[optind];
+ eb_start = simple_strtoul(argv[optind + 1], &error);
+ eb_cnt = simple_strtoul(argv[optind + 2], &error);
+ break;
+ default:
+ case 0:
+ errmsg("no MTD device specified");
+ case 1:
+ errmsg("no start erase block specified");
+ case 2:
+ errmsg("no erase block count specified");
+ error = 1;
+ break;
+ }
+ if (error)
+ return errmsg("Try `--help' for more information");
+
+ /*
+ * Locate MTD and prepare for erasure
+ */
+ mtd_desc = libmtd_open();
+ if (mtd_desc == NULL)
+ return errmsg("can't initialize libmtd");
+
+ if ((fd = open(mtd_device, O_RDWR)) < 0)
+ return sys_errmsg("%s", mtd_device);
+
+ if (mtd_get_dev_info(mtd_desc, mtd_device, &mtd) < 0)
+ return errmsg("mtd_get_dev_info failed");
+
+ isNAND = mtd.type == MTD_NANDFLASH ? 1 : 0;
+
+ if (jffs2) {
+ cleanmarker.magic = cpu_to_je16 (JFFS2_MAGIC_BITMASK);
+ cleanmarker.nodetype = cpu_to_je16 (JFFS2_NODETYPE_CLEANMARKER);
+ if (!isNAND)
+ cleanmarker.totlen = cpu_to_je32(sizeof(cleanmarker));
+ else {
+ struct nand_oobinfo oobinfo;
+
+ if (ioctl(fd, MEMGETOOBSEL, &oobinfo) != 0)
+ return sys_errmsg("%s: unable to get NAND oobinfo", mtd_device);
+
+ /* Check for autoplacement */
+ if (oobinfo.useecc == MTD_NANDECC_AUTOPLACE) {
+ /* Get the position of the free bytes */
+ if (!oobinfo.oobfree[0][1])
+ return errmsg(" Eeep. Autoplacement selected and no empty space in oob");
+ clmpos = oobinfo.oobfree[0][0];
+ clmlen = oobinfo.oobfree[0][1];
+ if (clmlen > 8)
+ clmlen = 8;
+ } else {
+ /* Legacy mode */
+ switch (mtd.oob_size) {
+ case 8:
+ clmpos = 6;
+ clmlen = 2;
+ break;
+ case 16:
+ clmpos = 8;
+ clmlen = 8;
+ break;
+ case 64:
+ clmpos = 16;
+ clmlen = 8;
+ break;
+ }
+ }
+ cleanmarker.totlen = cpu_to_je32(8);
+ }
+ cleanmarker.hdr_crc = cpu_to_je32(mtd_crc32(0, &cleanmarker, sizeof(cleanmarker) - 4));
}
- if (argc > 2)
- start = strtol(argv[2], NULL, 0);
- else
- start = 0;
-
- if (argc > 3)
- count = strtol(argv[3], NULL, 0);
- else
- count = 1;
+ /*
+ * Now do the actual erasing of the MTD device
+ */
+ if (eb_cnt == 0)
+ eb_cnt = (mtd.size / mtd.eb_size) - eb_start;
+
+ for (eb = eb_start; eb < eb_start + eb_cnt; eb++) {
+ offset = eb * mtd.eb_size;
+
+ if (!noskipbad) {
+ int ret = mtd_is_bad(&mtd, fd, eb);
+ if (ret > 0) {
+ verbose(!quiet, "Skipping bad block at %08"PRIx64, offset);
+ continue;
+ } else if (ret < 0) {
+ if (errno == EOPNOTSUPP) {
+ noskipbad = 1;
+ if (isNAND)
+ return errmsg("%s: Bad block check not available", mtd_device);
+ } else
+ return sys_errmsg("%s: MTD get bad block failed", mtd_device);
+ }
+ }
- if(argc > 4)
- unlock = strtol(argv[4], NULL, 0);
- else
- unlock = 0;
+ show_progress(&mtd, offset, eb, eb_start, eb_cnt);
+ if (unlock) {
+ if (mtd_unlock(&mtd, fd, eb) != 0) {
+ sys_errmsg("%s: MTD unlock failure", mtd_device);
+ continue;
+ }
+ }
- // Open and size the device
- if ((Fd = open(argv[1],O_RDWR)) < 0)
- {
- fprintf(stderr,"File open error\n");
- return 8;
- }
+ if (mtd_erase(mtd_desc, &mtd, fd, eb) != 0) {
+ sys_errmsg("%s: MTD Erase failure", mtd_device);
+ continue;
+ }
- printf("Erase Total %d Units\n", count);
+ /* format for JFFS2 ? */
+ if (!jffs2)
+ continue;
- if (ioctl(Fd,MEMGETREGIONCOUNT,®count) == 0)
- {
- if(regcount == 0)
- {
- res = non_region_erase(Fd, start, count, unlock);
- }
- else
- {
- res = region_erase(Fd, start, count, unlock, regcount);
+ /* write cleanmarker */
+ if (isNAND) {
+ if (mtd_write_oob(mtd_desc, &mtd, fd, offset + clmpos, clmlen, &cleanmarker) != 0) {
+ sys_errmsg("%s: MTD writeoob failure", mtd_device);
+ continue;
+ }
+ } else {
+ if (lseek(fd, (loff_t)offset, SEEK_SET) < 0) {
+ sys_errmsg("%s: MTD lseek failure", mtd_device);
+ continue;
+ }
+ if (write(fd, &cleanmarker, sizeof(cleanmarker)) != sizeof(cleanmarker)) {
+ sys_errmsg("%s: MTD write failure", mtd_device);
+ continue;
+ }
}
+ verbose(!quiet, " Cleanmarker written at %"PRIx64, offset);
}
+ offset += mtd.eb_size;
+ show_progress(&mtd, offset, eb, eb_start, eb_cnt);
+ bareverbose(!quiet, "\n");
- return res;
+ return 0;
}
diff --git a/flash_eraseall b/flash_eraseall
new file mode 100755
index 0000000..c5539b3
--- /dev/null
+++ b/flash_eraseall
@@ -0,0 +1,4 @@
+#!/bin/sh
+echo "${0##*/} has been replaced by \`flash_erase <mtddev> 0 0\`; please use it" 1>&2
+[ $# -ne 0 ] && set -- "$@" 0 0
+exec flash_erase "$@"
diff --git a/flash_eraseall.c b/flash_eraseall.c
deleted file mode 100644
index cb6f632..0000000
--- a/flash_eraseall.c
+++ /dev/null
@@ -1,276 +0,0 @@
-/* eraseall.c -- erase the whole of a MTD device
-
- Copyright (C) 2000 Arcom Control System Ltd
-
- Renamed to flash_eraseall.c
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-#include <sys/types.h>
-#include <stdio.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <stdarg.h>
-#include <stdint.h>
-#include <libgen.h>
-#include <ctype.h>
-#include <time.h>
-#include <getopt.h>
-#include <sys/ioctl.h>
-#include <sys/mount.h>
-#include <crc32.h>
-#include <libmtd.h>
-
-#include <mtd/mtd-user.h>
-#include <mtd/jffs2-user.h>
-
-#define PROGRAM "flash_eraseall"
-#define VERSION "$Revision: 1.22 $"
-
-static const char *exe_name;
-static const char *mtd_device;
-static int quiet; /* true -- don't output progress */
-static int jffs2; /* format for jffs2 usage */
-
-static struct jffs2_unknown_node cleanmarker;
-int target_endian = __BYTE_ORDER;
-
-static void show_progress (struct mtd_dev_info *mtd, uint64_t start)
-{
- printf("\rErasing %d Kibyte @ %llx -- %2llu %% complete.",
- mtd->eb_size / 1024, (unsigned long long)start,
- (unsigned long long) start * 100 / mtd->size);
- fflush(stdout);
-}
-
-static void display_help (void)
-{
- printf("Usage: %s [OPTION] MTD_DEVICE\n"
- "Erases all of the specified MTD device.\n"
- "\n"
- " -j, --jffs2 format the device for jffs2\n"
- " -q, --quiet don't display progress messages\n"
- " --silent same as --quiet\n"
- " --help display this help and exit\n"
- " --version output version information and exit\n",
- exe_name);
-}
-
-
-static void display_version (void)
-{
- printf(PROGRAM " " VERSION "\n"
- "\n"
- "Copyright (C) 2000 Arcom Control Systems Ltd\n"
- "\n"
- PROGRAM " comes with NO WARRANTY\n"
- "to the extent permitted by law.\n"
- "\n"
- "You may redistribute copies of " PROGRAM "\n"
- "under the terms of the GNU General Public Licence.\n"
- "See the file `COPYING' for more information.\n");
-}
-
-int main (int argc, char *argv[])
-{
- libmtd_t mtd_desc;
- struct mtd_dev_info mtd;
- int fd, clmpos = 0, clmlen = 8, eb;
- int isNAND, bbtest = 1;
- int error = 0;
- uint64_t offset = 0;
-
- exe_name = argv[0];
- for (;;) {
- int option_index = 0;
- static const char *short_options = "jq";
- static const struct option long_options[] = {
- {"help", no_argument, 0, 0},
- {"version", no_argument, 0, 0},
- {"jffs2", no_argument, 0, 'j'},
- {"quiet", no_argument, 0, 'q'},
- {"silent", no_argument, 0, 'q'},
-
- {0, 0, 0, 0},
- };
-
- int c = getopt_long(argc, argv, short_options,
- long_options, &option_index);
- if (c == EOF)
- break;
-
- switch (c) {
- case 0:
- switch (option_index) {
- case 0:
- display_help();
- return 0;
- case 1:
- display_version();
- return 0;
- }
- break;
- case 'q':
- quiet = 1;
- break;
- case 'j':
- jffs2 = 1;
- break;
- case '?':
- error = 1;
- break;
- }
- }
- if (optind == argc) {
- fprintf(stderr, "%s: no MTD device specified\n", exe_name);
- error = 1;
- }
- if (error) {
- fprintf(stderr, "Try `%s --help' for more information.\n",
- exe_name);
- return 1;
- }
- mtd_device = argv[optind];
-
- mtd_desc = libmtd_open();
- if (mtd_desc == NULL) {
- fprintf(stderr, "%s: can't initialize libmtd\n", exe_name);
- return 1;
- }
-
- if ((fd = open(mtd_device, O_RDWR)) < 0) {
- fprintf(stderr, "%s: %s: %s\n", exe_name, mtd_device, strerror(errno));
- return 1;
- }
-
- if (mtd_get_dev_info(mtd_desc, mtd_device, &mtd) < 0) {
- fprintf(stderr, "%s: mtd_get_dev_info failed\n", exe_name);
- return 1;
- }
-
- isNAND = mtd.type == MTD_NANDFLASH ? 1 : 0;
-
- if (jffs2) {
- cleanmarker.magic = cpu_to_je16 (JFFS2_MAGIC_BITMASK);
- cleanmarker.nodetype = cpu_to_je16 (JFFS2_NODETYPE_CLEANMARKER);
- if (!isNAND)
- cleanmarker.totlen = cpu_to_je32 (sizeof (struct jffs2_unknown_node));
- else {
- struct nand_oobinfo oobinfo;
-
- if (ioctl(fd, MEMGETOOBSEL, &oobinfo) != 0) {
- fprintf(stderr, "%s: %s: unable to get NAND oobinfo\n", exe_name, mtd_device);
- return 1;
- }
-
- /* Check for autoplacement */
- if (oobinfo.useecc == MTD_NANDECC_AUTOPLACE) {
- /* Get the position of the free bytes */
- if (!oobinfo.oobfree[0][1]) {
- fprintf (stderr, " Eeep. Autoplacement selected and no empty space in oob\n");
- return 1;
- }
- clmpos = oobinfo.oobfree[0][0];
- clmlen = oobinfo.oobfree[0][1];
- if (clmlen > 8)
- clmlen = 8;
- } else {
- /* Legacy mode */
- switch (mtd.oob_size) {
- case 8:
- clmpos = 6;
- clmlen = 2;
- break;
- case 16:
- clmpos = 8;
- clmlen = 8;
- break;
- case 64:
- clmpos = 16;
- clmlen = 8;
- break;
- }
- }
- cleanmarker.totlen = cpu_to_je32(8);
- }
- cleanmarker.hdr_crc = cpu_to_je32 (mtd_crc32 (0, &cleanmarker, sizeof (struct jffs2_unknown_node) - 4));
- }
-
- for (eb = 0; eb < (mtd.size / mtd.eb_size); eb++) {
- offset = eb * mtd.eb_size;
- if (bbtest) {
- int ret = mtd_is_bad(&mtd, fd, eb);
- if (ret > 0) {
- if (!quiet)
- printf ("\nSkipping bad block at 0x%08llx\n", (unsigned long long)offset);
- continue;
- } else if (ret < 0) {
- if (errno == EOPNOTSUPP) {
- bbtest = 0;
- if (isNAND) {
- fprintf(stderr, "%s: %s: Bad block check not available\n", exe_name, mtd_device);
- return 1;
- }
- } else {
- fprintf(stderr, "\n%s: %s: MTD get bad block failed: %s\n", exe_name, mtd_device, strerror(errno));
- return 1;
- }
- }
- }
-
- if (!quiet)
- show_progress(&mtd, offset);
-
- if (mtd_erase(mtd_desc, &mtd, fd, eb) != 0) {
- fprintf(stderr, "\n%s: %s: MTD Erase failure: %s\n", exe_name, mtd_device, strerror(errno));
- continue;
- }
-
- /* format for JFFS2 ? */
- if (!jffs2)
- continue;
-
- /* write cleanmarker */
- if (isNAND) {
- if (mtd_write_oob(mtd_desc, &mtd, fd, offset + clmpos, clmlen, &cleanmarker) != 0) {
- fprintf(stderr, "\n%s: %s: MTD writeoob failure: %s\n", exe_name, mtd_device, strerror(errno));
- continue;
- }
- } else {
- if (lseek (fd, (loff_t)offset, SEEK_SET) < 0) {
- fprintf(stderr, "\n%s: %s: MTD lseek failure: %s\n", exe_name, mtd_device, strerror(errno));
- continue;
- }
- if (write (fd , &cleanmarker, sizeof (cleanmarker)) != sizeof (cleanmarker)) {
- fprintf(stderr, "\n%s: %s: MTD write failure: %s\n", exe_name, mtd_device, strerror(errno));
- continue;
- }
- }
- if (!quiet)
- printf (" Cleanmarker written at %llx.", (unsigned long long)offset);
- }
- if (!quiet) {
- show_progress(&mtd, offset);
- printf("\n");
- }
-
- return 0;
-}
-
--
1.7.2.3
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [PATCH v3] mtd-utils: unify flash_erase and flash_eraseall
2010-09-27 6:50 ` [PATCH v3] " Mike Frysinger
@ 2010-09-27 6:56 ` Artem Bityutskiy
0 siblings, 0 replies; 30+ messages in thread
From: Artem Bityutskiy @ 2010-09-27 6:56 UTC (permalink / raw)
To: Mike Frysinger; +Cc: linux-mtd
On Mon, 2010-09-27 at 02:50 -0400, Mike Frysinger wrote:
> These have overlapping functionality, and while flash_eraseall supports
> newer 64bit ioctls, flash_erase does not. So rather than graft support
> onto flash_erase, merge the functionality of two into flash_erase so we
> only have to support one util from now on.
>
> A simple wrapper is provided to ease old flash_eraseall users into the
> new combined flash_erase util.
>
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> ---
> v3
> - rebase after recent common.h changes
Pushed, thanks.
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 4/4] mtd-utils: unify flash_erase and flash_eraseall
2010-09-24 1:53 ` [PATCH 4/4] mtd-utils: unify flash_erase and flash_eraseall Mike Frysinger
2010-09-24 4:35 ` Jon Povey
2010-09-25 6:07 ` [PATCH 4/4 v2] " Mike Frysinger
@ 2010-09-28 9:46 ` Artem Bityutskiy
2 siblings, 0 replies; 30+ messages in thread
From: Artem Bityutskiy @ 2010-09-28 9:46 UTC (permalink / raw)
To: Mike Frysinger; +Cc: linux-mtd
On Thu, 2010-09-23 at 21:53 -0400, Mike Frysinger wrote:
> These have overlapping functionality, and while flash_eraseall supports
> newer 64bit ioctls, flash_erase does not. So rather than graft support
> onto flash_erase, merge the functionality of two into flash_erase so we
> only have to support one util from now on.
>
> A simple wrapper is provided to ease old flash_eraseall users into the
> new combined flash_erase util.
>
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
And BTW, thanks for good clean-ups!
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 30+ messages in thread
end of thread, other threads:[~2010-09-28 9:48 UTC | newest]
Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-24 1:53 [PATCH 1/4] libmtd: add lock/unlock helpers Mike Frysinger
2010-09-24 1:53 ` [PATCH 2/4] mtd-utils: new bareverbose() helper Mike Frysinger
2010-09-24 4:24 ` Jon Povey
2010-09-25 6:05 ` [PATCH 2/4 v2] " Mike Frysinger
2010-09-25 10:52 ` Artem Bityutskiy
2010-09-24 1:53 ` [PATCH 3/4] mtd-utils: new strtoX helpers Mike Frysinger
2010-09-24 4:31 ` Jon Povey
2010-09-24 5:35 ` Mike Frysinger
2010-09-24 6:13 ` Jon Povey
2010-09-24 12:34 ` Mike Frysinger
2010-09-25 6:06 ` [PATCH 3/4 v2] " Mike Frysinger
2010-09-25 10:54 ` Artem Bityutskiy
2010-09-25 18:59 ` Mike Frysinger
2010-09-25 19:31 ` Artem Bityutskiy
2010-09-25 19:37 ` Mike Frysinger
2010-09-26 11:42 ` Artem Bityutskiy
2010-09-26 11:41 ` Artem Bityutskiy
2010-09-27 6:39 ` Artem Bityutskiy
2010-09-27 6:42 ` [PATCH v3] " Mike Frysinger
2010-09-27 6:44 ` Artem Bityutskiy
2010-09-24 1:53 ` [PATCH 4/4] mtd-utils: unify flash_erase and flash_eraseall Mike Frysinger
2010-09-24 4:35 ` Jon Povey
2010-09-24 5:36 ` Mike Frysinger
2010-09-24 5:42 ` Jon Povey
2010-09-24 12:42 ` Mike Frysinger
2010-09-25 6:07 ` [PATCH 4/4 v2] " Mike Frysinger
2010-09-27 6:50 ` [PATCH v3] " Mike Frysinger
2010-09-27 6:56 ` Artem Bityutskiy
2010-09-28 9:46 ` [PATCH 4/4] " Artem Bityutskiy
2010-09-25 10:50 ` [PATCH 1/4] libmtd: add lock/unlock helpers Artem Bityutskiy
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).