[PATCH 09/11] common: memtest: prepare for reuse in self test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



memtest is quite talkative: it narrates status and advances a progress
bar. For non-interactive use, e.g. for selftest, this is a bit much,
so hide that behidnd a new MEMTEST_VERBOSE flag.

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
 commands/Kconfig   |  1 +
 commands/memtest.c |  5 +++--
 common/Kconfig     |  3 +++
 common/Makefile    |  2 +-
 common/memtest.c   | 44 ++++++++++++++++++++++++++------------------
 include/memtest.h  |  7 +++++--
 6 files changed, 39 insertions(+), 23 deletions(-)

diff --git a/commands/Kconfig b/commands/Kconfig
index 3a43682b2b2c..4d3ff631a8bf 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -1708,6 +1708,7 @@ config CMD_MEMSET
 
 config CMD_MEMTEST
 	tristate
+	select MEMTEST
 	prompt "memtest"
 	help
 	  The memtest command can test the registered barebox memory.
diff --git a/commands/memtest.c b/commands/memtest.c
index 864947fa94f9..9fa148b3aa41 100644
--- a/commands/memtest.c
+++ b/commands/memtest.c
@@ -15,6 +15,7 @@
 static int do_test_one_area(struct mem_test_resource *r, int bus_only,
 		unsigned cache_flag)
 {
+	unsigned flags = MEMTEST_VERBOSE;
 	int ret;
 
 	printf("Testing memory space: %pa -> %pa:\n",
@@ -22,14 +23,14 @@ static int do_test_one_area(struct mem_test_resource *r, int bus_only,
 
 	remap_range((void *)r->r->start, resource_size(r->r), cache_flag);
 
-	ret = mem_test_bus_integrity(r->r->start, r->r->end);
+	ret = mem_test_bus_integrity(r->r->start, r->r->end, flags);
 	if (ret < 0)
 		return ret;
 
 	if (bus_only)
 		return 0;
 
-	ret = mem_test_moving_inversions(r->r->start, r->r->end);
+	ret = mem_test_moving_inversions(r->r->start, r->r->end, flags);
 	if (ret < 0)
 		return ret;
 	printf("done.\n\n");
diff --git a/common/Kconfig b/common/Kconfig
index bd1df889e69a..ce94718c848a 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -144,6 +144,9 @@ config MEMINFO
 	bool "display memory info"
 	default y
 
+config MEMTEST
+	bool
+
 config ENVIRONMENT_VARIABLES
 	bool "environment variables support"
 
diff --git a/common/Makefile b/common/Makefile
index 8dc475f3244c..7fb864f61480 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -27,7 +27,7 @@ obj-$(CONFIG_BLOCK)		+= block.o
 obj-$(CONFIG_BLSPEC)		+= blspec.o
 obj-$(CONFIG_BOOTM)		+= bootm.o booti.o
 obj-$(CONFIG_CMD_LOADS)		+= s_record.o
-obj-$(CONFIG_CMD_MEMTEST)	+= memtest.o
+obj-$(CONFIG_MEMTEST)		+= memtest.o
 obj-$(CONFIG_COMMAND_SUPPORT)	+= command.o
 obj-$(CONFIG_CONSOLE_FULL)	+= console.o
 obj-$(CONFIG_CONSOLE_SIMPLE)	+= console_simple.o
diff --git a/common/memtest.c b/common/memtest.c
index d47e4a672ed9..aa16d94eeda0 100644
--- a/common/memtest.c
+++ b/common/memtest.c
@@ -160,7 +160,7 @@ static void mem_test_report_failure(const char *failure_description,
 }
 
 int mem_test_bus_integrity(resource_size_t _start,
-			   resource_size_t _end)
+			   resource_size_t _end, unsigned int flags)
 {
 	static const uint64_t bitpattern[] = {
 		0x0000000000000001ULL,	/* single bit */
@@ -190,7 +190,8 @@ int mem_test_bus_integrity(resource_size_t _start,
 	dummy = start + 1;
 	num_words = (_end - _start + 1)/sizeof(resource_size_t);
 
-	printf("Starting data line test.\n");
+	if (flags & MEMTEST_VERBOSE)
+		printf("Starting data line test.\n");
 
 	/*
 	 * Data line test: write a pattern to the first
@@ -294,7 +295,8 @@ int mem_test_bus_integrity(resource_size_t _start,
 	 */
 	start[0] = anti_pattern;
 
-	printf("Check for address bits stuck high.\n");
+	if (flags & MEMTEST_VERBOSE)
+		printf("Check for address bits stuck high.\n");
 
 	/*
 	 * Check for address bits stuck high.
@@ -313,8 +315,8 @@ int mem_test_bus_integrity(resource_size_t _start,
 	 */
 	start[0] = pattern;
 
-	printf("Check for address bits stuck "
-			"low or shorted.\n");
+	if (flags & MEMTEST_VERBOSE)
+		printf("Check for address bits stuck low or shorted.\n");
 
 	/*
 	 * Check for address bits stuck low or shorted.
@@ -340,7 +342,7 @@ int mem_test_bus_integrity(resource_size_t _start,
 	return 0;
 }
 
-static int update_progress(resource_size_t offset)
+static int update_progress(resource_size_t offset, unsigned flags)
 {
 	/* Only check every 4k to reduce overhead */
 	if (offset & (SZ_4K - 1))
@@ -349,12 +351,14 @@ static int update_progress(resource_size_t offset)
 	if (ctrlc())
 		return -EINTR;
 
-	show_progress(offset);
+	if (flags & MEMTEST_VERBOSE)
+		show_progress(offset);
 
 	return 0;
 }
 
-int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
+int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end,
+			       unsigned flags)
 {
 	volatile resource_size_t *start, num_words, offset, temp, anti_pattern;
 	int ret;
@@ -368,8 +372,12 @@ int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
 	start = (resource_size_t *)_start;
 	num_words = (_end - _start + 1)/sizeof(resource_size_t);
 
-	printf("Starting moving inversions test of RAM:\n"
-	       "Fill with address, compare, fill with inverted address, compare again\n");
+	if (flags & MEMTEST_VERBOSE) {
+		printf("Starting moving inversions test of RAM:\n"
+		       "Fill with address, compare, fill with inverted address, compare again\n");
+
+		init_progression_bar(3 * num_words);
+	}
 
 	/*
 	 * Description: Test the integrity of a physical
@@ -382,11 +390,9 @@ int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
 	 *		selected by the caller.
 	 */
 
-	init_progression_bar(3 * num_words);
-
 	/* Fill memory with a known pattern */
 	for (offset = 0; offset < num_words; offset++) {
-		ret = update_progress(offset);
+		ret = update_progress(offset, flags);
 		if (ret)
 			return ret;
 		start[offset] = offset + 1;
@@ -394,7 +400,7 @@ int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
 
 	/* Check each location and invert it for the second pass */
 	for (offset = 0; offset < num_words; offset++) {
-		ret = update_progress(num_words + offset);
+		ret = update_progress(num_words + offset, flags);
 		if (ret)
 			return ret;
 
@@ -413,7 +419,7 @@ int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
 
 	/* Check each location for the inverted pattern and zero it */
 	for (offset = 0; offset < num_words; offset++) {
-		ret = update_progress(2 * num_words + offset);
+		ret = update_progress(2 * num_words + offset, flags);
 		if (ret)
 			return ret;
 
@@ -430,10 +436,12 @@ int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
 
 		start[offset] = 0;
 	}
-	show_progress(3 * num_words);
+	if (flags & MEMTEST_VERBOSE) {
+		show_progress(3 * num_words);
 
-	/* end of progressbar */
-	printf("\n");
+		/* end of progressbar */
+		printf("\n");
+	}
 
 	return 0;
 }
diff --git a/include/memtest.h b/include/memtest.h
index df0a391cc3c2..3de30631ae24 100644
--- a/include/memtest.h
+++ b/include/memtest.h
@@ -3,6 +3,7 @@
 #define __MEMTEST_H
 
 #include <linux/ioport.h>
+#include <linux/bitops.h>
 
 struct mem_test_resource {
 	struct resource *r;
@@ -13,7 +14,9 @@ int mem_test_request_regions(struct list_head *list);
 void mem_test_release_regions(struct list_head *list);
 struct mem_test_resource *mem_test_biggest_region(struct list_head *list);
 
-int mem_test_bus_integrity(resource_size_t _start, resource_size_t _end);
-int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end);
+#define MEMTEST_VERBOSE		BIT(0)
+
+int mem_test_bus_integrity(resource_size_t _start, resource_size_t _end, unsigned flags);
+int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end, unsigned flags);
 
 #endif /* __MEMTEST_H */
-- 
2.39.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux