Patchwork flash_eraseall: only add cleanmarkers on known flashtypes

login
register
mail settings
Submitter Sebastian Siewior
Date March 23, 2009, 10:42 p.m.
Message ID <1237848138-18157-3-git-send-email-sebastian@breakpoint.cc>
Download mbox | patch
Permalink /patch/24937/
State New, archived
Headers show

Comments

Sebastian Siewior - March 23, 2009, 10:42 p.m.
- data flash and an UBI flash do not use clean markers. Do not create
  them, even if the users says so.
- don't generate clean markers on unknown media/new media. Theoreticly
  nobody should use jffs2 on new media anyway :)

Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
---
 flash_eraseall.c |   25 ++++++++++++++++++++++---
 1 files changed, 22 insertions(+), 3 deletions(-)
Artem Bityutskiy - March 24, 2009, 6:02 a.m.
On Mon, 2009-03-23 at 23:42 +0100, Sebastian Andrzej Siewior wrote:
> +       switch (meminfo->type) {
> +       case MTD_ROM:
> +       case MTD_RAM:
> +       case MTD_NORFLASH:
>                 cleanmarker.totlen = cpu_to_je32(sizeof(struct
> jffs2_unknown_node));
> -       else {
> -               struct nand_oobinfo oobinfo;
> +               break;
> +
> +       case MTD_DATAFLASH:
> +       case MTD_UBIVOLUME:
> +               fprintf(stderr, "JFFS2 layout not supported on this
> flash.\n");
> +               return -1;
> +               break;

This should also include MLC NAND flash. To make you nice patches
even better you should call MEMGETOOBSEL ioctl in case of NAND and
check if there is really enough bytes for clean-marker.

But I guess you do not have to do this.
Artem Bityutskiy - March 24, 2009, 6:03 a.m.
On Tue, 2009-03-24 at 08:02 +0200, Artem Bityutskiy wrote:
> On Mon, 2009-03-23 at 23:42 +0100, Sebastian Andrzej Siewior wrote:
> > +       switch (meminfo->type) {
> > +       case MTD_ROM:
> > +       case MTD_RAM:
> > +       case MTD_NORFLASH:
> >                 cleanmarker.totlen = cpu_to_je32(sizeof(struct
> > jffs2_unknown_node));
> > -       else {
> > -               struct nand_oobinfo oobinfo;
> > +               break;
> > +
> > +       case MTD_DATAFLASH:
> > +       case MTD_UBIVOLUME:
> > +               fprintf(stderr, "JFFS2 layout not supported on this
> > flash.\n");
> > +               return -1;
> > +               break;
> 
> This should also include MLC NAND flash. To make you nice patches
> even better you should call MEMGETOOBSEL ioctl in case of NAND and
> check if there is really enough bytes for clean-marker.
> 
> But I guess you do not have to do this.

Err, sorry, this seems to be already there :-) Need some coffee.

Patch

diff --git a/flash_eraseall.c b/flash_eraseall.c
index 3da56ee..0a4010e 100644
--- a/flash_eraseall.c
+++ b/flash_eraseall.c
@@ -60,12 +60,25 @@  static int clmlen = 8;
 
 static int prepare_clean_marker(mtd_info_t *meminfo)
 {
+	struct nand_oobinfo oobinfo;
+
 	cleanmarker.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
 	cleanmarker.nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER);
-	if (meminfo->type != MTD_NANDFLASH)
+
+	switch (meminfo->type) {
+	case MTD_ROM:
+	case MTD_RAM:
+	case MTD_NORFLASH:
 		cleanmarker.totlen = cpu_to_je32(sizeof(struct jffs2_unknown_node));
-	else {
-		struct nand_oobinfo oobinfo;
+		break;
+
+	case MTD_DATAFLASH:
+	case MTD_UBIVOLUME:
+		fprintf(stderr, "JFFS2 layout not supported on this flash.\n");
+		return -1;
+		break;
+
+	case MTD_NANDFLASH:
 
 		if (ioctl(fd, MEMGETOOBSEL, &oobinfo) != 0) {
 			fprintf(stderr, "%s: %s: unable to get NAND oobinfo\n",
@@ -103,6 +116,12 @@  static int prepare_clean_marker(mtd_info_t *meminfo)
 			}
 		}
 		cleanmarker.totlen = cpu_to_je32(8);
+		break;
+	default:
+		fprintf(stderr, "Unknown flash type, just erasing\n");
+		return -1;
+		break;
+
 	}
 	cleanmarker.hdr_crc = cpu_to_je32(crc32(0, &cleanmarker,
 				sizeof(struct jffs2_unknown_node) - 4));