Skip to contentSkip to conversation

add new memtest command

PATCH In review Alexander Aring 3 participants 17 messages Feb 7, 2013

lore
Share & tools
lore
#0 lore raw

v3 cover add new memtest command

The new memtest command supports to enable or disable caching during testing(only arm architecture) and skipping barebox regions for avoid a barebox killing, if you want to write on barebox allocated regions.

If you run memtest without a argument, memtest will run on all registered memory banks.

The new memtest command has these arguments:
-s #ADDRESS [for start address]
-e #ADDRESS [for end address]
-i #ITER [for numbers of iterations] -c [don't disable caching]
-b [do bus testing only]

v2:
- change stdout of memtest to make it more beautiful

v3:
- fix testing of address bus <-- this never worked before
- put mem_test function into common/memory_test.c
- fix some comment issues
- align quietly start and end address
- fix some newline issues

Alexander Aring (6):
common: fix codestyle in ALIGN macros
common: add ALIGN_DOWN macro
memory: add function address_in_sdram_regions
memtest: remove memtest command
common: add mem_test routine
commands: add new memtest command

 commands/Kconfig      |  17 +-
 commands/Makefile     |   2 +-
 commands/memtest.c    | 573 +++++++++++++++++++++++++-------------------------
 common/Kconfig        |   7 +
 common/Makefile       |   1 +
 common/memory.c       |  16 ++
 common/memory_test.c  | 399 +++++++++++++++++++++++++++++++++++
 include/common.h      |   5 +-
 include/memory.h      |   6 +
 include/memory_test.h |  13 ++
 10 files changed, 747 insertions(+), 292 deletions(-)
 create mode 100644 common/memory_test.c
 create mode 100644 include/memory_test.h
Signature · 7 lines
1.8.1.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH v3 1/6 common: fix codestyle in ALIGN macros

---
 include/common.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/common.h +2 -2
index e559b94..1c7d599 100644
@@ -182,8 +182,8 @@ int run_shell(void);
 #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
 #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
 
-#define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
-#define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
+#define ALIGN(x, a)		__ALIGN_MASK(x, (typeof(x))(a) - 1)
+#define __ALIGN_MASK(x, mask)	(((x) + (mask)) & ~(mask))
 #define PTR_ALIGN(p, a)		((typeof(p))ALIGN((unsigned long)(p), (a)))
 #define IS_ALIGNED(x, a)		(((x) & ((typeof(x))(a) - 1)) == 0)
 
Signature · 7 lines
1.8.1.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH v3 2/6 common: add ALIGN_DOWN macro

In reply to Alexander Aring
---
 include/common.h | 1 +
 1 file changed, 1 insertion(+)
include/common.h +1 -0
index 1c7d599..73d51c1 100644
@@ -184,6 +184,7 @@ int run_shell(void);
 
 #define ALIGN(x, a)		__ALIGN_MASK(x, (typeof(x))(a) - 1)
 #define __ALIGN_MASK(x, mask)	(((x) + (mask)) & ~(mask))
+#define ALIGN_DOWN(x, a)	((x) & ~((typeof(x))(a) - 1))
 #define PTR_ALIGN(p, a)		((typeof(p))ALIGN((unsigned long)(p), (a)))
 #define IS_ALIGNED(x, a)		(((x) & ((typeof(x))(a) - 1)) == 0)
 
Signature · 7 lines
1.8.1.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH v3 3/6 memory: add function address_in_sdram_regions

In reply to Alexander Aring

Add function address_in_sdram_regions to check if a address is in any sdram region.

Also added new macro 'ADDRESS_IN_REGIONS' to check if address is in a special boundary with start and end address.

---
 common/memory.c  | 16 ++++++++++++++++
 include/memory.h |  6 ++++++
 2 files changed, 22 insertions(+)
common/memory.c +16 -0
index 81641f0..d2e9164 100644
@@ -162,6 +162,22 @@ int release_sdram_region(struct resource *res)
 	return release_region(res);
 }
 
