From dwmw2 at infradead.org  Mon Aug 11 05:00:48 2003
From: dwmw2 at infradead.org (David Woodhouse)
Date: Mon May 15 21:48:41 2006
Subject: mtd/drivers/mtd ftl.c,1.51,1.52
Message-ID: <E19m8Xn-0003ph-00@phoenix.infradead.org>

Update of /home/cvs/mtd/drivers/mtd
In directory phoenix.infradead.org:/tmp/cvs-serv14712

Modified Files:
	ftl.c 
Log Message:
Remove bogus check in NumEraseUnits


Index: ftl.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/ftl.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- ftl.c	23 Jun 2003 12:00:08 -0000	1.51
+++ ftl.c	11 Aug 2003 09:00:44 -0000	1.52
@@ -188,7 +188,7 @@
 	printk(KERN_NOTICE "ftl_cs: FTL header not found.\n");
 	return -ENOENT;
     }
-    if ((le16_to_cpu(header.NumEraseUnits) > 65536) || header.BlockSize != 9 ||
+    if (header.BlockSize != 9 ||
 	(header.EraseUnitSize < 10) || (header.EraseUnitSize > 31) ||
 	(header.NumTransferUnits >= le16_to_cpu(header.NumEraseUnits))) {
 	printk(KERN_NOTICE "ftl_cs: FTL header corrupt!\n");


From dwmw2 at infradead.org  Mon Aug 11 06:37:07 2003
From: dwmw2 at infradead.org (David Woodhouse)
Date: Mon May 15 21:48:41 2006
Subject: mtd/drivers/mtd/chips cfi_cmdset_0001.c,1.128,1.129
Message-ID: <E19mA31-0007Zp-00@phoenix.infradead.org>

Update of /home/cvs/mtd/drivers/mtd/chips
In directory phoenix.infradead.org:/tmp/cvs-serv29106

Modified Files:
	cfi_cmdset_0001.c 
Log Message:
Fix check for !map->virt case in point


Index: cfi_cmdset_0001.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/chips/cfi_cmdset_0001.c,v
retrieving revision 1.128
retrieving revision 1.129
diff -u -r1.128 -r1.129
--- cfi_cmdset_0001.c	22 Jul 2003 13:23:38 -0000	1.128
+++ cfi_cmdset_0001.c	11 Aug 2003 10:37:04 -0000	1.129
@@ -494,12 +494,10 @@
 	int chipnum;
 	int ret = 0;
 
-	if (from + len > mtd->size)
+	if (!map->virt || (from + len > mtd->size))
 		return -EINVAL;
 	
 	*mtdbuf = (void *)map->virt + from;
-	if(*mtdbuf == NULL)
-		return -EINVAL; /* can not point this region */
 	*retlen = 0;
 
 	/* Now lock the chip(s) to POINT state */


From gleixner at infradead.org  Mon Aug 11 08:41:09 2003
From: gleixner at infradead.org (gleixner@infradead.org)
Date: Mon May 15 21:48:41 2006
Subject: mtd/drivers/mtd/chips cfi_cmdset_0001.c,1.129,1.130
Message-ID: <E19mBz3-00075S-00@phoenix.infradead.org>

Update of /home/cvs/mtd/drivers/mtd/chips
In directory phoenix.infradead.org:/tmp/cvs-serv27013

Modified Files:
	cfi_cmdset_0001.c 
Log Message:
initialize cfi->cmdset_priv before calling fixup, else oops in fixupp_intelstrata

Index: cfi_cmdset_0001.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/chips/cfi_cmdset_0001.c,v
retrieving revision 1.129
retrieving revision 1.130
diff -u -r1.129 -r1.130
--- cfi_cmdset_0001.c	11 Aug 2003 10:37:04 -0000	1.129
+++ cfi_cmdset_0001.c	11 Aug 2003 12:41:05 -0000	1.130
@@ -199,6 +199,9 @@
 		extp->BlkStatusRegMask = le16_to_cpu(extp->BlkStatusRegMask);
 		extp->ProtRegAddr = le16_to_cpu(extp->ProtRegAddr);
 
+		/* Install our own private info structure */
+		cfi->cmdset_priv = extp;	
+
 		cfi_fixup(map, fixup_table);
 			
 #ifdef DEBUG_CFI_FEATURES
@@ -209,8 +212,6 @@
 		if(extp->SuspendCmdSupport & 1) {
 			printk(KERN_NOTICE "cfi_cmdset_0001: Erase suspend on write enabled\n");
 		}
-		/* Install our own private info structure */
-		cfi->cmdset_priv = extp;	
 	}
 
 	for (i=0; i< cfi->numchips; i++) {


From dwmw2 at infradead.org  Tue Aug 19 05:19:40 2003
From: dwmw2 at infradead.org (David Woodhouse)
Date: Mon May 15 21:48:41 2006
Subject: mtd/drivers/mtd/maps Config.in,1.52,1.53
Message-ID: <E19p2eS-00030C-00@phoenix.infradead.org>

Update of /home/cvs/mtd/drivers/mtd/maps
In directory phoenix.infradead.org:/tmp/cvs-serv11521/maps

Modified Files:
	Config.in 
Log Message:
MIPS map drivers enabled again

Index: Config.in
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/maps/Config.in,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -r1.52 -r1.53
--- Config.in	29 May 2003 09:44:18 -0000	1.52
+++ Config.in	19 Aug 2003 09:19:37 -0000	1.53
@@ -67,11 +67,13 @@
   fi
 fi
 
-if [ "$CONFIG_MIPS_PB1000" = "y" -o  "$CONFIG_MIPS_PB1100" = "y" -o "$CONFIG_MIPS_PB1500" = "y" ]; then
-   tristate '  Pb1x00 MTD support' CONFIG_MTD_PB1XXX
-   if [ "$CONFIG_MIPS_PB1500" = "y" -o "$CONFIG_MIPS_PB1100" = "m" ]; then
-      bool '  Pb1x00 boot flash device' CONFIG_MTD_PB1500_BOOT 
-      bool '  Pb1x00 user flash device (2nd 32MiB bank)' CONFIG_MTD_PB1500_USER
+if [ "$CONFIG_MIPS" = "y" -o "$CONFIG_MIPS64" = "y" ]; then
+   if [ "$CONFIG_MIPS_PB1000" = "y" -o  "$CONFIG_MIPS_PB1100" = "y" -o "$CONFIG_MIPS_PB1500" = "y" ]; then
+      tristate '  Pb1x00 MTD support' CONFIG_MTD_PB1XXX
+      if [ "$CONFIG_MIPS_PB1500" = "y" -o "$CONFIG_MIPS_PB1100" = "m" ]; then
+         bool '  Pb1x00 boot flash device' CONFIG_MTD_PB1500_BOOT 
+         bool '  Pb1x00 user flash device (2nd 32MiB bank)' CONFIG_MTD_PB1500_USER
+      fi
    fi
    dep_tristate '  Flash chip mapping on ITE QED-4N-S01B, Globespan IVR or custom board' CONFIG_MTD_CSTM_MIPS_IXX $CONFIG_MTD_CFI $CONFIG_MTD_JEDEC $CONFIG_MTD_PARTITIONS 
    if [ "$CONFIG_MTD_CSTM_MIPS_IXX" = "y" -o "$CONFIG_MTD_CSTM_MIPS_IXX" = "m" ]; then


From dwmw2 at infradead.org  Tue Aug 19 05:24:39 2003
From: dwmw2 at infradead.org (David Woodhouse)
Date: Mon May 15 21:48:41 2006
Subject: mtd/patches Configure.help,1.41,1.42
Message-ID: <E19p2jG-00031B-00@phoenix.infradead.org>

Update of /home/cvs/mtd/patches
In directory phoenix.infradead.org:/tmp/cvs-serv11575/patches

Modified Files:
	Configure.help 
Log Message:
MS02-NV patch from Maciej W. Rozycki.


Index: Configure.help
===================================================================
RCS file: /home/cvs/mtd/patches/Configure.help,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- Configure.help	27 Nov 2002 00:24:38 -0000	1.41
+++ Configure.help	19 Aug 2003 09:24:36 -0000	1.42
@@ -729,6 +729,18 @@
   really usefull if you are developing on this driver or suspect a possible
   hardware or driver bug.  If unsure say N.
 
+DEC MS02-NV NVRAM module support
+CONFIG_MTD_MS02NV
+  This is an MTD driver for the DEC's MS02-NV (54-20948-01) battery
+  backed-up NVRAM module.  The module was originally meant as an NFS
+  accelerator.  Say Y here if you have a DECstation 5000/2x0 or a
+  DECsystem 5900 equipped with such a module.
+
+  If you want to compile this driver as a module ( = code which can be
+  inserted in and removed from the running kernel whenever you want),
+  say M here and read <file:Documentation/modules.txt>.  The module will
+  be called ms02-nv.o.
+
 Use extra onboard system memory as MTD device
 CONFIG_MTD_SLRAM
   If your CPU cannot cache all of the physical memory in your machine,


From dwmw2 at infradead.org  Tue Aug 19 05:24:38 2003
From: dwmw2 at infradead.org (David Woodhouse)
Date: Mon May 15 21:48:41 2006
Subject: 
 mtd/drivers/mtd/devices Kconfig,1.5,1.6 ms02-nv.c,1.4,1.5 ms02-nv.h,1.1,1.2
Message-ID: <E19p2jG-000316-00@phoenix.infradead.org>

Update of /home/cvs/mtd/drivers/mtd/devices
In directory phoenix.infradead.org:/tmp/cvs-serv11575/drivers/mtd/devices

Modified Files:
	Kconfig ms02-nv.c ms02-nv.h 
Log Message:
MS02-NV patch from Maciej W. Rozycki.


Index: Kconfig
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/devices/Kconfig,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Kconfig	9 Jul 2003 13:51:56 -0000	1.5
+++ Kconfig	19 Aug 2003 09:24:35 -0000	1.6
@@ -40,9 +40,17 @@
 
 config MTD_MS02NV
 	tristate "DEC MS02-NV NVRAM module support"
-	depends on DECSTATION
+	depends on MTD && DECSTATION
 	help
-	  Support for NVRAM module on DECstation.
+	  This is an MTD driver for the DEC's MS02-NV (54-20948-01) battery
+	  backed-up NVRAM module.  The module was originally meant as an NFS
+	  accelerator.  Say Y here if you have a DECstation 5000/2x0 or a
+	  DECsystem 5900 equipped with such a module.
+
+	  If you want to compile this driver as a module ( = code which can be
+	  inserted in and removed from the running kernel whenever you want),
+	  say M here and read <file:Documentation/modules.txt>.  The module will
+	  be called ms02-nv.o.
 
 config MTD_SLRAM
 	tristate "Uncached system RAM"

Index: ms02-nv.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/devices/ms02-nv.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ms02-nv.c	20 May 2003 21:03:07 -0000	1.4
+++ ms02-nv.c	19 Aug 2003 09:24:35 -0000	1.5
@@ -1,10 +1,10 @@
 /*
- *      Copyright (c) 2001 Maciej W. Rozycki
+ *	Copyright (c) 2001 Maciej W. Rozycki
  *
- *      This program is free software; you can redistribute it and/or
- *      modify it under the terms of the GNU General Public License
- *      as published by the Free Software Foundation; either version
- *      2 of the License, or (at your option) any later version.
+ *	This program is free software; you can redistribute it and/or
+ *	modify it under the terms of the GNU General Public License
+ *	as published by the Free Software Foundation; either version
+ *	2 of the License, or (at your option) any later version.
  *
  *	$Id$
  */
@@ -29,7 +29,7 @@
 
 
 static char version[] __initdata =
-        "ms02-nv.c: v.1.0.0  13 Aug 2001  Maciej W. Rozycki.\n";
+	"ms02-nv.c: v.1.0.0  13 Aug 2001  Maciej W. Rozycki.\n";
 
 MODULE_AUTHOR("Maciej W. Rozycki <macro@ds2.pg.gda.pl>");
 MODULE_DESCRIPTION("DEC MS02-NV NVRAM module driver");
@@ -293,12 +293,12 @@
 
 	switch (mips_machtype) {
 	case MACH_DS5000_200:
-		csr = (volatile u32 *)KN02_CSR_ADDR;
+		csr = (volatile u32 *)KN02_CSR_BASE;
 		if (*csr & KN02_CSR_BNK32M)
 			stride = 2;
 		break;
 	case MACH_DS5000_2X0:
-	case MACH_DS5000:
+	case MACH_DS5900:
 		csr = (volatile u32 *)KN03_MCR_BASE;
 		if (*csr & KN03_MCR_BNK32M)
 			stride = 2;

Index: ms02-nv.h
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/devices/ms02-nv.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ms02-nv.h	13 Sep 2002 13:46:55 -0000	1.1
+++ ms02-nv.h	19 Aug 2003 09:24:35 -0000	1.2
@@ -1,10 +1,14 @@
 /*
- *      Copyright (c) 2001 Maciej W. Rozycki
+ *	Copyright (c) 2001, 2003  Maciej W. Rozycki
  *
- *      This program is free software; you can redistribute it and/or
- *      modify it under the terms of the GNU General Public License
- *      as published by the Free Software Foundation; either version
- *      2 of the License, or (at your option) any later version.
+ *	DEC MS02-NV (54-20948-01) battery backed-up NVRAM module for
+ *	DECstation/DECsystem 5000/2x0 and DECsystem 5900 and 5900/260
+ *	systems.
+ *
+ *	This program is free software; you can redistribute it and/or
+ *	modify it under the terms of the GNU General Public License
+ *	as published by the Free Software Foundation; either version
+ *	2 of the License, or (at your option) any later version.
  *
  *	$Id$
  */
@@ -12,22 +16,80 @@
 #include <linux/ioport.h>
 #include <linux/mtd/mtd.h>
 
+/*
+ * Addresses are decoded as follows:
+ *
+ * 0x000000 - 0x3fffff	SRAM
+ * 0x400000 - 0x7fffff	CSR
+ *
+ * Within the SRAM area the following ranges are forced by the system
+ * firmware:
+ *
+ * 0x000000 - 0x0003ff	diagnostic area, destroyed upon a reboot
+ * 0x000400 - ENDofRAM	storage area, available to operating systems
+ *
+ * but we can't really use the available area right from 0x000400 as
+ * the first word is used by the firmware as a status flag passed
+ * from an operating system.  If anything but the valid data magic
+ * ID value is found, the firmware considers the SRAM clean, i.e.
+ * containing no valid data, and disables the battery resulting in
+ * data being erased as soon as power is switched off.  So the choice
+ * for the start address of the user-available is 0x001000 which is
+ * nicely page aligned.  The area between 0x000404 and 0x000fff may
+ * be used by the driver for own needs.
+ *
+ * The diagnostic area defines two status words to be read by an
+ * operating system, a magic ID to distinguish a MS02-NV board from
+ * anything else and a status information providing results of tests
+ * as well as the size of SRAM available, which can be 1MB or 2MB
+ * (that's what the firmware handles; no idea if 2MB modules ever
+ * existed).
+ *
+ * The firmware only handles the MS02-NV board if installed in the
+ * last (15th) slot, so for any other location the status information
+ * stored in the SRAM cannot be relied upon.  But from the hardware
+ * point of view there is no problem using up to 14 such boards in a
+ * system -- only the 1st slot needs to be filled with a DRAM module.
+ * The MS02-NV board is ECC-protected, like other MS02 memory boards.
+ *
+ * The state of the battery as provided by the CSR is reflected on
+ * the two onboard LEDs.  When facing the battery side of the board,
+ * with the LEDs at the top left and the battery at the bottom right
+ * (i.e. looking from the back side of the system box), their meaning
+ * is as follows (the system has to be powered on):
+ *
+ * left LED		battery disable status: lit = enabled
+ * right LED		battery condition status: lit = OK
+ */
+
 /* MS02-NV iomem register offsets. */
 #define MS02NV_CSR		0x400000	/* control & status register */
 
+/* MS02-NV CSR status bits. */
+#define MS02NV_CSR_BATT_OK	0x01		/* battery OK */
+#define MS02NV_CSR_BATT_OFF	0x02		/* battery disabled */
+
+
 /* MS02-NV memory offsets. */
 #define MS02NV_DIAG		0x0003f8	/* diagnostic status */
 #define MS02NV_MAGIC		0x0003fc	/* MS02-NV magic ID */
-#define MS02NV_RAM		0x000400	/* general-purpose RAM start */
+#define MS02NV_VALID		0x000400	/* valid data magic ID */
+#define MS02NV_RAM		0x001000	/* user-exposed RAM start */
 
-/* MS02-NV diagnostic status constants. */
-#define MS02NV_DIAG_SIZE_MASK	0xf0		/* RAM size mask */
-#define MS02NV_DIAG_SIZE_SHIFT	0x10		/* RAM size shift (left) */
+/* MS02-NV diagnostic status bits. */
+#define MS02NV_DIAG_TEST	0x01		/* SRAM test done (?) */
+#define MS02NV_DIAG_RO		0x02		/* SRAM r/o test done */
+#define MS02NV_DIAG_RW		0x04		/* SRAM r/w test done */
+#define MS02NV_DIAG_FAIL	0x08		/* SRAM test failed */
+#define MS02NV_DIAG_SIZE_MASK	0xf0		/* SRAM size mask */
+#define MS02NV_DIAG_SIZE_SHIFT	0x10		/* SRAM size shift (left) */
 
 /* MS02-NV general constants. */
 #define MS02NV_ID		0x03021966	/* MS02-NV magic ID value */
+#define MS02NV_VALID_ID		0xbd100248	/* valid data magic ID value */
 #define MS02NV_SLOT_SIZE	0x800000	/* size of the address space
 						   decoded by the module */
+
 
 typedef volatile u32 ms02nv_uint;
 


From dwmw2 at infradead.org  Tue Aug 19 05:25:38 2003
From: dwmw2 at infradead.org (David Woodhouse)
Date: Mon May 15 21:48:41 2006
Subject: mtd/drivers/mtd/devices ms02-nv.c,1.5,1.6 ms02-nv.h,1.2,1.3
Message-ID: <E19p2kE-00031h-00@phoenix.infradead.org>

Update of /home/cvs/mtd/drivers/mtd/devices
In directory phoenix.infradead.org:/tmp/cvs-serv11614/drivers/mtd/devices

Modified Files:
	ms02-nv.c ms02-nv.h 
Log Message:
s/MB/MiB/g


Index: ms02-nv.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/devices/ms02-nv.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ms02-nv.c	19 Aug 2003 09:24:35 -0000	1.5
+++ ms02-nv.c	19 Aug 2003 09:25:36 -0000	1.6
@@ -38,9 +38,9 @@
 
 /*
  * Addresses we probe for an MS02-NV at.  Modules may be located
- * at any 8MB boundary within a 0MB up to 112MB range or at any 32MB
- * boundary within a 0MB up to 448MB range.  We don't support a module
- * at 0MB, though.
+ * at any 8MiB boundary within a 0MiB up to 112MiB range or at any 32MiB
+ * boundary within a 0MiB up to 448MiB range.  We don't support a module
+ * at 0MiB, though.
  */
 static ulong ms02nv_addrs[] __initdata = {
 	0x07000000, 0x06800000, 0x06000000, 0x05800000, 0x05000000,
@@ -130,7 +130,7 @@
 
 	int ret = -ENODEV;
 
-	/* The module decodes 8MB of address space. */
+	/* The module decodes 8MiB of address space. */
 	mod_res = kmalloc(sizeof(*mod_res), GFP_KERNEL);
 	if (!mod_res)
 		return -ENOMEM;
@@ -233,7 +233,7 @@
 		goto err_out_csr_res;
 	}
 
-	printk(KERN_INFO "mtd%d: %s at 0x%08lx, size %uMB.\n",
+	printk(KERN_INFO "mtd%d: %s at 0x%08lx, size %uMiB.\n",
 		mtd->index, ms02nv_name, addr, size >> 20);
 
 	mp->next = root_ms02nv_mtd;

Index: ms02-nv.h
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/devices/ms02-nv.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ms02-nv.h	19 Aug 2003 09:24:35 -0000	1.2
+++ ms02-nv.h	19 Aug 2003 09:25:36 -0000	1.3
@@ -41,8 +41,8 @@
  * The diagnostic area defines two status words to be read by an
  * operating system, a magic ID to distinguish a MS02-NV board from
  * anything else and a status information providing results of tests
- * as well as the size of SRAM available, which can be 1MB or 2MB
- * (that's what the firmware handles; no idea if 2MB modules ever
+ * as well as the size of SRAM available, which can be 1MiB or 2MiB
+ * (that's what the firmware handles; no idea if 2MiB modules ever
  * existed).
  *
  * The firmware only handles the MS02-NV board if installed in the


From joern at infradead.org  Thu Aug 21 13:52:33 2003
From: joern at infradead.org (joern@infradead.org)
Date: Mon May 15 21:48:41 2006
Subject: mtd/drivers/mtd/devices phram.c,NONE,1.1 Kconfig,1.6,1.7
 Makefile.common,1.3,1.4
Message-ID: <E19ptbt-0000Xd-00@phoenix.infradead.org>

Update of /home/cvs/mtd/drivers/mtd/devices
In directory phoenix.infradead.org:/home/joern/mtd/drivers/mtd/devices

Modified Files:
	Kconfig Makefile.common 
Added Files:
	phram.c 
Log Message:
Add phram as a substiute for slram.  The code is a bit cleaner and the new
command line interface much better.  Thanks, Rusty!



--- NEW FILE phram.c ---
/**
 *
 * $Id: phram.c,v 1.1 2003/08/21 17:52:30 joern Exp $
 *
 * Copyright (c) Jochen Schaeuble <psionic@psionic.de>
 * 07/2003	rewritten by Joern Engel <joern@wh.fh-wedel.de>
 *
 * DISCLAIMER:  This driver makes use of Rusty's excellent module code,
 * so it will not work for 2.4 without changes and it wont work for 2.4
 * as a module without major changes.  Oh well!
 *
 * Usage:
 *
 * one commend line parameter per device, each in the form:
 *   phram=<name>,<start>,<len>
 * <name> may be up to 63 characters.
 * <start> and <len> can be octal, decimal or hexadecimal.  If followed
 * by "k", "M" or "G", the numbers will be interpreted as kilo, mega or
 * gigabytes.
 *
 */

#include <asm/io.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/mtd/mtd.h>

#define ERROR(fmt, args...) printk(KERN_ERR "phram: " fmt , ## args)

struct phram_mtd_list {
	struct list_head list;
	struct mtd_info *mtdinfo;
};

static LIST_HEAD(phram_list);



int phram_erase(struct mtd_info *mtd, struct erase_info *instr)
{
	u_char *start = (u_char *)mtd->priv;

	if (instr->addr + instr->len > mtd->size)
		return -EINVAL;
	
	memset(start + instr->addr, 0xff, instr->len);

	/* This'll catch a few races. Free the thing before returning :) 
	 * I don't feel at all ashamed. This kind of thing is possible anyway
	 * with flash, but unlikely.
	 */

	instr->state = MTD_ERASE_DONE;

	if (instr->callback)
		(*(instr->callback))(instr);
	else
		kfree(instr);

	return 0;
}

int phram_point(struct mtd_info *mtd, loff_t from, size_t len,
		size_t *retlen, u_char **mtdbuf)
{
	u_char *start = (u_char *)mtd->priv;

	if (from + len > mtd->size)
		return -EINVAL;
	
	*mtdbuf = start + from;
	*retlen = len;
	return 0;
}

void phram_unpoint(struct mtd_info *mtd, u_char *addr, loff_t from, size_t len)
{
}

int phram_read(struct mtd_info *mtd, loff_t from, size_t len,
		size_t *retlen, u_char *buf)
{
	u_char *start = (u_char *)mtd->priv;

	if (from + len > mtd->size)
		return -EINVAL;
	
	memcpy(buf, start + from, len);

	*retlen = len;
	return 0;
}

int phram_write(struct mtd_info *mtd, loff_t to, size_t len,
		size_t *retlen, const u_char *buf)
{
	u_char *start = (u_char *)mtd->priv;

	if (to + len > mtd->size)
		return -EINVAL;
	
	memcpy(start + to, buf, len);

	*retlen = len;
	return 0;
}



static void unregister_devices(void)
{
	struct phram_mtd_list *this;

	list_for_each_entry(this, &phram_list, list) {
		del_mtd_device(this->mtdinfo);
		iounmap(this->mtdinfo->priv);
		kfree(this->mtdinfo);
		kfree(this);
	}
}

static int register_device(char *name, unsigned long start, unsigned long len)
{
	struct phram_mtd_list *new;
	int ret = -ENOMEM;

	new = kmalloc(sizeof(*new), GFP_KERNEL);
	if (!new)
		goto out0;

	new->mtdinfo = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
	if (!new->mtdinfo)
		goto out1;
	
	memset(new->mtdinfo, 0, sizeof(struct mtd_info));

	ret = -EIO;
	new->mtdinfo->priv = ioremap(start, len);
	if (!new->mtdinfo->priv) {
		ERROR("ioremap failed\n");
		goto out2;
	}


	new->mtdinfo->name = name;
	new->mtdinfo->size = len;
	new->mtdinfo->flags = MTD_CAP_RAM | MTD_ERASEABLE | MTD_VOLATILE;
        new->mtdinfo->erase = phram_erase;
	new->mtdinfo->point = phram_point;
	new->mtdinfo->unpoint = phram_unpoint;
	new->mtdinfo->read = phram_read;
	new->mtdinfo->write = phram_write;
	new->mtdinfo->owner = THIS_MODULE;
	new->mtdinfo->type = MTD_RAM;
	new->mtdinfo->erasesize = 0x0;

	ret = -EAGAIN;
	if (add_mtd_device(new->mtdinfo)) {
		ERROR("Failed to register new device\n");
		goto out3;
	}

	list_add_tail(&new->list, &phram_list);
	return 0;	

out3:
	iounmap(new->mtdinfo->priv);
out2:
	kfree(new->mtdinfo);
out1:
	kfree(new);
out0:
	return ret;
}

static int ustrtoul(const char *cp, char **endp, unsigned int base)
{
	unsigned long result = simple_strtoul(cp, endp, base);

	switch (**endp) {
	case 'G':
		result *= 1024;
	case 'M':
		result *= 1024;
	case 'k':
		result *= 1024;
		endp++;
	}
	return result;
}

static int parse_num32(uint32_t *num32, const char *token)
{
	char *endp;
	unsigned long n;

	n = ustrtoul(token, &endp, 0);
	if (*endp)
		return -EINVAL;

	*num32 = n;
	return 0;
}

static int parse_name(char **pname, const char *token)
{
	size_t len;
	char *name;

	len = strlen(token) + 1;
	if (len > 64)
		return -ENOSPC;

	name = kmalloc(len, GFP_KERNEL);
	if (!name)
		return -ENOMEM;

	strcpy(name, token);

	*pname = name;
	return 0;
}

#define parse_err(fmt, args...) do {	\
	ERROR(fmt , ## args);	\
	return 0;		\
} while (0)

static int phram_setup(const char *val, struct kernel_param *kp)
{
	char buf[64+12+12], *str = buf;
	char *token[3];
	char *name;
	uint32_t start;
	uint32_t len;
	int i, ret;

	if (strnlen(val, sizeof(str)) >= sizeof(str))
		parse_err("parameter too long\n");

	strcpy(str, val);

	for (i=0; i<3; i++)
		token[i] = strsep(&str, ",");

	if (str)
		parse_err("too many arguments\n");

	if (!token[2])
		parse_err("not enough arguments\n");

	ret = parse_name(&name, token[0]);
	if (ret == -ENOMEM)
		parse_err("out of memory\n");
	if (ret == -ENOSPC)
		parse_err("name too long\n");
	if (ret)
		return 0;

	ret = parse_num32(&start, token[1]);
	if (ret)
		parse_err("illegal start address\n");

	ret = parse_num32(&len, token[2]);
	if (ret)
		parse_err("illegal device length\n");

	register_device(name, start, len);

	return 0;
}

module_param_call(phram, phram_setup, NULL, NULL, 000);
MODULE_PARM_DESC(phram, "Memory region to map. \"map=<name>,<start><length>\"");

/*
 * Just for compatibility with slram, this is horrible and should go someday.
 */
static int __init slram_setup(const char *val, struct kernel_param *kp)
{
	char buf[256], *str = buf;

	if (!val || !val[0])
		parse_err("no arguments to \"slram=\"\n");

	if (strnlen(val, sizeof(str)) >= sizeof(str))
		parse_err("parameter too long\n");

	strcpy(str, val);

	while (str) {
		char *token[3];
		char *name;
		uint32_t start;
		uint32_t len;
		int i, ret;

		for (i=0; i<3; i++) {
			token[i] = strsep(&str, ",");
			if (token[i])
				continue;
			parse_err("wrong number of arguments to \"slram=\"\n");
		}

		/* name */
		ret = parse_name(&name, token[0]);
		if (ret == -ENOMEM)
			parse_err("of memory\n");
		if (ret == -ENOSPC)
			parse_err("too long\n");
		if (ret)
			return 1;

		/* start */
		ret = parse_num32(&start, token[1]);
		if (ret)
			parse_err("illegal start address\n");

		/* len */
		if (token[2][0] == '+')
			ret = parse_num32(&len, token[2] + 1);
		else
			ret = parse_num32(&len, token[2]);

		if (ret)
			parse_err("illegal device length\n");

		if (token[2][0] != '+') {
			if (len < start)
				parse_err("end < start\n");
			len -= start;
		}

		register_device(name, start, len);
	}
	return 1;
}

module_param_call(slram, slram_setup, NULL, NULL, 000);
MODULE_PARM_DESC(slram, "List of memory regions to map. \"map=<name>,<start><length/end>\"");


int __init init_phram(void)
{
	printk(KERN_ERR "phram loaded\n");
	return 0;
}

static void __exit cleanup_phram(void)
{
	unregister_devices();
}

module_init(init_phram);
module_exit(cleanup_phram);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Jörn Engel <joern@wh.fh-wedel.de>");
MODULE_DESCRIPTION("MTD driver for physical RAM");

Index: Kconfig
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/devices/Kconfig,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Kconfig	19 Aug 2003 09:24:35 -0000	1.6
+++ Kconfig	21 Aug 2003 17:52:29 -0000	1.7
@@ -60,6 +60,16 @@
 	  you can still use it for storage or swap by using this driver to
 	  present it to the system as a Memory Technology Device.
 
+config MTD_PHRAM
+	tristate "Physical system RAM"
+	depends on MTD
+	help
+	  This is a re-implementation of the slram driver above.
+
+	  Use this driver to access physical memory that the kernel proper
+	  doesn't have access to, memory beyond the mem=xxx limit, nvram,
+	  memory on the video card, etc...
+
 config MTD_LART
 	tristate "28F160xx flash driver for LART"
 	depends on SA1100_LART && MTD

Index: Makefile.common
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/devices/Makefile.common,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Makefile.common	28 May 2003 10:54:23 -0000	1.3
+++ Makefile.common	21 Aug 2003 17:52:29 -0000	1.4
@@ -20,6 +20,7 @@
 obj-$(CONFIG_MTD_DOC2001PLUS)	+= doc2001plus.o
 obj-$(CONFIG_MTD_DOCPROBE)	+= docprobe.o docecc.o
 obj-$(CONFIG_MTD_SLRAM)		+= slram.o
+obj-$(CONFIG_MTD_PHRAM)		+= phram.o
 obj-$(CONFIG_MTD_PMC551)	+= pmc551.o
 obj-$(CONFIG_MTD_MS02NV)	+= ms02-nv.o
 obj-$(CONFIG_MTD_MTDRAM)	+= mtdram.o


From dwmw2 at infradead.org  Sun Aug 24 05:58:54 2003
From: dwmw2 at infradead.org (David Woodhouse)
Date: Mon May 15 21:48:41 2006
Subject: mtd/fs/jffs2 nodemgmt.c,1.95,1.96
Message-ID: <E19qreA-0003oz-2Y@phoenix.infradead.org>

Update of /home/cvs/mtd/fs/jffs2
In directory phoenix.infradead.org:/tmp/cvs-serv14670

Modified Files:
	nodemgmt.c 
Log Message:
Fix typo in block list dumping


Index: nodemgmt.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/nodemgmt.c,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -r1.95 -r1.96
--- nodemgmt.c	30 Jun 2003 10:58:57 -0000	1.95
+++ nodemgmt.c	24 Aug 2003 09:58:51 -0000	1.96
@@ -672,7 +672,7 @@
 
 		list_for_each(this, &c->erasable_pending_wbuf_list) {
 			struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
-			printk(KERN_DEBUG "erase_pending_wbuf_list: %08x (used %08x, dirty %08x, wasted %08x, unchecked %08x, free %08x)\n",
+			printk(KERN_DEBUG "erasable_pending_wbuf_list: %08x (used %08x, dirty %08x, wasted %08x, unchecked %08x, free %08x)\n",
 			       jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, jeb->unchecked_size, jeb->free_size);
 		}
 	}


From dwmw2 at infradead.org  Sun Aug 24 06:29:13 2003
From: dwmw2 at infradead.org (David Woodhouse)
Date: Mon May 15 21:48:42 2006
Subject: mtd/fs/jffs2 file.c,1.86,1.87 nodelist.h,1.94,1.95
 nodemgmt.c,1.96,1.97 os-linux.h,1.28,1.29 super-v24.c,1.66,1.67
 super.c,1.81,1.82 wbuf.c,1.34,1.35
Message-ID: <E19qs7U-0003uO-Q6@phoenix.infradead.org>

Update of /home/cvs/mtd/fs/jffs2
In directory phoenix.infradead.org:/tmp/cvs-serv15022

Modified Files:
	file.c nodelist.h nodemgmt.c os-linux.h super-v24.c super.c 
	wbuf.c 
Log Message:
Remove magic arg to jffs2_flush_wbuf()

Index: file.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/file.c,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -r1.86 -r1.87
--- file.c	30 Jun 2003 10:58:57 -0000	1.86
+++ file.c	24 Aug 2003 10:29:09 -0000	1.87
@@ -44,7 +44,7 @@
 	 */
 	down(&c->alloc_sem);
 	down(&f->sem);
-	jffs2_flush_wbuf(c,2);
+	jffs2_flush_wbuf_gc(c);
 	up(&f->sem);
 	up(&c->alloc_sem);
 			

Index: nodelist.h
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/nodelist.h,v
retrieving revision 1.94
retrieving revision 1.95
diff -u -r1.94 -r1.95
--- nodelist.h	3 Jul 2003 10:35:45 -0000	1.94
+++ nodelist.h	24 Aug 2003 10:29:09 -0000	1.95
@@ -383,7 +383,8 @@
 
 #ifdef CONFIG_JFFS2_FS_NAND
 /* wbuf.c */
-int jffs2_flush_wbuf(struct jffs2_sb_info *c, int pad);
+int jffs2_flush_wbuf_gc(struct jffs2_sb_info *c);
+int jffs2_flush_wbuf_pad(struct jffs2_sb_info *c);
 int jffs2_check_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
 int jffs2_write_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
 int jffs2_nand_read_failcnt(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);

Index: nodemgmt.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/nodemgmt.c,v
retrieving revision 1.96
retrieving revision 1.97
diff -u -r1.96 -r1.97
--- nodemgmt.c	24 Aug 2003 09:58:51 -0000	1.96
+++ nodemgmt.c	24 Aug 2003 10:29:09 -0000	1.97
@@ -161,7 +161,7 @@
 		if (jffs2_wbuf_dirty(c)) {
 			spin_unlock(&c->erase_completion_lock);
 			D1(printk(KERN_DEBUG "jffs2_do_reserve_space: Flushing write buffer\n"));			    
-			jffs2_flush_wbuf(c, 1);
+			jffs2_flush_wbuf_pad(c);
 			spin_lock(&c->erase_completion_lock);
 			/* We know nobody's going to have changed nextblock. Just continue */
 		}
@@ -219,7 +219,7 @@
 				D1(printk(KERN_DEBUG "jffs2_do_reserve_space: Flushing write buffer\n"));
 				/* c->nextblock is NULL, no update to c->nextblock allowed */			    
 				spin_unlock(&c->erase_completion_lock);
-				jffs2_flush_wbuf(c, 1);
+				jffs2_flush_wbuf_pad(c);
 				spin_lock(&c->erase_completion_lock);
 				/* Have another go. It'll be on the erasable_list now */
 				return -EAGAIN;
@@ -347,7 +347,7 @@
 		if (jffs2_wbuf_dirty(c)) {
 			/* Flush the last write in the block if it's outstanding */
 			spin_unlock(&c->erase_completion_lock);
-			jffs2_flush_wbuf(c, 1);
+			jffs2_flush_wbuf_pad(c);
 			spin_lock(&c->erase_completion_lock);
 		}
 

Index: os-linux.h
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/os-linux.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- os-linux.h	2 Jul 2003 10:46:00 -0000	1.28
+++ os-linux.h	24 Aug 2003 10:29:09 -0000	1.29
@@ -111,7 +111,8 @@
 
 #define jffs2_flash_write(c, ofs, len, retlen, buf) ((c)->mtd->write((c)->mtd, ofs, len, retlen, buf))
 #define jffs2_flash_read(c, ofs, len, retlen, buf) ((c)->mtd->read((c)->mtd, ofs, len, retlen, buf))
-#define jffs2_flush_wbuf(c, flag) do { ; } while(0)
+#define jffs2_flush_wbuf_pad(c, flag) do { ; } while(0)
+#define jffs2_flush_wbuf_gc(c, flag) do { ; } while(0)
 #define jffs2_nand_read_failcnt(c,jeb) do { ; } while(0)
 #define jffs2_write_nand_badblock(c,jeb) do { ; } while(0)
 #define jffs2_nand_flash_setup(c) (0)

Index: super-v24.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/super-v24.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -r1.66 -r1.67
--- super-v24.c	30 Jun 2003 10:58:58 -0000	1.66
+++ super-v24.c	24 Aug 2003 10:29:09 -0000	1.67
@@ -84,7 +84,7 @@
 	if (!(sb->s_flags & MS_RDONLY))
 		jffs2_stop_garbage_collect_thread(c);
 	down(&c->alloc_sem);
-	jffs2_flush_wbuf(c, 1);
+	jffs2_flush_wbuf_pad(c);
 	up(&c->alloc_sem);
 	jffs2_free_ino_caches(c);
 	jffs2_free_raw_node_refs(c);

Index: super.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/super.c,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -r1.81 -r1.82
--- super.c	1 Jul 2003 09:49:53 -0000	1.81
+++ super.c	24 Aug 2003 10:29:09 -0000	1.82
@@ -258,7 +258,7 @@
 	if (!(sb->s_flags & MS_RDONLY))
 		jffs2_stop_garbage_collect_thread(c);
 	down(&c->alloc_sem);
-	jffs2_flush_wbuf(c, 1);
+	jffs2_flush_wbuf_pad(c);
 	up(&c->alloc_sem);
 	jffs2_free_ino_caches(c);
 	jffs2_free_raw_node_refs(c);

Index: wbuf.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/wbuf.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- wbuf.c	1 Jul 2003 22:37:20 -0000	1.34
+++ wbuf.c	24 Aug 2003 10:29:09 -0000	1.35
@@ -109,7 +109,7 @@
 	/* if !c->nextblock then the tail will have got flushed from
 	   jffs2_do_reserve_space() anyway. */
 	if(c->nextblock)
-		jffs2_flush_wbuf(c, 2); /* pad and adjust nextblock */
+		jffs2_flush_wbuf_gc(c);
 
 	up(&c->alloc_sem);
 }
@@ -120,7 +120,7 @@
    1: Pad, do not adjust nextblock free_size
    2: Pad, adjust nextblock free_size
 */
-int jffs2_flush_wbuf(struct jffs2_sb_info *c, int pad)
+static int __jffs2_flush_wbuf(struct jffs2_sb_info *c, int pad)
 {
 	int ret;
 	size_t retlen;
@@ -216,12 +216,22 @@
 	spin_unlock(&c->erase_completion_lock);
 
 	memset(c->wbuf,0xff,c->wbuf_pagesize);
-	/* adjust write buffer offset, else we get a non contigous write bug */
+	/* adjust write buffer offset, else we get a non contiguous write bug */
 	c->wbuf_ofs+= c->wbuf_pagesize;
 	c->wbuf_len = 0;
 	return 0;
 }
 
+int jffs2_flush_wbuf_gc(struct jffs2_sb_info *c)
+{
+	return __jffs2_flush_wbuf(c, 2);
+}
+
+int jffs2_flush_wbuf_pad(struct jffs2_sb_info *c)
+{
+	return __jffs2_flush_wbuf(c, 1);
+}
+
 #define PAGE_DIV(x) ( (x) & (~(c->wbuf_pagesize - 1)) )
 #define PAGE_MOD(x) ( (x) & (c->wbuf_pagesize - 1) )
 int jffs2_flash_writev(struct jffs2_sb_info *c, const struct iovec *invecs, unsigned long count, loff_t to, size_t *retlen)
@@ -258,7 +268,7 @@
 		/* It's a write to a new block */
 		if (c->wbuf_len) {
 			D1(printk(KERN_DEBUG "jffs2_flash_writev() to 0x%lx causes flush of wbuf at 0x%08x\n", (unsigned long)to, c->wbuf_ofs));
-			ret = jffs2_flush_wbuf(c, 1);
+			ret = jffs2_flush_wbuf_pad(c);
 			if (ret) {
 				/* the underlying layer has to check wbuf_len to do the cleanup */
 				D1(printk(KERN_WARNING "jffs2_flush_wbuf() called from jffs2_flash_writev() failed %d\n", ret));
@@ -324,7 +334,7 @@
 		}			
 		
 		/* write buffer is full, flush buffer */
-		ret = jffs2_flush_wbuf(c, 0);
+		ret = __jffs2_flush_wbuf(c, 0);
 		if (ret) {
 			/* the underlying layer has to check wbuf_len to do the cleanup */
 			D1(printk(KERN_WARNING "jffs2_flush_wbuf() called from jffs2_flash_writev() failed %d\n", ret));


From dwmw2 at infradead.org  Sun Aug 24 07:14:24 2003
From: dwmw2 at infradead.org (David Woodhouse)
Date: Mon May 15 21:48:42 2006
Subject: mtd/fs/jffs2 super-v24.c,1.67,1.68 super.c,1.82,1.83
Message-ID: <E19qspE-0004BU-G8@phoenix.infradead.org>

Update of /home/cvs/mtd/fs/jffs2
In directory phoenix.infradead.org:/tmp/cvs-serv16082

Modified Files:
	super-v24.c super.c 
Log Message:
sync_fs() to make sys_sync() work

Index: super-v24.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/super-v24.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -r1.67 -r1.68
--- super-v24.c	24 Aug 2003 10:29:09 -0000	1.67
+++ super-v24.c	24 Aug 2003 11:14:21 -0000	1.68
@@ -28,7 +28,8 @@
 #define MTD_BLOCK_MAJOR 31
 #endif
 
-void jffs2_put_super (struct super_block *);
+static void jffs2_put_super (struct super_block *);
+static int jffs2_sync_fs(struct super_block *);
 
 static struct super_operations jffs2_super_operations =
 {
@@ -37,7 +38,8 @@
 	write_super:	jffs2_write_super,
 	statfs:		jffs2_statfs,
 	remount_fs:	jffs2_remount_fs,
-	clear_inode:	jffs2_clear_inode
+	clear_inode:	jffs2_clear_inode,
+	sync_fs:	jffs2_sync_fs,
 };
 
 
@@ -74,7 +76,7 @@
 	return sb;
 }
 
-void jffs2_put_super (struct super_block *sb)
+static void jffs2_put_super (struct super_block *sb)
 {
 	struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
 
@@ -96,6 +98,24 @@
 	put_mtd_device(c->mtd);
 	
 	D1(printk(KERN_DEBUG "jffs2_put_super returning\n"));
+}
+
+static int jffs2_sync_fs(struct super_block *sb)
+{
+	struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
+	int ret;
+
+	if (!jffs2_wbuf_dirty(c))
+		return 0;
+
+	/* Flush with GC is OK -- it leaves a partially-written node
+	   but only a GC node, so no data are lost if it's not 
+	   complete and we immediately power off */
+	down(&c->alloc_sem);
+	ret = jffs2_flush_wbuf_gc(c);
+	up(&c->alloc_sem);
+			
+	return ret;	
 }
 
 static DECLARE_FSTYPE_DEV(jffs2_fs_type, "jffs2", jffs2_read_super);

Index: super.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/super.c,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -r1.82 -r1.83
--- super.c	24 Aug 2003 10:29:09 -0000	1.82
+++ super.c	24 Aug 2003 11:14:21 -0000	1.83
@@ -27,7 +27,8 @@
 #include <linux/namei.h>
 #include "nodelist.h"
 
-void jffs2_put_super (struct super_block *);
+static void jffs2_put_super(struct super_block *);
+static int jffs2_sync_fs(struct super_block *, int);
 
 
 static kmem_cache_t *jffs2_inode_cachep;
@@ -66,7 +67,8 @@
 	.write_super =	jffs2_write_super,
 	.statfs =	jffs2_statfs,
 	.remount_fs =	jffs2_remount_fs,
-	.clear_inode =	jffs2_clear_inode
+	.clear_inode =	jffs2_clear_inode,
+	.sync_fs =	jffs2_sync_fs,
 };
 
 static int jffs2_sb_compare(struct super_block *sb, void *data)
@@ -248,8 +250,7 @@
 	return jffs2_get_sb_mtdnr(fs_type, flags, dev_name, data, minor(dev));
 }
 
-
-void jffs2_put_super (struct super_block *sb)
+static void jffs2_put_super (struct super_block *sb)
 {
 	struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
 
@@ -271,6 +272,24 @@
 	D1(printk(KERN_DEBUG "jffs2_put_super returning\n"));
 }
 
+static int jffs2_sync_fs(struct super_block *sb, int wait)
+{
+	struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
+	int ret;
+
+	if (!wait || !jffs2_wbuf_dirty(c))
+		return 0;
+
+	/* Flush with GC is OK -- it leaves a partially-written node
+	   but only a GC node, so no data are lost if it's not 
+	   complete and we immediately power off */
+	down(&c->alloc_sem);
+	ret = jffs2_flush_wbuf_gc(c);
+	up(&c->alloc_sem);
+			
+	return ret;	
+}
+
 static void jffs2_kill_sb(struct super_block *sb)
 {
 	struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
@@ -278,15 +297,13 @@
 	put_mtd_device(c->mtd);
 	kfree(c);
 }
- 
+
 static struct file_system_type jffs2_fs_type = {
 	.owner =	THIS_MODULE,
 	.name =		"jffs2",
 	.get_sb =	jffs2_get_sb,
 	.kill_sb =	jffs2_kill_sb,
 };
-
-
 
 static int __init init_jffs2_fs(void)
 {


From dwmw2 at infradead.org  Sun Aug 24 16:34:55 2003
From: dwmw2 at infradead.org (David Woodhouse)
Date: Mon May 15 21:48:42 2006
Subject: mtd/include/linux jffs2_fs_sb.h,1.39,1.40
Message-ID: <E19r1Ze-0005hv-UG@phoenix.infradead.org>

Update of /home/cvs/mtd/include/linux
In directory phoenix.infradead.org:/tmp/cvs-serv21935/include/linux

Modified Files:
	jffs2_fs_sb.h 
Log Message:
Clean up flush_wbuf functions

Index: jffs2_fs_sb.h
===================================================================
RCS file: /home/cvs/mtd/include/linux/jffs2_fs_sb.h,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- jffs2_fs_sb.h	30 Jun 2003 14:36:47 -0000	1.39
+++ jffs2_fs_sb.h	24 Aug 2003 20:34:52 -0000	1.40
@@ -87,6 +87,7 @@
 #ifdef CONFIG_JFFS2_FS_NAND
 	/* Write-behind buffer for NAND flash */
 	unsigned char *wbuf;
+	uint32_t wbuf_partnode_ofs;		/* Start offset of node ending in wbuf */
 	uint32_t wbuf_ofs;
 	uint32_t wbuf_len;
 	uint32_t wbuf_pagesize;


From dwmw2 at infradead.org  Sun Aug 24 16:34:56 2003
From: dwmw2 at infradead.org (David Woodhouse)
Date: Mon May 15 21:48:42 2006
Subject: mtd/fs/jffs2 TODO,1.10,1.11 file.c,1.87,1.88 os-linux.h,1.29,1.30
 super-v24.c,1.68,1.69 super.c,1.83,1.84 wbuf.c,1.35,1.36
Message-ID: <E19r1Zf-0005i1-Ro@phoenix.infradead.org>

Update of /home/cvs/mtd/fs/jffs2
In directory phoenix.infradead.org:/tmp/cvs-serv21935/fs/jffs2

Modified Files:
	TODO file.c os-linux.h super-v24.c super.c wbuf.c 
Log Message:
Clean up flush_wbuf functions

Index: TODO
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/TODO,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- TODO	9 Sep 2002 16:31:21 -0000	1.10
+++ TODO	24 Aug 2003 20:34:52 -0000	1.11
@@ -11,14 +11,10 @@
  - test, test, test
 
  - NAND flash support:
-	- flush_wbuf using GC to fill it, don't just pad.
 	- Deal with write errors. Data don't get lost - we just have to write 
 	  the affected node(s) out again somewhere else.
 	- make fsync flush only if actually required
-	- make sys_sync() work.
 	- reboot notifier
-	- timed flush of old wbuf
-	- fix magical second arg of jffs2_flush_wbuf(). Split into two or more functions instead.
 
 
  - Optimisations:

Index: file.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/file.c,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -r1.87 -r1.88
--- file.c	24 Aug 2003 10:29:09 -0000	1.87
+++ file.c	24 Aug 2003 20:34:52 -0000	1.88
@@ -28,25 +28,12 @@
 int jffs2_fsync(struct file *filp, struct dentry *dentry, int datasync)
 {
 	struct inode *inode = dentry->d_inode;
-	struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
 	struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
 
-	if (!jffs2_wbuf_dirty(c))
-		return 0;
-
-	/* flush write buffer and update c->nextblock */
-	
-	/* FIXME NAND */
-	/* At the moment we flush the buffer, to make sure
-	 * that every thing is on the flash.
-	 * maybe we have to think about it to find a smarter
-	 * solution.
-	 */
-	down(&c->alloc_sem);
-	down(&f->sem);
+	/* Trigger GC to flush the pending writes.
+	   FIXME: We should do this only if our particular inode has
+	   writes pending in the wbuf */
 	jffs2_flush_wbuf_gc(c);
-	up(&f->sem);
-	up(&c->alloc_sem);
 			
 	return 0;	
 }

Index: os-linux.h
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/os-linux.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- os-linux.h	24 Aug 2003 10:29:09 -0000	1.29
+++ os-linux.h	24 Aug 2003 20:34:52 -0000	1.30
@@ -111,8 +111,8 @@
 
 #define jffs2_flash_write(c, ofs, len, retlen, buf) ((c)->mtd->write((c)->mtd, ofs, len, retlen, buf))
 #define jffs2_flash_read(c, ofs, len, retlen, buf) ((c)->mtd->read((c)->mtd, ofs, len, retlen, buf))
-#define jffs2_flush_wbuf_pad(c, flag) do { ; } while(0)
-#define jffs2_flush_wbuf_gc(c, flag) do { ; } while(0)
+#define jffs2_flush_wbuf_pad(c) ({ (void)(c), 0; })
+#define jffs2_flush_wbuf_gc(c) ({ (void)(c), 0; })
 #define jffs2_nand_read_failcnt(c,jeb) do { ; } while(0)
 #define jffs2_write_nand_badblock(c,jeb) do { ; } while(0)
 #define jffs2_nand_flash_setup(c) (0)

Index: super-v24.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/super-v24.c,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -r1.68 -r1.69
--- super-v24.c	24 Aug 2003 11:14:21 -0000	1.68
+++ super-v24.c	24 Aug 2003 20:34:53 -0000	1.69
@@ -103,19 +103,11 @@
 static int jffs2_sync_fs(struct super_block *sb)
 {
 	struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
-	int ret;
-
-	if (!jffs2_wbuf_dirty(c))
-		return 0;
 
 	/* Flush with GC is OK -- it leaves a partially-written node
 	   but only a GC node, so no data are lost if it's not 
 	   complete and we immediately power off */
-	down(&c->alloc_sem);
-	ret = jffs2_flush_wbuf_gc(c);
-	up(&c->alloc_sem);
-			
-	return ret;	
+	return jffs2_flush_wbuf_gc(c);
 }
 
 static DECLARE_FSTYPE_DEV(jffs2_fs_type, "jffs2", jffs2_read_super);

Index: super.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/super.c,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -r1.83 -r1.84
--- super.c	24 Aug 2003 11:14:21 -0000	1.83
+++ super.c	24 Aug 2003 20:34:53 -0000	1.84
@@ -275,19 +275,14 @@
 static int jffs2_sync_fs(struct super_block *sb, int wait)
 {
 	struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
-	int ret;
 
-	if (!wait || !jffs2_wbuf_dirty(c))
-		return 0;
+	if (wait)
+		/* Flush with GC is OK -- it leaves a partially-written node
+		   but only a GC node, so no data are lost if it's not 
+		   complete and we immediately power off */
+		return jffs2_flush_wbuf_gc(c);
 
-	/* Flush with GC is OK -- it leaves a partially-written node
-	   but only a GC node, so no data are lost if it's not 
-	   complete and we immediately power off */
-	down(&c->alloc_sem);
-	ret = jffs2_flush_wbuf_gc(c);
-	up(&c->alloc_sem);
-			
-	return ret;	
+	return 0;	
 }
 
 static void jffs2_kill_sb(struct super_block *sb)

Index: wbuf.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/wbuf.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- wbuf.c	24 Aug 2003 10:29:09 -0000	1.35
+++ wbuf.c	24 Aug 2003 20:34:53 -0000	1.36
@@ -105,13 +105,10 @@
 		return;
 	}
 	
-	
+	up(&c->alloc_sem);
 	/* if !c->nextblock then the tail will have got flushed from
 	   jffs2_do_reserve_space() anyway. */
-	if(c->nextblock)
-		jffs2_flush_wbuf_gc(c);
-
-	up(&c->alloc_sem);
+	jffs2_flush_wbuf_gc(c);
 }
 
 
@@ -217,21 +214,49 @@
 
 	memset(c->wbuf,0xff,c->wbuf_pagesize);
 	/* adjust write buffer offset, else we get a non contiguous write bug */
-	c->wbuf_ofs+= c->wbuf_pagesize;
+	c->wbuf_ofs += c->wbuf_pagesize;
+	c->wbuf_partnode_ofs = c->wbuf_ofs;
 	c->wbuf_len = 0;
 	return 0;
 }
 
+/* Trigger garbage collection to flush the write-buffer. */
 int jffs2_flush_wbuf_gc(struct jffs2_sb_info *c)
 {
-	return __jffs2_flush_wbuf(c, 2);
+	uint32_t old_wbuf_ofs;
+	uint32_t old_wbuf_len;
+	int ret = 0;
+
+	down(&c->alloc_sem);
+	old_wbuf_ofs = c->wbuf_ofs;
+	old_wbuf_len = c->wbuf_len;
+
+	while (old_wbuf_len &&
+	       old_wbuf_ofs == c->wbuf_ofs) {
+
+		up(&c->alloc_sem);
+
+		ret = jffs2_garbage_collect_pass(c);
+		if (ret) {
+			/* GC failed. Flush it with padding instead */
+			down(&c->alloc_sem);
+			ret = __jffs2_flush_wbuf(c, 2);
+			break;
+		}
+		down(&c->alloc_sem);
+	}
+
+	up(&c->alloc_sem);
+	return ret;
 }
 
+/* Pad write-buffer to end and write it, wasting space. */
 int jffs2_flush_wbuf_pad(struct jffs2_sb_info *c)
 {
 	return __jffs2_flush_wbuf(c, 1);
 }
 
+
 #define PAGE_DIV(x) ( (x) & (~(c->wbuf_pagesize - 1)) )
 #define PAGE_MOD(x) ( (x) & (c->wbuf_pagesize - 1) )
 int jffs2_flash_writev(struct jffs2_sb_info *c, const struct iovec *invecs, unsigned long count, loff_t to, size_t *retlen)
@@ -343,7 +368,8 @@
 		}
 		outvec_to += donelen;
 		c->wbuf_ofs = outvec_to;
-		
+		c->wbuf_partnode_ofs = to;
+
 		/* All invecs done ? */
 		if (invec == count)
 			goto alldone;
@@ -400,6 +426,7 @@
 		
 		donelen += wbuf_retlen;
 		c->wbuf_ofs = PAGE_DIV(outvec_to) + PAGE_DIV(totlen);
+		c->wbuf_partnode_ofs = to;
 
 		if (remainder) {
 			outvecs[splitvec].iov_base += split_ofs;
@@ -782,6 +809,7 @@
 	/* Initialise write buffer */
 	c->wbuf_pagesize = c->mtd->oobblock;
 	c->wbuf_ofs = 0xFFFFFFFF;
+	c->wbuf_partnode_ofs = c->wbuf_ofs;
 
 	/* Initialise process for timed wbuf flush */
 	INIT_WORK(&c->wbuf_task,(void*) jffs2_wbuf_process, (void *)c);


From dwmw2 at infradead.org  Mon Aug 25 06:34:43 2003
From: dwmw2 at infradead.org (David Woodhouse)
Date: Mon May 15 21:48:42 2006
Subject: mtd/drivers/mtd/nand diskonchip.c,1.4,1.5
Message-ID: <E19rEgN-0000oN-Nq@phoenix.infradead.org>

Update of /home/cvs/mtd/drivers/mtd/nand
In directory phoenix.infradead.org:/tmp/cvs-serv3100

Modified Files:
	diskonchip.c 
Log Message:
Add block_bad method, faked at the moment -- at least to prevent the
checking of byte 5 of OOB area from causing false positives.


Index: diskonchip.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/nand/diskonchip.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- diskonchip.c	11 Jul 2003 15:06:42 -0000	1.4
+++ diskonchip.c	25 Aug 2003 10:34:41 -0000	1.5
@@ -370,6 +370,12 @@
 	return 1; 
 }	
 
