mtd: map_rom: Support UBI on ROM

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Mon Feb 16 18:59:03 PST 2015


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=6958024ad5cdd78deae4da47a8722b06317dff45
Commit:     6958024ad5cdd78deae4da47a8722b06317dff45
Parent:     3fc1cf5f0af4b625adff03c610f188fa8bc89911
Author:     Aaron Sierra <asierra at xes-inc.com>
AuthorDate: Thu Sep 25 12:20:24 2014 -0500
Committer:  Brian Norris <computersforpeace at gmail.com>
CommitDate: Fri Jan 9 23:24:27 2015 -0800

    mtd: map_rom: Support UBI on ROM
    
    UBI needs to know the physical erase block size, even on read-only
    devices, since it defines the on-device layout. Use a device-tree
    provided value to support previously written UBI on read-only NOR.
    
    UBI also needs a non-zero writebufsize, so we set it to one.
    
    Note: This was implemented because hardware write-protected CFI
          NOR cannot be probed for the physical erase block size.
    
    Signed-off-by: Joe Schultz <jschultz at xes-inc.ccom>
    Signed-off-by: Aaron Sierra <asierra at xes-inc.ccom>
    [Brian: removed unneeded #ifdef, note 'optional' erase-size property]
    Signed-off-by: Brian Norris <computersforpeace at gmail.com>
---
 Documentation/devicetree/bindings/mtd/mtd-physmap.txt |  5 +++++
 drivers/mtd/chips/map_rom.c                           | 13 ++++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/mtd/mtd-physmap.txt b/Documentation/devicetree/bindings/mtd/mtd-physmap.txt
index 6b9f680..4a0a48b 100644
--- a/Documentation/devicetree/bindings/mtd/mtd-physmap.txt
+++ b/Documentation/devicetree/bindings/mtd/mtd-physmap.txt
@@ -36,6 +36,11 @@ are defined:
  - vendor-id : Contains the flash chip's vendor id (1 byte).
  - device-id : Contains the flash chip's device id (1 byte).
 
+For ROM compatible devices (and ROM fallback from cfi-flash), the following
+additional (optional) property is defined:
+
+ - erase-size : The chip's physical erase block size in bytes.
+
 The device tree may optionally contain sub-nodes describing partitions of the
 address space. See partition.txt for more detail.
 
diff --git a/drivers/mtd/chips/map_rom.c b/drivers/mtd/chips/map_rom.c
index 47a43cf..e67f73a 100644
--- a/drivers/mtd/chips/map_rom.c
+++ b/drivers/mtd/chips/map_rom.c
@@ -11,6 +11,7 @@
 #include <linux/errno.h>
 #include <linux/slab.h>
 #include <linux/init.h>
+#include <linux/of.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/map.h>
 
@@ -28,6 +29,15 @@ static struct mtd_chip_driver maprom_chipdrv = {
 	.module	= THIS_MODULE
 };
 
+static unsigned int default_erasesize(struct map_info *map)
+{
+	const __be32 *erase_size = NULL;
+
+	erase_size = of_get_property(map->device_node, "erase-size", NULL);
+
+	return !erase_size ? map->size : be32_to_cpu(*erase_size);
+}
+
 static struct mtd_info *map_rom_probe(struct map_info *map)
 {
 	struct mtd_info *mtd;
@@ -47,8 +57,9 @@ static struct mtd_info *map_rom_probe(struct map_info *map)
 	mtd->_sync = maprom_nop;
 	mtd->_erase = maprom_erase;
 	mtd->flags = MTD_CAP_ROM;
-	mtd->erasesize = map->size;
+	mtd->erasesize = default_erasesize(map);
 	mtd->writesize = 1;
+	mtd->writebufsize = 1;
 
 	__module_get(THIS_MODULE);
 	return mtd;



More information about the linux-mtd-cvs mailing list