+/*
+ * Check if specific address are in any allocated region.
+ */
+int address_in_sdram_regions(resource_size_t address)
+{
+	struct memory_bank *bank = NULL;
+	struct resource *r = NULL;
+
+	for_each_memory_bank(bank)
+		list_for_each_entry(r, &bank->res->children, sibling)
+			if (ADDRESS_IN_REGIONS(address, r->start, r->end))
+				return 1;
+
+	return 0;
+}
+
 #ifdef CONFIG_OFTREE
 
 /*
include/memory.h +6 -0
index 165d2dc..e12a28d 100644
@@ -27,4 +27,10 @@ struct resource *request_sdram_region(const char *name, resource_size_t start,
 		resource_size_t size);
 int release_sdram_region(struct resource *res);
 
+#define ADDRESS_IN_REGIONS(address, region_start, region_end) \
+	((address >= region_start) && \
+	 (address <= region_end))
+
+int address_in_sdram_regions(resource_size_t address);
+
 #endif
Signature · 7 lines
1.8.1.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

PATCH v3 4/6 memtest: remove memtest command

In reply to Alexander Aring

Remove memtest command.

---
 commands/Kconfig   |   9 --
 commands/Makefile  |   1 -
 commands/memtest.c | 351 -----------------------------------------------------
 3 files changed, 361 deletions(-)
 delete mode 100644 commands/memtest.c
commands/Kconfig +0 -9
index d3c338c..7cc759c 100644
@@ -516,15 +516,6 @@ config CMD_NANDTEST
 	select PARTITION_NEED_MTD
 	prompt "nandtest"
 
-config CMD_MTEST
-	tristate
-	prompt "mtest"
-
-config CMD_MTEST_ALTERNATIVE
-	bool
-	depends on CMD_MTEST
-	prompt "alternative mtest implementation"
-
 endmenu
 
 menu "video command"
commands/Makefile +0 -1
index 0ae6b95..393ba51 100644
@@ -7,7 +7,6 @@ obj-$(CONFIG_CMD_LOADY)		+= loadxy.o
 obj-$(CONFIG_CMD_LOADS)		+= loads.o
 obj-$(CONFIG_CMD_ECHO)		+= echo.o
 obj-$(CONFIG_CMD_MEMORY)	+= mem.o
-obj-$(CONFIG_CMD_MTEST)		+= memtest.o
 obj-$(CONFIG_CMD_EDIT)		+= edit.o
 obj-$(CONFIG_CMD_EXEC)		+= exec.o
 obj-$(CONFIG_CMD_SLEEP)		+= sleep.o
commands/memtest.c deleted +0 -351

351 lines not on this page · raw message

Signature · 7 lines
1.8.1.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

PATCH v3 5/6 common: add mem_test routine

In reply to Alexander Aring

Useful to detect timing problems if someone porting a new device to barebox.

This test includes a data bus test, address bus test and integrity check of memory.

Allocated barebox regions between start and end will skip automatically.

---
 common/Kconfig        |   7 +
 common/Makefile       |   1 +
 common/memory_test.c  | 399 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/memory_test.h |  13 ++
 4 files changed, 420 insertions(+)
 create mode 100644 common/memory_test.c
 create mode 100644 include/memory_test.h
common/Kconfig +7 -0
index 3f6c11e..c6988df 100644
@@ -100,6 +100,13 @@ config MEMINFO
 	bool "display memory info"
 	default y
 
+config MEMTEST
+	bool "Offers routines for memory test"
+	help
+	  Offers memtest routines in common/memory_test.c
+	  This is helpful for porting devices to detect
+	  memory timing problems.
+
 config ENVIRONMENT_VARIABLES
 	bool "environment variables support"
 
common/Makefile +1 -0
index 7206eed..684953c 100644
@@ -17,6 +17,7 @@ obj-$(CONFIG_MALLOC_DLMALLOC) += dlmalloc.o
 obj-$(CONFIG_MALLOC_TLSF) += tlsf_malloc.o
 obj-$(CONFIG_MALLOC_TLSF) += tlsf.o
 obj-$(CONFIG_MALLOC_DUMMY) += dummy_malloc.o
+obj-$(CONFIG_MEMTEST) += memory_test.o
 obj-y += clock.o
 obj-$(CONFIG_BANNER) += version.o
 obj-$(CONFIG_MEMINFO) += meminfo.o
common/memory_test.c new file +399 -0

399 lines not on this page · raw message

include/memory_test.h new file +13 -0
new file mode 100644
index 0000000..6959dc6
@@ -0,0 +1,13 @@
+
+#ifndef __MEMORY_TEST_H
+#define __MEMORY_TEST_H
+
+#include <progress.h>
+#include <common.h>
+#include <memory.h>
+#include <types.h>
+
+int mem_test(vu_long _start, vu_long _end,
+		int bus_only);
+
+#endif
Signature · 7 lines
1.8.1.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

Re: [PATCH 5/6] common: add mem_test routine

Quoted 8 lines · Alexander Aring

Useful to detect timing problems if someone porting a new device to barebox.

This test includes a data bus test, address bus test and integrity check of memory.

Allocated barebox regions between start and end will skip automatically.

Some nitpicking inline.

Is there a nice alternative to usage of the vu_long type?

Quoted 163 lines
---
 common/Kconfig        |   7 +
 common/Makefile       |   1 +
 common/memory_test.c  | 399 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/memory_test.h |  13 ++
 4 files changed, 420 insertions(+)
 create mode 100644 common/memory_test.c
 create mode 100644 include/memory_test.h
common/Kconfig +7 -0
index 3f6c11e..c6988df 100644
@@ -100,6 +100,13 @@ config MEMINFO
 	bool "display memory info"
 	default y
 
+config MEMTEST
+	bool "Offers routines for memory test"
+	help
+	  Offers memtest routines in common/memory_test.c
+	  This is helpful for porting devices to detect
+	  memory timing problems.
+
 config ENVIRONMENT_VARIABLES
 	bool "environment variables support"
 
common/Makefile +1 -0
index 7206eed..684953c 100644
@@ -17,6 +17,7 @@ obj-$(CONFIG_MALLOC_DLMALLOC) += dlmalloc.o
 obj-$(CONFIG_MALLOC_TLSF) += tlsf_malloc.o
 obj-$(CONFIG_MALLOC_TLSF) += tlsf.o
 obj-$(CONFIG_MALLOC_DUMMY) += dummy_malloc.o
+obj-$(CONFIG_MEMTEST) += memory_test.o
 obj-y += clock.o
 obj-$(CONFIG_BANNER) += version.o
 obj-$(CONFIG_MEMINFO) += meminfo.o
common/memory_test.c new file +116 -0
new file mode 100644
index 0000000..80b4ff4
@@ -0,0 +1,399 @@
+/*
+ * memory_test.c
+ *
+ * Copyright (c) 2013 Alexander Aring <[email protected]>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <memory_test.h>
+
+static const vu_long bitpattern[] = {
+	0x00000001,	/* single bit */
+	0x00000003,	/* two adjacent bits */
+	0x00000007,	/* three adjacent bits */
+	0x0000000F,	/* four adjacent bits */
+	0x00000005,	/* two non-adjacent bits */
+	0x00000015,	/* three non-adjacent bits */
+	0x00000055,	/* four non-adjacent bits */
+	0xAAAAAAAA,	/* alternating 1/0 */
+};
+
+/*
+ * Perform a memory test. The complete test
+ * loops until interrupted by ctrl-c.
+ *
+ * Highly recommended to test with disabled and
+ * enabled cache.
+ *
+ * start: start address
+ * end: end address
+ * bus_only: skip integrity check
+ */
+int mem_test(vu_long _start, vu_long _end,
+		int bus_only)
+{
+	vu_long *start;
+	vu_long *dummy;
+
+	vu_long val;
+	vu_long readback;
+	vu_long offset;
+	vu_long offset2;
+	vu_long pattern;
+	vu_long temp;
+	vu_long anti_pattern;
+	vu_long num_words;
+
+	int i;
+	int ret;
+
+	if (!IS_ALIGNED(_start, sizeof(vu_long)))
+		_start = ALIGN(_start, sizeof(vu_long));
+	/*
+	 * check if end is a multiple of vu_long.
+	 * need to add 1 because ALIGNED works with
+	 * inclusive byte at end address.
+	 *
+	 * Also check on _end == 0. Otherwise we get a
+	 * underflow.
+	 */
+	if (!IS_ALIGNED(_end + 1, sizeof(vu_long)) && _end)
+		_end = ALIGN_DOWN(_end, sizeof(vu_long)) - 1;
+
+	/*
+	 * TODO
+	 * recheck after align. That's not a quite
+	 * solution now because we already done this
+	 * in memtest command.
+	 */
+	if (_end <= _start)
+		return -1;
+
+	start = (vu_long *)_start;
+	/*
+	 * Point the dummy to start[1]
+	 */
+	dummy = start+1;
+	num_words = (_end - _start + 1)/sizeof(vu_long);
+
+	/*
+	 * Checking if start and dummy address are in one
+	 * of barebox regions. Otherwise next data line testing
+	 * will maybe fail.
+	 */
+	ret = address_in_sdram_regions((vu_long)start);
+	ret |= address_in_sdram_regions((vu_long)dummy);
+	if (ret) {
+		printf("WARNING (data line): "
+				"address 0x%08lx is in sdram regions.\n"
+				"Try another start address to fix this issue.\n",
+				(vu_long)start);
+		return -1;
+	}
+
+	printf("Starting data line test.\n");
+
+	/*
+	 * Data line test: write a pattern to the first
+	 * location, write the 1's complement to a 'parking'
+	 * address (changes the state of the data bus so a
+	 * floating bus doen't give a false OK), and then
+	 * read the value back. Note that we read it back
+	 * into a variable because the next time we read it,
+	 * it might be right (been there, tough to explain to
+	 * the quality guys why it prints a failure when the

common/memory_test.c line 126

Quoted 10 lines
common/memory_test.c new file +10 -0
+	 * "is" and "should be" are obviously the same in the
+	 * error message).
+	 *
+	 * Rather than exhaustively testing, we test some
+	 * patterns by shifting '1' bits through a field of
+	 * '0's and '0' bits through a field of '1's (i.e.
+	 * pattern and ~pattern).
+	 */
+	for (i = 0; i < sizeof(bitpattern)/
+			sizeof(bitpattern[0]); i++) {

ARRAY_SIZE(bitpattern)

Quoted 249 lines
common/memory_test.c new file +249 -0
+		val = bitpattern[i];
+
+		for (; val != 0; val <<= 1) {
+			*start = val;
+			/* clear the test data off of the bus */
+			*dummy = ~val;
+			readback = *start;
+
+			if (readback != val) {
+				printf("FAILURE (data line): "
+					"expected 0x%08lx, actual 0x%08lx at address 0x%08lx.\n",
+					val, readback, (vu_long)start);
+				return -1;
+			}
+
+			*start = ~val;
+			*dummy = val;
+			readback = *start;
+			if (readback != ~val) {
+				printf("FAILURE (data line): "
+					"Is 0x%08lx, should be 0x%08lx at address 0x%08lx.\n",
+					readback,
+					~val, (vu_long)start);
+				return -1;
+			}
+		}
+	}
+
+
+	/*
+	 * Based on code whose Original Author and Copyright
+	 * information follows: Copyright (c) 1998 by Michael
+	 * Barr. This software is placed into the public
+	 * domain and may be used for any purpose. However,
+	 * this notice must not be changed or removed and no
+	 * warranty is either expressed or implied by its
+	 * publication or distribution.
+	 */
+
+	/*
+	 * Address line test
+	 *
+	 * Description: Test the address bus wiring in a
+	 *              memory region by performing a walking
+	 *              1's test on the relevant bits of the
+	 *              address and checking for aliasing.
+	 *              This test will find single-bit
+	 *              address failures such as stuck -high,
+	 *              stuck-low, and shorted pins. The base
+	 *              address and size of the region are
+	 *              selected by the caller.
+	 *
+	 * Notes:	For best results, the selected base
+	 *              address should have enough LSB 0's to
+	 *              guarantee single address bit changes.
+	 *              For example, to test a 64-Kbyte
+	 *              region, select a base address on a
+	 *              64-Kbyte boundary. Also, select the
+	 *              region size as a power-of-two if at
+	 *              all possible.
+	 *
+	 * ## NOTE ##	Be sure to specify start and end
+	 *              addresses such that num_words has
+	 *              lots of bits set. For example an
+	 *              address range of 01000000 02000000 is
+	 *              bad while a range of 01000000
+	 *              01ffffff is perfect.
+	 */
+
+	pattern = 0xAAAAAAAA;
+	anti_pattern = 0x55555555;
+
+	/*
+	 * Write the default pattern at each of the
+	 * power-of-two offsets.
+	 */
+	for (offset = 1; offset <= num_words; offset <<= 1) {
+		ret = address_in_sdram_regions((vu_long)&start[offset]);
+		if (ret) {
+			printf("WARNING (stuck high): "
+					"address 0x%08lx is in barebox regions.\n",
+					(vu_long)&start[offset]);
+			continue;
+		}
+
+		start[offset] = pattern;
+	}
+
+	printf("Check for address bits stuck high.\n");
+
+	/*
+	 * Check for address bits stuck high.
+	 */
+	for (offset = 1; offset <= num_words; offset <<= 1) {
+		ret = address_in_sdram_regions((vu_long)&start[offset]);
+		if (ret)
+			continue;
+
+		temp = start[offset];
+		if (temp != pattern) {
+			printf("FAILURE: Address bit "
+					"stuck high @ 0x%08lx:"
+					" expected 0x%08lx, actual 0x%08lx.\n",
+					(vu_long)&start[offset],
+					pattern, temp);
+			return -1;
+		}
+	}
+
+	printf("Check for address bits stuck "
+			"low or shorted.\n");
+
+	/*
+	 * Check for address bits stuck low or shorted.
+	 */
+	for (offset2 = 1; offset2 <= num_words; offset2 <<= 1) {
+		ret = address_in_sdram_regions(
+				(vu_long)&start[offset2]);
+		if (ret) {
+			printf("WARNING (low high): "
+					"address 0x%08lx is in barebox regions.\n",
+					(vu_long)&start[offset2]);
+			continue;
+		}
+
+		start[offset2] = anti_pattern;
+
+		for (offset = 1; offset <= num_words; offset <<= 1) {
+			ret = address_in_sdram_regions(
+					(vu_long)&start[offset]);
+			if (ret)
+				continue;
+
+			temp = start[offset];
+
+			/*
+			 * That's some complicated for loop with
+			 * condition offset != test_offset inside. I
+			 * think this is necessary to put some another
+			 * address on the bus.
+			 *
+			 * TODO
+			 * check if loop is necessary.
+			 */
+			if ((temp != pattern) &&
+					(offset != offset2)) {
+				printf("FAILURE: Address bit stuck"
+						" low or shorted @"
+						" 0x%08lx: expected 0x%08lx, actual 0x%08lx.\n",
+						(vu_long)&start[offset],
+						pattern, temp);
+				return -1;
+			}
+		}
+		start[offset2] = pattern;
+	}
+
+	/*
+	 * We tested only the bus if != 0
+	 * leaving here
+	 */
+	if (bus_only)
+		return 0;
+
+	printf("Starting integrity check of physicaly ram.\n"
+			"Filling ram with patterns...\n");
+
+	/*
+	 * Description: Test the integrity of a physical
+	 *		memory device by performing an
+	 *		increment/decrement test over the
+	 *		entire region. In the process every
+	 *		storage bit in the device is tested
+	 *		as a zero and a one. The base address
+	 *		and the size of the region are
+	 *		selected by the caller.
+	 */
+
+	/*
+	 * Fill memory with a known pattern.
+	 */
+	init_progression_bar(num_words);
+	for (offset = 0; offset < num_words; offset++) {
+		if (!(offset & 0xfff)) {
+			if (ctrlc())
+				return -EINTR;
+			show_progress(offset);
+		}
+
+		ret = address_in_sdram_regions((vu_long)&start[offset]);
+		if (ret)
+			continue;
+
+		start[offset] = offset + 1;
+	}
+
+	show_progress(offset);
+
+	printf("\nCompare written patterns...\n");
+
+	/*
+	 * Check each location and invert it for the second pass.
+	 */
+	init_progression_bar(num_words - 1);
+	for (offset = 0; offset < num_words; offset++) {
+		if (!(offset & 0xfff)) {
+			if (ctrlc())
+				return -EINTR;
+			show_progress(offset);
+		}
+
+		ret = address_in_sdram_regions((vu_long)&start[offset]);
+		if (ret)
+			continue;
+
+		temp = start[offset];
+		if (temp != (offset + 1)) {
+			printf("\nFAILURE (read/write) @ 0x%08lx:"
+					" expected 0x%08lx, actual 0x%08lx.\n",
+					(vu_long)&start[offset],
+					(offset + 1), temp);
+			return -1;
+		}
+
+		anti_pattern = ~(offset + 1);
+		start[offset] = anti_pattern;
+	}
+
+	show_progress(offset);
+
+	printf("\nFilling ram with inverted pattern and compare it...\n");
+
+	/*
+	 * Check each location for the inverted pattern and zero it.
+	 */
+	init_progression_bar(num_words - 1);
+	for (offset = 0; offset < num_words; offset++) {
+		if (!(offset & 0xfff)) {
+			if (ctrlc())
+				return -EINTR;
+			show_progress(offset);
+		}
+
+		ret = address_in_sdram_regions((vu_long)&start[offset]);
+		/*
+		 * Step over barebox mem usage
+		 */
+		if (ret)
+			continue;

common/memory_test.c line 385

Quoted 10 lines
common/memory_test.c new file +10 -0
+
+		anti_pattern = ~(offset + 1);
+		temp = start[offset];
+
+		if (temp != anti_pattern) {
+			printf("\nFAILURE (read/write): @ 0x%08lx:"
+					" expected 0x%08lx, actual 0x%08lx.\n",
+					(vu_long)&start[offset],
+					anti_pattern, temp);
+			return -1;

what about returning an errno?

Quoted 24 lines
common/memory_test.c new file +14 -0
+		}
+
+		start[offset] = 0;
+	}
+
+	show_progress(offset);
+
+	/*
+	 * end of progressbar
+	 */
+	printf("\n");
+
+	return 0;
+}
include/memory_test.h new file +3 -0
new file mode 100644
index 0000000..6959dc6
@@ -0,0 +1,13 @@
+
+#ifndef __MEMORY_TEST_H
+#define __MEMORY_TEST_H

include/memory_test.h line 13

Quoted 10 lines
include/memory_test.h new file +10 -0
+
+#include <progress.h>
+#include <common.h>
+#include <memory.h>
+#include <types.h>
+
+int mem_test(vu_long _start, vu_long _end,
+		int bus_only);
+
+#endif

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#7 lore raw

Re: [PATCH 5/6] common: add mem_test routine

Hi,

Quoted 7 lines · Marc Kleine-Budde
Quoted 6 lines · Alexander Aring

Useful to detect timing problems if someone porting a new device to barebox.

This test includes a data bus test, address bus test and integrity check of memory.

Quoted 6 lines
Quoted 2 lines

Allocated barebox regions between start and end will skip automatically.

Some nitpicking inline.

Is there a nice alternative to usage of the vu_long type?

I can use a volatile version of resource_size_t.

Quoted 167 lines
Quoted 167 lines
---
 common/Kconfig        |   7 +
 common/Makefile       |   1 +
 common/memory_test.c  | 399 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/memory_test.h |  13 ++
 4 files changed, 420 insertions(+)
 create mode 100644 common/memory_test.c
 create mode 100644 include/memory_test.h
common/Kconfig +7 -0
index 3f6c11e..c6988df 100644
@@ -100,6 +100,13 @@ config MEMINFO
 	bool "display memory info"
 	default y
 
+config MEMTEST
+	bool "Offers routines for memory test"
+	help
+	  Offers memtest routines in common/memory_test.c
+	  This is helpful for porting devices to detect
+	  memory timing problems.
+
 config ENVIRONMENT_VARIABLES
 	bool "environment variables support"
 
common/Makefile +1 -0
index 7206eed..684953c 100644
@@ -17,6 +17,7 @@ obj-$(CONFIG_MALLOC_DLMALLOC) += dlmalloc.o
 obj-$(CONFIG_MALLOC_TLSF) += tlsf_malloc.o
 obj-$(CONFIG_MALLOC_TLSF) += tlsf.o
 obj-$(CONFIG_MALLOC_DUMMY) += dummy_malloc.o
+obj-$(CONFIG_MEMTEST) += memory_test.o
 obj-y += clock.o
 obj-$(CONFIG_BANNER) += version.o
 obj-$(CONFIG_MEMINFO) += meminfo.o
common/memory_test.c new file +120 -0
new file mode 100644
index 0000000..80b4ff4
@@ -0,0 +1,399 @@
+/*
+ * memory_test.c
+ *
+ * Copyright (c) 2013 Alexander Aring <[email protected]>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <memory_test.h>
+
+static const vu_long bitpattern[] = {
+	0x00000001,	/* single bit */
+	0x00000003,	/* two adjacent bits */
+	0x00000007,	/* three adjacent bits */
+	0x0000000F,	/* four adjacent bits */
+	0x00000005,	/* two non-adjacent bits */
+	0x00000015,	/* three non-adjacent bits */
+	0x00000055,	/* four non-adjacent bits */
+	0xAAAAAAAA,	/* alternating 1/0 */
+};
+
+/*
+ * Perform a memory test. The complete test
+ * loops until interrupted by ctrl-c.
+ *
+ * Highly recommended to test with disabled and
+ * enabled cache.
+ *
+ * start: start address
+ * end: end address
+ * bus_only: skip integrity check
+ */
+int mem_test(vu_long _start, vu_long _end,
+		int bus_only)
+{
+	vu_long *start;
+	vu_long *dummy;
+
+	vu_long val;
+	vu_long readback;
+	vu_long offset;
+	vu_long offset2;
+	vu_long pattern;
+	vu_long temp;
+	vu_long anti_pattern;
+	vu_long num_words;
+
+	int i;
+	int ret;
+
+	if (!IS_ALIGNED(_start, sizeof(vu_long)))
+		_start = ALIGN(_start, sizeof(vu_long));
+	/*
+	 * check if end is a multiple of vu_long.
+	 * need to add 1 because ALIGNED works with
+	 * inclusive byte at end address.
+	 *
+	 * Also check on _end == 0. Otherwise we get a
+	 * underflow.
+	 */
+	if (!IS_ALIGNED(_end + 1, sizeof(vu_long)) && _end)
+		_end = ALIGN_DOWN(_end, sizeof(vu_long)) - 1;
+
+	/*
+	 * TODO
+	 * recheck after align. That's not a quite
+	 * solution now because we already done this
+	 * in memtest command.
+	 */
+	if (_end <= _start)
+		return -1;
+
+	start = (vu_long *)_start;
+	/*
+	 * Point the dummy to start[1]
+	 */
+	dummy = start+1;
+	num_words = (_end - _start + 1)/sizeof(vu_long);
+
+	/*
+	 * Checking if start and dummy address are in one
+	 * of barebox regions. Otherwise next data line testing
+	 * will maybe fail.
+	 */
+	ret = address_in_sdram_regions((vu_long)start);
+	ret |= address_in_sdram_regions((vu_long)dummy);
+	if (ret) {
+		printf("WARNING (data line): "
+				"address 0x%08lx is in sdram regions.\n"
+				"Try another start address to fix this issue.\n",
+				(vu_long)start);
+		return -1;
+	}
+
+	printf("Starting data line test.\n");
+
+	/*
+	 * Data line test: write a pattern to the first
+	 * location, write the 1's complement to a 'parking'
+	 * address (changes the state of the data bus so a
+	 * floating bus doen't give a false OK), and then
+	 * read the value back. Note that we read it back
+	 * into a variable because the next time we read it,
+	 * it might be right (been there, tough to explain to
+	 * the quality guys why it prints a failure when the
+	 * "is" and "should be" are obviously the same in the
+	 * error message).
+	 *
+	 * Rather than exhaustively testing, we test some
Quoted 9 lines

common/memory_test.c line 126

Quoted 6 lines
common/memory_test.c new file +6 -0
+	 * patterns by shifting '1' bits through a field of
+	 * '0's and '0' bits through a field of '1's (i.e.
+	 * pattern and ~pattern).
+	 */
+	for (i = 0; i < sizeof(bitpattern)/
+			sizeof(bitpattern[0]); i++) {

ARRAY_SIZE(bitpattern)

Ok.

Quoted 253 lines
Quoted 253 lines
common/memory_test.c new file +253 -0
+		val = bitpattern[i];
+
+		for (; val != 0; val <<= 1) {
+			*start = val;
+			/* clear the test data off of the bus */
+			*dummy = ~val;
+			readback = *start;
+
+			if (readback != val) {
+				printf("FAILURE (data line): "
+					"expected 0x%08lx, actual 0x%08lx at address 0x%08lx.\n",
+					val, readback, (vu_long)start);
+				return -1;
+			}
+
+			*start = ~val;
+			*dummy = val;
+			readback = *start;
+			if (readback != ~val) {
+				printf("FAILURE (data line): "
+					"Is 0x%08lx, should be 0x%08lx at address 0x%08lx.\n",
+					readback,
+					~val, (vu_long)start);
+				return -1;
+			}
+		}
+	}
+
+
+	/*
+	 * Based on code whose Original Author and Copyright
+	 * information follows: Copyright (c) 1998 by Michael
+	 * Barr. This software is placed into the public
+	 * domain and may be used for any purpose. However,
+	 * this notice must not be changed or removed and no
+	 * warranty is either expressed or implied by its
+	 * publication or distribution.
+	 */
+
+	/*
+	 * Address line test
+	 *
+	 * Description: Test the address bus wiring in a
+	 *              memory region by performing a walking
+	 *              1's test on the relevant bits of the
+	 *              address and checking for aliasing.
+	 *              This test will find single-bit
+	 *              address failures such as stuck -high,
+	 *              stuck-low, and shorted pins. The base
+	 *              address and size of the region are
+	 *              selected by the caller.
+	 *
+	 * Notes:	For best results, the selected base
+	 *              address should have enough LSB 0's to
+	 *              guarantee single address bit changes.
+	 *              For example, to test a 64-Kbyte
+	 *              region, select a base address on a
+	 *              64-Kbyte boundary. Also, select the
+	 *              region size as a power-of-two if at
+	 *              all possible.
+	 *
+	 * ## NOTE ##	Be sure to specify start and end
+	 *              addresses such that num_words has
+	 *              lots of bits set. For example an
+	 *              address range of 01000000 02000000 is
+	 *              bad while a range of 01000000
+	 *              01ffffff is perfect.
+	 */
+
+	pattern = 0xAAAAAAAA;
+	anti_pattern = 0x55555555;
+
+	/*
+	 * Write the default pattern at each of the
+	 * power-of-two offsets.
+	 */
+	for (offset = 1; offset <= num_words; offset <<= 1) {
+		ret = address_in_sdram_regions((vu_long)&start[offset]);
+		if (ret) {
+			printf("WARNING (stuck high): "
+					"address 0x%08lx is in barebox regions.\n",
+					(vu_long)&start[offset]);
+			continue;
+		}
+
+		start[offset] = pattern;
+	}
+
+	printf("Check for address bits stuck high.\n");
+
+	/*
+	 * Check for address bits stuck high.
+	 */
+	for (offset = 1; offset <= num_words; offset <<= 1) {
+		ret = address_in_sdram_regions((vu_long)&start[offset]);
+		if (ret)
+			continue;
+
+		temp = start[offset];
+		if (temp != pattern) {
+			printf("FAILURE: Address bit "
+					"stuck high @ 0x%08lx:"
+					" expected 0x%08lx, actual 0x%08lx.\n",
+					(vu_long)&start[offset],
+					pattern, temp);
+			return -1;
+		}
+	}
+
+	printf("Check for address bits stuck "
+			"low or shorted.\n");
+
+	/*
+	 * Check for address bits stuck low or shorted.
+	 */
+	for (offset2 = 1; offset2 <= num_words; offset2 <<= 1) {
+		ret = address_in_sdram_regions(
+				(vu_long)&start[offset2]);
+		if (ret) {
+			printf("WARNING (low high): "
+					"address 0x%08lx is in barebox regions.\n",
+					(vu_long)&start[offset2]);
+			continue;
+		}
+
+		start[offset2] = anti_pattern;
+
+		for (offset = 1; offset <= num_words; offset <<= 1) {
+			ret = address_in_sdram_regions(
+					(vu_long)&start[offset]);
+			if (ret)
+				continue;
+
+			temp = start[offset];
+
+			/*
+			 * That's some complicated for loop with
+			 * condition offset != test_offset inside. I
+			 * think this is necessary to put some another
+			 * address on the bus.
+			 *
+			 * TODO
+			 * check if loop is necessary.
+			 */
+			if ((temp != pattern) &&
+					(offset != offset2)) {
+				printf("FAILURE: Address bit stuck"
+						" low or shorted @"
+						" 0x%08lx: expected 0x%08lx, actual 0x%08lx.\n",
+						(vu_long)&start[offset],
+						pattern, temp);
+				return -1;
+			}
+		}
+		start[offset2] = pattern;
+	}
+
+	/*
+	 * We tested only the bus if != 0
+	 * leaving here
+	 */
+	if (bus_only)
+		return 0;
+
+	printf("Starting integrity check of physicaly ram.\n"
+			"Filling ram with patterns...\n");
+
+	/*
+	 * Description: Test the integrity of a physical
+	 *		memory device by performing an
+	 *		increment/decrement test over the
+	 *		entire region. In the process every
+	 *		storage bit in the device is tested
+	 *		as a zero and a one. The base address
+	 *		and the size of the region are
+	 *		selected by the caller.
+	 */
+
+	/*
+	 * Fill memory with a known pattern.
+	 */
+	init_progression_bar(num_words);
+	for (offset = 0; offset < num_words; offset++) {
+		if (!(offset & 0xfff)) {
+			if (ctrlc())
+				return -EINTR;
+			show_progress(offset);
+		}
+
+		ret = address_in_sdram_regions((vu_long)&start[offset]);
+		if (ret)
+			continue;
+
+		start[offset] = offset + 1;
+	}
+
+	show_progress(offset);
+
+	printf("\nCompare written patterns...\n");
+
+	/*
+	 * Check each location and invert it for the second pass.
+	 */
+	init_progression_bar(num_words - 1);
+	for (offset = 0; offset < num_words; offset++) {
+		if (!(offset & 0xfff)) {
+			if (ctrlc())
+				return -EINTR;
+			show_progress(offset);
+		}
+
+		ret = address_in_sdram_regions((vu_long)&start[offset]);
+		if (ret)
+			continue;
+
+		temp = start[offset];
+		if (temp != (offset + 1)) {
+			printf("\nFAILURE (read/write) @ 0x%08lx:"
+					" expected 0x%08lx, actual 0x%08lx.\n",
+					(vu_long)&start[offset],
+					(offset + 1), temp);
+			return -1;
+		}
+
+		anti_pattern = ~(offset + 1);
+		start[offset] = anti_pattern;
+	}
+
+	show_progress(offset);
+
+	printf("\nFilling ram with inverted pattern and compare it...\n");
+
+	/*
+	 * Check each location for the inverted pattern and zero it.
+	 */
+	init_progression_bar(num_words - 1);
+	for (offset = 0; offset < num_words; offset++) {
+		if (!(offset & 0xfff)) {
+			if (ctrlc())
+				return -EINTR;
+			show_progress(offset);
+		}
+
+		ret = address_in_sdram_regions((vu_long)&start[offset]);
+		/*
+		 * Step over barebox mem usage
+		 */
+		if (ret)
+			continue;
+
+		anti_pattern = ~(offset + 1);
+		temp = start[offset];
+
Quoted 9 lines

common/memory_test.c line 385

Quoted 6 lines
common/memory_test.c new file +6 -0
+		if (temp != anti_pattern) {
+			printf("\nFAILURE (read/write): @ 0x%08lx:"
+					" expected 0x%08lx, actual 0x%08lx.\n",
+					(vu_long)&start[offset],
+					anti_pattern, temp);
+			return -1;

what about returning an errno?

Ok. I will change that.

Regards
Alex

Quoted 28 lines
Quoted 28 lines
common/memory_test.c new file +14 -0
+		}
+
+		start[offset] = 0;
+	}
+
+	show_progress(offset);
+
+	/*
+	 * end of progressbar
+	 */
+	printf("\n");
+
+	return 0;
+}
include/memory_test.h new file +8 -0
new file mode 100644
index 0000000..6959dc6
@@ -0,0 +1,13 @@
+
+#ifndef __MEMORY_TEST_H
+#define __MEMORY_TEST_H
+
+#include <progress.h>
+#include <common.h>
+#include <memory.h>
+#include <types.h>
Quoted 15 lines