+static int doc200x_block_bad(struct mtd_info *mtd, unsigned long block)
+{
+	/* FIXME: Look it up in the BBT */
+	return 0;
+}
+
 struct doc_priv mydoc = {
 	.physadr = 0xd4000,
 	.curfloor = -1,
@@ -385,6 +391,7 @@
 	.hwcontrol = doc200x_hwcontrol,
 	.dev_ready = doc200x_dev_ready,
 	.waitfunc = doc200x_wait,
+	.block_bad = doc200x_block_bad,
 	.eccmode = NAND_ECC_SOFT,
 	.data_buf = mydatabuf,
 };


From dwmw2 at infradead.org  Mon Aug 25 07:31:49 2003
From: dwmw2 at infradead.org (David Woodhouse)
Date: Mon May 15 21:48:42 2006
Subject: mtd/fs/jffs2 dir.c,1.77,1.78 file.c,1.88,1.89 gc.c,1.103,1.104
 nodelist.h,1.95,1.96 os-linux.h,1.30,1.31 super-v24.c,1.69,1.70
 wbuf.c,1.36,1.37 write.c,1.65,1.66
Message-ID: <E19rFZd-0000zp-Oe@phoenix.infradead.org>

Update of /home/cvs/mtd/fs/jffs2
In directory phoenix.infradead.org:/tmp/cvs-serv3827

