[U-Boot] [PATCH 07/20] Use common mtest iteration counting
Simon Glass
sjg at chromium.org
Wed Dec 26 19:57:00 CET 2012
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>
---
common/cmd_mem.c | 123 ++++++++++++++++++++++++++----------------------------
1 files changed, 59 insertions(+), 64 deletions(-)
diff --git a/common/cmd_mem.c b/common/cmd_mem.c
index 36ac6f4..41c1e70 100644
--- a/common/cmd_mem.c
+++ b/common/cmd_mem.c
@@ -621,11 +621,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;
@@ -652,27 +650,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'
@@ -705,7 +682,7 @@ static int mem_test_alt(vu_long *start, vu_long *end,
errs++;
if (ctrlc()) {
putc('\n');
- return 1;
+ return -1;
}
}
*addr = ~val;
@@ -718,7 +695,7 @@ static int mem_test_alt(vu_long *start, vu_long *end,
errs++;
if (ctrlc()) {
putc('\n');
- return 1;
+ return -1;
}
}
}
@@ -786,7 +763,7 @@ static int mem_test_alt(vu_long *start, vu_long *end,
errs++;
if (ctrlc()) {
putc('\n');
- return 1;
+ return -1;
}
}
}
@@ -808,7 +785,7 @@ static int mem_test_alt(vu_long *start, vu_long *end,
errs++;
if (ctrlc()) {
putc('\n');
- return 1;
+ return -1;
}
}
}
@@ -850,7 +827,7 @@ static int mem_test_alt(vu_long *start, vu_long *end,
errs++;
if (ctrlc()) {
putc('\n');
- return 1;
+ return -1;
}
}
@@ -872,37 +849,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",
@@ -926,24 +904,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;
}
/*
@@ -957,7 +924,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
@@ -984,10 +953,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.7.7.3
More information about the U-Boot
mailing list