MVME2100 flash mapping patch - please review

Oliver Korpilla okorpil at fh-landshut.de
Fri Apr 23 04:23:09 EDT 2004


Hello!

I patched my kernel.org 2.4.25 with an "older" release of mtd (file 
cfi_cmdset_0002.c is version 1.93 instead of 1.98, release was tagged 
mtd in CVS), and patched it with my patch as attached below this message.

This is my mtd-related output at booting:

Motorola MVME2100 flash device: 0x400000 at 0xff000000
Found: AMD AM29LV800BT
MVME2100 flash: Found 4 x16 devices at 0x0 in 32-bit mode
number of JEDEC chips: 1
Creating 2 MTD partitions on "MVME2100 flash":
0x00000000-0x00100000 : "MVME2100 flash BOOT partition"
0x00100000-0x00400000 : "MVME2100 flash rootfs partition"

I got the following output when executing some commands on it:

/ # eraseall /dev/mtd0
Erasing 256 Kibyte @ 3c0000 -- 93 % complete.
/ # einfo /dev/mtd0
Device /dev/mtd0 has 4 erase regions
Region 0 is at 0x0 with size 0x40000 and has 0xf blocks
Region 1 is at 0x3c0000 with size 0x20000 and has 0x1 blocks
Region 2 is at 0x3e0000 with size 0x8000 and has 0x2 blocks
Region 3 is at 0x3f0000 with size 0x10000 and has 0x1 blocks
/ # mtd_debug info /dev/mtd0
mtd.type = MTD_NORFLASH
mtd.flags = MTD_CAP_NORFLASH
mtd.size = 4194304 (4M)
mtd.erasesize = 262144 (256K)
mtd.oobblock = 0
mtd.oobsize = 0
mtd.ecctype = MTD_ECC_NONE
regions = 4

region[0].offset = 0x00000000
region[0].erasesize = 262144 (256K)
region[0].numblocks = 15
region[0].regionindex = 0
region[1].offset = 0x003c0000
region[1].erasesize = 131072 (128K)
region[1].numblocks = 1
region[1].regionindex = 1
region[2].offset = 0x003e0000
region[2].erasesize = 32768 (32K)
region[2].numblocks = 2
region[2].regionindex = 2
region[3].offset = 0x003f0000
region[3].erasesize = 65536 (64K)
region[3].numblocks = 1
region[3].regionindex = 3


Please comment on the patch as found below! I'm a newbie to mtd, and to 
be honest: My job is getting the board work, not writing a good driver, 
so hopefully this will suffice. Hope I didn't screw up to badly.

I pasted it into the message, hope it'll work for you.

Thanks in advance,
Oliver Korpilla

Here the patch - vs kernel.org 2.4.25 patched with the MTD with release 
mtd - modelled after mbx860.c

diff -urN linux-2.4.25/drivers/mtd/maps/Config.in 
linux-2.4.25-mtd_patch/drivers/mtd/maps/Config.in
--- linux-2.4.25/drivers/mtd/maps/Config.in     2004-04-22 
22:04:32.000000000 +0200
+++ linux-2.4.25-mtd_patch/drivers/mtd/maps/Config.in   2004-04-22 
21:54:06.000000000 +0200
@@ -35,8 +35,13 @@
  fi

  if [ "$CONFIG_PPC32" = "y" ]; then
-  if [ "$CONFIG_6xx" = "y" -a "$CONFIG_8260" = "y" ]; then
-    dep_tristate '  Flash device on SBC8240' CONFIG_MTD_SBC8240 
$CONFIG_MTD_JEDECPROBE
+  if [ "$CONFIG_6xx" = "y" ]; then
+    if [ "$CONFIG_8260" = "y" ]; then
+      dep_tristate '  Flash device on SBC8240' CONFIG_MTD_SBC8240 
$CONFIG_MTD_JEDECPROBE
+    fi
+    if [ "$CONFIG_MVME2100" = "y" ]; then
+      dep_tristate '  Flash device on MVME2100' CONFIG_MTD_MVME2100 
$CONFIG_MTD_JEDECPROBE
+    fi
    fi
    if [ "$CONFIG_8xx" = "y" ]; then
      if [ "$CONFIG_TQM8xxL" = "y" ]; then
diff -urN linux-2.4.25/drivers/mtd/maps/Makefile 
linux-2.4.25-mtd_patch/drivers/mtd/maps/Makefile
--- linux-2.4.25/drivers/mtd/maps/Makefile      2004-04-22 
22:04:32.000000000 +0200
+++ linux-2.4.25-mtd_patch/drivers/mtd/maps/Makefile    2004-04-22 
21:54:06.000000000 +0200
@@ -63,6 +63,7 @@
  obj-$(CONFIG_MTD_ARCTIC)       += arctic-mtd.o
  obj-$(CONFIG_MTD_H720X)                += h720x-flash.o
  obj-$(CONFIG_MTD_SBC8240)      += sbc8240.o
+obj-$(CONFIG_MTD_MVME2100)     += mvme2100.o
  obj-$(CONFIG_MTD_NOR_TOTO)     += omap-toto-flash.o
  obj-$(CONFIG_MTD_MPC1211)      += mpc1211.o
  obj-$(CONFIG_MTD_IXP425)       += ixp425.o
diff -urN linux-2.4.25/drivers/mtd/maps/mvme2100.c 
linux-2.4.25-mtd_patch/drivers/mtd/maps/mvme2100.c
--- linux-2.4.25/drivers/mtd/maps/mvme2100.c    1970-01-01 
01:00:00.000000000 +0100
+++ linux-2.4.25-mtd_patch/drivers/mtd/maps/mvme2100.c  2004-04-22 
21:54:06.000000000 +0200
@@ -0,0 +1,115 @@
+/*
+ * Handle mapping of the flash on MVME2100 boards.
+ *
+ * Author:      Oliver Korpilla
+ * Copyright:   (C) 2004 Systerra Computer GmbH
+ *
+ * Modelled after the mbx860.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <asm/io.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/map.h>
+#include <linux/mtd/partitions.h>+
+
+/* Soldered flash bank starts here */
+#define FLASH_ADDR 0xff000000
+/* Soldered flash bank contains 4MB by default */
+#define FLASH_SIZE 0x00400000
+
+/* Flash partition sizes */
+/* Reserve 1MB for the kernel */
+#define KERNEL_PARTITION_OFFSET 0x0
+#define KERNEL_PARTITION_SIZE   0x100000
+/* Use the other 3MB for the root filesystem */
+#define ROOTFS_PARTITION_OFFSET 0x100000
+#define ROOTFS_PARTITION_SIZE   0x300000
+
+
+#define NUM_PARTITIONS 2
+
+/* partition_info gives details on the logical partitions that the 
split the
+ * single flash device into. If the size if zero we use up to the end 
of the
+ * device. */
+static struct mtd_partition partition_info[]=
+  {
+    {
+      .name   = "MVME2100 flash BOOT partition",
+      .offset = KERNEL_PARTITION_OFFSET,
+      .size   = KERNEL_PARTITION_SIZE
+    },
+    {
+      .name   = "MVME2100 flash rootfs partition",
+      .offset = ROOTFS_PARTITION_OFFSET,
+      .size   = ROOTFS_PARTITION_SIZE
+    }
+  };
+
+static struct mtd_info *mymtd;
+
+struct map_info mvme2100_map = {
+        .name = "MVME2100 flash",
+        .size = FLASH_SIZE,
+        .phys = FLASH_ADDR,
+        .buswidth = 4,
+};
+
+int __init init_mvme2100(void)
+{
+  printk(KERN_NOTICE "Motorola MVME2100 flash device: 0x%x at 0x%x\n", 
FLASH_SIZE, FLASH_ADDR);
+
+  /* Remap flash physical to a virtual address */
+  mvme2100_map.virt = (unsigned long)ioremap(FLASH_ADDR, FLASH_SIZE);
+
+  /* Check for a failed mapping */
+  if (!mvme2100_map.virt) {
+    printk("Failed to ioremap\n");
+    return -EIO;
+  }
+  /* Initialize with the map data */
+  simple_map_init(&mvme2100_map);
+
+  /* Probe for a JEDEC chip  */
+  mymtd = do_map_probe("jedec_probe", &mvme2100_map);
+
+  /* Setup devices and partitions */
+  if (mymtd) {
+    mymtd->owner = THIS_MODULE;
+    add_mtd_device(mymtd);
+    add_mtd_partitions(mymtd, partition_info, NUM_PARTITIONS);
+    return 0;
+  }
+
+  /* Unmap the temporary virtual address */
+  iounmap((void *)mvme2100_map.virt);
+  return -ENXIO;
+}
+
+static void __exit cleanup_mvme2100(void)
+{
+  if (mymtd) {
+    del_mtd_device(mymtd);
+    map_destroy(mymtd);
+  }
+  if (mvme2100_map.virt) {
+    iounmap((void *)mvme2100_map.virt);
+    mvme2100_map.virt = 0;
+  }
+}
+
+module_init(init_mvme2100);
+module_exit(cleanup_mvme2100);
+
+MODULE_AUTHOR("Oliver Korpilla <okorpil at fh-landshut.de>");
+MODULE_DESCRIPTION("MTD map driver for Motorola MVME2100 board");
+MODULE_LICENSE("GPL");





More information about the linux-mtd mailing list