Modified Files:
	dir.c file.c gc.c nodelist.h os-linux.h super-v24.c wbuf.c 
	write.c 
Log Message:
Keep track of whether we're writing for GC or not

Index: dir.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/dir.c,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -r1.77 -r1.78
--- dir.c	5 Jun 2003 14:42:24 -0000	1.77
+++ dir.c	25 Aug 2003 11:31:46 -0000	1.78
@@ -338,7 +338,7 @@
 	ri->data_crc = cpu_to_je32(crc32(0, target, strlen(target)));
 	ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
 	
-	fn = jffs2_write_dnode(c, f, ri, target, strlen(target), phys_ofs, &writtenlen);
+	fn = jffs2_write_dnode(c, f, ri, target, strlen(target), phys_ofs, &writtenlen, NOT_GC);
 
 	jffs2_free_raw_inode(ri);
 
@@ -396,7 +396,7 @@
 	rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
 	rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen));
 
-	fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, &writtenlen);
+	fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, &writtenlen, NOT_GC);
 
 	if (IS_ERR(fd)) {
 		/* dirent failed to write. Delete the inode normally 
@@ -475,7 +475,7 @@
 	ri->data_crc = cpu_to_je32(0);
 	ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
 	
-	fn = jffs2_write_dnode(c, f, ri, NULL, 0, phys_ofs, &writtenlen);
+	fn = jffs2_write_dnode(c, f, ri, NULL, 0, phys_ofs, &writtenlen, NOT_GC);
 
 	jffs2_free_raw_inode(ri);
 
@@ -533,7 +533,7 @@
 	rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
 	rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen));
 
-	fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, &writtenlen);
+	fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, &writtenlen, NOT_GC);
 	
 	if (IS_ERR(fd)) {
 		/* dirent failed to write. Delete the inode normally 
@@ -635,7 +635,7 @@
 	ri->data_crc = cpu_to_je32(crc32(0, &dev, devlen));
 	ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
 	
-	fn = jffs2_write_dnode(c, f, ri, (char *)&dev, devlen, phys_ofs, &writtenlen);
+	fn = jffs2_write_dnode(c, f, ri, (char *)&dev, devlen, phys_ofs, &writtenlen, NOT_GC);
 
 	jffs2_free_raw_inode(ri);
 
@@ -696,7 +696,7 @@
 	rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
 	rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen));
 
-	fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, &writtenlen);
+	fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, &writtenlen, NOT_GC);
 	
 	if (IS_ERR(fd)) {
 		/* dirent failed to write. Delete the inode normally 

Index: file.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/file.c,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -r1.88 -r1.89
--- file.c	24 Aug 2003 20:34:52 -0000	1.88
+++ file.c	25 Aug 2003 11:31:46 -0000	1.89
@@ -167,7 +167,7 @@
 	else
 		ri->data_crc = cpu_to_je32(0);
 
-	new_metadata = jffs2_write_dnode(c, f, ri, mdata, mdatalen, phys_ofs, NULL);
+	new_metadata = jffs2_write_dnode(c, f, ri, mdata, mdatalen, phys_ofs, NULL, NOT_GC);
 	if (S_ISLNK(inode->i_mode))
 		kfree(mdata);
 	
@@ -308,7 +308,7 @@
 		ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
 		ri.data_crc = cpu_to_je32(0);
 		
-		fn = jffs2_write_dnode(c, f, &ri, NULL, 0, phys_ofs, NULL);
+		fn = jffs2_write_dnode(c, f, &ri, NULL, 0, phys_ofs, NULL, NOT_GC);
 
 		if (IS_ERR(fn)) {
 			ret = PTR_ERR(fn);

Index: gc.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/gc.c,v
retrieving revision 1.103
retrieving revision 1.104
diff -u -r1.103 -r1.104
--- gc.c	22 May 2003 18:01:02 -0000	1.103
+++ gc.c	25 Aug 2003 11:31:46 -0000	1.104
@@ -684,7 +684,7 @@
 	ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
 	ri.data_crc = cpu_to_je32(crc32(0, mdata, mdatalen));
 
-	new_fn = jffs2_write_dnode(c, f, &ri, mdata, mdatalen, phys_ofs, NULL);
+	new_fn = jffs2_write_dnode(c, f, &ri, mdata, mdatalen, phys_ofs, NULL, IS_GC);
 
 	if (IS_ERR(new_fn)) {
 		printk(KERN_WARNING "Error writing new dnode: %ld\n", PTR_ERR(new_fn));
@@ -728,7 +728,7 @@
 		       sizeof(rd)+rd.nsize, ret);
 		return ret;
 	}
-	new_fd = jffs2_write_dirent(c, f, &rd, fd->name, rd.nsize, phys_ofs, NULL);
+	new_fd = jffs2_write_dirent(c, f, &rd, fd->name, rd.nsize, phys_ofs, NULL, IS_GC);
 
 	if (IS_ERR(new_fd)) {
 		printk(KERN_WARNING "jffs2_write_dirent in garbage_collect_dirent failed: %ld\n", PTR_ERR(new_fd));
@@ -951,7 +951,7 @@
 		       sizeof(ri), ret);
 		return ret;
 	}
-	new_fn = jffs2_write_dnode(c, f, &ri, NULL, 0, phys_ofs, NULL);
+	new_fn = jffs2_write_dnode(c, f, &ri, NULL, 0, phys_ofs, NULL, IS_GC);
 
 	if (IS_ERR(new_fn)) {
 		printk(KERN_WARNING "Error writing new hole node: %ld\n", PTR_ERR(new_fn));
@@ -1114,7 +1114,7 @@
 		ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
 		ri.data_crc = cpu_to_je32(crc32(0, writebuf, cdatalen));
 	
-		new_fn = jffs2_write_dnode(c, f, &ri, writebuf, cdatalen, phys_ofs, NULL);
+		new_fn = jffs2_write_dnode(c, f, &ri, writebuf, cdatalen, phys_ofs, NULL, IS_GC);
 
 		if (IS_ERR(new_fn)) {
 			printk(KERN_WARNING "Error writing new dnode: %ld\n", PTR_ERR(new_fn));

Index: nodelist.h
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/nodelist.h,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -r1.95 -r1.96
--- nodelist.h	24 Aug 2003 10:29:09 -0000	1.95
+++ nodelist.h	25 Aug 2003 11:31:46 -0000	1.96
@@ -314,8 +314,11 @@
 
 /* write.c */
 int jffs2_do_new_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, uint32_t mode, struct jffs2_raw_inode *ri);
-struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_inode *ri, const unsigned char *data, uint32_t datalen, uint32_t flash_ofs,  uint32_t *writelen);
-struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_dirent *rd, const unsigned char *name, uint32_t namelen, uint32_t flash_ofs,  uint32_t *writelen);
+
+#define NOT_GC 0
+#define IS_GC 1
+struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_inode *ri, const unsigned char *data, uint32_t datalen, uint32_t flash_ofs,  uint32_t *writelen, int is_gc);
+struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_dirent *rd, const unsigned char *name, uint32_t namelen, uint32_t flash_ofs,  uint32_t *writelen, int is_gc);
 int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
 			    struct jffs2_raw_inode *ri, unsigned char *buf, 
 			    uint32_t offset, uint32_t writelen, uint32_t *retlen);

Index: os-linux.h
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/os-linux.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- os-linux.h	24 Aug 2003 20:34:52 -0000	1.30
+++ os-linux.h	25 Aug 2003 11:31:46 -0000	1.31
@@ -71,7 +71,7 @@
 
 /* Hmmm. P'raps generic code should only ever see versions of signal
    functions which do the locking automatically? */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,40)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,40) && !defined(__rh_config_h__)
 #define current_sig_lock current->sigmask_lock
 #else
 #define current_sig_lock current->sighand->siglock
@@ -118,7 +118,7 @@
 #define jffs2_nand_flash_setup(c) (0)
 #define jffs2_nand_flash_cleanup(c) do {} while(0)
 #define jffs2_wbuf_dirty(c) (0)
-#define jffs2_flash_writev jffs2_flash_direct_writev
+#define jffs2_flash_writev(a,b,c,d,e) jffs2_flash_direct_writev(a,b,c,d,e,0)
 #define jffs2_wbuf_timeout NULL
 #define jffs2_wbuf_process NULL
 
@@ -133,7 +133,7 @@
 struct kstatfs;
 
 /* wbuf.c */
-int jffs2_flash_writev(struct jffs2_sb_info *c, const struct iovec *vecs, unsigned long count, loff_t to, size_t *retlen);
+int jffs2_flash_writev(struct jffs2_sb_info *c, const struct iovec *vecs, unsigned long count, loff_t to, size_t *retlen, uint32_t ino);
 int jffs2_flash_write(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *retlen, const u_char *buf);
 int jffs2_flash_read(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *retlen, u_char *buf);
 int jffs2_check_oob_empty(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,int mode);

Index: super-v24.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/super-v24.c,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -r1.69 -r1.70
--- super-v24.c	24 Aug 2003 20:34:53 -0000	1.69
+++ super-v24.c	25 Aug 2003 11:31:47 -0000	1.70
@@ -104,6 +104,7 @@
 {
 	struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
 
+	D1(printk(KERN_DEBUG "jffs2_sync_fs() called\n"));
 	/* Flush with GC is OK -- it leaves a partially-written node
 	   but only a GC node, so no data are lost if it's not 
 	   complete and we immediately power off */

Index: wbuf.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/wbuf.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- wbuf.c	24 Aug 2003 20:34:53 -0000	1.36
+++ wbuf.c	25 Aug 2003 11:31:47 -0000	1.37
@@ -227,6 +227,8 @@
 	uint32_t old_wbuf_len;
 	int ret = 0;
 
+	D1(printk(KERN_DEBUG "jffs2_flush_wbuf_gc() called...\n"));
+
 	down(&c->alloc_sem);
 	old_wbuf_ofs = c->wbuf_ofs;
 	old_wbuf_len = c->wbuf_len;
@@ -236,6 +238,8 @@
 
 		up(&c->alloc_sem);
 
+		D1(printk(KERN_DEBUG "jffs2_flush_wbuf_gc() calls gc pass\n"));
+
 		ret = jffs2_garbage_collect_pass(c);
 		if (ret) {
 			/* GC failed. Flush it with padding instead */
@@ -246,6 +250,8 @@
 		down(&c->alloc_sem);
 	}
 
+	D1(printk(KERN_DEBUG "jffs2_flush_wbuf_gc() ends...\n"));
+
 	up(&c->alloc_sem);
 	return ret;
 }
@@ -259,7 +265,7 @@
 
 #define PAGE_DIV(x) ( (x) & (~(c->wbuf_pagesize - 1)) )
 #define PAGE_MOD(x) ( (x) & (c->wbuf_pagesize - 1) )
-int jffs2_flash_writev(struct jffs2_sb_info *c, const struct iovec *invecs, unsigned long count, loff_t to, size_t *retlen)
+int jffs2_flash_writev(struct jffs2_sb_info *c, const struct iovec *invecs, unsigned long count, loff_t to, size_t *retlen, uint32_t ino)
 {
 	struct iovec outvecs[3];
 	uint32_t totlen = 0;
@@ -476,7 +482,7 @@
 
 	vecs[0].iov_base = (unsigned char *) buf;
 	vecs[0].iov_len = len;
-	return jffs2_flash_writev(c, vecs, 1, ofs, retlen);
+	return jffs2_flash_writev(c, vecs, 1, ofs, retlen, NOT_GC);
 }
 
 /*

Index: write.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/write.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -r1.65 -r1.66
--- write.c	21 Jan 2003 18:11:29 -0000	1.65
+++ write.c	25 Aug 2003 11:31:47 -0000	1.66
@@ -86,7 +86,7 @@
 /* jffs2_write_dnode - given a raw_inode, allocate a full_dnode for it, 
    write it to the flash, link it into the existing inode/fragment list */
 
-struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_inode *ri, const unsigned char *data, uint32_t datalen, uint32_t flash_ofs,  uint32_t *writelen)
+struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_inode *ri, const unsigned char *data, uint32_t datalen, uint32_t flash_ofs,  uint32_t *writelen, int is_gc)
 
 {
 	struct jffs2_raw_node_ref *raw;
@@ -133,7 +133,7 @@
 	if (!datalen || !data)
 		cnt = 1;
 
-	ret = jffs2_flash_writev(c, vecs, cnt, flash_ofs, &retlen);
+	ret = jffs2_flash_writev(c, vecs, cnt, flash_ofs, &retlen, is_gc?0:f->inocache->ino);
 		
 	if (ret || (retlen != sizeof(*ri) + datalen)) {
 		printk(KERN_NOTICE "Write of %zd bytes at 0x%08x failed. returned %d, retlen %zd\n", 
@@ -191,7 +191,7 @@
 	return fn;
 }
 
-struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_dirent *rd, const unsigned char *name, uint32_t namelen, uint32_t flash_ofs,  uint32_t *writelen)
+struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_dirent *rd, const unsigned char *name, uint32_t namelen, uint32_t flash_ofs,  uint32_t *writelen, int is_gc)
 {
 	struct jffs2_raw_node_ref *raw;
 	struct jffs2_full_dirent *fd;
@@ -239,7 +239,7 @@
 	fd->name[namelen]=0;
 	fd->raw = raw;
 
-	ret = jffs2_flash_writev(c, vecs, 2, flash_ofs, &retlen);
+	ret = jffs2_flash_writev(c, vecs, 2, flash_ofs, &retlen, is_gc?0:fd->ino);
 	if (ret || (retlen != sizeof(*rd) + namelen)) {
 		printk(KERN_NOTICE "Write of %zd bytes at 0x%08x failed. returned %d, retlen %zd\n", 
 			       sizeof(*rd)+namelen, flash_ofs, ret, retlen);
@@ -331,7 +331,7 @@
 		ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
 		ri->data_crc = cpu_to_je32(crc32(0, comprbuf, cdatalen));
 
-		fn = jffs2_write_dnode(c, f, ri, comprbuf, cdatalen, phys_ofs, NULL);
+		fn = jffs2_write_dnode(c, f, ri, comprbuf, cdatalen, phys_ofs, NULL, NOT_GC);
 
 		if (comprtype != JFFS2_COMPR_NONE)
 			kfree(comprbuf);
@@ -397,7 +397,7 @@
 	ri->data_crc = cpu_to_je32(0);
 	ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
 
-	fn = jffs2_write_dnode(c, f, ri, NULL, 0, phys_ofs, &writtenlen);
+	fn = jffs2_write_dnode(c, f, ri, NULL, 0, phys_ofs, &writtenlen, NOT_GC);
 
 	D1(printk(KERN_DEBUG "jffs2_do_create created file with mode 0x%x\n",
 		  jemode_to_cpu(ri->mode)));
@@ -455,7 +455,7 @@
 	rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
 	rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
 
-	fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, &writtenlen);
+	fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, &writtenlen, NOT_GC);
 
 	jffs2_free_raw_dirent(rd);
 	