include/memory_test.h line 13

Quoted 6 lines
include/memory_test.h new file +5 -0
+
+int mem_test(vu_long _start, vu_long _end,
+		int bus_only);
+
+#endif

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#8 lore raw

Re: [PATCH 5/6] common: add mem_test routine

In reply to Alexander Aring
Quoted 91 lines · Alexander Aring

Useful to detect timing problems if someone porting a new device to barebox.

This test includes a data bus test, address bus test and integrity check of memory.

Allocated barebox regions between start and end will skip automatically.

---
 common/Kconfig        |   7 +
 common/Makefile       |   1 +
 common/memory_test.c  | 399 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/memory_test.h |  13 ++
 4 files changed, 420 insertions(+)
 create mode 100644 common/memory_test.c
 create mode 100644 include/memory_test.h
common/Kconfig +7 -0
index 3f6c11e..c6988df 100644
@@ -100,6 +100,13 @@ config MEMINFO
 	bool "display memory info"
 	default y
 
+config MEMTEST
+	bool "Offers routines for memory test"
+	help
+	  Offers memtest routines in common/memory_test.c
+	  This is helpful for porting devices to detect
+	  memory timing problems.
+
 config ENVIRONMENT_VARIABLES
 	bool "environment variables support"
 
common/Makefile +1 -0
index 7206eed..684953c 100644
@@ -17,6 +17,7 @@ obj-$(CONFIG_MALLOC_DLMALLOC) += dlmalloc.o
 obj-$(CONFIG_MALLOC_TLSF) += tlsf_malloc.o
 obj-$(CONFIG_MALLOC_TLSF) += tlsf.o
 obj-$(CONFIG_MALLOC_DUMMY) += dummy_malloc.o
+obj-$(CONFIG_MEMTEST) += memory_test.o
 obj-y += clock.o
 obj-$(CONFIG_BANNER) += version.o
 obj-$(CONFIG_MEMINFO) += meminfo.o
