* Prepare for release

* Fix problems in memory test on some boards (which was not
  non-destructive as intended)

* Patch by Gary Jennejohn, 28 Oct 2003:
  Change fs/fat/fat.c to put I/O buffers in BSS instead on the stack
  to prevent stack overflow on ARM systems
diff --git a/board/RRvision/RRvision.c b/board/RRvision/RRvision.c
index d6f5c2a..8ed561d 100644
--- a/board/RRvision/RRvision.c
+++ b/board/RRvision/RRvision.c
@@ -230,8 +230,8 @@
 	volatile immap_t *immap = (immap_t *) CFG_IMMR;
 	volatile memctl8xx_t *memctl = &immap->im_memctl;
 	volatile long int *addr;
-	ulong cnt, val;
-	ulong save[32];			/* to make test non-destructive */
+ 	ulong cnt, val, size;
+ 	ulong save[32];			/* to make test non-destructive */
 	unsigned char i = 0;
 
 	memctl->memc_mamr = mamr_value;
@@ -250,7 +250,13 @@
 
 	/* check at base address */
 	if ((val = *addr) != 0) {
+		/* Restore the original data before leaving the function.
+		 */
 		*addr = save[i];
+		for (cnt = 1; cnt <= maxsize / sizeof(long); cnt <<= 1) {
+			addr  = (volatile ulong *) base + cnt;
+			*addr = save[--i];
+		}
 		return (0);
 	}
 
@@ -261,7 +267,14 @@
 		*addr = save[--i];
 
 		if (val != (~cnt)) {
-			return (cnt * sizeof (long));
+			size = cnt * sizeof (long);
+			/* Restore the original data before returning
+			 */
+			for (cnt <<= 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
+				addr  = (volatile ulong *) base + cnt;
+				*addr = save[--i];
+			}
+			return (size);
 		}
 	}
 	return (maxsize);
diff --git a/board/atc/atc.c b/board/atc/atc.c
index 9aa942f..fad7646 100644
--- a/board/atc/atc.c
+++ b/board/atc/atc.c
@@ -269,7 +269,7 @@
 			  ulong orx, volatile uchar * base)
 {
 	volatile uchar c = 0xff;
-	ulong cnt, val;
+	ulong cnt, val, size;
 	volatile ulong *addr;
 	volatile uint *sdmr_ptr;
 	volatile uint *orx_ptr;
@@ -344,7 +344,13 @@
 	*addr = 0;
 
 	if ((val = *addr) != 0) {
+		/* Restore the original data before leaving the function.
+		 */
 		*addr = save[i];
+		for (cnt = 1; cnt <= maxsize / sizeof(long); cnt <<= 1) {
+			addr  = (volatile ulong *) base + cnt;
+			*addr = save[--i];
+		}
 		return (0);
 	}
 
@@ -353,10 +359,17 @@
 		val = *addr;
 		*addr = save[--i];
 		if (val != ~cnt) {
+			size = cnt * sizeof (long);
+			/* Restore the original data before returning
+			 */
+			for (cnt <<= 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
+				addr  = (volatile ulong *) base + cnt;
+				*addr = save[--i];
+			}
 			/* Write the actual size to ORx
 			 */
-			*orx_ptr = orx | ~(cnt * sizeof (long) - 1);
-			return (cnt * sizeof (long));
+			*orx_ptr = orx | ~(size - 1);
+			return (size);
 		}
 	}
 	return (maxsize);
diff --git a/board/c2mon/c2mon.c b/board/c2mon/c2mon.c
index 171d06e..0fdcebe 100644
--- a/board/c2mon/c2mon.c
+++ b/board/c2mon/c2mon.c
@@ -228,8 +228,8 @@
 	volatile immap_t *immap = (immap_t *) CFG_IMMR;
 	volatile memctl8xx_t *memctl = &immap->im_memctl;
 	volatile long int *addr;
-	ulong cnt, val;
-	ulong save[32];			/* to make test non-destructive */
+ 	ulong cnt, val, size;
+ 	ulong save[32];			/* to make test non-destructive */
 	unsigned char i = 0;
 
 	memctl->memc_mamr = mamr_value;