@@ -513,7 +513,7 @@
 	rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
 	rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
 
-	fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, NULL);
+	fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, NULL, NOT_GC);
 	
 	jffs2_free_raw_dirent(rd);
 
@@ -598,7 +598,7 @@
 	rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
 	rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
 
-	fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, NULL);
+	fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, NULL, NOT_GC);
 	
 	jffs2_free_raw_dirent(rd);
 


From dwmw2 at infradead.org  Mon Aug 25 07:38:08 2003
From: dwmw2 at infradead.org (David Woodhouse)
Date: Mon May 15 21:48:42 2006
Subject: mtd/fs/jffs2 file.c,1.89,1.90 nodelist.h,1.96,1.97
 super-v24.c,1.70,1.71 super.c,1.84,1.85 wbuf.c,1.37,1.38
Message-ID: <E19rFfk-00011b-13@phoenix.infradead.org>

Update of /home/cvs/mtd/fs/jffs2
In directory phoenix.infradead.org:/tmp/cvs-serv3937

Modified Files:
	file.c nodelist.h super-v24.c super.c wbuf.c 
Log Message:
jffs2_flush_wbuf_gc() takes ino argument, for fsync sanity

Index: file.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/file.c,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -r1.89 -r1.90
--- file.c	25 Aug 2003 11:31:46 -0000	1.89
+++ file.c	25 Aug 2003 11:38:05 -0000	1.90
@@ -30,10 +30,8 @@
 	struct inode *inode = dentry->d_inode;
 	struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
 
-	/* Trigger GC to flush the pending writes.
-	   FIXME: We should do this only if our particular inode has
-	   writes pending in the wbuf */
-	jffs2_flush_wbuf_gc(c);
+	/* Trigger GC to flush any pending writes for this inode */
+	jffs2_flush_wbuf_gc(c, inode->i_ino);
 			
 	return 0;	
 }

Index: nodelist.h
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/nodelist.h,v
retrieving revision 1.96
retrieving revision 1.97
diff -u -r1.96 -r1.97
--- nodelist.h	25 Aug 2003 11:31:46 -0000	1.96
+++ nodelist.h	25 Aug 2003 11:38:05 -0000	1.97
@@ -386,7 +386,7 @@
 
 #ifdef CONFIG_JFFS2_FS_NAND
 /* wbuf.c */
-int jffs2_flush_wbuf_gc(struct jffs2_sb_info *c);
+int jffs2_flush_wbuf_gc(struct jffs2_sb_info *c, uint32_t ino);
 int jffs2_flush_wbuf_pad(struct jffs2_sb_info *c);
 int jffs2_check_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
 int jffs2_write_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);

Index: super-v24.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/super-v24.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -r1.70 -r1.71
--- super-v24.c	25 Aug 2003 11:31:47 -0000	1.70
+++ super-v24.c	25 Aug 2003 11:38:05 -0000	1.71
@@ -108,7 +108,7 @@
 	/* Flush with GC is OK -- it leaves a partially-written node
 	   but only a GC node, so no data are lost if it's not 
 	   complete and we immediately power off */
-	return jffs2_flush_wbuf_gc(c);
+	return jffs2_flush_wbuf_gc(c, 0);
 }
 
 static DECLARE_FSTYPE_DEV(jffs2_fs_type, "jffs2", jffs2_read_super);

Index: super.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/super.c,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -r1.84 -r1.85
--- super.c	24 Aug 2003 20:34:53 -0000	1.84
+++ super.c	25 Aug 2003 11:38:05 -0000	1.85
@@ -280,7 +280,7 @@
 		/* Flush with GC is OK -- it leaves a partially-written node
 		   but only a GC node, so no data are lost if it's not 
 		   complete and we immediately power off */
-		return jffs2_flush_wbuf_gc(c);
+		return jffs2_flush_wbuf_gc(c, 0);
 
 	return 0;	
 }

Index: wbuf.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/wbuf.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- wbuf.c	25 Aug 2003 11:31:47 -0000	1.37
+++ wbuf.c	25 Aug 2003 11:38:05 -0000	1.38
@@ -108,7 +108,7 @@
 	up(&c->alloc_sem);
 	/* if !c->nextblock then the tail will have got flushed from
 	   jffs2_do_reserve_space() anyway. */
-	jffs2_flush_wbuf_gc(c);
+	jffs2_flush_wbuf_gc(c, 0);
 }
 
 
@@ -220,14 +220,17 @@
 	return 0;
 }
 
-/* Trigger garbage collection to flush the write-buffer. */
-int jffs2_flush_wbuf_gc(struct jffs2_sb_info *c)
+/* Trigger garbage collection to flush the write-buffer. 
+   If ino arg is zero, do it if _any_ real (i.e. not GC) writes are
+   outstanding. If ino arg non-zero, do it only if a write for the 
+   given inode is outstanding. */
+int jffs2_flush_wbuf_gc(struct jffs2_sb_info *c, uint32_t ino)
 {
 	uint32_t old_wbuf_ofs;
 	uint32_t old_wbuf_len;
 	int ret = 0;
 
-	D1(printk(KERN_DEBUG "jffs2_flush_wbuf_gc() called...\n"));
+	D1(printk(KERN_DEBUG "jffs2_flush_wbuf_gc() called for ino #%u...\n", ino));
 
 	down(&c->alloc_sem);
 	old_wbuf_ofs = c->wbuf_ofs;


From dwmw2 at infradead.org  Mon Aug 25 08:03:22 2003
From: dwmw2 at infradead.org (David Woodhouse)
Date: Mon May 15 21:48:42 2006
Subject: mtd/include/linux jffs2_fs_sb.h,1.40,1.41
Message-ID: <E19rG4A-00016N-BE@phoenix.infradead.org>

Update of /home/cvs/mtd/include/linux
In directory phoenix.infradead.org:/tmp/cvs-serv4228/include/linux

Modified Files:
	jffs2_fs_sb.h 
Log Message:
Make wbuf code actually keep track of which inodes are dirty.


Index: jffs2_fs_sb.h
===================================================================
RCS file: /home/cvs/mtd/include/linux/jffs2_fs_sb.h,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- jffs2_fs_sb.h	24 Aug 2003 20:34:52 -0000	1.40
+++ jffs2_fs_sb.h	25 Aug 2003 12:03:19 -0000	1.41
@@ -15,6 +15,8 @@
 #define JFFS2_SB_FLAG_RO 1
 #define JFFS2_SB_FLAG_MOUNTING 2
 
+struct jffs2_inodirty;
+
 /* A struct for the overall file system control.  Pointers to
    jffs2_sb_info structs are named `c' in the source code.  
    Nee jffs_control
@@ -91,6 +93,7 @@
 	uint32_t wbuf_ofs;
 	uint32_t wbuf_len;
 	uint32_t wbuf_pagesize;
+	struct jffs2_inodirty *wbuf_inodes;
 	struct work_struct wbuf_task;		/* task for timed wbuf flush */
 	struct timer_list wbuf_timer;		/* timer for flushing wbuf */
 


From dwmw2 at infradead.org  Mon Aug 25 08:03:22 2003
From: dwmw2 at infradead.org (David Woodhouse)
Date: Mon May 15 21:48:42 2006
Subject: mtd/fs/jffs2 wbuf.c,1.38,1.39
Message-ID: <E19rG4A-00016S-Mm@phoenix.infradead.org>

Update of /home/cvs/mtd/fs/jffs2
In directory phoenix.infradead.org:/tmp/cvs-serv4228/fs/jffs2

Modified Files:
	wbuf.c 
Log Message:
Make wbuf code actually keep track of which inodes are dirty.


Index: wbuf.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/wbuf.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- wbuf.c	25 Aug 2003 11:38:05 -0000	1.38
+++ wbuf.c	25 Aug 2003 12:03:20 -0000	1.39
@@ -24,6 +24,70 @@
 /* two seconds timeout for timed wbuf-flushing */
 #define WBUF_FLUSH_TIMEOUT	2 * HZ
 
+struct jffs2_inodirty {
+	uint32_t ino;
+	struct jffs2_inodirty *next;
+};
+
+static struct jffs2_inodirty inodirty_nomem;
+
+static int jffs2_wbuf_pending_for_ino(struct jffs2_sb_info *c, uint32_t ino)
+{
+	struct jffs2_inodirty *this = c->wbuf_inodes;
+
+	/* If a malloc failed, consider _everything_ dirty */
+	if (this == &inodirty_nomem)
+		return 1;
+
+	/* If ino == 0, _any_ non-GC writes mean 'yes' */
+	if (this && !ino)
+		return 1;
+
+	/* Look to see if the inode in question is pending in the wbuf */
+	while (this) {
+		if (this->ino == ino)
+			return 1;
+		this = this->next;
+	}
+	return 0;
+}
+
+static void jffs2_clear_wbuf_ino_list(struct jffs2_sb_info *c)
+{
+	struct jffs2_inodirty *this;
+
+	this = c->wbuf_inodes;
+
+	if (this != &inodirty_nomem) {
+		while (this) {
+			struct jffs2_inodirty *next = this->next;
+			kfree(this);
+			this = next;
+		}
+	}
+	c->wbuf_inodes = NULL;
+}
+
+static void jffs2_wbuf_dirties_inode(struct jffs2_sb_info *c, uint32_t ino)
+{
+	struct jffs2_inodirty *new;
+
+	if (jffs2_wbuf_pending_for_ino(c, ino))
+		return;
+
+	new = kmalloc(sizeof(*new), GFP_KERNEL);
+	if (!new) {
+		D1(printk(KERN_DEBUG "No memory to allocate inodirty. Fallback to all considered dirty\n"));
+		jffs2_clear_wbuf_ino_list(c);
+		c->wbuf_inodes = &inodirty_nomem;
+		return;
+	}
+	new->ino = ino;
+	new->next = c->wbuf_inodes;
+	c->wbuf_inodes = new;
+	return;
+}
+
 static inline void jffs2_refile_wbuf_blocks(struct jffs2_sb_info *c)
 {
 	struct list_head *this, *next;
@@ -210,6 +274,7 @@
 	/* Stick any now-obsoleted blocks on the erase_pending_list */
 	spin_lock(&c->erase_completion_lock);
 	jffs2_refile_wbuf_blocks(c);
+	jffs2_clear_wbuf_ino_list(c);
 	spin_unlock(&c->erase_completion_lock);
 
 	memset(c->wbuf,0xff,c->wbuf_pagesize);
@@ -233,6 +298,12 @@
 	D1(printk(KERN_DEBUG "jffs2_flush_wbuf_gc() called for ino #%u...\n", ino));
 
 	down(&c->alloc_sem);
+	if (!jffs2_wbuf_pending_for_ino(c, ino)) {
+		D1(printk(KERN_DEBUG "Ino #%d not pending in wbuf. Returning\n", ino));
+		up(&c->alloc_sem);
+		return 0;
+	}
+
 	old_wbuf_ofs = c->wbuf_ofs;
 	old_wbuf_len = c->wbuf_len;
 
@@ -462,7 +533,11 @@
 	}
 	c->wbuf_len = wbuf_ptr - c->wbuf;
 
-alldone:	
+	/* If there's a remainder in the wbuf and it's a non-GC write,
+	   remember that the wbuf affects this ino */
+	if (c->wbuf_len && ino)
+		jffs2_wbuf_dirties_inode(c, ino);
+alldone:
 	*retlen = donelen;
 	/* Setup timed wbuf flush, if buffer len != 0 */
 	if (c->wbuf_len) {


From dwmw2 at infradead.org  Mon Aug 25 08:07:05 2003
From: dwmw2 at infradead.org (David Woodhouse)
Date: Mon May 15 21:48:43 2006
Subject: mtd/fs/jffs2 TODO,1.11,1.12
Message-ID: <E19rG7l-00017t-2x@phoenix.infradead.org>

Update of /home/cvs/mtd/fs/jffs2
In directory phoenix.infradead.org:/tmp/cvs-serv4307

Modified Files:
	TODO 
Log Message:
Update TODO list to reflect current status


Index: TODO
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/TODO,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- TODO	24 Aug 2003 20:34:52 -0000	1.11
+++ TODO	25 Aug 2003 12:07:02 -0000	1.12
@@ -13,8 +13,7 @@
  - NAND flash support:
 	- Deal with write errors. Data don't get lost - we just have to write 
 	  the affected node(s) out again somewhere else.
-	- make fsync flush only if actually required
-	- reboot notifier
+	- reboot notifier (not needed; sync and unmount DTRT and nothing else autosyncs on reboot)
 
 
  - Optimisations:


From dwmw2 at infradead.org  Mon Aug 25 09:24:14 2003
From: dwmw2 at infradead.org (David Woodhouse)
Date: Mon May 15 21:48:43 2006
Subject: mtd/include/linux jffs2_fs_sb.h,1.41,1.42
Message-ID: <E19rHKQ-0001Qg-Ut@phoenix.infradead.org>

Update of /home/cvs/mtd/include/linux
In directory phoenix.infradead.org:/tmp/cvs-serv5481/include/linux

Modified Files:
	jffs2_fs_sb.h 
Log Message:
Make the timed sync happen from kupdated, don't muck around with our
own timers and schedule_work() any more. Remove sync_fs() since using
write_super() is sufficient for now.


Index: jffs2_fs_sb.h
===================================================================
RCS file: /home/cvs/mtd/include/linux/jffs2_fs_sb.h,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- jffs2_fs_sb.h	25 Aug 2003 12:03:19 -0000	1.41
+++ jffs2_fs_sb.h	25 Aug 2003 13:24:12 -0000	1.42
@@ -94,8 +94,6 @@
 	uint32_t wbuf_len;
 	uint32_t wbuf_pagesize;
 	struct jffs2_inodirty *wbuf_inodes;
-	struct work_struct wbuf_task;		/* task for timed wbuf flush */
-	struct timer_list wbuf_timer;		/* timer for flushing wbuf */
 
 	/* Information about out-of-band area usage... */
 	struct nand_oobinfo *oobinfo;


From dwmw2 at infradead.org  Mon Aug 25 09:24:15 2003
From: dwmw2 at infradead.org (David Woodhouse)
Date: Mon May 15 21:48:43 2006
Subject: mtd/fs/jffs2 background.c,1.39,1.40 fs.c,1.26,1.27
 super-v24.c,1.71,1.72 super.c,1.85,1.86 wbuf.c,1.39,1.40
Message-ID: <E19rHKR-0001Ql-GI@phoenix.infradead.org>

Update of /home/cvs/mtd/fs/jffs2
In directory phoenix.infradead.org:/tmp/cvs-serv5481/fs/jffs2

Modified Files:
	background.c fs.c super-v24.c super.c wbuf.c 
Log Message:
Make the timed sync happen from kupdated, don't muck around with our
own timers and schedule_work() any more. Remove sync_fs() since using
write_super() is sufficient for now.


Index: background.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/background.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- background.c	30 Jun 2003 10:58:57 -0000	1.39
+++ background.c	25 Aug 2003 13:24:12 -0000	1.40
@@ -61,14 +61,6 @@
 
 void jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c)
 {
-#ifdef CONFIG_JFFS2_FS_NAND
-	if (jffs2_cleanmarker_oob(c)) {
-		/* stop a eventually scheduled wbuf flush timer */
-		del_timer_sync(&c->wbuf_timer);
-		/* make sure, that a scheduled wbuf flush task is completed */
-		flush_scheduled_work();
-	}
-#endif
 	spin_lock(&c->erase_completion_lock);
 	if (c->gc_task) {
 		D1(printk(KERN_DEBUG "jffs2: Killing GC task %d\n", c->gc_task->pid));

Index: fs.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/fs.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- fs.c	2 Jul 2003 10:46:00 -0000	1.26
+++ fs.c	25 Aug 2003 13:24:12 -0000	1.27
@@ -192,6 +192,7 @@
 	D1(printk(KERN_DEBUG "jffs2_write_super()\n"));
 	jffs2_garbage_collect_trigger(c);
 	jffs2_erase_pending_blocks(c);
+	jffs2_flush_wbuf_gc(c, 0);
 }
 
 

Index: super-v24.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/super-v24.c,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -r1.71 -r1.72
--- super-v24.c	25 Aug 2003 11:38:05 -0000	1.71
+++ super-v24.c	25 Aug 2003 13:24:12 -0000	1.72
@@ -29,7 +29,6 @@
 #endif
 
 static void jffs2_put_super (struct super_block *);
-static int jffs2_sync_fs(struct super_block *);
 
 static struct super_operations jffs2_super_operations =
 {
@@ -39,7 +38,6 @@
 	statfs:		jffs2_statfs,
 	remount_fs:	jffs2_remount_fs,
 	clear_inode:	jffs2_clear_inode,
-	sync_fs:	jffs2_sync_fs,
 };
 
 
@@ -98,17 +96,6 @@
 	put_mtd_device(c->mtd);
 	
 	D1(printk(KERN_DEBUG "jffs2_put_super returning\n"));
-}
-
-static int jffs2_sync_fs(struct super_block *sb)
-{
-	struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
-
-	D1(printk(KERN_DEBUG "jffs2_sync_fs() called\n"));
-	/* Flush with GC is OK -- it leaves a partially-written node
-	   but only a GC node, so no data are lost if it's not 
-	   complete and we immediately power off */
-	return jffs2_flush_wbuf_gc(c, 0);
 }
 
 static DECLARE_FSTYPE_DEV(jffs2_fs_type, "jffs2", jffs2_read_super);

Index: super.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/super.c,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -r1.85 -r1.86
--- super.c	25 Aug 2003 11:38:05 -0000	1.85
+++ super.c	25 Aug 2003 13:24:12 -0000	1.86
@@ -28,8 +28,6 @@
 #include "nodelist.h"
 
 static void jffs2_put_super(struct super_block *);
-static int jffs2_sync_fs(struct super_block *, int);
-
 
 static kmem_cache_t *jffs2_inode_cachep;
 
@@ -68,7 +66,6 @@
 	.statfs =	jffs2_statfs,
 	.remount_fs =	jffs2_remount_fs,
 	.clear_inode =	jffs2_clear_inode,
-	.sync_fs =	jffs2_sync_fs,
 };
 
 static int jffs2_sb_compare(struct super_block *sb, void *data)
@@ -270,19 +267,6 @@
 		c->mtd->sync(c->mtd);
 
 	D1(printk(KERN_DEBUG "jffs2_put_super returning\n"));
-}
-
-static int jffs2_sync_fs(struct super_block *sb, int wait)
-{
-	struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
-
-	if (wait)
-		/* Flush with GC is OK -- it leaves a partially-written node
-		   but only a GC node, so no data are lost if it's not 
-		   complete and we immediately power off */
-		return jffs2_flush_wbuf_gc(c, 0);
-
-	return 0;	
 }
 
 static void jffs2_kill_sb(struct super_block *sb)

Index: wbuf.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/wbuf.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- wbuf.c	25 Aug 2003 12:03:20 -0000	1.39
+++ wbuf.c	25 Aug 2003 13:24:13 -0000	1.40
@@ -72,6 +72,9 @@
 {
 	struct jffs2_inodirty *new;
 
+	/* Mark the superblock dirty so that kupdated will flush... */
+	OFNI_BS_2SFFJ(c)->s_dirt = 1;
+
 	if (jffs2_wbuf_pending_for_ino(c, ino))
 		return;
 
@@ -117,64 +120,6 @@
 	}
 }
 
-/* 
-*	Timed flushing of wbuf. If we have no consecutive write to wbuf, within	
-*	the specified time, we flush the contents with padding !
-*/
-void jffs2_wbuf_timeout (unsigned long data)
-{
-	struct jffs2_sb_info *c = (struct jffs2_sb_info *) data;
-	/* 
-	* Wake up the flush process, we need process context to have the right 
-	* to sleep on flash write
-	*/
-	D1(printk(KERN_DEBUG "jffs2_wbuf_timeout(): timer expired\n"));
-	schedule_work(&c->wbuf_task);
-}
-
-/*
-*	Process for timed wbuf flush
-*
-*	FIXME What happens, if we have a write failure there ????
-*/
-void jffs2_wbuf_process (void *data)
-{
-	struct jffs2_sb_info *c = (struct jffs2_sb_info *) data;	
-	
-	D1(printk(KERN_DEBUG "jffs2_wbuf_process() entered\n"));
-	
-	/* Check, if the timer is active again */
-	if (timer_pending (&c->wbuf_timer)) {
-		D1(printk (KERN_DEBUG "Nothing to do, timer is active again\n"));
-		return;
-	}
-
-	if (down_trylock(&c->alloc_sem)) {
-		/* If someone else has the alloc_sem, they're about to
-		   write anyway. So no need to waste space by
-		   padding */
-		D1(printk (KERN_DEBUG "jffs2_wbuf_process() alloc_sem already occupied\n"));
-		return;
-	}	
-
-	D1(printk (KERN_DEBUG "jffs2_wbuf_process() alloc_sem got\n"));
-
-	if (!c->nextblock) {
-		D1(printk(KERN_DEBUG "jffs2_wbuf_process(): nextblock NULL, nothing to do\n"));
-		if (c->wbuf_len) {
-			printk(KERN_WARNING "jffs2_wbuf_process(): c->wbuf_len is 0x%03x but nextblock is NULL!\n", c->wbuf_len);
-			up(&c->alloc_sem);
-			BUG();
-		}
-		return;
-	}
-	
-	up(&c->alloc_sem);
-	/* if !c->nextblock then the tail will have got flushed from
-	   jffs2_do_reserve_space() anyway. */
-	jffs2_flush_wbuf_gc(c, 0);
-}
-
 
 /* Meaning of pad argument:
    0: Do not pad. Probably pointless - we only ever use this when we can't pad anyway.
@@ -197,9 +142,6 @@
 		BUG();
 	}
 
-	/* delete a eventually started timed wbuf flush */
-	del_timer_sync(&c->wbuf_timer);
-
 	if(!c->wbuf || !c->wbuf_len)
 		return 0;
 
@@ -535,15 +477,12 @@
 
 	/* If there's a remainder in the wbuf and it's a non-GC write,
 	   remember that the wbuf affects this ino */
-	if (c->wbuf_len && ino)
-		jffs2_wbuf_dirties_inode(c, ino);
 alldone:
 	*retlen = donelen;
-	/* Setup timed wbuf flush, if buffer len != 0 */
-	if (c->wbuf_len) {
-		D1(printk (KERN_DEBUG "jffs2_flash_writev: mod wbuf_timer\n"));	
-		mod_timer(&c->wbuf_timer, jiffies + WBUF_FLUSH_TIMEOUT);
-	}
+
+	if (c->wbuf_len && ino)
+		jffs2_wbuf_dirties_inode(c, ino);
+
 	return 0;
 }
 
@@ -894,14 +833,6 @@
 	c->wbuf_pagesize = c->mtd->oobblock;
 	c->wbuf_ofs = 0xFFFFFFFF;
 	c->wbuf_partnode_ofs = c->wbuf_ofs;
-
-	/* Initialise process for timed wbuf flush */
-	INIT_WORK(&c->wbuf_task,(void*) jffs2_wbuf_process, (void *)c);
-
-	/* Initialise timer for timed wbuf flush */
-	init_timer(&c->wbuf_timer);
-	c->wbuf_timer.function = jffs2_wbuf_timeout;
-	c->wbuf_timer.data = (unsigned long) c;
 
 	/* FIXME: If we had a generic way of describing the hardware's
 	   use of OOB area, we could perhaps make this generic too. */


From ppopov at infradead.org  Thu Aug 28 02:50:27 2003
From: ppopov at infradead.org (ppopov@infradead.org)
Date: Mon May 15 21:48:43 2006
Subject: mtd/drivers/mtd/maps db1x00-flash.c,NONE,1.1 Config.in,1.53,1.54
 Makefile.common,1.2,1.3 pb1xxx-flash.c,1.9,1.10
Message-ID: <E19sGbz-0008Hf-1C@phoenix.infradead.org>

Update of /home/cvs/mtd/drivers/mtd/maps
In directory phoenix.infradead.org:/tmp/cvs-serv31826/drivers/mtd/maps

Modified Files:
	Config.in Makefile.common pb1xxx-flash.c 
Added Files:
	db1x00-flash.c 
Log Message:
Updated the pb1x00 and db1x00 mapping files with the new APIs.


--- NEW FILE db1x00-flash.c ---
/*
 * Flash memory access on Alchemy Db1xxx boards
 * 
 * (C) 2003 Pete Popov <ppopov@pacbell.net>
 * 
 */

#include <linux/config.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/init.h>
#include <linux/kernel.h>

#include <linux/mtd/mtd.h>
#include <linux/mtd/map.h>
#include <linux/mtd/partitions.h>

#include <asm/io.h>
#include <asm/au1000.h>
#include <asm/db1x00.h>

#ifdef 	DEBUG_RW
#define	DBG(x...)	printk(x)
#else
#define	DBG(x...)	
#endif

static unsigned long window_addr;
static unsigned long window_size;
static unsigned long flash_size;

static BCSR * const bcsr = (BCSR *)0xAE000000;
static unsigned char flash_buswidth = 4;

/* 
 * The Db1x boards support different flash densities. We setup
 * the mtd_partition structures below for default of 64Mbit 
 * flash densities, and override the partitions sizes, if
 * necessary, after we check the board status register.
 */

#ifdef DB1X00_BOTH_BANKS
/* both banks will be used. Combine the first bank and the first 
 * part of the second bank together into a single jffs/jffs2
 * partition.
 */
static struct mtd_partition db1x00_partitions[] = {
        {
                .name         =  "User FS",
                .size         =  0x1c00000,
                .offset       =  0x0000000
        },{
                .name         =  "yamon",
                .size         =  0x0100000,
		.offset       =  MTDPART_OFS_APPEND,
                .mask_flags   =  MTD_WRITEABLE
        },{
                .name         =  "raw kernel",
		.size         =  (0x300000-0x40000), /* last 256KB is env */
		.offset       =  MTDPART_OFS_APPEND,
        }
};
#elif defined(DB1X00_BOOT_ONLY)
static struct mtd_partition db1x00_partitions[] = {
        {
                .name         =  "User FS",
                .size         =  0x00c00000,
                .offset       =  0x0000000
        },{
                .name         =  "yamon",
                .size         =  0x0100000,
		.offset       =  MTDPART_OFS_APPEND,
                .mask_flags   =  MTD_WRITEABLE
        },{
                .name         =  "raw kernel",
		.size         =  (0x300000-0x40000), /* last 256KB is env */
		.offset       =  MTDPART_OFS_APPEND,
        }
};
#elif defined(DB1X00_USER_ONLY)
static struct mtd_partition db1x00_partitions[] = {
        {
                .name         =  "User FS",
                .size         =  0x0e00000,
                .offset       =  0x0000000
        },{
                .name         =  "raw kernel",
		.size         =  MTDPART_SIZ_FULL,
		.offset       =  MTDPART_OFS_APPEND,
        }
};
#else
#error MTD_DB1X00 define combo error /* should never happen */
#endif
#define NB_OF(x)  (sizeof(x)/sizeof(x[0]))

#define NAME     	"Db1x00 Linux Flash"

static struct map_info db1xxx_mtd_map = {
	.name		= NAME,
};

static struct mtd_partition *parsed_parts;
static struct mtd_info *db1xxx_mtd;

/*
 * Probe the flash density and setup window address and size
 * based on user CONFIG options. There are times when we don't
 * want the MTD driver to be probing the boot or user flash,
 * so having the option to enable only one bank is important.
 */
int setup_flash_params(void)
{
	switch ((bcsr->status >> 14) & 0x3) {
		case 0: /* 64Mbit devices */
			flash_size = 0x800000; /* 8MB per part */
#if defined(DB1X00_BOTH_BANKS)
			window_addr = 0x1E000000;
			window_size = 0x2000000; 
#elif defined(DB1X00_BOOT_ONLY)
			window_addr = 0x1F000000;
			window_size = 0x1000000; 
#else /* USER ONLY */
			window_addr = 0x1E000000;
			window_size = 0x1000000; 
#endif
			break;
		case 1:
			/* 128 Mbit devices */
			flash_size = 0x1000000; /* 16MB per part */
#if defined(DB1X00_BOTH_BANKS)
			window_addr = 0x1C000000;
			window_size = 0x4000000;
			/* USERFS from 0x1C00 0000 to 0x1FC0 0000 */
			db1x00_partitions[0].size = 0x3C00000;
#elif defined(DB1X00_BOOT_ONLY)
			window_addr = 0x1E000000;
			window_size = 0x2000000;
			/* USERFS from 0x1E00 0000 to 0x1FC0 0000 */
			db1x00_partitions[0].size = 0x1C00000;
#else /* USER ONLY */
			window_addr = 0x1C000000;
			window_size = 0x2000000;
			/* USERFS from 0x1C00 0000 to 0x1DE00000 */
			db1x00_partitions[0].size = 0x1DE0000;
#endif
			break;
		case 2:
			/* 256 Mbit devices */
			flash_size = 0x4000000; /* 64MB per part */
#if defined(DB1X00_BOTH_BANKS)
			return 1;
#elif defined(DB1X00_BOOT_ONLY)
			/* Boot ROM flash bank only; no user bank */
			window_addr = 0x1C000000;
			window_size = 0x4000000;
			/* USERFS from 0x1C00 0000 to 0x1FC00000 */
			db1x00_partitions[0].size = 0x3C00000;
#else /* USER ONLY */
			return 1;
#endif
			break;
		default:
			return 1;
	}
	db1xxx_mtd_map.size = window_size;
	db1xxx_mtd_map.buswidth = flash_buswidth;
	db1xxx_mtd_map.phys = window_addr;
	db1xxx_mtd_map.buswidth = flash_buswidth;
	return 0;
}