common/memory_test.c new file +36 -0
new file mode 100644
index 0000000..80b4ff4
@@ -0,0 +1,399 @@
+/*
+ * memory_test.c
+ *
+ * Copyright (c) 2013 Alexander Aring <[email protected]>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <memory_test.h>
+
+static const vu_long bitpattern[] = {
+	0x00000001,	/* single bit */
+	0x00000003,	/* two adjacent bits */
+	0x00000007,	/* three adjacent bits */
+	0x0000000F,	/* four adjacent bits */
+	0x00000005,	/* two non-adjacent bits */
+	0x00000015,	/* three non-adjacent bits */
+	0x00000055,	/* four non-adjacent bits */
+	0xAAAAAAAA,	/* alternating 1/0 */
+};
+
+/*
+ * Perform a memory test. The complete test
+ * loops until interrupted by ctrl-c.
+ *

common/memory_test.c line 46

Quoted 10 lines
common/memory_test.c new file +10 -0
+ * Highly recommended to test with disabled and
+ * enabled cache.
+ *
+ * start: start address
+ * end: end address
+ * bus_only: skip integrity check
+ */
+int mem_test(vu_long _start, vu_long _end,
+		int bus_only)
+{

I thought we agreed on using request_sdram_region here and drop the address_in_sdram_regions in this function.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw

Re: [PATCH 5/6] common: add mem_test routine

Hi Sascha,

Quoted 97 lines · Sascha Hauer
Quoted 96 lines · Alexander Aring

Useful to detect timing problems if someone porting a new device to barebox.

This test includes a data bus test, address bus test and integrity check of memory.

Allocated barebox regions between start and end will skip automatically.

---
 common/Kconfig        |   7 +
 common/Makefile       |   1 +
 common/memory_test.c  | 399 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/memory_test.h |  13 ++
 4 files changed, 420 insertions(+)
 create mode 100644 common/memory_test.c
 create mode 100644 include/memory_test.h
common/Kconfig +7 -0
index 3f6c11e..c6988df 100644
@@ -100,6 +100,13 @@ config MEMINFO
 	bool "display memory info"
 	default y
 
+config MEMTEST
+	bool "Offers routines for memory test"
+	help
+	  Offers memtest routines in common/memory_test.c
+	  This is helpful for porting devices to detect
+	  memory timing problems.
+
 config ENVIRONMENT_VARIABLES
 	bool "environment variables support"
 
common/Makefile +1 -0
index 7206eed..684953c 100644
@@ -17,6 +17,7 @@ obj-$(CONFIG_MALLOC_DLMALLOC) += dlmalloc.o
 obj-$(CONFIG_MALLOC_TLSF) += tlsf_malloc.o
 obj-$(CONFIG_MALLOC_TLSF) += tlsf.o
 obj-$(CONFIG_MALLOC_DUMMY) += dummy_malloc.o
+obj-$(CONFIG_MEMTEST) += memory_test.o
 obj-y += clock.o
 obj-$(CONFIG_BANNER) += version.o
 obj-$(CONFIG_MEMINFO) += meminfo.o
common/memory_test.c new file +41 -0
new file mode 100644
index 0000000..80b4ff4
@@ -0,0 +1,399 @@
+/*
+ * memory_test.c
+ *
+ * Copyright (c) 2013 Alexander Aring <[email protected]>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <memory_test.h>
+
+static const vu_long bitpattern[] = {
+	0x00000001,	/* single bit */
+	0x00000003,	/* two adjacent bits */
+	0x00000007,	/* three adjacent bits */
+	0x0000000F,	/* four adjacent bits */
+	0x00000005,	/* two non-adjacent bits */
+	0x00000015,	/* three non-adjacent bits */
+	0x00000055,	/* four non-adjacent bits */
+	0xAAAAAAAA,	/* alternating 1/0 */
+};
+
+/*
+ * Perform a memory test. The complete test
+ * loops until interrupted by ctrl-c.
+ *
+ * Highly recommended to test with disabled and
+ * enabled cache.
+ *
+ * start: start address
+ * end: end address
Quoted 9 lines

common/memory_test.c line 46

Quoted 5 lines
common/memory_test.c new file +5 -0
+ * bus_only: skip integrity check
+ */
+int mem_test(vu_long _start, vu_long _end,
+		int bus_only)
+{

I thought we agreed on using request_sdram_region here and drop the address_in_sdram_regions in this function.

I don't know what you meant :-(
Sorry.

You want that I am checking if a region is already requested. In that case request_sdram_region will return NULL. Then I know it isn't a barebox region.
That's ok until integrity check.
This will check 4-bytewise if this is a reqyested region and if not it will create them.
I can do this, but this will result a long list of requested regions.

A nice solution is to handle it in the function which enable and disable caching. There I can request a big area of free memory.
I need to request free regions there and call mem_test function for that.

I will try that out.

Regards
Alex

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#10 lore raw

Re: [PATCH 5/6] common: add mem_test routine

Quoted 110 lines · Alexander Aring

Hi Sascha,

Quoted 97 lines · Sascha Hauer
Quoted 96 lines · Alexander Aring

Useful to detect timing problems if someone porting a new device to barebox.

This test includes a data bus test, address bus test and integrity check of memory.

Allocated barebox regions between start and end will skip automatically.

---
 common/Kconfig        |   7 +
 common/Makefile       |   1 +
 common/memory_test.c  | 399 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/memory_test.h |  13 ++
 4 files changed, 420 insertions(+)
 create mode 100644 common/memory_test.c
 create mode 100644 include/memory_test.h
common/Kconfig +7 -0
index 3f6c11e..c6988df 100644
@@ -100,6 +100,13 @@ config MEMINFO
 	bool "display memory info"
 	default y
 
+config MEMTEST
+	bool "Offers routines for memory test"
+	help
+	  Offers memtest routines in common/memory_test.c
+	  This is helpful for porting devices to detect
+	  memory timing problems.
+
 config ENVIRONMENT_VARIABLES
 	bool "environment variables support"
 
common/Makefile +1 -0
index 7206eed..684953c 100644
@@ -17,6 +17,7 @@ obj-$(CONFIG_MALLOC_DLMALLOC) += dlmalloc.o
 obj-$(CONFIG_MALLOC_TLSF) += tlsf_malloc.o
 obj-$(CONFIG_MALLOC_TLSF) += tlsf.o
 obj-$(CONFIG_MALLOC_DUMMY) += dummy_malloc.o
+obj-$(CONFIG_MEMTEST) += memory_test.o
 obj-y += clock.o
 obj-$(CONFIG_BANNER) += version.o
 obj-$(CONFIG_MEMINFO) += meminfo.o
common/memory_test.c new file +41 -0
new file mode 100644
index 0000000..80b4ff4
@@ -0,0 +1,399 @@
+/*
+ * memory_test.c
+ *
+ * Copyright (c) 2013 Alexander Aring <[email protected]>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <memory_test.h>
+
+static const vu_long bitpattern[] = {
+	0x00000001,	/* single bit */
+	0x00000003,	/* two adjacent bits */
+	0x00000007,	/* three adjacent bits */
+	0x0000000F,	/* four adjacent bits */
+	0x00000005,	/* two non-adjacent bits */
+	0x00000015,	/* three non-adjacent bits */
+	0x00000055,	/* four non-adjacent bits */
+	0xAAAAAAAA,	/* alternating 1/0 */
+};
+
+/*
+ * Perform a memory test. The complete test
+ * loops until interrupted by ctrl-c.
+ *
+ * Highly recommended to test with disabled and
+ * enabled cache.
+ *
+ * start: start address
+ * end: end address
Quoted 9 lines

common/memory_test.c line 46

Quoted 5 lines
common/memory_test.c new file +5 -0
+ * bus_only: skip integrity check
+ */
+int mem_test(vu_long _start, vu_long _end,
+		int bus_only)
+{

I thought we agreed on using request_sdram_region here and drop the address_in_sdram_regions in this function.

Quoted 4 lines

I don't know what you meant :-(
Sorry.

You want that I am checking if a region is already requested.

I didn't want that you check if a region is already requested, I want you to request the region that you are testing. That's what request_sdram_region is good for. Just use it.

Quoted 6 lines

In that case request_sdram_region will return NULL. Then I know it isn't a barebox region.
That's ok until integrity check.
This will check 4-bytewise if this is a reqyested region and if not it will create them.
I can do this, but this will result a long list of requested regions.

Drop the address_in_sdram_regions completely from this function. Instead, do a request_sdram_region in the memtest command.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#11 lore raw

Re: [PATCH 5/6] common: add mem_test routine

Hi Sascha,

Quoted 127 lines · Sascha Hauer
Quoted 110 lines · Alexander Aring

Hi Sascha,

Quoted 97 lines · Sascha Hauer
Quoted 96 lines · Alexander Aring

Useful to detect timing problems if someone porting a new device to barebox.

This test includes a data bus test, address bus test and integrity check of memory.

Allocated barebox regions between start and end will skip automatically.

---
 common/Kconfig        |   7 +
 common/Makefile       |   1 +
 common/memory_test.c  | 399 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/memory_test.h |  13 ++
 4 files changed, 420 insertions(+)
 create mode 100644 common/memory_test.c
 create mode 100644 include/memory_test.h
common/Kconfig +7 -0
index 3f6c11e..c6988df 100644
@@ -100,6 +100,13 @@ config MEMINFO
 	bool "display memory info"
 	default y
 
+config MEMTEST
+	bool "Offers routines for memory test"
+	help
+	  Offers memtest routines in common/memory_test.c
+	  This is helpful for porting devices to detect
+	  memory timing problems.
+
 config ENVIRONMENT_VARIABLES
 	bool "environment variables support"
 
common/Makefile +1 -0
index 7206eed..684953c 100644
@@ -17,6 +17,7 @@ obj-$(CONFIG_MALLOC_DLMALLOC) += dlmalloc.o
 obj-$(CONFIG_MALLOC_TLSF) += tlsf_malloc.o
 obj-$(CONFIG_MALLOC_TLSF) += tlsf.o
 obj-$(CONFIG_MALLOC_DUMMY) += dummy_malloc.o
+obj-$(CONFIG_MEMTEST) += memory_test.o
 obj-y += clock.o
 obj-$(CONFIG_BANNER) += version.o
 obj-$(CONFIG_MEMINFO) += meminfo.o
common/memory_test.c new file +41 -0
new file mode 100644
index 0000000..80b4ff4
@@ -0,0 +1,399 @@
+/*
+ * memory_test.c
+ *
+ * Copyright (c) 2013 Alexander Aring <[email protected]>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <memory_test.h>
+
+static const vu_long bitpattern[] = {
+	0x00000001,	/* single bit */
+	0x00000003,	/* two adjacent bits */
+	0x00000007,	/* three adjacent bits */
+	0x0000000F,	/* four adjacent bits */
+	0x00000005,	/* two non-adjacent bits */
+	0x00000015,	/* three non-adjacent bits */
+	0x00000055,	/* four non-adjacent bits */
+	0xAAAAAAAA,	/* alternating 1/0 */
+};
+
+/*
+ * Perform a memory test. The complete test
+ * loops until interrupted by ctrl-c.
+ *
+ * Highly recommended to test with disabled and
+ * enabled cache.
+ *
+ * start: start address
+ * end: end address
Quoted 9 lines

common/memory_test.c line 46

Quoted 5 lines
common/memory_test.c new file +5 -0
+ * bus_only: skip integrity check
+ */
+int mem_test(vu_long _start, vu_long _end,
+		int bus_only)
+{

I thought we agreed on using request_sdram_region here and drop the address_in_sdram_regions in this function.

Quoted 4 lines

I don't know what you meant :-(
Sorry.

You want that I am checking if a region is already requested.

I didn't want that you check if a region is already requested, I want you to request the region that you are testing. That's what request_sdram_region is good for. Just use it.

Quoted 6 lines

In that case request_sdram_region will return NULL. Then I know it isn't a barebox region.
That's ok until integrity check.
This will check 4-bytewise if this is a reqyested region and if not it will create them.
I can do this, but this will result a long list of requested regions.

Quoted 3 lines

Drop the address_in_sdram_regions completely from this function. Instead, do a request_sdram_region in the memtest command.

I will try to do that. Apologize for the inconvenience. It takes long time to write a new memtest command... but good software will take a long time.

Regards
Alex

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#12 lore raw

PATCH v3 6/6 commands: add new memtest command

In reply to Alexander Aring

Add new memtest command which can enable or disable caching on non allocted barebox regions(test area).

This command simply parse and check parameters then call the mem_test routine.

If no address parameters are given then mem_test will call for each memory bank.

---
 commands/Kconfig   |  10 ++
 commands/Makefile  |   1 +
 commands/memtest.c | 362 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 373 insertions(+)
 create mode 100644 commands/memtest.c
commands/Kconfig +10 -0
index 7cc759c..d158c3f 100644
@@ -516,6 +516,16 @@ config CMD_NANDTEST
 	select PARTITION_NEED_MTD
 	prompt "nandtest"
 
+config CMD_MEMTEST
+    tristate
+    select MEMTEST
+    prompt "memtest"
+	help
+	  This command enables a memtest to test installed memory.
+	  During this test allocated iomem regions will be skipped.
+	  If tested architecture has MMU with PTE flags support,
+	  caching can be set enabled or disabled.
+
 endmenu
 
 menu "video command"
commands/Makefile +1 -0
index 393ba51..b39b489 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_CMD_LOADY)		+= loadxy.o
 obj-$(CONFIG_CMD_LOADS)		+= loads.o
 obj-$(CONFIG_CMD_ECHO)		+= echo.o
 obj-$(CONFIG_CMD_MEMORY)	+= mem.o
