[U-Boot] [PATCH] mtest: Disable dcache during test

Benoît Thébaudeau benoit.thebaudeau at advansee.com
Fri Aug 10 21:16:15 CEST 2012


mtest is supposed to test many types of memory accesses in many different
conditions. If dcache is enabled, memory accesses are likely bursts, and some
memory accesses are simply skipped. Hence, dcache should be disabled during
mtest operation so that what mtest actually tests is not masked by dcache.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau at advansee.com>
Cc: Wolfgang Denk <wd at denx.de>
---
 .../common/cmd_mem.c                               |   39 ++++++++++++++------
 1 file changed, 27 insertions(+), 12 deletions(-)

diff --git u-boot-4d3c95f.orig/common/cmd_mem.c u-boot-4d3c95f/common/cmd_mem.c
index 18f0a3f..5d2b735 100644
--- u-boot-4d3c95f.orig/common/cmd_mem.c
+++ u-boot-4d3c95f/common/cmd_mem.c
@@ -600,6 +600,8 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	ulong	errs = 0;
 	int iterations = 1;
 	int iteration_limit;
+	int dcache;
+	int ret = 1;
 
 #if defined(CONFIG_SYS_ALT_MEMTEST)
 	vu_long	len;
@@ -651,6 +653,13 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	else
 		iteration_limit = 0;
 
+	/* Perform tests on the underlying memory rather than on the D-cache. */
+	dcache = dcache_status();
+	if (dcache) {
+		dcache_disable();
+		invalidate_dcache_all();
+	}
+
 #if defined(CONFIG_SYS_ALT_MEMTEST)
 	printf ("Testing %08x ... %08x:\n", (uint)start, (uint)end);
 	debug("%s:%d: start 0x%p end 0x%p\n",
@@ -659,14 +668,15 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	for (;;) {
 		if (ctrlc()) {
 			putc ('\n');
-			return 1;
+			goto end;
 		}
 
 
 		if (iteration_limit && iterations > iteration_limit) {
 			printf("Tested %d iteration(s) with %lu errors.\n",
 				iterations-1, errs);
-			return errs != 0;
+			ret = errs != 0;
+			goto end;
 		}
 
 		printf("Iteration: %6d\r", iterations);
@@ -704,7 +714,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			    errs++;
 			    if (ctrlc()) {
 				putc ('\n');
-				return 1;
+				goto end;
 			    }
 			}
 			*addr  = ~val;
@@ -717,7 +727,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			    errs++;
 			    if (ctrlc()) {
 				putc ('\n');
-				return 1;
+				goto end;
 			    }
 			}
 		    }
@@ -787,7 +797,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			errs++;
 			if (ctrlc()) {
 			    putc ('\n');
-			    return 1;
+			    goto end;
 			}
 		    }
 		}
@@ -809,7 +819,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			    errs++;
 			    if (ctrlc()) {
 				putc ('\n');
-				return 1;
+				goto end;
 			    }
 			}
 		    }
@@ -851,7 +861,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			errs++;
 			if (ctrlc()) {
 			    putc ('\n');
-			    return 1;
+			    goto end;
 			}
 		    }
 
@@ -873,7 +883,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			errs++;
 			if (ctrlc()) {
 			    putc ('\n');
-			    return 1;
+			    goto end;
 			}
 		    }
 		    start[offset] = 0;
@@ -885,13 +895,14 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	for (;;) {
 		if (ctrlc()) {
 			putc ('\n');
-			return 1;
+			goto end;
 		}
 
 		if (iteration_limit && iterations > iteration_limit) {
 			printf("Tested %d iteration(s) with %lu errors.\n",
 				iterations-1, errs);
-			return errs != 0;
+			ret = errs != 0;
+			goto end;
 		}
 		++iterations;
 
@@ -918,7 +929,7 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 				errs++;
 				if (ctrlc()) {
 					putc ('\n');
-					return 1;
+					goto end;
 				}
 			}
 			val += incr;
@@ -939,7 +950,11 @@ int do_mem_mtest (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		incr = -incr;
 	}
 #endif
-	return 0;	/* not reached */
+
+end:
+	if (dcache)
+		dcache_enable();
+	return ret;
 }
 
 


More information about the U-Boot mailing list