Add a common get_ram_size() function and modify the the
board-specific files to invoke that common implementation.
diff --git a/board/atc/atc.c b/board/atc/atc.c
index fad7646..d2c6b3b 100644
--- a/board/atc/atc.c
+++ b/board/atc/atc.c
@@ -269,13 +269,10 @@
 			  ulong orx, volatile uchar * base)
 {
 	volatile uchar c = 0xff;
-	ulong cnt, val, size;
-	volatile ulong *addr;
 	volatile uint *sdmr_ptr;
 	volatile uint *orx_ptr;
+	ulong maxsize, size;
 	int i;
-	ulong save[32];		/* to make test non-destructive */
-	ulong maxsize;
 
 	/* 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
@@ -325,54 +322,11 @@
 	*sdmr_ptr = sdmr | PSDMR_OP_NORM | PSDMR_RFEN;
 	*base = c;
 
-	/*
-	 * Check memory range for valid RAM. A simple memory test determines
-	 * the actually available RAM size between addresses `base' and
-	 * `base + maxsize'. Some (not all) hardware errors are detected:
-	 * - short between address lines
-	 * - short between data lines
-	 */
-	i = 0;
-	for (cnt = maxsize / sizeof (long); cnt > 0; cnt >>= 1) {
-		addr = (volatile ulong *) base + cnt;	/* pointer arith! */
-		save[i++] = *addr;
-		*addr = ~cnt;
-	}
-
-	addr = (volatile ulong *) base;
-	save[i] = *addr;
-	*addr = 0;
+	size = get_ram_size((long *)base, maxsize);
 
-	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);
-	}
+	*orx_ptr = orx | ~(size - 1);
 
-	for (cnt = 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
-		addr = (volatile ulong *) base + cnt;	/* pointer arith! */
-		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 | ~(size - 1);
-			return (size);
-		}
-	}
-	return (maxsize);
+	return (size);
 }
 
 int misc_init_r(void)