+obj-$(CONFIG_CMD_MEMTEST)	+= memtest.o
 obj-$(CONFIG_CMD_EDIT)		+= edit.o
 obj-$(CONFIG_CMD_EXEC)		+= exec.o
 obj-$(CONFIG_CMD_SLEEP)		+= sleep.o
commands/memtest.c new file +362 -0

362 lines not on this page · raw message

Signature · 7 lines
1.8.1.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#13 lore raw

Re: [PATCH 6/6] commands: add new memtest command

Quoted 10 lines · Alexander Aring

Add new memtest command which can enable or disable caching on non allocted barebox regions(test area).

This command simply parse and check parameters then call the mem_test routine.

If no address parameters are given then mem_test will call for each memory bank.

A howto-get-rid-of-ifdef nitpick inline

Quoted 75 lines
---
 commands/Kconfig   |  10 ++
 commands/Makefile  |   1 +
 commands/memtest.c | 362 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 373 insertions(+)
 create mode 100644 commands/memtest.c
commands/Kconfig +10 -0
index 7cc759c..d158c3f 100644
@@ -516,6 +516,16 @@ config CMD_NANDTEST
 	select PARTITION_NEED_MTD
 	prompt "nandtest"
 
+config CMD_MEMTEST
+    tristate
+    select MEMTEST
+    prompt "memtest"
+	help
+	  This command enables a memtest to test installed memory.
+	  During this test allocated iomem regions will be skipped.
+	  If tested architecture has MMU with PTE flags support,
+	  caching can be set enabled or disabled.
+
 endmenu
 
 menu "video command"
commands/Makefile +1 -0
index 393ba51..b39b489 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_CMD_LOADY)		+= loadxy.o
 obj-$(CONFIG_CMD_LOADS)		+= loads.o
 obj-$(CONFIG_CMD_ECHO)		+= echo.o
 obj-$(CONFIG_CMD_MEMORY)	+= mem.o
+obj-$(CONFIG_CMD_MEMTEST)	+= memtest.o
 obj-$(CONFIG_CMD_EDIT)		+= edit.o
 obj-$(CONFIG_CMD_EXEC)		+= exec.o
 obj-$(CONFIG_CMD_SLEEP)		+= sleep.o
commands/memtest.c new file +29 -0
new file mode 100644
index 0000000..22e8006
@@ -0,0 +1,362 @@
+/*
+ * memtest - Perform a memory test
+ *
+ * (C) Copyright 2013
+ * Alexander Aring <[email protected]>, Pengutronix
+ *
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, [email protected].
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <command.h>

commands/memtest.c line 39

Quoted 10 lines
commands/memtest.c new file +10 -0
+#include <getopt.h>
+#include <asm/mmu.h>
+
+#include <memory_test.h>
+
+/*
+ * In CONFIG_MMU we have a special c flag.
+ */
+#ifdef CONFIG_MMU
+static char optstr[] = "s:e:i:cb";

const?

commands/memtest.c line 48

Quoted 9 lines
commands/memtest.c new file +9 -0
+
+/*
+ * PTE flags variables to set cached and
+ * uncached regions.
+ */
+static uint32_t pte_flags_cached;
+static uint32_t pte_flags_uncached;
+#else
+static char optstr[] = "s:e:i:b";

const?

commands/memtest.c line 51

Quoted 3 lines
commands/memtest.c new file +3 -0
+#endif
+
+#ifdef CONFIG_MMU

Can

Quoted 182 lines
commands/memtest.c new file +182 -0
+static void print_region(vu_long start, vu_long size, uint32_t flags)
+{
+	if (!size)
+		return;
+
+	printf("\t0x%08lx - "
+			"0x%08lx (size 0x%08lx)\n",
+			start, start + size - 1, size);
+}
+
+static void do_remap_range(struct memory_bank *bank, uint32_t flags)
+{
+	struct resource *r = NULL;
+	struct resource *r_prev = NULL;
+
+	vu_long size;
+	vu_long start;
+	vu_long end;
+
+	if (flags == pte_flags_uncached)
+		printf("Set non caching regions:\n");
+	else if (flags == pte_flags_cached)
+		printf("Set caching regions:\n");
+	else
+		BUG();
+
+	/*
+	 * We assume that the regions are sorted in this list
+	 */
+	list_for_each_entry(r, &bank->res->children, sibling) {
+		/*
+		 * Do on head element for bank boundary
+		 */
+		if (r->sibling.prev == &bank->res->children) {
+			/*
+			 * remember last used element
+			 */
+			r_prev = r;
+
+			start = PAGE_ALIGN(bank->start);
+			end = PAGE_ALIGN_DOWN(r->start) - 1;
+			if (start >= end)
+				continue;
+			size = end - start + 1;
+
+			print_region(start, size, flags);
+			remap_range((void *)start, size, flags);
+
+			continue;
+		}
+		/*
+		 * Between used regions
+		 */
+		start = PAGE_ALIGN(r_prev->end);
+		end = PAGE_ALIGN_DOWN(r->start) - 1;
+		if (start < end) {
+			size = end - start + 1;
+			print_region(start, size, flags);
+			remap_range((void *)start, size, flags);
+		}
+
+		r_prev = r;
+		/*
+		 * Do on head element for bank boundary
+		 */
+		if (list_is_last(&r->sibling, &bank->res->children)) {
+			start = PAGE_ALIGN(r->end);
+			end = PAGE_ALIGN_DOWN(bank->start + bank->size) - 1;
+			if (start >= end)
+				continue;
+			size = end - start + 1;
+
+			print_region(start, size, flags);
+			remap_range((void *)start, size, flags);
+		}
+	}
+}
+#endif
+
+static int do_mem_memtest(int argc, char *argv[])
+{
+	/*
+	 * Set start address to 0xffffffff which
+	 * can't be.
+	 */
+	vu_long start = 0xffffffff;
+	vu_long end = 0;
+
+	uint i;
+	uint max_i = 1;
+
+#ifdef CONFIG_MMU
+	int cache = 0;
+#endif
+	int bus_only = 0;
+	int err = 0;
+	int cnt = 0;
+	int opt;
+
+	struct memory_bank *bank = NULL;
+	struct resource *r = NULL;
+
+	while ((opt = getopt(argc, argv, optstr)) > 0) {
+		switch (opt) {
+		case 's':
+			start = simple_strtoul(optarg, NULL, 0);
+			break;
+		case 'e':
+			end = simple_strtoul(optarg, NULL, 0);
+			break;
+		case 'i':
+			max_i = simple_strtoul(optarg, NULL, 0);
+			break;
+#ifdef CONFIG_MMU
+		case 'c':
+			cache = 1;
+			break;
+#endif
+		case 'b':
+			bus_only = 1;
+			break;
+		default:
+			return COMMAND_ERROR_USAGE;
+		}
+	}
+
+	if (optind > argc)
+		return COMMAND_ERROR_USAGE;
+
+	/*
+	 * Error if no end address
+	 */
+	if (start != 0xffffffff && !end) {
+		printf("Please add an end address.\n");
+		return 1;
+	}
+
+	/*
+	 * Error if no start address
+	 */
+	if (end && start == 0xffffffff) {
+		printf("Please add a start address.\n");
+		return 1;
+	}
+
+	/*
+	 * Check parameters
+	 */
+	if (start != 0xffffffff && end) {
+		if (end <= start) {
+			printf("End address less than or"
+					" equal start address.\n");
+			return 1;
+		}
+
+		/*
+		 * Check if given start and end address are in any banks
+		 */
+		for_each_memory_bank(bank) {
+			if (ADDRESS_IN_REGIONS(start, bank->start,
+						bank->start + bank->size))
+				cnt++;
+
+			if (ADDRESS_IN_REGIONS(end, bank->start,
+						bank->start + bank->size))
+				cnt++;
+		}
+
+		if (cnt != 2) {
+			printf("Start or end addresses are"
+					" not in any ram bank.\n");
+			return 1;
+		}
+	}
+
+#ifdef CONFIG_MMU
+	/*
+	 * Get pte flags. Which are configured at
+	 * runtime at booting.
+	 */
+	pte_flags_cached = mmu_get_pte_cached_flags();
+	pte_flags_uncached = mmu_get_pte_uncached_flags();

commands/memtest.c line 243

Quoted 10 lines
commands/memtest.c new file +10 -0
+#endif
+
+	printf("Skipping regions:\n");
+	for_each_memory_bank(bank) {
+		list_for_each_entry(r, &bank->res->children, sibling)
+			printf("\t0x%08x - "
+					"0x%08x (size 0x%08x) %s\n",
+					r->start, r->end,
+					r->end - r->start + 1, r->name);
+#ifdef CONFIG_MMU

Use if (IS_ENABLED(CONFIG_MMU) and you can get rid of most ifdefs

Marc

Quoted 120 lines
commands/memtest.c new file +119 -0
+		/*
+		 * Disable or enable caching
+		 */
+		if (cache)
+			do_remap_range(bank, pte_flags_cached);
+		else
+			do_remap_range(bank, pte_flags_uncached);
+#endif
+	}
+
+	/*
+	 * Do test if we set a start or end address
+	 */
+	if (start != 0xffffffff && end) {
+		printf("Testing address range:\n\t0x%08lx - 0x%08lx"
+				" (size 0x%08lx)\n",
+				start, end, end - start + 1);
+
+		for (i = 1; (i <= max_i) || !max_i; i++) {
+			printf("Iteration: %u\n", i);
+
+			/*
+			 * Do the Memtest
+			 */
+			err = mem_test(start, end, bus_only);
+			if (err == -EINTR) {
+				printf("Test interrupted.\n");
+				goto err;
+			}
+
+			if (err < 0) {
+				printf("Test failed.\n");
+				goto err;
+			}
+			printf("Tested %u iteration(s) without errors.\n", i);
+		}
+#ifdef CONFIG_MMU
+		/*
+		 * Renable caching
+		 */
+		if (!cache)
+			for_each_memory_bank(bank)
+				do_remap_range(bank, pte_flags_cached);
+#endif
+		printf("Memtest done.\n");
+
+		return 0;
+	}
+
+	/*
+	 * If we set no start or end address
+	 * we do the test on all ram banks
+	 */
+	for (i = 1; (i <= max_i) || !max_i; i++) {
+		for_each_memory_bank(bank) {
+			start = bank->start;
+			end = bank->start + bank->size - 1;
+
+			printf("Iteration: %u\n", i);
+
+			printf("Testing address range:\n\t0x%08lx - "
+					"0x%08lx (size 0x%08lx) on bank /dev/%s\n",
+					start, end, bank->size,
+					bank->res->name);
+
+			err = mem_test(start, end, bus_only);
+			if (err == -EINTR) {
+				printf("Test interrupted.\n");
+				goto err;
+			}
+
+			if (err < 0) {
+				printf("Test on bank /dev/%s failed.\n",
+						bank->res->name);
+				goto err;
+			}
+			printf("Tested %u iteration(s) without errors.\n", i);
+		}
+	}
+#ifdef CONFIG_MMU
+	/*
+	 * Renable caching
+	 */
+	if (!cache)
+		for_each_memory_bank(bank)
+			do_remap_range(bank, pte_flags_cached);
+#endif
+	printf("Memtest done.\n");
+
+	return 0;
+
+err:
+#ifdef CONFIG_MMU
+	/*
+	 * Enable caching
+	 */
+	for_each_memory_bank(bank)
+		do_remap_range(bank, pte_flags_cached);
+#endif
+
+	return 1;
+}
+
+static const __maybe_unused char cmd_memtest_help[] =
+"Usage: memtest [OPTION]...\n"
+"memtest related commands\n"
+"	-s	<start>		start address to begin memtest.\n"
+"	-e	<end>		end address to stop memtest.\n"
+"	-i	<iterations>	iterations [default=1, endless=0].\n"
+#ifdef CONFIG_MMU
+"	-c			run test with enable cache.\n"
+#endif
+"	-b			only test bus datalines.";
+
+BAREBOX_CMD_START(memtest)
+	.cmd		= do_mem_memtest,
+	.usage		= "Memory Test",
+	BAREBOX_CMD_HELP(cmd_memtest_help)
+BAREBOX_CMD_END
Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#14 lore raw

Re: [PATCH 6/6] commands: add new memtest command

Quoted 93 lines · Marc Kleine-Budde
Quoted 10 lines · Alexander Aring

Add new memtest command which can enable or disable caching on non allocted barebox regions(test area).

This command simply parse and check parameters then call the mem_test routine.

If no address parameters are given then mem_test will call for each memory bank.

A howto-get-rid-of-ifdef nitpick inline

Quoted 79 lines
---
 commands/Kconfig   |  10 ++
 commands/Makefile  |   1 +
 commands/memtest.c | 362 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 373 insertions(+)
 create mode 100644 commands/memtest.c
commands/Kconfig +10 -0
index 7cc759c..d158c3f 100644
@@ -516,6 +516,16 @@ config CMD_NANDTEST
 	select PARTITION_NEED_MTD
 	prompt "nandtest"
 
+config CMD_MEMTEST
+    tristate
+    select MEMTEST
+    prompt "memtest"
+	help
+	  This command enables a memtest to test installed memory.
+	  During this test allocated iomem regions will be skipped.
+	  If tested architecture has MMU with PTE flags support,
+	  caching can be set enabled or disabled.
+
 endmenu
 
 menu "video command"
commands/Makefile +1 -0
index 393ba51..b39b489 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_CMD_LOADY)		+= loadxy.o
 obj-$(CONFIG_CMD_LOADS)		+= loads.o
 obj-$(CONFIG_CMD_ECHO)		+= echo.o
 obj-$(CONFIG_CMD_MEMORY)	+= mem.o