int __init db1x00_mtd_init(void)
{
	struct mtd_partition *parts;
	int nb_parts = 0;
	
	if (setup_flash_params()) 
		return -ENXIO;

	/*
	 * Static partition definition selection
	 */
	parts = db1x00_partitions;
	nb_parts = NB_OF(db1x00_partitions);

	/*
	 * Now let's probe for the actual flash.  Do it here since
	 * specific machine settings might have been set above.
	 */
	printk(KERN_NOTICE "Db1xxx flash: probing %d-bit flash bus\n", 
			db1xxx_mtd_map.buswidth*8);
	db1xxx_mtd_map.virt = (unsigned long)ioremap(window_addr, window_size);
	db1xxx_mtd = do_map_probe("cfi_probe", &db1xxx_mtd_map);
	if (!db1xxx_mtd) return -ENXIO;
	db1xxx_mtd->owner = THIS_MODULE;

	add_mtd_partitions(db1xxx_mtd, parts, nb_parts);
	return 0;
}

static void __exit db1x00_mtd_cleanup(void)
{
	if (db1xxx_mtd) {
		del_mtd_partitions(db1xxx_mtd);
		map_destroy(db1xxx_mtd);
		if (parsed_parts)
			kfree(parsed_parts);
	}
}

module_init(db1x00_mtd_init);
module_exit(db1x00_mtd_cleanup);

MODULE_AUTHOR("Pete Popov");
MODULE_DESCRIPTION("Db1x00 mtd map driver");
MODULE_LICENSE("GPL");

Index: Config.in
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/maps/Config.in,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -r1.53 -r1.54
--- Config.in	19 Aug 2003 09:19:37 -0000	1.53
+++ Config.in	28 Aug 2003 06:50:24 -0000	1.54
@@ -75,6 +75,11 @@
          bool '  Pb1x00 user flash device (2nd 32MiB bank)' CONFIG_MTD_PB1500_USER
       fi
    fi
+   tristate '  Db1x00 MTD support' CONFIG_MTD_DB1X00
+   if [ "$CONFIG_MTD_DB1X00" = "y" -o "$CONFIG_MTD_DB1X00" = "m" ]; then
+      bool '  Db1x00 boot flash device' CONFIG_MTD_DB1X00_BOOT 
+      bool '  Db1x00 user flash device (2nd bank)' CONFIG_MTD_DB1X00_USER
+   fi
    dep_tristate '  Flash chip mapping on ITE QED-4N-S01B, Globespan IVR or custom board' CONFIG_MTD_CSTM_MIPS_IXX $CONFIG_MTD_CFI $CONFIG_MTD_JEDEC $CONFIG_MTD_PARTITIONS 
    if [ "$CONFIG_MTD_CSTM_MIPS_IXX" = "y" -o "$CONFIG_MTD_CSTM_MIPS_IXX" = "m" ]; then
       hex '    Physical start address of flash mapping' CONFIG_MTD_CSTM_MIPS_IXX_START 0x8000000

Index: Makefile.common
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/maps/Makefile.common,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Makefile.common	28 May 2003 10:48:41 -0000	1.2
+++ Makefile.common	28 Aug 2003 06:50:24 -0000	1.3
@@ -48,6 +48,7 @@
 obj-$(CONFIG_MTD_SOLUTIONENGINE)+= solutionengine.o
 obj-$(CONFIG_MTD_PCI)		+= pci.o
 obj-$(CONFIG_MTD_PB1XXX)	+= pb1xxx-flash.o
+obj-$(CONFIG_MTD_DB1X00)        += db1x00-flash.o
 obj-$(CONFIG_MTD_LASAT)		+= lasat.o
 obj-$(CONFIG_MTD_AUTCPU12)	+= autcpu12-nvram.o
 obj-$(CONFIG_MTD_EDB7312)	+= edb7312.o

Index: pb1xxx-flash.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/maps/pb1xxx-flash.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- pb1xxx-flash.c	23 Jun 2003 11:48:18 -0000	1.9
+++ pb1xxx-flash.c	28 Aug 2003 06:50:24 -0000	1.10
@@ -9,8 +9,8 @@
 #include <linux/config.h>
 #include <linux/module.h>
 #include <linux/types.h>
-#include <linux/kernel.h>
 #include <linux/init.h>
+#include <linux/kernel.h>
 
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/map.h>
@@ -26,102 +26,87 @@
 #endif
 
 #ifdef CONFIG_MIPS_PB1000
+
 #define WINDOW_ADDR 0x1F800000
 #define WINDOW_SIZE 0x800000
-#endif
-
-
-static struct map_info pb1xxx_map = {
-	.name =	"Pb1xxx flash",
-};
 
-
-#ifdef CONFIG_MIPS_PB1000
-
-static unsigned long flash_size = 0x00800000;
-static unsigned char flash_buswidth = 4;
 static struct mtd_partition pb1xxx_partitions[] = {
         {
-                .name = "yamon env",
-                .size = 0x00020000,
-                .offset = 0,
-                .mask_flags = MTD_WRITEABLE
-        },{
-                .name = "User FS",
-                .size = 0x003e0000,
-                .offset = 0x20000,
-        },{
-                .name = "boot code",
-                .size = 0x100000,
-                .offset = 0x400000,
-                .mask_flags = MTD_WRITEABLE
-        },{
-                .name = "raw/kernel",
-                .size = 0x300000,
-                .offset = 0x500000
-        }
+                .name         =  "yamon env",
+                .size         =   0x00020000,
+                .offset       =   0,
+                .mask_flags   =   MTD_WRITEABLE},
+	{
+                .name         =   "User FS",
+                .size         =   0x003e0000,
+                .offset       =   0x20000,},
+	{
+                .name         =   "boot code",
+                .size         =   0x100000,
+                .offset       =   0x400000,
+                .mask_flags   =   MTD_WRITEABLE},
+	{
+                .name         =   "raw/kernel",
+                .size         =   0x300000,
+                .offset       =   0x500000}
 };
 
 #elif defined(CONFIG_MIPS_PB1500) || defined(CONFIG_MIPS_PB1100)
 
-static unsigned char flash_buswidth = 4;
 #if defined(CONFIG_MTD_PB1500_BOOT) && defined(CONFIG_MTD_PB1500_USER)
-/* both 32MiB banks will be used. Combine the first 32MiB bank and the
- * first 28MiB of the second bank together into a single jffs/jffs2
+/* both 32MB banks will be used. Combine the first 32MB bank and the
+ * first 28MB of the second bank together into a single jffs/jffs2
  * partition.
  */
-static unsigned long flash_size = 0x04000000;
 #define WINDOW_ADDR 0x1C000000
 #define WINDOW_SIZE 0x4000000
 static struct mtd_partition pb1xxx_partitions[] = {
         {
-                .name = "User FS",
-                .size =   0x3c00000,
-                .offset = 0x0000000
-        },{
-                .name = "yamon",
-                .size = 0x0100000,
-                .offset = 0x3c00000,
-                .mask_flags = MTD_WRITEABLE
-        },{
-                .name = "raw kernel",
-                .size = 0x02c0000,
-                .offset = 0x3d00000
+                .name         =   "User FS",
+                .size         =   0x3c00000,
+                .offset       =   0x0000000
+        },{
+                .name         =   "yamon",
+                .size         =   0x0100000,
+                .offset       =   0x3c00000,
+                .mask_flags   =   MTD_WRITEABLE
+        },{
+                .name         =   "raw kernel",
+                .size         =   0x02c0000,
+                .offset       =   0x3d00000
         }
 };
 #elif defined(CONFIG_MTD_PB1500_BOOT) && !defined(CONFIG_MTD_PB1500_USER)
-static unsigned long flash_size = 0x02000000;
 #define WINDOW_ADDR 0x1E000000
 #define WINDOW_SIZE 0x2000000
 static struct mtd_partition pb1xxx_partitions[] = {
         {
-                .name = "User FS",
-                .size =   0x1c00000,
-                .offset = 0x0000000
-        },{
-                .name = "yamon",
-                .size = 0x0100000,
-                .offset = 0x1c00000,
-                .mask_flags = MTD_WRITEABLE
-        },{
-                .name = "raw kernel",
-                .size = 0x02c0000,
-                .offset = 0x1d00000
+                .name         =   "User FS",
+                .size         =   0x1c00000,
+                .offset       =   0x0000000
+        },{
+                .name         =   "yamon",
+                .size         =   0x0100000,
+                .offset       =   0x1c00000,
+                .mask_flags   =   MTD_WRITEABLE
+        },{
+                .name         =   "raw kernel",
+                .size         =   0x02c0000,
+                .offset       =   0x1d00000
         }
 };
 #elif !defined(CONFIG_MTD_PB1500_BOOT) && defined(CONFIG_MTD_PB1500_USER)
-static unsigned long flash_size = 0x02000000;
 #define WINDOW_ADDR 0x1C000000
 #define WINDOW_SIZE 0x2000000
 static struct mtd_partition pb1xxx_partitions[] = {
         {
-                .name = "User FS",
-                .size =   0x1e00000,
-                .offset = 0x0000000
-        },{
-                .name = "raw kernel",
-                .size = 0x0200000,
-                .offset = 0x1e00000,
+                .name         =   "User FS",
+                .size         =    0x1e00000,
+                .offset       =    0x0000000
+        },{
+                .name         =    "raw kernel",
+                .size         =    0x0200000,
+                .offset       =    0x1e00000,
         }
 };
 #else
@@ -131,8 +116,20 @@
 #error Unsupported board
 #endif
 
-static struct mtd_partition *parsed_parts;
-static struct mtd_info *mymtd;
+#define NAME     	"Pb1x00 Linux Flash"
+#define PADDR    	WINDOW_ADDR
+#define BUSWIDTH	4
+#define SIZE		WINDOW_SIZE
+#define PARTITIONS	4
+
+static struct map_info pb1xxx_mtd_map = {
+	.name		= NAME,
+	.size		= SIZE,
+	.buswidth	= BUSWIDTH,
+	.phys		= PADDR,
+};
+
+static struct mtd_info *pb1xxx_mtd;
 
 int __init pb1xxx_mtd_init(void)
 {
@@ -140,49 +137,38 @@
 	int nb_parts = 0;
 	char *part_type;
 	
-	/* Default flash buswidth */
-	pb1xxx_map.buswidth = flash_buswidth;
-
 	/*
 	 * Static partition definition selection
 	 */
 	part_type = "static";
 	parts = pb1xxx_partitions;
 	nb_parts = ARRAY_SIZE(pb1xxx_partitions);
-	pb1xxx_map.size = flash_size;
 
 	/*
 	 * Now let's probe for the actual flash.  Do it here since
 	 * specific machine settings might have been set above.
 	 */
 	printk(KERN_NOTICE "Pb1xxx flash: probing %d-bit flash bus\n", 
-			pb1xxx_map.buswidth*8);
-	pb1xxx_map.phys = WINDOW_ADDR;
-	pb1xxx_map.virt = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);
-
-	simple_map_init(&pb1xxx_map);
-
-	mymtd = do_map_probe("cfi_probe", &pb1xxx_map);
-	if (!mymtd) {
-		iounmap(pb1xxx_map.virt);
-		return -ENXIO;
-	}
-	mymtd->owner = THIS_MODULE;
+			BUSWIDTH*8);
+	pb1xxx_mtd_map.virt = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);
+
+	simple_map_init(&pb1xxx_mtd_map);
+
+	pb1xxx_mtd = do_map_probe("cfi_probe", &pb1xxx_mtd_map);
+	if (!pb1xxx_mtd) return -ENXIO;
+	pb1xxx_mtd->owner = THIS_MODULE;
 
-	add_mtd_partitions(mymtd, parts, nb_parts);
+	add_mtd_partitions(pb1xxx_mtd, parts, nb_parts);
 	return 0;
 }
 
 static void __exit pb1xxx_mtd_cleanup(void)
 {
-	if (mymtd) {
-		del_mtd_partitions(mymtd);
-		map_destroy(mymtd);
-		if (parsed_parts)
-			kfree(parsed_parts);
+	if (pb1xxx_mtd) {
+		del_mtd_partitions(pb1xxx_mtd);
+		map_destroy(pb1xxx_mtd);
+		iounmap((void *) pb1xxx_mtd_map.virt);
 	}
-	if (pb1xxx_map.virt)
-		iounmap(pb1xxx_map.virt);
 }
 
 module_init(pb1xxx_mtd_init);


From dwmw2 at infradead.org  Fri Aug 29 10:25:51 2003
From: dwmw2 at infradead.org (David Woodhouse)
Date: Mon May 15 21:48:43 2006
Subject: mtd/patches patchin.sh,1.15,1.16
Message-ID: <E19skCF-0007SD-Ea@phoenix.infradead.org>

Update of /home/cvs/mtd/patches
In directory phoenix.infradead.org:/tmp/cvs-serv28634

Modified Files:
	patchin.sh 
Log Message:
Be helpful when invoked with no args


Index: patchin.sh
===================================================================
RCS file: /home/cvs/mtd/patches/patchin.sh,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- patchin.sh	12 Jun 2003 09:22:45 -0000	1.15
+++ patchin.sh	29 Aug 2003 14:25:48 -0000	1.16
@@ -62,8 +62,8 @@
 # Display usage of this script
 usage () {
 	echo "usage:  $0 [-c] [-j] kernelpath"
-	echo "-c copy files to kernel tree instead of building links"
-	echo "-j include jffs2 filesystem" 
+	echo "   -c  -- copy files to kernel tree instead of building links"
+	echo "   -j  -- include jffs2 filesystem" 
 	exit 1
 }
 
@@ -105,6 +105,10 @@
 done
 shift `expr $OPTIND - 1`
 LINUXDIR=$1
+
+if [ -z $LINUXDIR ]; then
+    usage;
+fi
 
 # Check if kerneldir contains a Makefile
 if [ ! -f $LINUXDIR/Makefile ] 


From dwmw2 at infradead.org  Fri Aug 29 11:31:47 2003
From: dwmw2 at infradead.org (David Woodhouse)
Date: Mon May 15 21:48:43 2006
Subject: mtd/fs/jffs2 wbuf.c,1.40,1.41
Message-ID: <E19slE3-0007ma-41@phoenix.infradead.org>

Update of /home/cvs/mtd/fs/jffs2
In directory phoenix.infradead.org:/tmp/cvs-serv29897

Modified Files:
	wbuf.c 
Log Message:
Be more explicit when reporting an apparently-bad block.


Index: wbuf.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/wbuf.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- wbuf.c	25 Aug 2003 13:24:13 -0000	1.40
+++ wbuf.c	29 Aug 2003 15:31:44 -0000	1.41
@@ -678,7 +678,8 @@
 
 		/* Check for bad block marker */
 		if (buf[c->badblock_pos] != 0xff) {
-			D1 (printk (KERN_WARNING "jffs2_check_nand_cleanmarker(): Bad block at %08x\n", jeb->offset));
+			D1 (printk (KERN_WARNING "jffs2_check_nand_cleanmarker(): Bad block at %08x (has %02x %02x in badblock_pos %d\n",
+				    jeb->offset, buf[c->badblock_pos],  buf[c->badblock_pos + oob_size], c->badblock_pos));
 			return 2;
 		}
 