@@ -248,7 +248,13 @@
 
 	/* check at base address */
 	if ((val = *addr) != 0) {
+		/* Restore the original data before leaving the function.
+		 */
 		*addr = save[i];
+		for (cnt = 1; cnt <= maxsize / sizeof(long); cnt <<= 1) {
+			addr  = (volatile ulong *) base + cnt;
+			*addr = save[--i];
+		}
 		return (0);
 	}
 
@@ -259,7 +265,14 @@
 		*addr = save[--i];
 
 		if (val != (~cnt)) {
-			return (cnt * sizeof (long));
+			size = cnt * sizeof (long);
+			/* Restore the original data before returning
+			 */
+			for (cnt <<= 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
+				addr  = (volatile ulong *) base + cnt;
+				*addr = save[--i];
+			}
+			return (size);
 		}
 	}
 	return (maxsize);
diff --git a/board/etx094/etx094.c b/board/etx094/etx094.c
index d48772b..e52ca85 100644
--- a/board/etx094/etx094.c
+++ b/board/etx094/etx094.c
@@ -321,8 +321,8 @@
 	volatile immap_t *immap = (immap_t *) CFG_IMMR;
 	volatile memctl8xx_t *memctl = &immap->im_memctl;
 	volatile long int *addr;
-	ulong cnt, val;
-	ulong save[32];			/* to make test non-destructive */
+ 	ulong cnt, val, size;
+ 	ulong save[32];			/* to make test non-destructive */
 	unsigned char i = 0;
 
 	memctl->memc_mamr = mamr_value;
@@ -341,7 +341,13 @@
 
 	/* check at base address */
 	if ((val = *addr) != 0) {
+		/* Restore the original data before leaving the function.
+		 */
 		*addr = save[i];
+		for (cnt = 1; cnt <= maxsize / sizeof(long); cnt <<= 1) {
+			addr  = (volatile ulong *) base + cnt;
+			*addr = save[--i];
+		}
 		return (0);
 	}
 
@@ -352,7 +358,14 @@
 		*addr = save[--i];
 
 		if (val != (~cnt)) {
-			return (cnt * sizeof (long));
+			size = cnt * sizeof (long);
+			/* Restore the original data before returning
+			 */
+			for (cnt <<= 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
+				addr  = (volatile ulong *) base + cnt;
+				*addr = save[--i];
+			}
+			return (size);
 		}
 	}
 	return (maxsize);
diff --git a/board/evb64260/flash.c b/board/evb64260/flash.c
index bc52c12..7ca6f0a 100644
--- a/board/evb64260/flash.c
+++ b/board/evb64260/flash.c
@@ -97,7 +97,7 @@
 #ifndef CONFIG_P3G4
 	    printf("[");
 	    print_size (size, "");