+obj-$(CONFIG_CMD_MEMTEST)	+= memtest.o
 obj-$(CONFIG_CMD_EDIT)		+= edit.o
 obj-$(CONFIG_CMD_EXEC)		+= exec.o
 obj-$(CONFIG_CMD_SLEEP)		+= sleep.o
commands/memtest.c new file +33 -0
new file mode 100644
index 0000000..22e8006
@@ -0,0 +1,362 @@
+/*
+ * memtest - Perform a memory test
+ *
+ * (C) Copyright 2013
+ * Alexander Aring <[email protected]>, Pengutronix
+ *
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, [email protected].
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <command.h>
+#include <getopt.h>
+#include <asm/mmu.h>
+
+#include <memory_test.h>
Quoted 9 lines

commands/memtest.c line 39

Quoted 6 lines
commands/memtest.c new file +6 -0
+
+/*
+ * In CONFIG_MMU we have a special c flag.
+ */
+#ifdef CONFIG_MMU
+static char optstr[] = "s:e:i:cb";

const?

This will print a compiler warning because the getopt implementation doesn't accept a const char* because getopt will change this string.

But I can cast it later.

Regards
Alex

Quoted 327 lines

commands/memtest.c line 48

Quoted 9 lines
commands/memtest.c new file +9 -0
+
+/*
+ * PTE flags variables to set cached and
+ * uncached regions.
+ */
+static uint32_t pte_flags_cached;
+static uint32_t pte_flags_uncached;
+#else
+static char optstr[] = "s:e:i:b";

const?

commands/memtest.c line 51

Quoted 3 lines
commands/memtest.c new file +3 -0
+#endif
+
+#ifdef CONFIG_MMU

Can

