add brcm47xx mtd corruption fix by b.sander (#1502)
[openwrt.git] / target / linux / brcm47xx-2.6 / files / drivers / mtd / maps / bcm47xx-flash.c
index 93cda8b..6a82f36 100644 (file)
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
+#include <linux/sched.h>
 #include <linux/wait.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/map.h>
 #ifdef CONFIG_MTD_PARTITIONS
 #include <linux/mtd/partitions.h>
 #endif
-#include <linux/squashfs_fs.h>
-#include <linux/jffs2.h>
 #include <linux/crc32.h>
+#ifdef CONFIG_SSB
 #include <linux/ssb/ssb.h>
+#endif
 #include <asm/io.h>
 
 
@@ -74,26 +75,24 @@ struct trx_header {
 #define WINDOW_SIZE 0x400000
 #define BUSWIDTH 2
 
+#ifdef CONFIG_SSB
 extern struct ssb_bus ssb;
+#endif
 static struct mtd_info *bcm947xx_mtd;
 
 static void bcm947xx_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
 {
-#define MIPS_MEMCPY_ALIGN 4
-       map_word ret;
-       ssize_t transfer;
-       ssize_t done = 0;
-       if ((len >= MIPS_MEMCPY_ALIGN) && (!(from & (MIPS_MEMCPY_ALIGN - 1))) && (!(((unsigned int)to & (MIPS_MEMCPY_ALIGN - 1))))) {
-               done = len & ~(MIPS_MEMCPY_ALIGN - 1);
-               memcpy_fromio(to, map->virt + from, done);
-       }
-       while (done < len) {
-               ret = map->read(map, from + done);
-               transfer = len - done;
-               if (transfer > map->bankwidth)
-                       transfer = map->bankwidth;
-               memcpy((void *)((unsigned long)to + done), &ret.x[0], transfer);
-               done += transfer;
+       if (len==1) {
+               memcpy_fromio(to, map->virt + from, len);
+       } else {
+               int i;
+               u16 *dest = (u16 *) to;
+               u16 *src  = (u16 *) (map->virt + from);
+               for (i = 0; i < (len / 2); i++) {
+                       dest[i] = src[i];
+               }
+               if (len & 1)
+                       *((u8 *)dest+len-1) = src[i] & 0xff;
        }
 }
 
@@ -111,7 +110,6 @@ static struct mtd_partition bcm947xx_parts[] = {
        { name: "linux", offset: 0, size: 0, },
        { name: "rootfs", offset: 0, size: 0, },
        { name: "nvram", offset: 0, size: 0, },
-       { name: "OpenWrt", offset: 0, size: 0, },
        { name: NULL, },
 };
 
@@ -275,24 +273,8 @@ find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part)
        if (mtd->read(mtd, part->offset, sizeof(buf), &len, buf) || len != sizeof(buf))
                return 0;
 
-       if (*((__u32 *) buf) == SQUASHFS_MAGIC) {
-               printk(KERN_INFO "%s: Filesystem type: squashfs, size=0x%x\n", mtd->name, (u32) sb->bytes_used);
-
-               /* Update the squashfs partition size based on the superblock info */
-               part->size = sb->bytes_used;
-               len = part->offset + part->size;
-               len +=  (mtd->erasesize - 1);
-               len &= ~(mtd->erasesize - 1);
-               part->size = len - part->offset;
-       } else if (*((__u16 *) buf) == JFFS2_MAGIC_BITMASK) {
-               printk(KERN_INFO "%s: Filesystem type: jffs2\n", mtd->name);
-
-               /* Move the squashfs outside of the trx */
-               part->size = 0;
-       } else {
-               printk(KERN_INFO "%s: Filesystem type: unknown\n", mtd->name);
-               return 0;
-       }
+       /* Move the fs outside of the trx */
+       part->size = 0;
 
        if (trx.len != part->offset + part->size - off) {
                /* Update the trx offsets and length */
@@ -370,34 +352,8 @@ init_mtd_partitions(struct mtd_info *mtd, size_t size)
        }
 
        /* find and size rootfs */
-       if (find_root(mtd,size,&bcm947xx_parts[2])==0) {
-               /* entirely jffs2 */
-               bcm947xx_parts[4].name = NULL;
-               bcm947xx_parts[2].size = size - bcm947xx_parts[2].offset - 
-                               bcm947xx_parts[3].size;
-       } else {
-               /* legacy setup */
-               /* calculate leftover flash, and assign it to the jffs2 partition */
-               if (cfe_size != 384 * 1024) {
-                       bcm947xx_parts[4].offset = bcm947xx_parts[2].offset + 
-                               bcm947xx_parts[2].size;
-                       if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
-                               bcm947xx_parts[4].offset += mtd->erasesize - 
-                                       (bcm947xx_parts[4].offset % mtd->erasesize);
-                       }
-                       bcm947xx_parts[4].size = bcm947xx_parts[3].offset - 
-                               bcm947xx_parts[4].offset;
-               } else {
-                       bcm947xx_parts[4].offset = bcm947xx_parts[2].offset + 
-                               bcm947xx_parts[2].size;
-                       if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
-                               bcm947xx_parts[4].offset += mtd->erasesize - 
-                                       (bcm947xx_parts[4].offset % mtd->erasesize);
-                       }
-                       bcm947xx_parts[4].size = size - bcm947xx_parts[3].size - 
-                               bcm947xx_parts[4].offset;
-               }
-       }
+       find_root(mtd,size,&bcm947xx_parts[2]);
+       bcm947xx_parts[2].size = size - bcm947xx_parts[2].offset - bcm947xx_parts[3].size;
 
        return bcm947xx_parts;
 }
@@ -405,13 +361,17 @@ init_mtd_partitions(struct mtd_info *mtd, size_t size)
 
 int __init init_bcm947xx_map(void)
 {
+#ifdef CONFIG_SSB
        struct ssb_mipscore *mcore = &ssb.mipscore;
+#endif
        size_t size;
        int ret = 0;
 #ifdef CONFIG_MTD_PARTITIONS
        struct mtd_partition *parts;
        int i;
 #endif
+
+#ifdef CONFIG_SSB
        u32 window = mcore->flash_window;
        u32 window_size = mcore->flash_window_size;
 
@@ -419,21 +379,27 @@ int __init init_bcm947xx_map(void)
        bcm947xx_map.phys = window;
        bcm947xx_map.size = window_size;
        bcm947xx_map.virt = ioremap_nocache(window, window_size);
+#else
+       printk("flash init: 0x%08x 0x%08x\n", WINDOW_ADDR, WINDOW_SIZE);
+       bcm947xx_map.virt = ioremap_nocache(WINDOW_ADDR, WINDOW_SIZE);
+#endif
 
        if (!bcm947xx_map.virt) {
                printk("Failed to ioremap\n");
                return -EIO;
        }
+
        simple_map_init(&bcm947xx_map);
        
-       bcm947xx_map.copy_from = bcm947xx_map_copy_from;
-       
        if (!(bcm947xx_mtd = do_map_probe("cfi_probe", &bcm947xx_map))) {
                printk("Failed to do_map_probe\n");
                iounmap((void *)bcm947xx_map.virt);
                return -ENXIO;
        }
 
+       /* override copy_from routine */
+       bcm947xx_map.copy_from = bcm947xx_map_copy_from;
+
        bcm947xx_mtd->owner = THIS_MODULE;
 
        size = bcm947xx_mtd->size;
This page took 0.032241 seconds and 4 git commands to generate.