linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Shachar Shemesh <shachar@shemesh.biz>
To: Linux MTD <linux-mtd@lists.infradead.org>
Subject: Wrong flash type in m25p80 driver
Date: Sun, 16 May 2010 18:40:07 +0300	[thread overview]
Message-ID: <4BF011D7.4010907@shemesh.biz> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1683 bytes --]

Hi all,

I've found a problem in the m25p80 driver (drives a bunch of SPI flash 
chips based on similar commands). While the commands that drive those 
chips are almost exactly the same, some variance between the chips does 
exist. Almost all of them have 64KB erase blocks, but some also have 
smaller 4KB erase sectors (terminology differs between chips, but the 
two sizes, fairly universally, don't).

My understanding of the mtd_info struct is that this is precisely what 
the "writesize" field is for - specifying different maximal and minimal 
erase sizes. The current m25p80 driver does not specify the two sizes 
correctly, which leads to total failure when trying to use it to create 
UBIFS volumes.

The second problem I'm having with this driver is that it reports itself 
as NOR flash. This is obviously not the case, but I'm a bit at a loss as 
to what is. These are not, exactly, NAND flashes. DATAFLASH is closer to 
the mark, as both these and the DATAFLASH had SPI interfaces, but 
setting the type to DATAFLASH triggers nasty behavior by the jffs2 code, 
which assumes that data flashes have erase blocks of either 536 or 1056 
bytes. The result is that it allocates 512KB of erase blocks, causing a 
1.5MB of overhead on each volume. For a 4MB flash, that is a large 
overhead to accept.

I'm attaching a patch to the m25p80 driver. I would love to receive 
comments on the correct flash type to put there for proper operation. 
Something that is compatible with jffs2 would be appreciated. I've 
written a fix to the jffs2 code, but I'm not sure of its correctness.

Thanks,
Shachar

-- 
Shachar Shemesh
Lingnu Open Source Consulting Ltd.
http://www.lingnu.com


[-- Attachment #1.2: Type: text/html, Size: 1971 bytes --]

[-- Attachment #2: erasesize.patch --]
[-- Type: text/x-patch, Size: 2299 bytes --]

Index: drivers/mtd/devices/m25p80.c
===================================================================
--- drivers/mtd/devices/m25p80.c	(revision 3333)
+++ drivers/mtd/devices/m25p80.c	(working copy)
@@ -212,7 +212,7 @@
 {
 	DEBUG(MTD_DEBUG_LEVEL3, "%s: %s %dKiB at 0x%08x\n",
 			dev_name(&flash->spi->dev), __func__,
-			flash->mtd.erasesize / 1024, offset);
+			flash->mtd.writesize / 1024, offset);
 
 	/* Wait until finished previous write command. */
 	if (wait_till_ready(flash))
@@ -255,7 +255,7 @@
 	/* sanity checks */
 	if (instr->addr + instr->len > flash->mtd.size)
 		return -EINVAL;
-	div_u64_rem(instr->len, mtd->erasesize, &rem);
+	div_u64_rem(instr->len, mtd->writesize, &rem);
 	if (rem)
 		return -EINVAL;
 
@@ -286,8 +286,8 @@
 				return -EIO;
 			}
 
-			addr += mtd->erasesize;
-			len -= mtd->erasesize;
+			addr += mtd->writesize;
+			len -= mtd->writesize;
 		}
 	}
 
@@ -831,9 +831,8 @@
 	else
 		flash->mtd.name = dev_name(&spi->dev);
 
-	flash->mtd.type = MTD_NORFLASH;
-	flash->mtd.writesize = 1;
-	flash->mtd.flags = MTD_CAP_NORFLASH;
+	flash->mtd.type = MTD_DATAFLASH;
+	flash->mtd.flags = MTD_WRITEABLE;
 	flash->mtd.size = info->sector_size * info->n_sectors;
 	flash->mtd.erase = m25p80_erase;
 	flash->mtd.read = m25p80_read;
@@ -845,12 +844,13 @@
 		flash->mtd.write = m25p80_write;
 
 	/* prefer "small sector" erase if possible */
-	if (info->flags & SECT_4K) {
+	flash->mtd.erasesize = info->sector_size;
+	if (info->flags & SECT_4K && (info->sector_size%4096)==0 ) {
 		flash->erase_opcode = OPCODE_BE_4K;
-		flash->mtd.erasesize = 4096;
+		flash->mtd.writesize = 4096;
 	} else {
 		flash->erase_opcode = OPCODE_SE;
-		flash->mtd.erasesize = info->sector_size;
+		flash->mtd.writesize = info->sector_size;
 	}
 
 	flash->mtd.dev.parent = &spi->dev;
@@ -860,10 +860,11 @@
 
 	DEBUG(MTD_DEBUG_LEVEL2,
 		"mtd .name = %s, .size = 0x%llx (%lldMiB) "
-			".erasesize = 0x%.8x (%uKiB) .numeraseregions = %d\n",
+			".erasesize = 0x%.8x (%uKiB) .writesize = 0x%.8x (%uKiB) .numeraseregions = %d\n",
 		flash->mtd.name,
 		(long long)flash->mtd.size, (long long)(flash->mtd.size >> 20),
 		flash->mtd.erasesize, flash->mtd.erasesize / 1024,
+		flash->mtd.writesize, flash->mtd.writesize / 1024,
 		flash->mtd.numeraseregions);
 
 	if (flash->mtd.numeraseregions)

             reply	other threads:[~2010-05-16 15:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-16 15:40 Shachar Shemesh [this message]
2010-05-16 18:40 ` Wrong flash type in m25p80 driver Mike Frysinger
     [not found]   ` <4BF041A3.70304@shemesh.biz>
2010-05-16 19:17     ` Mike Frysinger
     [not found]       ` <4BF04DBE.5020309@shemesh.biz>
2010-05-17  4:54         ` Mike Frysinger
2010-05-17 16:50           ` Carl-Daniel Hailfinger
2010-05-18  6:37             ` Shachar Shemesh
2010-05-18 12:12               ` Carl-Daniel Hailfinger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4BF011D7.4010907@shemesh.biz \
    --to=shachar@shemesh.biz \
    --cc=linux-mtd@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).