Quoted 182 lines
commands/memtest.c new file +182 -0
+static void print_region(vu_long start, vu_long size, uint32_t flags)
+{
+	if (!size)
+		return;
+
+	printf("\t0x%08lx - "
+			"0x%08lx (size 0x%08lx)\n",
+			start, start + size - 1, size);
+}
+
+static void do_remap_range(struct memory_bank *bank, uint32_t flags)
+{
+	struct resource *r = NULL;
+	struct resource *r_prev = NULL;
+
+	vu_long size;
+	vu_long start;
+	vu_long end;
+
+	if (flags == pte_flags_uncached)
+		printf("Set non caching regions:\n");
+	else if (flags == pte_flags_cached)
+		printf("Set caching regions:\n");
+	else
+		BUG();
+
+	/*
+	 * We assume that the regions are sorted in this list
+	 */
+	list_for_each_entry(r, &bank->res->children, sibling) {
+		/*
+		 * Do on head element for bank boundary
+		 */
+		if (r->sibling.prev == &bank->res->children) {
+			/*
+			 * remember last used element
+			 */
+			r_prev = r;
+
+			start = PAGE_ALIGN(bank->start);
+			end = PAGE_ALIGN_DOWN(r->start) - 1;
+			if (start >= end)
+				continue;
+			size = end - start + 1;
+
+			print_region(start, size, flags);
+			remap_range((void *)start, size, flags);
+
+			continue;
+		}
+		/*
+		 * Between used regions
+		 */
+		start = PAGE_ALIGN(r_prev->end);
+		end = PAGE_ALIGN_DOWN(r->start) - 1;
+		if (start < end) {
+			size = end - start + 1;
+			print_region(start, size, flags);
+			remap_range((void *)start, size, flags);
+		}
+
+		r_prev = r;
+		/*
+		 * Do on head element for bank boundary
+		 */
+		if (list_is_last(&r->sibling, &bank->res->children)) {
+			start = PAGE_ALIGN(r->end);
+			end = PAGE_ALIGN_DOWN(bank->start + bank->size) - 1;
+			if (start >= end)
+				continue;
+			size = end - start + 1;
+
+			print_region(start, size, flags);
+			remap_range((void *)start, size, flags);
+		}
+	}
+}
+#endif
+
+static int do_mem_memtest(int argc, char *argv[])
+{
+	/*
+	 * Set start address to 0xffffffff which
+	 * can't be.
+	 */
+	vu_long start = 0xffffffff;
+	vu_long end = 0;
+
+	uint i;
+	uint max_i = 1;
+
+#ifdef CONFIG_MMU
+	int cache = 0;
+#endif
+	int bus_only = 0;
+	int err = 0;
+	int cnt = 0;
+	int opt;
+
+	struct memory_bank *bank = NULL;
+	struct resource *r = NULL;
+
+	while ((opt = getopt(argc, argv, optstr)) > 0) {
+		switch (opt) {
+		case 's':
+			start = simple_strtoul(optarg, NULL, 0);
+			break;
+		case 'e':
+			end = simple_strtoul(optarg, NULL, 0);
+			break;
+		case 'i':
+			max_i = simple_strtoul(optarg, NULL, 0);
+			break;
+#ifdef CONFIG_MMU
+		case 'c':
+			cache = 1;
+			break;
+#endif
+		case 'b':
+			bus_only = 1;
+			break;
+		default:
+			return COMMAND_ERROR_USAGE;
+		}
+	}
+
+	if (optind > argc)
+		return COMMAND_ERROR_USAGE;
+
+	/*
+	 * Error if no end address
+	 */
+	if (start != 0xffffffff && !end) {
+		printf("Please add an end address.\n");
+		return 1;
+	}
+
+	/*
+	 * Error if no start address
+	 */
+	if (end && start == 0xffffffff) {
+		printf("Please add a start address.\n");
+		return 1;
+	}
+
+	/*
+	 * Check parameters
+	 */
+	if (start != 0xffffffff && end) {
+		if (end <= start) {
+			printf("End address less than or"
+					" equal start address.\n");
+			return 1;
+		}
+
+		/*
+		 * Check if given start and end address are in any banks
+		 */
+		for_each_memory_bank(bank) {
+			if (ADDRESS_IN_REGIONS(start, bank->start,
+						bank->start + bank->size))
+				cnt++;
+
+			if (ADDRESS_IN_REGIONS(end, bank->start,
+						bank->start + bank->size))
+				cnt++;
+		}
+
+		if (cnt != 2) {
+			printf("Start or end addresses are"
+					" not in any ram bank.\n");
+			return 1;
+		}
+	}
+
+#ifdef CONFIG_MMU
+	/*
+	 * Get pte flags. Which are configured at
+	 * runtime at booting.
+	 */
+	pte_flags_cached = mmu_get_pte_cached_flags();
+	pte_flags_uncached = mmu_get_pte_uncached_flags();

commands/memtest.c line 243

Quoted 10 lines
commands/memtest.c new file +10 -0
+#endif
+
+	printf("Skipping regions:\n");
+	for_each_memory_bank(bank) {
+		list_for_each_entry(r, &bank->res->children, sibling)
+			printf("\t0x%08x - "
+					"0x%08x (size 0x%08x) %s\n",
+					r->start, r->end,
+					r->end - r->start + 1, r->name);
+#ifdef CONFIG_MMU

Use if (IS_ENABLED(CONFIG_MMU) and you can get rid of most ifdefs

Marc

Quoted 112 lines
commands/memtest.c new file +112 -0
+		/*
+		 * Disable or enable caching
+		 */
+		if (cache)
+			do_remap_range(bank, pte_flags_cached);
+		else
+			do_remap_range(bank, pte_flags_uncached);
+#endif
+	}
+
+	/*
+	 * Do test if we set a start or end address
+	 */
+	if (start != 0xffffffff && end) {
+		printf("Testing address range:\n\t0x%08lx - 0x%08lx"
+				" (size 0x%08lx)\n",
+				start, end, end - start + 1);
+
+		for (i = 1; (i <= max_i) || !max_i; i++) {
+			printf("Iteration: %u\n", i);
+
+			/*
+			 * Do the Memtest
+			 */
+			err = mem_test(start, end, bus_only);
+			if (err == -EINTR) {
+				printf("Test interrupted.\n");
+				goto err;
+			}
+
+			if (err < 0) {
+				printf("Test failed.\n");
+				goto err;
+			}
+			printf("Tested %u iteration(s) without errors.\n", i);
+		}
+#ifdef CONFIG_MMU
+		/*
+		 * Renable caching
+		 */
+		if (!cache)
+			for_each_memory_bank(bank)
+				do_remap_range(bank, pte_flags_cached);
+#endif
+		printf("Memtest done.\n");
+
+		return 0;
+	}
+
+	/*
+	 * If we set no start or end address
+	 * we do the test on all ram banks
+	 */
+	for (i = 1; (i <= max_i) || !max_i; i++) {
+		for_each_memory_bank(bank) {
+			start = bank->start;
+			end = bank->start + bank->size - 1;
+
+			printf("Iteration: %u\n", i);
+
+			printf("Testing address range:\n\t0x%08lx - "
+					"0x%08lx (size 0x%08lx) on bank /dev/%s\n",
+					start, end, bank->size,
+					bank->res->name);
+
+			err = mem_test(start, end, bus_only);
+			if (err == -EINTR) {
+				printf("Test interrupted.\n");
+				goto err;
+			}
+
+			if (err < 0) {
+				printf("Test on bank /dev/%s failed.\n",
+						bank->res->name);
+				goto err;
+			}
+			printf("Tested %u iteration(s) without errors.\n", i);
+		}
+	}
+#ifdef CONFIG_MMU
+	/*
+	 * Renable caching
+	 */
+	if (!cache)
+		for_each_memory_bank(bank)
+			do_remap_range(bank, pte_flags_cached);
+#endif
+	printf("Memtest done.\n");
+
+	return 0;
+
+err:
+#ifdef CONFIG_MMU
+	/*
+	 * Enable caching
+	 */
+	for_each_memory_bank(bank)
+		do_remap_range(bank, pte_flags_cached);
+#endif
+
+	return 1;
+}
+
+static const __maybe_unused char cmd_memtest_help[] =
+"Usage: memtest [OPTION]...\n"
+"memtest related commands\n"
+"	-s	<start>		start address to begin memtest.\n"
+"	-e	<end>		end address to stop memtest.\n"
+"	-i	<iterations>	iterations [default=1, endless=0].\n"
+#ifdef CONFIG_MMU
+"	-c			run test with enable cache.\n"
+#endif
Quoted 16 lines
Quoted 8 lines
commands/memtest.c new file +7 -0
+"	-b			only test bus datalines.";
+
+BAREBOX_CMD_START(memtest)
+	.cmd		= do_mem_memtest,
+	.usage		= "Memory Test",
+	BAREBOX_CMD_HELP(cmd_memtest_help)
+BAREBOX_CMD_END
Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#15 lore raw

Re: [PATCH 6/6] commands: add new memtest command

Quoted 104 lines · Alexander Aring
Quoted 93 lines · Marc Kleine-Budde
Quoted 10 lines · Alexander Aring

Add new memtest command which can enable or disable caching on non allocted barebox regions(test area).

This command simply parse and check parameters then call the mem_test routine.

If no address parameters are given then mem_test will call for each memory bank.

A howto-get-rid-of-ifdef nitpick inline

Quoted 79 lines
---
 commands/Kconfig   |  10 ++
 commands/Makefile  |   1 +
 commands/memtest.c | 362 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 373 insertions(+)
 create mode 100644 commands/memtest.c
commands/Kconfig +10 -0
index 7cc759c..d158c3f 100644
@@ -516,6 +516,16 @@ config CMD_NANDTEST
 	select PARTITION_NEED_MTD
 	prompt "nandtest"
 
+config CMD_MEMTEST
+    tristate
+    select MEMTEST
+    prompt "memtest"
+	help
+	  This command enables a memtest to test installed memory.
+	  During this test allocated iomem regions will be skipped.
+	  If tested architecture has MMU with PTE flags support,
+	  caching can be set enabled or disabled.
+
 endmenu
 
 menu "video command"
commands/Makefile +1 -0
index 393ba51..b39b489 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_CMD_LOADY)		+= loadxy.o
 obj-$(CONFIG_CMD_LOADS)		+= loads.o
 obj-$(CONFIG_CMD_ECHO)		+= echo.o
 obj-$(CONFIG_CMD_MEMORY)	+= mem.o
+obj-$(CONFIG_CMD_MEMTEST)	+= memtest.o
 obj-$(CONFIG_CMD_EDIT)		+= edit.o
 obj-$(CONFIG_CMD_EXEC)		+= exec.o
 obj-$(CONFIG_CMD_SLEEP)		+= sleep.o
commands/memtest.c new file +33 -0
new file mode 100644
index 0000000..22e8006
@@ -0,0 +1,362 @@
+/*
+ * memtest - Perform a memory test
+ *
+ * (C) Copyright 2013
+ * Alexander Aring <[email protected]>, Pengutronix
+ *
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, [email protected].
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <command.h>
+#include <getopt.h>
+#include <asm/mmu.h>
+
+#include <memory_test.h>
Quoted 9 lines

commands/memtest.c line 39

Quoted 6 lines
commands/memtest.c new file +6 -0
+
+/*
+ * In CONFIG_MMU we have a special c flag.
+ */
+#ifdef CONFIG_MMU
+static char optstr[] = "s:e:i:cb";

const?

Quoted 2 lines

This will print a compiler warning because the getopt implementation doesn't accept a const char* because getopt will change this string.

getopt does not modify this string. The prototype of getopt could be changed to take a const char *.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#16 lore raw

Re: [PATCH 6/6] commands: add new memtest command

Hi,

Quoted 105 lines · Sascha Hauer
Quoted 104 lines · Alexander Aring
Quoted 102 lines · Marc Kleine-Budde
Quoted 10 lines · Alexander Aring

Add new memtest command which can enable or disable caching on non allocted barebox regions(test area).

This command simply parse and check parameters then call the mem_test routine.

If no address parameters are given then mem_test will call for each memory bank.

A howto-get-rid-of-ifdef nitpick inline

Quoted 75 lines
---
 commands/Kconfig   |  10 ++
 commands/Makefile  |   1 +
 commands/memtest.c | 362 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 373 insertions(+)
 create mode 100644 commands/memtest.c
commands/Kconfig +10 -0
index 7cc759c..d158c3f 100644
@@ -516,6 +516,16 @@ config CMD_NANDTEST
 	select PARTITION_NEED_MTD
 	prompt "nandtest"
 
+config CMD_MEMTEST
+    tristate
+    select MEMTEST
+    prompt "memtest"
+	help
+	  This command enables a memtest to test installed memory.
+	  During this test allocated iomem regions will be skipped.
+	  If tested architecture has MMU with PTE flags support,
+	  caching can be set enabled or disabled.
+
 endmenu
 
 menu "video command"
commands/Makefile +1 -0
index 393ba51..b39b489 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_CMD_LOADY)		+= loadxy.o
 obj-$(CONFIG_CMD_LOADS)		+= loads.o
 obj-$(CONFIG_CMD_ECHO)		+= echo.o
 obj-$(CONFIG_CMD_MEMORY)	+= mem.o
+obj-$(CONFIG_CMD_MEMTEST)	+= memtest.o
 obj-$(CONFIG_CMD_EDIT)		+= edit.o
 obj-$(CONFIG_CMD_EXEC)		+= exec.o
 obj-$(CONFIG_CMD_SLEEP)		+= sleep.o
commands/memtest.c new file +29 -0
new file mode 100644
index 0000000..22e8006
@@ -0,0 +1,362 @@
+/*
+ * memtest - Perform a memory test
+ *
+ * (C) Copyright 2013
+ * Alexander Aring <[email protected]>, Pengutronix
+ *
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, [email protected].
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <command.h>

commands/memtest.c line 39

Quoted 10 lines
commands/memtest.c new file +10 -0
+#include <getopt.h>
+#include <asm/mmu.h>
+
+#include <memory_test.h>
+
+/*
+ * In CONFIG_MMU we have a special c flag.
+ */
+#ifdef CONFIG_MMU
+static char optstr[] = "s:e:i:cb";

const?

Quoted 6 lines
Quoted 2 lines

This will print a compiler warning because the getopt implementation doesn't accept a const char* because getopt will change this string.

getopt does not modify this string. The prototype of getopt could be changed to take a const char *.

Ok I will fix this.

Regards
Alex

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox