[U-Boot] [PATCH v3 07/22] Use common mtest iteration counting

Simon Glass sjg at chromium.org
Mon Feb 25 04:33:17 CET 2013


The iteration code is the same for each version of the memory test, so
pull it out into the common function.

Signed-off-by: Simon Glass <sjg at chromium.org>
---
Changes in v3: None
Changes in v2: None

 common/cmd_mem.c | 123 ++++++++++++++++++++++++++-----------------------------
 1 file changed, 59 insertions(+), 64 deletions(-)

diff --git a/common/cmd_mem.c b/common/cmd_mem.c
index 0e7a4c6..02ff658 100644
--- a/common/cmd_mem.c
+++ b/common/cmd_mem.c
@@ -626,11 +626,9 @@ int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 }
 #endif /* CONFIG_LOOPW */
 
-static int mem_test_alt(vu_long *start, vu_long *end,
-			  int iteration_limit)
+static ulong mem_test_alt(vu_long *start, vu_long *end)
 {
 	vu_long *addr;
-	int iterations = 1;
 	ulong errs = 0;
 	ulong val, readback;
 	int j;
@@ -657,27 +655,6 @@ static int mem_test_alt(vu_long *start, vu_long *end,
 		0xaaaaaaaa,	/* alternating 1/0 */
 	};
 
-	printf("Testing %08x ... %08x:\n", (uint)(uintptr_t)start,
-	       (uint)(uintptr_t)end);
-	debug("%s:%d: start 0x%p end 0x%p\n",
-		__func__, __LINE__, start, end);
-
-	for (;;) {
-		if (ctrlc()) {
-			putc('\n');
-			return 1;
-		}
-
-		if (iteration_limit && iterations > iteration_limit) {
-			printf("Tested %d iteration(s) with %lu errors.\n",
-				iterations-1, errs);
-			return errs != 0;
-		}
-
-		printf("Iteration: %6d\r", iterations);
-		debug("\n");
-		iterations++;
-
 		/*
 		 * Data line test: write a pattern to the first
 		 * location, write the 1's complement to a 'parking'
@@ -710,7 +687,7 @@ static int mem_test_alt(vu_long *start, vu_long *end,
 				errs++;
 				if (ctrlc()) {
 					putc('\n');
-					return 1;
+					return -1;
 				}
 			}
 			*addr  = ~val;
@@ -723,7 +700,7 @@ static int mem_test_alt(vu_long *start, vu_long *end,
 				errs++;
 				if (ctrlc()) {
 					putc('\n');
-					return 1;
+					return -1;
 				}
 			}
 		    }
@@ -791,7 +768,7 @@ static int mem_test_alt(vu_long *start, vu_long *end,
 			errs++;
 			if (ctrlc()) {
 			    putc('\n');
-			    return 1;
+			    return -1;
 			}
 		    }
 		}
@@ -813,7 +790,7 @@ static int mem_test_alt(vu_long *start, vu_long *end,
 			    errs++;
 			    if (ctrlc()) {
 				putc('\n');
-				return 1;
+				return -1;
 			    }
 			}
 		    }
@@ -855,7 +832,7 @@ static int mem_test_alt(vu_long *start, vu_long *end,
 			errs++;
 			if (ctrlc()) {
 				putc('\n');
-				return 1;
+				return -1;
 			}
 		    }
 
@@ -877,37 +854,38 @@ static int mem_test_alt(vu_long *start, vu_long *end,
 			errs++;
 			if (ctrlc()) {
 				putc('\n');
-				return 1;
+				return -1;
 			}
 		    }
 		    start[offset] = 0;
 		}
-	}
+
+	return 0;
 }
 
-static int mem_test_quick(vu_long *start, vu_long *end,
-			  int iteration_limit, vu_long pattern)
+static ulong mem_test_quick(vu_long *start, vu_long *end, vu_long pattern,
+			    int iteration)
 {
 	vu_long *addr;
-	int iterations = 1;
 	ulong errs = 0;
 	ulong incr;
 	ulong val, readback;
 
+	/* Alternate the pattern */
 	incr = 1;
-	for (;;) {
-		if (ctrlc()) {
-			putc('\n');
-			return 1;
-		}
-
-		if (iteration_limit && iterations > iteration_limit) {
-			printf("Tested %d iteration(s) with %lu errors.\n",
-				iterations-1, errs);
-			return errs != 0;
-		}
-		++iterations;
-
+	if (iteration & 1) {
+		incr = -incr;
+		/*
+		 * Flip the pattern each time to make lots of zeros and
+		 * then, the next time, lots of ones.  We decrement
+		 * the "negative" patterns and increment the "positive"
+		 * patterns to preserve this feature.
+		 */
+		if (pattern & 0x80000000)
+			pattern = -pattern;	/* complement & increment */
+		else
+			pattern = ~pattern;
+	}
 		printf("\rPattern %08lX  Writing..."
 			"%12s"
 			"\b\b\b\b\b\b\b\b\b\b",
@@ -931,24 +909,13 @@ static int mem_test_quick(vu_long *start, vu_long *end,
 				errs++;
 				if (ctrlc()) {
 					putc('\n');
-					return 1;
+					return -1;
 				}
 			}
 			val += incr;
 		}
 
-		/*
-		 * Flip the pattern each time to make lots of zeros and
-		 * then, the next time, lots of ones.  We decrement
-		 * the "negative" patterns and increment the "positive"
-		 * patterns to preserve this feature.
-		 */
-		if (pattern & 0x80000000)
-			pattern = -pattern;	/* complement & increment */
-		else
-			pattern = ~pattern;
-		incr = -incr;
-	}
+	return 0;
 }
 
 /*
@@ -962,7 +929,9 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
 	vu_long *start, *end;
 	int iteration_limit;
 	int ret;
+	ulong errs = 0;	/* number of errors, or -1 if interrupted */
 	ulong pattern;
+	int iteration;
 #if defined(CONFIG_SYS_ALT_MEMTEST)
 	const int alt_test = 1;
 #else
@@ -989,10 +958,36 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
 	else
 		iteration_limit = 0;
 
-	if (alt_test)
-		ret = mem_test_alt(start, end, iteration_limit);
-	else
-		ret = mem_test_quick(start, end, iteration_limit, pattern);
+	printf("Testing %08x ... %08x:\n", (uint)(uintptr_t)start,
+	       (uint)(uintptr_t)end);
+	debug("%s:%d: start 0x%p end 0x%p\n",
+		__func__, __LINE__, start, end);
+
+	for (iteration = 0;
+			!iteration_limit || iteration < iteration_limit;
+			iteration++) {
+		if (ctrlc()) {
+			putc('\n');
+			errs = -1UL;
+			break;
+		}
+
+		printf("Iteration: %6d\r", iteration + 1);
+		debug("\n");
+		if (alt_test)
+			errs = mem_test_alt(start, end);
+		else
+			errs = mem_test_quick(start, end, pattern, iteration);
+	}
+
+	if (errs == -1UL) {
+		/* Memory test was aborted */
+		ret = 1;
+	} else {
+		printf("Tested %d iteration(s) with %lu errors.\n",
+			iteration, errs);
+		ret = errs != 0;
+	}
 
 	return ret;	/* not reached */
 }
-- 
1.8.1.3



More information about the U-Boot mailing list