-	    printf("@%08lX] ", size>>20, base);
+	    printf("@%08lX] ", base);
 #endif
 
 	    if (flash_info[i].flash_id == FLASH_UNKNOWN) {
diff --git a/board/rmu/rmu.c b/board/rmu/rmu.c
index 331fb98..5fda4c0 100644
--- a/board/rmu/rmu.c
+++ b/board/rmu/rmu.c
@@ -94,39 +94,41 @@
 
 long int initdram (int board_type)
 {
-    volatile immap_t     *immap  = (immap_t *)CFG_IMMR;
-    volatile memctl8xx_t *memctl = &immap->im_memctl;
-    long int size9 ;
+	volatile immap_t *immap = (immap_t *) CFG_IMMR;
+	volatile memctl8xx_t *memctl = &immap->im_memctl;
+	long int size9;
 
-    upmconfig(UPMA, (uint *)sdram_table, sizeof(sdram_table)/sizeof(uint));
+	upmconfig (UPMA, (uint *) sdram_table,
+		   sizeof (sdram_table) / sizeof (uint));
 
 	/* Refresh clock prescalar */
-    memctl->memc_mptpr = CFG_MPTPR ;
+	memctl->memc_mptpr = CFG_MPTPR;
 
-    memctl->memc_mar  = 0x00000088;
+	memctl->memc_mar = 0x00000088;
 
 	/* Map controller banks 1 to the SDRAM bank */
-    memctl->memc_or1 = CFG_OR1_PRELIM;
-    memctl->memc_br1 = CFG_BR1_PRELIM;
+	memctl->memc_or1 = CFG_OR1_PRELIM;
+	memctl->memc_br1 = CFG_BR1_PRELIM;
 
-    memctl->memc_mamr = CFG_MAMR_9COL & (~(MAMR_PTAE)); /* no refresh yet */
+	memctl->memc_mamr = CFG_MAMR_9COL & (~(MAMR_PTAE));	/* no refresh yet */
 
-    udelay(200);
+	udelay (200);
 
-    /* perform SDRAM initializsation sequence */
+	/* perform SDRAM initializsation sequence */
 
-	memctl->memc_mcr  = 0x80002136 ; /* SDRAM bank 0 */
-    udelay(1);
+	memctl->memc_mcr = 0x80002136;	/* SDRAM bank 0 */
+	udelay (1);
 
-    memctl->memc_mamr |= MAMR_PTAE;	/* enable refresh */
+	memctl->memc_mamr |= MAMR_PTAE;	/* enable refresh */
 
-    udelay (1000);
+	udelay (1000);
 
 	/* Check Bank 0 Memory Size,
 	 * 9 column mode
 	 */
 
-	size9 = dram_size (CFG_MAMR_9COL, (ulong *)SDRAM_BASE_PRELIM, SDRAM_MAX_SIZE) ;
+	size9 = dram_size (CFG_MAMR_9COL, (ulong *) SDRAM_BASE_PRELIM,
+			   SDRAM_MAX_SIZE);
 
 	/*
 	 * Final mapping:
@@ -135,7 +137,7 @@
 	memctl->memc_or1 = ((-size9) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
 	udelay (1000);
 
-    return (size9);
+	return (size9);
 }
 
 /* ------------------------------------------------------------------------- */
@@ -148,44 +150,58 @@
  * - short between data lines
  */
 
-static long int dram_size (long int mamr_value, long int *base, long int maxsize)
+static long int dram_size (long int mamr_value, long int *base,
+			   long int maxsize)
 {
-    volatile immap_t     *immap  = (immap_t *)CFG_IMMR;
-    volatile memctl8xx_t *memctl = &immap->im_memctl;
-    volatile long int	 *addr;
-    ulong		  cnt, val;
-    ulong		  save[32];	/* to make test non-destructive */
-    unsigned char	  i = 0;
+	volatile immap_t *immap = (immap_t *) CFG_IMMR;
+	volatile memctl8xx_t *memctl = &immap->im_memctl;
+	volatile long int *addr;
+	ulong cnt, val, size;
+	ulong save[32];		/* to make test non-destructive */
+	unsigned char i = 0;
 
-    memctl->memc_mamr = mamr_value;
+	memctl->memc_mamr = mamr_value;
 
-    for (cnt = maxsize/sizeof(long); cnt > 0; cnt >>= 1) {
-	addr = base + cnt;	/* pointer arith! */
+	for (cnt = maxsize / sizeof (long); cnt > 0; cnt >>= 1) {
+		addr = base + cnt;	/* pointer arith! */
 
-	save[i++] = *addr;
-	*addr = ~cnt;
-    }
+		save[i++] = *addr;
+		*addr = ~cnt;
+	}
 
-    /* write 0 to base address */
-    addr = base;
-    save[i] = *addr;
-    *addr = 0;
+	/* write 0 to base address */
+	addr = base;
+	save[i] = *addr;
+	*addr = 0;
 
-    /* check at base address */
-    if ((val = *addr) != 0) {
-	*addr = save[i];
-	return (0);
-    }
+	/* check at base address */
+	if ((val = *addr) != 0) {
+		/* Restore the original data before leaving the function.
+		 */
+		*addr = save[i];
+		for (cnt = 1; cnt <= maxsize / sizeof(long); cnt <<= 1) {
+			addr  = (volatile ulong *) base + cnt;
+			*addr = save[--i];
+		}
+		return (0);
+	}
 
-    for (cnt = 1; cnt <= maxsize/sizeof(long); cnt <<= 1) {
-	addr = base + cnt;	/* pointer arith! */
+	for (cnt = 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
+		addr = base + cnt;	/* pointer arith! */
 
-	val = *addr;
-	*addr = save[--i];
+		val = *addr;
+		*addr = save[--i];
 
-	if (val != (~cnt)) {
-	    return (cnt * sizeof(long));
+		if (val != (~cnt)) {
+			size = cnt * sizeof (long);
+			/* Restore the original data before returning
+			 */
+			for (cnt <<= 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
+				addr  = (volatile ulong *) base + cnt;
+				*addr = save[--i];
+			}
+			return (size);
+		}
 	}
-    }
-    return (maxsize);
+	return (maxsize);
 }
diff --git a/board/tqm8260/tqm8260.c b/board/tqm8260/tqm8260.c
index 556a1e3..a0a38ca 100644
--- a/board/tqm8260/tqm8260.c
+++ b/board/tqm8260/tqm8260.c
@@ -230,7 +230,7 @@
 	volatile uint *orx_ptr;
 	int i;
 	ulong save[32];				/* to make test non-destructive */
-	ulong maxsize;
+	ulong maxsize, size;
 
 	/* We must be able to test a location outsize the maximum legal size
 	 * to find out THAT we are outside; but this address still has to be
@@ -299,7 +299,13 @@
 	*addr = 0;
 
 	if ((val = *addr) != 0) {
+		/* Restore the original data before leaving the function.
+		 */
 		*addr = save[i];
+		for (cnt = 1; cnt <= maxsize / sizeof(long); cnt <<= 1) {
+			addr  = (volatile ulong *) base + cnt;
+			*addr = save[--i];
+		}
 		return (0);
 	}
 
@@ -308,10 +314,17 @@
 		val = *addr;
 		*addr = save[--i];
 		if (val != ~cnt) {
+			size = cnt * sizeof (long);
+			/* Restore the original data before leaving the function.
+			 */ 
+			for (cnt <<= 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
+				addr  = (volatile ulong *) base + cnt;
+				*addr = save[--i];
+			}
 			/* Write the actual size to ORx
 			 */
-			*orx_ptr = orx | ~(cnt * sizeof (long) - 1);
-			return (cnt * sizeof (long));
+			*orx_ptr = orx | ~(size - 1);
+			return (size);
 		}
 	}
 	return (maxsize);
diff --git a/board/tqm8xx/tqm8xx.c b/board/tqm8xx/tqm8xx.c
index 53f1f2a..badc794 100644
--- a/board/tqm8xx/tqm8xx.c
+++ b/board/tqm8xx/tqm8xx.c
@@ -389,8 +389,8 @@
 	volatile immap_t *immap = (immap_t *) CFG_IMMR;
 	volatile memctl8xx_t *memctl = &immap->im_memctl;
 	volatile long int *addr;
-	ulong cnt, val;
-	ulong save[32];				/* to make test non-destructive */
+	ulong cnt, val, size;
+	ulong save[32];			/* to make test non-destructive */
 	unsigned char i = 0;
 
 	memctl->memc_mamr = mamr_value;
@@ -409,7 +409,13 @@
 
 	/* check at base address */
 	if ((val = *addr) != 0) {
+		/* Restore the original data before leaving the function.
+		 */
 		*addr = save[i];
+		for (cnt = 1; cnt <= maxsize / sizeof(long); cnt <<= 1) {
+			addr  = (volatile ulong *) base + cnt;
+			*addr = save[--i];
+		}
 		return (0);
 	}
 
@@ -420,7 +426,14 @@
 		*addr = save[--i];
 
 		if (val != (~cnt)) {
-			return (cnt * sizeof (long));
+			size = cnt * sizeof (long);
+			/* Restore the original data before returning
+			 */
+			for (cnt <<= 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
+				addr  = (volatile ulong *) base + cnt;
+				*addr = save[--i];
+			}
+			return (size);
 		}
 	}
 	return (maxsize);