Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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@xes-inc.ccom>
Signed-off-by: Aaron Sierra <asierra@xes-inc.ccom>
[Brian: removed unneeded #ifdef, note 'optional' erase-size property]
Signed-off-by: Brian Norris <computersforpeace@gmail.com>

authored by

Aaron Sierra and committed by
Brian Norris
6958024a 3fc1cf5f

+17 -1
+5
Documentation/devicetree/bindings/mtd/mtd-physmap.txt
··· 36 36 - vendor-id : Contains the flash chip's vendor id (1 byte). 37 37 - device-id : Contains the flash chip's device id (1 byte). 38 38 39 + For ROM compatible devices (and ROM fallback from cfi-flash), the following 40 + additional (optional) property is defined: 41 + 42 + - erase-size : The chip's physical erase block size in bytes. 43 + 39 44 The device tree may optionally contain sub-nodes describing partitions of the 40 45 address space. See partition.txt for more detail. 41 46
+12 -1
drivers/mtd/chips/map_rom.c
··· 11 11 #include <linux/errno.h> 12 12 #include <linux/slab.h> 13 13 #include <linux/init.h> 14 + #include <linux/of.h> 14 15 #include <linux/mtd/mtd.h> 15 16 #include <linux/mtd/map.h> 16 17 ··· 28 27 .name = "map_rom", 29 28 .module = THIS_MODULE 30 29 }; 30 + 31 + static unsigned int default_erasesize(struct map_info *map) 32 + { 33 + const __be32 *erase_size = NULL; 34 + 35 + erase_size = of_get_property(map->device_node, "erase-size", NULL); 36 + 37 + return !erase_size ? map->size : be32_to_cpu(*erase_size); 38 + } 31 39 32 40 static struct mtd_info *map_rom_probe(struct map_info *map) 33 41 { ··· 57 47 mtd->_sync = maprom_nop; 58 48 mtd->_erase = maprom_erase; 59 49 mtd->flags = MTD_CAP_ROM; 60 - mtd->erasesize = map->size; 50 + mtd->erasesize = default_erasesize(map); 61 51 mtd->writesize = 1; 52 + mtd->writebufsize = 1; 62 53 63 54 __module_get(THIS_MODULE); 64 55 return mtd;