mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* memtest updates
@ 2015-10-27  8:29 Sascha Hauer
  2015-10-27  8:29 ` [PATCH 1/9] memtest: move request/release regions to common/ Sascha Hauer
                   ` (9 more replies)
  0 siblings, 10 replies; 15+ messages in thread
From: Sascha Hauer @ 2015-10-27  8:29 UTC (permalink / raw)
  To: Barebox List

This series has some updates for the memory test. The output and the
code are made more compact and some additional options are added. Also
the remap_range function is reworked.

Sascha

----------------------------------------------------------------
Sascha Hauer (9):
      memtest: move request/release regions to common/
      rework remap_range
      memtest: split tests in separate functions
      memtest: Make output more compact
      memtest: Make comments single line when appropriate
      memtest: move ctrlc check / progress showing into separate function
      memtest: move error handling to end of function
      memtest: By default only test biggest region
      memtest: Make cached/uncached test configurable

 arch/arm/cpu/mmu.c              |  30 +++--
 arch/arm/include/asm/mmu.h      |  23 +---
 arch/blackfin/include/asm/mmu.h |  14 +--
 arch/mips/include/asm/mmu.h     |  14 +--
 arch/nios2/include/asm/mmu.h    |  14 +--
 arch/openrisc/include/asm/mmu.h |  14 +--
 arch/ppc/cpu-85xx/mmu.c         |  20 ++-
 arch/ppc/include/asm/mmu.h      |  23 +---
 arch/sandbox/include/asm/mmu.h  |  14 +--
 arch/x86/include/asm/mmu.h      |  14 +--
 commands/memtest.c              | 205 ++++++++++++------------------
 common/memtest.c                | 269 ++++++++++++++++++++++++++--------------
 include/memtest.h               |   8 +-
 include/mmu.h                   |  41 ++++++
 14 files changed, 348 insertions(+), 355 deletions(-)
 create mode 100644 include/mmu.h

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 1/9] memtest: move request/release regions to common/
  2015-10-27  8:29 memtest updates Sascha Hauer
@ 2015-10-27  8:29 ` Sascha Hauer
  2015-10-27  8:29 ` [PATCH 2/9] rework remap_range Sascha Hauer
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Sascha Hauer @ 2015-10-27  8:29 UTC (permalink / raw)
  To: Barebox List

Normally code providing a feature should be implemented in common/ which
is then called from the command code. Follow this rule and move some more
of the memtest code to common/.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/memtest.c | 107 +-------------------------------------------------
 common/memtest.c   | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/memtest.h  |   3 ++
 3 files changed, 117 insertions(+), 105 deletions(-)

diff --git a/commands/memtest.c b/commands/memtest.c
index 7561230..531b8e0 100644
--- a/commands/memtest.c
+++ b/commands/memtest.c
@@ -26,102 +26,8 @@
 #include <malloc.h>
 #include <common.h>
 #include <errno.h>
-
 #include <memtest.h>
 
-static int alloc_memtest_region(struct list_head *list,
-		resource_size_t start, resource_size_t size)
-{
-	struct resource *r_new;
-	struct mem_test_resource *r;
-
-	r = xzalloc(sizeof(struct mem_test_resource));
-	r_new = request_sdram_region("memtest", start, size);
-	if (!r_new)
-		return -EINVAL;
-
-	r->r = r_new;
-	list_add_tail(&r->list, list);
-
-	return 0;
-}
-
-static int request_memtest_regions(struct list_head *list)
-{
-	int ret;
-	struct memory_bank *bank;
-	struct resource *r, *r_prev = NULL;
-	resource_size_t start, end, size;
-
-	for_each_memory_bank(bank) {
-		/*
-		 * If we don't have any allocated region on bank,
-		 * we use the whole bank boundary
-		 */
-		if (list_empty(&bank->res->children)) {
-			start = PAGE_ALIGN(bank->res->start);
-			size = PAGE_ALIGN_DOWN(bank->res->end - start + 1);
-
-			if (size) {
-				ret = alloc_memtest_region(list, start, size);
-				if (ret < 0)
-					return ret;
-			}
-
-			continue;
-		}
-
-		r = list_first_entry(&bank->res->children,
-				     struct resource, sibling);
-		start = PAGE_ALIGN(bank->res->start);
-		end = PAGE_ALIGN_DOWN(r->start);
-		r_prev = r;
-		if (start != end) {
-			size = end - start;
-			ret = alloc_memtest_region(list, start, size);
-			if (ret < 0)
-				return ret;
-		}
-		/*
-		 * We assume that the regions are sorted in this list
-		 * So the first element has start boundary on bank->res->start
-		 * and the last element hast end boundary on bank->res->end.
-		 *
-		 * Between used regions. Start from second entry.
-		 */
-		list_for_each_entry_from(r, &bank->res->children, sibling) {
-			start = PAGE_ALIGN(r_prev->end + 1);
-			end = r->start - 1;
-			r_prev = r;
-			if (start >= end)
-				continue;
-
-			size = PAGE_ALIGN_DOWN(end - start + 1);
-			if (size == 0)
-				continue;
-			ret = alloc_memtest_region(list, start, size);
-			if (ret < 0)
-				return ret;
-		}
-
-		/*
-		 * Do on head element for bank boundary.
-		 */
-		r = list_last_entry(&bank->res->children,
-				     struct resource, sibling);
-		start = PAGE_ALIGN(r->end);
-		end = bank->res->end;
-		size = PAGE_ALIGN_DOWN(end - start + 1);
-		if (size && start < end && start > r->end) {
-			ret = alloc_memtest_region(list, start, size);
-			if (ret < 0)
-				return ret;
-		}
-	}
-
-	return 0;
-}
-
 static int __do_memtest(struct list_head *memtest_regions,
 		int bus_only, uint32_t cache_flag)
 {
@@ -148,7 +54,6 @@ static int do_memtest(int argc, char *argv[])
 {
 	int bus_only = 0, ret, opt;
 	uint32_t i, max_i = 1, pte_flags_cached, pte_flags_uncached;
-	struct mem_test_resource *r, *r_tmp;
 	struct list_head memtest_used_regions;
 
 	while ((opt = getopt(argc, argv, "i:b")) > 0) {
@@ -175,7 +80,7 @@ static int do_memtest(int argc, char *argv[])
 
 	INIT_LIST_HEAD(&memtest_used_regions);
 
-	ret = request_memtest_regions(&memtest_used_regions);
+	ret = mem_test_request_regions(&memtest_used_regions);
 	if (ret < 0)
 		goto out;
 
@@ -203,15 +108,7 @@ static int do_memtest(int argc, char *argv[])
 	}
 
 out:
-	list_for_each_entry_safe(r, r_tmp, &memtest_used_regions, list) {
-		/*
-		 * Ensure to leave with a cached on non used sdram regions.
-		 */
-		remap_range((void *)r->r->start, r->r->end -
-				r->r->start + 1, pte_flags_cached);
-		release_sdram_region(r->r);
-		free(r);
-	}
+	mem_test_release_regions(&memtest_used_regions);
 
 	if (ret < 0) {
 		/*
diff --git a/common/memtest.c b/common/memtest.c
index d8d1154..fc71e91 100644
--- a/common/memtest.c
+++ b/common/memtest.c
@@ -27,6 +27,118 @@
 #include <linux/sizes.h>
 #include <errno.h>
 #include <memtest.h>
+#include <malloc.h>
+#include <asm/mmu.h>
+
+static int alloc_memtest_region(struct list_head *list,
+		resource_size_t start, resource_size_t size)
+{
+	struct resource *r_new;
+	struct mem_test_resource *r;
+
+	r = xzalloc(sizeof(struct mem_test_resource));
+	r_new = request_sdram_region("memtest", start, size);
+	if (!r_new)
+		return -EINVAL;
+
+	r->r = r_new;
+	list_add_tail(&r->list, list);
+
+	return 0;
+}
+
+int mem_test_request_regions(struct list_head *list)
+{
+	int ret;
+	struct memory_bank *bank;
+	struct resource *r, *r_prev = NULL;
+	resource_size_t start, end, size;
+
+	for_each_memory_bank(bank) {
+		/*
+		 * If we don't have any allocated region on bank,
+		 * we use the whole bank boundary
+		 */
+		if (list_empty(&bank->res->children)) {
+			start = PAGE_ALIGN(bank->res->start);
+			size = PAGE_ALIGN_DOWN(bank->res->end - start + 1);
+
+			if (size) {
+				ret = alloc_memtest_region(list, start, size);
+				if (ret < 0)
+					return ret;
+			}
+
+			continue;
+		}
+
+		r = list_first_entry(&bank->res->children,
+				     struct resource, sibling);
+		start = PAGE_ALIGN(bank->res->start);
+		end = PAGE_ALIGN_DOWN(r->start);
+		r_prev = r;
+		if (start != end) {
+			size = end - start;
+			ret = alloc_memtest_region(list, start, size);
+			if (ret < 0)
+				return ret;
+		}
+		/*
+		 * We assume that the regions are sorted in this list
+		 * So the first element has start boundary on bank->res->start
+		 * and the last element hast end boundary on bank->res->end.
+		 *
+		 * Between used regions. Start from second entry.
+		 */
+		list_for_each_entry_from(r, &bank->res->children, sibling) {
+			start = PAGE_ALIGN(r_prev->end + 1);
+			end = r->start - 1;
+			r_prev = r;
+			if (start >= end)
+				continue;
+
+			size = PAGE_ALIGN_DOWN(end - start + 1);
+			if (size == 0)
+				continue;
+			ret = alloc_memtest_region(list, start, size);
+			if (ret < 0)
+				return ret;
+		}
+
+		/*
+		 * Do on head element for bank boundary.
+		 */
+		r = list_last_entry(&bank->res->children,
+				     struct resource, sibling);
+		start = PAGE_ALIGN(r->end);
+		end = bank->res->end;
+		size = PAGE_ALIGN_DOWN(end - start + 1);
+		if (size && start < end && start > r->end) {
+			ret = alloc_memtest_region(list, start, size);
+			if (ret < 0)
+				return ret;
+		}
+	}
+
+	return 0;
+}
+
+void mem_test_release_regions(struct list_head *list)
+{
+	struct mem_test_resource *r, *r_tmp;
+	uint32_t pte_flags_cached = mmu_get_pte_cached_flags();
+
+	list_for_each_entry_safe(r, r_tmp, list, list) {
+		/*
+		 * Ensure to leave with a cached on non used sdram regions.
+		 */
+		remap_range((void *)r->r->start, r->r->end -
+				r->r->start + 1, pte_flags_cached);
+
+		release_sdram_region(r->r);
+		free(r);
+	}
+}
 
 static void mem_test_report_failure(const char *failure_description,
 				    resource_size_t expected_value,
diff --git a/include/memtest.h b/include/memtest.h
index a337be8..1c67a73 100644
--- a/include/memtest.h
+++ b/include/memtest.h
@@ -8,6 +8,9 @@ struct mem_test_resource {
 	struct list_head list;
 };
 
+int mem_test_request_regions(struct list_head *list);
+void mem_test_release_regions(struct list_head *list);
+
 int mem_test(resource_size_t _start,
 		resource_size_t _end, int bus_only);
 
-- 
2.6.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 2/9] rework remap_range
  2015-10-27  8:29 memtest updates Sascha Hauer
  2015-10-27  8:29 ` [PATCH 1/9] memtest: move request/release regions to common/ Sascha Hauer
@ 2015-10-27  8:29 ` Sascha Hauer
  2015-10-27  8:29 ` [PATCH 3/9] memtest: split tests in separate functions Sascha Hauer
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Sascha Hauer @ 2015-10-27  8:29 UTC (permalink / raw)
  To: Barebox List

remap_range is for remapping regions with different cache attributes.
It is implemented for ARM and PowerPC only, the other architectures only
provide stubs.
Currently the new cache attributes are passed in an architecture specific
way and the attributes have to be retrieved by calls to
mmu_get_pte_cached_flags() and mmu_get_pte_uncached_flags().
Make this simpler by providing architecture independent flags which can
be directly passed to remap_range()
Also provide a MAP_ARCH_DEFAULT flag and a arch_can_remap() function.
The MAP_ARCH_DEFAULT defaults to whatever caching type the architecture
has as default. the arch_can_remap() function returns true if the
architecture can change the cache attributes, false otherwise. This
allows the memtest code to better find out what it has to do.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/cpu/mmu.c              | 30 +++++++++++++++------------
 arch/arm/include/asm/mmu.h      | 23 ++++-----------------
 arch/blackfin/include/asm/mmu.h | 14 +------------
 arch/mips/include/asm/mmu.h     | 14 +------------
 arch/nios2/include/asm/mmu.h    | 14 +------------
 arch/openrisc/include/asm/mmu.h | 14 +------------
 arch/ppc/cpu-85xx/mmu.c         | 20 +++++++++++++++---
 arch/ppc/include/asm/mmu.h      | 23 +++++----------------
 arch/sandbox/include/asm/mmu.h  | 14 +------------
 arch/x86/include/asm/mmu.h      | 14 +------------
 commands/memtest.c              | 45 +++++++++++++++++++++--------------------
 common/memtest.c                |  5 ++---
 include/mmu.h                   | 41 +++++++++++++++++++++++++++++++++++++
 13 files changed, 115 insertions(+), 156 deletions(-)
 create mode 100644 include/mmu.h

diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 470b448..81c2394 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -20,7 +20,7 @@
 #include <common.h>
 #include <dma-dir.h>
 #include <init.h>
-#include <asm/mmu.h>
+#include <mmu.h>
 #include <errno.h>
 #include <linux/sizes.h>
 #include <asm/memory.h>
@@ -81,16 +81,6 @@ static uint32_t pte_flags_uncached;
 
 #define PTE_MASK ((1 << 12) - 1)
 
-uint32_t mmu_get_pte_cached_flags()
-{
-	return pte_flags_cached;
-}
-
-uint32_t mmu_get_pte_uncached_flags()
-{
-	return pte_flags_uncached;
-}
-
 static void arm_mmu_not_initialized_error(void)
 {
 	/*
@@ -173,24 +163,38 @@ static void dma_inv_range(unsigned long start, unsigned long end)
 	__dma_inv_range(start, end);
 }
 
-void remap_range(void *_start, size_t size, uint32_t flags)
+int arch_remap_range(void *_start, size_t size, unsigned flags)
 {
 	unsigned long start = (unsigned long)_start;
 	u32 *p;
 	int numentries, i;
+	u32 pte_flags;
+
+	switch (flags) {
+	case MAP_CACHED:
+		pte_flags = pte_flags_cached;
+		break;
+	case MAP_UNCACHED:
+		pte_flags = pte_flags_uncached;
+		break;
+	default:
+		return -EINVAL;
+	}
 
 	numentries = size >> PAGE_SHIFT;
 	p = find_pte(start);
 
 	for (i = 0; i < numentries; i++) {
 		p[i] &= ~PTE_MASK;
-		p[i] |= flags | PTE_TYPE_SMALL;
+		p[i] |= pte_flags | PTE_TYPE_SMALL;
 	}
 
 	dma_flush_range((unsigned long)p,
 			(unsigned long)p + numentries * sizeof(u32));
 
 	tlb_invalidate();
+
+	return 0;
 }
 
 void *map_io_sections(unsigned long phys, void *_start, size_t size)
diff --git a/arch/arm/include/asm/mmu.h b/arch/arm/include/asm/mmu.h
index 3b19e9e..8de6544 100644
--- a/arch/arm/include/asm/mmu.h
+++ b/arch/arm/include/asm/mmu.h
@@ -27,32 +27,17 @@ static inline void setup_dma_coherent(unsigned long offset)
 }
 
 #ifdef CONFIG_MMU
-void remap_range(void *_start, size_t size, uint32_t flags);
+#define ARCH_HAS_REMAP
+#define MAP_ARCH_DEFAULT MAP_CACHED
+int arch_remap_range(void *_start, size_t size, unsigned flags);
 void *map_io_sections(unsigned long physaddr, void *start, size_t size);
-uint32_t mmu_get_pte_cached_flags(void);
-uint32_t mmu_get_pte_uncached_flags(void);
-
 #else
-
-static inline void remap_range(void *_start, size_t size, uint32_t flags)
-{
-}
-
+#define MAP_ARCH_DEFAULT MAP_UNCACHED
 static inline void *map_io_sections(unsigned long phys, void *start, size_t size)
 {
 	return (void *)phys;
 }
 
-static inline uint32_t mmu_get_pte_cached_flags(void)
-{
-	return 0;
-}
-
-static inline uint32_t mmu_get_pte_uncached_flags(void)
-{
-	return 0;
-}
-
 #endif
 
 #ifdef CONFIG_CACHE_L2X0
diff --git a/arch/blackfin/include/asm/mmu.h b/arch/blackfin/include/asm/mmu.h
index bf65420..95af871 100644
--- a/arch/blackfin/include/asm/mmu.h
+++ b/arch/blackfin/include/asm/mmu.h
@@ -1,18 +1,6 @@
 #ifndef __ASM_MMU_H
 #define __ASM_MMU_H
 
-static inline void remap_range(void *_start, size_t size, uint32_t flags)
-{
-}
-
-static inline uint32_t mmu_get_pte_cached_flags(void)
-{
-	return 0;
-}
-
-static inline uint32_t mmu_get_pte_uncached_flags(void)
-{
-	return 0;
-}
+#define MAP_ARCH_DEFAULT MAP_UNCACHED
 
 #endif /* __ASM_MMU_H */
diff --git a/arch/mips/include/asm/mmu.h b/arch/mips/include/asm/mmu.h
index bf65420..95af871 100644
--- a/arch/mips/include/asm/mmu.h
+++ b/arch/mips/include/asm/mmu.h
@@ -1,18 +1,6 @@
 #ifndef __ASM_MMU_H
 #define __ASM_MMU_H
 
-static inline void remap_range(void *_start, size_t size, uint32_t flags)
-{
-}
-
-static inline uint32_t mmu_get_pte_cached_flags(void)
-{
-	return 0;
-}
-
-static inline uint32_t mmu_get_pte_uncached_flags(void)
-{
-	return 0;
-}
+#define MAP_ARCH_DEFAULT MAP_UNCACHED
 
 #endif /* __ASM_MMU_H */
diff --git a/arch/nios2/include/asm/mmu.h b/arch/nios2/include/asm/mmu.h
index bf65420..95af871 100644
--- a/arch/nios2/include/asm/mmu.h
+++ b/arch/nios2/include/asm/mmu.h
@@ -1,18 +1,6 @@
 #ifndef __ASM_MMU_H
 #define __ASM_MMU_H
 
-static inline void remap_range(void *_start, size_t size, uint32_t flags)
-{
-}
-
-static inline uint32_t mmu_get_pte_cached_flags(void)
-{
-	return 0;
-}
-
-static inline uint32_t mmu_get_pte_uncached_flags(void)
-{
-	return 0;
-}
+#define MAP_ARCH_DEFAULT MAP_UNCACHED
 
 #endif /* __ASM_MMU_H */
diff --git a/arch/openrisc/include/asm/mmu.h b/arch/openrisc/include/asm/mmu.h
index bf65420..95af871 100644
--- a/arch/openrisc/include/asm/mmu.h
+++ b/arch/openrisc/include/asm/mmu.h
@@ -1,18 +1,6 @@
 #ifndef __ASM_MMU_H
 #define __ASM_MMU_H
 
-static inline void remap_range(void *_start, size_t size, uint32_t flags)
-{
-}
-
-static inline uint32_t mmu_get_pte_cached_flags(void)
-{
-	return 0;
-}
-
-static inline uint32_t mmu_get_pte_uncached_flags(void)
-{
-	return 0;
-}
+#define MAP_ARCH_DEFAULT MAP_UNCACHED
 
 #endif /* __ASM_MMU_H */
diff --git a/arch/ppc/cpu-85xx/mmu.c b/arch/ppc/cpu-85xx/mmu.c
index 7e86e6b..27cac2f 100644
--- a/arch/ppc/cpu-85xx/mmu.c
+++ b/arch/ppc/cpu-85xx/mmu.c
@@ -16,15 +16,27 @@
 #include <asm/cache.h>
 #include <mach/mmu.h>
 
-void remap_range(void *_start, size_t size, uint32_t flags)
+int arch_remap_range(void *_start, size_t size, unsigned flags)
 {
-	uint32_t ptr, start, tsize, valid, wimge;
+	uint32_t ptr, start, tsize, valid, wimge, pte_flags;
 	unsigned long epn;
 	phys_addr_t rpn = 0;
 	int esel = 0;
 
+	switch (flags) {
+	case MAP_UNCACHED:
+		pte_flags = MAS2_I;
+		break;
+	case MAP_SYSTEM_RAM:
+	case MAP_CACHED:
+		pte_flags = 0;
+		break;
+	default:
+		return -EINVAL;
+	}
+
 	ptr = start = (uint32_t)_start;
-	wimge = flags | MAS2_M;
+	wimge = pte_flags | MAS2_M;
 
 	while (ptr < (start + size)) {
 		esel = e500_find_tlb_idx((void *)ptr, 1);
@@ -41,6 +53,8 @@ void remap_range(void *_start, size_t size, uint32_t flags)
 		/* convert tsize to bytes to increment address. */
 		ptr += (1ULL << ((tsize) + 10));
 	}
+
+	return 0;
 }
 
 uint32_t mmu_get_pte_cached_flags(void)
diff --git a/arch/ppc/include/asm/mmu.h b/arch/ppc/include/asm/mmu.h
index 6e15975..03ac644 100644
--- a/arch/ppc/include/asm/mmu.h
+++ b/arch/ppc/include/asm/mmu.h
@@ -557,25 +557,12 @@ extern int write_bat(ppc_bat_t bat, unsigned long upper, unsigned long lower);
 
 #ifndef __ASSEMBLY__
 
+#define MAP_ARCH_DEFAULT MAP_CACHED
+
 #ifdef CONFIG_MMU
-void remap_range(void *_start, size_t size, uint32_t flags);
-uint32_t mmu_get_pte_cached_flags(void);
-uint32_t mmu_get_pte_uncached_flags(void);
-#else
-static inline void remap_range(void *_start, size_t size, uint32_t flags)
-{
-}
-
-static inline uint32_t mmu_get_pte_cached_flags(void)
-{
-	return 0;
-}
-
-static inline uint32_t mmu_get_pte_uncached_flags(void)
-{
-	return 0;
-}
-#endif /* CONFIG_MMU */
+#define ARCH_HAS_REMAP
+int arch_remap_range(void *_start, size_t size, unsigned flags);
+#else /* CONFIG_MMU */
 #endif
 
 #endif /* _PPC_MMU_H_ */
diff --git a/arch/sandbox/include/asm/mmu.h b/arch/sandbox/include/asm/mmu.h
index bf65420..95af871 100644
--- a/arch/sandbox/include/asm/mmu.h
+++ b/arch/sandbox/include/asm/mmu.h
@@ -1,18 +1,6 @@
 #ifndef __ASM_MMU_H
 #define __ASM_MMU_H
 
-static inline void remap_range(void *_start, size_t size, uint32_t flags)
-{
-}
-
-static inline uint32_t mmu_get_pte_cached_flags(void)
-{
-	return 0;
-}
-
-static inline uint32_t mmu_get_pte_uncached_flags(void)
-{
-	return 0;
-}
+#define MAP_ARCH_DEFAULT MAP_UNCACHED
 
 #endif /* __ASM_MMU_H */
diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
index bf65420..95af871 100644
--- a/arch/x86/include/asm/mmu.h
+++ b/arch/x86/include/asm/mmu.h
@@ -1,18 +1,6 @@
 #ifndef __ASM_MMU_H
 #define __ASM_MMU_H
 
-static inline void remap_range(void *_start, size_t size, uint32_t flags)
-{
-}
-
-static inline uint32_t mmu_get_pte_cached_flags(void)
-{
-	return 0;
-}
-
-static inline uint32_t mmu_get_pte_uncached_flags(void)
-{
-	return 0;
-}
+#define MAP_ARCH_DEFAULT MAP_UNCACHED
 
 #endif /* __ASM_MMU_H */
diff --git a/commands/memtest.c b/commands/memtest.c
index 531b8e0..db9e3db 100644
--- a/commands/memtest.c
+++ b/commands/memtest.c
@@ -21,15 +21,15 @@
 
 #include <command.h>
 #include <getopt.h>
-#include <asm/mmu.h>
 #include <memory.h>
 #include <malloc.h>
 #include <common.h>
 #include <errno.h>
 #include <memtest.h>
+#include <mmu.h>
 
 static int __do_memtest(struct list_head *memtest_regions,
-		int bus_only, uint32_t cache_flag)
+		int bus_only, unsigned cache_flag)
 {
 	struct mem_test_resource *r;
 	int ret;
@@ -53,7 +53,7 @@ static int __do_memtest(struct list_head *memtest_regions,
 static int do_memtest(int argc, char *argv[])
 {
 	int bus_only = 0, ret, opt;
-	uint32_t i, max_i = 1, pte_flags_cached, pte_flags_uncached;
+	uint32_t i, max_i = 1;
 	struct list_head memtest_used_regions;
 
 	while ((opt = getopt(argc, argv, "i:b")) > 0) {
@@ -72,12 +72,6 @@ static int do_memtest(int argc, char *argv[])
 	if (optind > argc)
 		return COMMAND_ERROR_USAGE;
 
-	/*
-	 * Get pte flags for enable and disable cache support on page.
-	 */
-	pte_flags_cached = mmu_get_pte_cached_flags();
-	pte_flags_uncached = mmu_get_pte_uncached_flags();
-
 	INIT_LIST_HEAD(&memtest_used_regions);
 
 	ret = mem_test_request_regions(&memtest_used_regions);
@@ -87,24 +81,31 @@ static int do_memtest(int argc, char *argv[])
 	for (i = 1; (i <= max_i) || !max_i; i++) {
 		if (max_i)
 			printf("Start iteration %u of %u.\n", i, max_i);
-		/*
-		 * First try a memtest with caching enabled.
-		 */
-		if (IS_ENABLED(CONFIG_MMU)) {
+
+		if (arch_can_remap()) {
+			/*
+			 * First try a memtest with caching enabled.
+			 */
 			printf("Do memtest with caching enabled.\n");
 			ret = __do_memtest(&memtest_used_regions,
-					bus_only, pte_flags_cached);
+					bus_only, MAP_CACHED);
+			if (ret < 0)
+				goto out;
+
+			/*
+			 * Second try a memtest with caching disabled.
+			 */
+			printf("Do memtest with caching disabled.\n");
+			ret = __do_memtest(&memtest_used_regions,
+					bus_only, MAP_UNCACHED);
+			if (ret < 0)
+				goto out;
+		} else {
+			ret = __do_memtest(&memtest_used_regions,
+					bus_only, MAP_DEFAULT);
 			if (ret < 0)
 				goto out;
 		}
-		/*
-		 * Second try a memtest with caching disabled.
-		 */
-		printf("Do memtest with caching disabled.\n");
-		ret = __do_memtest(&memtest_used_regions,
-				bus_only, pte_flags_uncached);
-		if (ret < 0)
-			goto out;
 	}
 
 out:
diff --git a/common/memtest.c b/common/memtest.c
index fc71e91..467eea5 100644
--- a/common/memtest.c
+++ b/common/memtest.c
@@ -28,7 +28,7 @@
 #include <errno.h>
 #include <memtest.h>
 #include <malloc.h>
-#include <asm/mmu.h>
+#include <mmu.h>
 
 static int alloc_memtest_region(struct list_head *list,
 		resource_size_t start, resource_size_t size)
@@ -126,14 +126,13 @@ int mem_test_request_regions(struct list_head *list)
 void mem_test_release_regions(struct list_head *list)
 {
 	struct mem_test_resource *r, *r_tmp;
-	uint32_t pte_flags_cached = mmu_get_pte_cached_flags();
 
 	list_for_each_entry_safe(r, r_tmp, list, list) {
 		/*
 		 * Ensure to leave with a cached on non used sdram regions.
 		 */
 		remap_range((void *)r->r->start, r->r->end -
-				r->r->start + 1, pte_flags_cached);
+				r->r->start + 1, MAP_DEFAULT);
 
 		release_sdram_region(r->r);
 		free(r);
diff --git a/include/mmu.h b/include/mmu.h
new file mode 100644
index 0000000..66b246f
--- /dev/null
+++ b/include/mmu.h
@@ -0,0 +1,41 @@
+#ifndef __MMU_H
+#define __MMU_H
+
+#define MAP_UNCACHED	0
+#define MAP_CACHED	1
+
+/*
+ * Depending on the architecture the default mapping can be
+ * cached or uncached. Without ARCH_HAS_REMAP being set this
+ * is mapping type is the only one supported.
+ */
+#define MAP_DEFAULT	MAP_ARCH_DEFAULT
+
+#include <asm/mmu.h>
+
+#ifndef ARCH_HAS_REMAP
+static inline int arch_remap_range(void *start, size_t size, unsigned flags)
+{
+	if (flags == MAP_ARCH_DEFAULT)
+		return 0;
+
+	return -EINVAL;
+}
+
+static inline bool arch_can_remap(void)
+{
+	return false;
+}
+#else
+static inline bool arch_can_remap(void)
+{
+	return true;
+}
+#endif
+
+static inline int remap_range(void *start, size_t size, unsigned flags)
+{
+	return arch_remap_range(start, size, flags);
+}
+
+#endif
-- 
2.6.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 3/9] memtest: split tests in separate functions
  2015-10-27  8:29 memtest updates Sascha Hauer
  2015-10-27  8:29 ` [PATCH 1/9] memtest: move request/release regions to common/ Sascha Hauer
  2015-10-27  8:29 ` [PATCH 2/9] rework remap_range Sascha Hauer
@ 2015-10-27  8:29 ` Sascha Hauer
  2015-10-27  8:29 ` [PATCH 4/9] memtest: Make output more compact Sascha Hauer
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Sascha Hauer @ 2015-10-27  8:29 UTC (permalink / raw)
  To: Barebox List

The memtest does a bus integrity check and a moving inversions test.
Split the tests into two separate functions so that the can be called
separately.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/memtest.c |  9 ++++++++-
 common/memtest.c   | 36 +-----------------------------------
 include/memtest.h  |  4 ++--
 3 files changed, 11 insertions(+), 38 deletions(-)

diff --git a/commands/memtest.c b/commands/memtest.c
index db9e3db..ccccc9c 100644
--- a/commands/memtest.c
+++ b/commands/memtest.c
@@ -41,7 +41,14 @@ static int __do_memtest(struct list_head *memtest_regions,
 		remap_range((void *)r->r->start, r->r->end -
 				r->r->start + 1, cache_flag);
 
-		ret = mem_test(r->r->start, r->r->end, bus_only);
+		ret = mem_test_bus_integrity(r->r->start, r->r->end);
+		if (ret < 0)
+			return ret;
+
+		if (bus_only)
+			continue;
+
+		ret = mem_test_moving_inversions(r->r->start, r->r->end);
 		if (ret < 0)
 			return ret;
 		printf("done.\n\n");
diff --git a/common/memtest.c b/common/memtest.c
index 467eea5..4a84dc3 100644
--- a/common/memtest.c
+++ b/common/memtest.c
@@ -331,8 +331,7 @@ int mem_test_bus_integrity(resource_size_t _start,
 	return 0;
 }
 
-int mem_test_dram(resource_size_t _start,
-		  resource_size_t _end)
+int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
 {
 	volatile resource_size_t *start, num_words, offset, temp, anti_pattern;
 
@@ -438,36 +437,3 @@ int mem_test_dram(resource_size_t _start,
 
 	return 0;
 }
-
-/*
- * Perform a memory test. The complete test
- * loops until interrupted by ctrl-c.
- *
- * Prameters:
- * start: start address for memory test.
- * end: end address of memory test.
- * bus_only: skip integrity check and do only a address/data bus
- *	     testing.
- *
- * Return value can be -EINVAL for invalid parameter or -EINTR
- * if memory test was interrupted.
- */
-int mem_test(resource_size_t _start,
-	       resource_size_t _end, int bus_only)
-{
-	int ret;
-
-	ret = mem_test_bus_integrity(_start, _end);
-
-	if (ret < 0)
-		return ret;
-
-	/*
-	 * We tested only the bus if != 0
-	 * leaving here
-	 */
-	if (!bus_only)
-		ret = mem_test_dram(_start, _end);
-
-	return ret;
-}
diff --git a/include/memtest.h b/include/memtest.h
index 1c67a73..3979d65 100644
--- a/include/memtest.h
+++ b/include/memtest.h
@@ -11,7 +11,7 @@ struct mem_test_resource {
 int mem_test_request_regions(struct list_head *list);
 void mem_test_release_regions(struct list_head *list);
 
-int mem_test(resource_size_t _start,
-		resource_size_t _end, int bus_only);
+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);
 
 #endif /* __MEMTEST_H */
-- 
2.6.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 4/9] memtest: Make output more compact
  2015-10-27  8:29 memtest updates Sascha Hauer
                   ` (2 preceding siblings ...)
  2015-10-27  8:29 ` [PATCH 3/9] memtest: split tests in separate functions Sascha Hauer
@ 2015-10-27  8:29 ` Sascha Hauer
  2015-10-27  8:29 ` [PATCH 5/9] memtest: Make comments single line when appropriate Sascha Hauer
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Sascha Hauer @ 2015-10-27  8:29 UTC (permalink / raw)
  To: Barebox List

Especially when called multiple times the output of the memory test
is quite verbose. Make it more compact by only describing once what
is being done and only use one progress bare instead of three.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/memtest.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/common/memtest.c b/common/memtest.c
index 4a84dc3..0559359 100644
--- a/common/memtest.c
+++ b/common/memtest.c
@@ -344,8 +344,8 @@ 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 integrity check of physicaly ram.\n"
-	       "Filling ram with patterns...\n");
+	printf("Starting moving inversions test of RAM:\n"
+	       "Fill with address, compare, fill with inverted address, compare again\n");
 
 	/*
 	 * Description: Test the integrity of a physical
@@ -358,11 +358,11 @@ 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.
 	 */
-	init_progression_bar(num_words);
-
 	for (offset = 0; offset < num_words; offset++) {
 		/*
 		 * Every 4K we update the progressbar.
@@ -375,18 +375,15 @@ int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
 		}
 		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 & (SZ_4K - 1))) {
 			if (ctrlc())
 				return -EINTR;
-			show_progress(offset);
+			show_progress(num_words + offset);
 		}
 
 		temp = start[offset];
@@ -401,18 +398,15 @@ int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
 		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 & (SZ_4K - 1))) {
 			if (ctrlc())
 				return -EINTR;
-			show_progress(offset);
+			show_progress(2 * num_words + offset);
 		}
 
 		anti_pattern = ~(offset + 1);
@@ -428,7 +422,7 @@ int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
 
 		start[offset] = 0;
 	}
-	show_progress(offset);
+	show_progress(3 * num_words);
 
 	/*
 	 * end of progressbar
-- 
2.6.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 5/9] memtest: Make comments single line when appropriate
  2015-10-27  8:29 memtest updates Sascha Hauer
                   ` (3 preceding siblings ...)
  2015-10-27  8:29 ` [PATCH 4/9] memtest: Make output more compact Sascha Hauer
@ 2015-10-27  8:29 ` Sascha Hauer
  2015-10-27  8:29 ` [PATCH 6/9] memtest: move ctrlc check / progress showing into separate function Sascha Hauer
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Sascha Hauer @ 2015-10-27  8:29 UTC (permalink / raw)
  To: Barebox List

Make the comments single line when they fit into a single line
to make the code a bit shorter.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/memtest.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)

diff --git a/common/memtest.c b/common/memtest.c
index 0559359..9bd9025 100644
--- a/common/memtest.c
+++ b/common/memtest.c
@@ -360,14 +360,9 @@ int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
 
 	init_progression_bar(3 * num_words);
 
-	/*
-	 * Fill memory with a known pattern.
-	 */
+	/* Fill memory with a known pattern */
 	for (offset = 0; offset < num_words; offset++) {
-		/*
-		 * Every 4K we update the progressbar.
-		 */
-
+		/* Every 4K we update the progressbar */
 		if (!(offset & (SZ_4K - 1))) {
 			if (ctrlc())
 				return -EINTR;
@@ -376,9 +371,7 @@ int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
 		start[offset] = offset + 1;
 	}
 
-	/*
-	 * Check each location and invert it for the second pass.
-	 */
+	/* Check each location and invert it for the second pass */
 	for (offset = 0; offset < num_words; offset++) {
 		if (!(offset & (SZ_4K - 1))) {
 			if (ctrlc())
@@ -399,9 +392,7 @@ int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
 		start[offset] = anti_pattern;
 	}
 
-	/*
-	 * Check each location for the inverted pattern and zero it.
-	 */
+	/* Check each location for the inverted pattern and zero it */
 	for (offset = 0; offset < num_words; offset++) {
 		if (!(offset & (SZ_4K - 1))) {
 			if (ctrlc())
@@ -424,9 +415,7 @@ int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
 	}
 	show_progress(3 * num_words);
 
-	/*
-	 * end of progressbar
-	 */
+	/* end of progressbar */
 	printf("\n");
 
 	return 0;
-- 
2.6.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 6/9] memtest: move ctrlc check / progress showing into separate function
  2015-10-27  8:29 memtest updates Sascha Hauer
                   ` (4 preceding siblings ...)
  2015-10-27  8:29 ` [PATCH 5/9] memtest: Make comments single line when appropriate Sascha Hauer
@ 2015-10-27  8:29 ` Sascha Hauer
  2015-10-27  8:30 ` [PATCH 7/9] memtest: move error handling to end of function Sascha Hauer
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Sascha Hauer @ 2015-10-27  8:29 UTC (permalink / raw)
  To: Barebox List

To make the actual test a bit better visible in the code.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/memtest.c | 39 +++++++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 16 deletions(-)

diff --git a/common/memtest.c b/common/memtest.c
index 9bd9025..dc7d032 100644
--- a/common/memtest.c
+++ b/common/memtest.c
@@ -331,6 +331,20 @@ int mem_test_bus_integrity(resource_size_t _start,
 	return 0;
 }
 
+static int update_progress(resource_size_t offset)
+{
+	/* Only check every 4k to reduce overhead */
+	if (offset & (SZ_4K - 1))
+		return 0;
+
+	if (ctrlc())
+		return -EINTR;
+
+	show_progress(offset);
+
+	return 0;
+}
+
 int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
 {
 	volatile resource_size_t *start, num_words, offset, temp, anti_pattern;
@@ -362,22 +376,17 @@ int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
 
 	/* Fill memory with a known pattern */
 	for (offset = 0; offset < num_words; offset++) {
-		/* Every 4K we update the progressbar */
-		if (!(offset & (SZ_4K - 1))) {
-			if (ctrlc())
-				return -EINTR;
-			show_progress(offset);
-		}
+		ret = update_progress(offset);
+		if (ret)
+			return ret;
 		start[offset] = offset + 1;
 	}
 
 	/* Check each location and invert it for the second pass */
 	for (offset = 0; offset < num_words; offset++) {
-		if (!(offset & (SZ_4K - 1))) {
-			if (ctrlc())
-				return -EINTR;
-			show_progress(num_words + offset);
-		}
+		ret = update_progress(num_words + offset);
+		if (ret)
+			return ret;
 
 		temp = start[offset];
 		if (temp != (offset + 1)) {
@@ -394,11 +403,9 @@ 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++) {
-		if (!(offset & (SZ_4K - 1))) {
-			if (ctrlc())
-				return -EINTR;
-			show_progress(2 * num_words + offset);
-		}
+		ret = update_progress(2 * num_words + offset);
+		if (ret)
+			return ret;
 
 		anti_pattern = ~(offset + 1);
 		temp = start[offset];
-- 
2.6.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 7/9] memtest: move error handling to end of function
  2015-10-27  8:29 memtest updates Sascha Hauer
                   ` (5 preceding siblings ...)
  2015-10-27  8:29 ` [PATCH 6/9] memtest: move ctrlc check / progress showing into separate function Sascha Hauer
@ 2015-10-27  8:30 ` Sascha Hauer
  2015-10-27  8:30 ` [PATCH 8/9] memtest: By default only test biggest region Sascha Hauer
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Sascha Hauer @ 2015-10-27  8:30 UTC (permalink / raw)
  To: Barebox List

Move error handling out of the test code to make the actual test
better visible.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/memtest.c | 38 ++++++++++++++++++--------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/common/memtest.c b/common/memtest.c
index dc7d032..026fd0d 100644
--- a/common/memtest.c
+++ b/common/memtest.c
@@ -347,7 +347,8 @@ static int update_progress(resource_size_t offset)
 
 int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
 {
-	volatile resource_size_t *start, num_words, offset, temp, anti_pattern;
+	volatile resource_size_t *start, num_words, offset, pattern, expected;
+	int ret;
 
 	_start = ALIGN(_start, sizeof(resource_size_t));
 	_end = ALIGN_DOWN(_end, sizeof(resource_size_t)) - 1;
@@ -388,17 +389,13 @@ int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
 		if (ret)
 			return ret;
 
-		temp = start[offset];
-		if (temp != (offset + 1)) {
-			printf("\n");
-			mem_test_report_failure("read/write",
-						(offset + 1),
-						temp, &start[offset]);
-			return -EIO;
-		}
+		pattern = start[offset];
+		expected = offset + 1;
+
+		if (pattern != expected)
+			goto mem_err;
 
-		anti_pattern = ~(offset + 1);
-		start[offset] = anti_pattern;
+		start[offset] = ~start[offset];
 	}
 
 	/* Check each location for the inverted pattern and zero it */
@@ -407,16 +404,11 @@ int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
 		if (ret)
 			return ret;
 
-		anti_pattern = ~(offset + 1);
-		temp = start[offset];
+		pattern = start[offset];
+		expected = ~(offset + 1);
 
-		if (temp != anti_pattern) {
-			printf("\n");
-			mem_test_report_failure("read/write",
-						anti_pattern,
-						temp, &start[offset]);
-			return -EIO;
-		}
+		if (pattern != expected)
+			goto mem_err;
 
 		start[offset] = 0;
 	}
@@ -426,4 +418,10 @@ int mem_test_moving_inversions(resource_size_t _start, resource_size_t _end)
 	printf("\n");
 
 	return 0;
+
+mem_err:
+	printf("\n");
+	mem_test_report_failure("read/write", expected, pattern, &start[offset]);
+
+	return -EIO;
 }
-- 
2.6.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 8/9] memtest: By default only test biggest region
  2015-10-27  8:29 memtest updates Sascha Hauer
                   ` (6 preceding siblings ...)
  2015-10-27  8:30 ` [PATCH 7/9] memtest: move error handling to end of function Sascha Hauer
@ 2015-10-27  8:30 ` Sascha Hauer
  2015-10-27  8:30 ` [PATCH 9/9] memtest: Make cached/uncached test configurable Sascha Hauer
  2015-10-27 16:55 ` memtest updates Alexander Aring
  9 siblings, 0 replies; 15+ messages in thread
From: Sascha Hauer @ 2015-10-27  8:30 UTC (permalink / raw)
  To: Barebox List

Often enough the biggest free region spans most free RAM, so
it doesn't add much value to test the remaining free regions. This
patch changes the default behaviour to only test the biggest free
region and adds the -t option to test all regions.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/memtest.c | 82 ++++++++++++++++++++++++++++++++++++------------------
 common/memtest.c   | 16 +++++++++++
 include/memtest.h  |  1 +
 3 files changed, 72 insertions(+), 27 deletions(-)

diff --git a/commands/memtest.c b/commands/memtest.c
index ccccc9c..7853cc5 100644
--- a/commands/memtest.c
+++ b/commands/memtest.c
@@ -28,42 +28,70 @@
 #include <memtest.h>
 #include <mmu.h>
 
-static int __do_memtest(struct list_head *memtest_regions,
+static int do_test_one_area(struct mem_test_resource *r, int bus_only,
+		unsigned cache_flag)
+{
+	int ret;
+
+	printf("Testing memory space: "
+			"0x%08x -> 0x%08x:\n",
+			r->r->start,  r->r->end);
+
+	remap_range((void *)r->r->start, r->r->end -
+			r->r->start + 1, cache_flag);
+
+	ret = mem_test_bus_integrity(r->r->start, r->r->end);
+	if (ret < 0)
+		return ret;
+
+	if (bus_only)
+		return 0;
+
+	ret = mem_test_moving_inversions_pattern(r->r->start, r->r->end, 0xdeadbeef);
+	if (ret < 0)
+		return ret;
+	printf("done.\n\n");
+
+	return 0;
+}
+
+static int do_memtest_thorough(struct list_head *memtest_regions,
 		int bus_only, unsigned cache_flag)
 {
 	struct mem_test_resource *r;
 	int ret;
 
 	list_for_each_entry(r, memtest_regions, list) {
-		printf("Testing memory space: "
-				"0x%08x -> 0x%08x:\n",
-				r->r->start,  r->r->end);
-		remap_range((void *)r->r->start, r->r->end -
-				r->r->start + 1, cache_flag);
-
-		ret = mem_test_bus_integrity(r->r->start, r->r->end);
-		if (ret < 0)
+		ret = do_test_one_area(r, bus_only, cache_flag);
+		if (ret)
 			return ret;
-
-		if (bus_only)
-			continue;
-
-		ret = mem_test_moving_inversions(r->r->start, r->r->end);
-		if (ret < 0)
-			return ret;
-		printf("done.\n\n");
 	}
 
 	return 0;
 }
 
+static int do_memtest_biggest(struct list_head *memtest_regions,
+		int bus_only, unsigned cache_flag)
+{
+	struct mem_test_resource *r;
+
+	r = mem_test_biggest_region(memtest_regions);
+	if (!r)
+		return -EINVAL;
+
+	return do_test_one_area(r, bus_only, cache_flag);
+}
+
 static int do_memtest(int argc, char *argv[])
 {
 	int bus_only = 0, ret, opt;
 	uint32_t i, max_i = 1;
 	struct list_head memtest_used_regions;
+	int (*memtest)(struct list_head *, int, unsigned);
+
+	memtest = do_memtest_biggest;
 
-	while ((opt = getopt(argc, argv, "i:b")) > 0) {
+	while ((opt = getopt(argc, argv, "i:bt")) > 0) {
 		switch (opt) {
 		case 'i':
 			max_i = simple_strtoul(optarg, NULL, 0);
@@ -71,6 +99,9 @@ static int do_memtest(int argc, char *argv[])
 		case 'b':
 			bus_only = 1;
 			break;
+		case 't':
+			memtest = do_memtest_thorough;
+			break;
 		default:
 			return COMMAND_ERROR_USAGE;
 		}
@@ -90,25 +121,21 @@ static int do_memtest(int argc, char *argv[])
 			printf("Start iteration %u of %u.\n", i, max_i);
 
 		if (arch_can_remap()) {
-			/*
-			 * First try a memtest with caching enabled.
-			 */
+			/* First do a memtest with caching enabled. */
 			printf("Do memtest with caching enabled.\n");
-			ret = __do_memtest(&memtest_used_regions,
+			ret = memtest(&memtest_used_regions,
 					bus_only, MAP_CACHED);
 			if (ret < 0)
 				goto out;
 
-			/*
-			 * Second try a memtest with caching disabled.
-			 */
+			/* Second do a memtest with caching disabled. */
 			printf("Do memtest with caching disabled.\n");
-			ret = __do_memtest(&memtest_used_regions,
+			ret = memtest(&memtest_used_regions,
 					bus_only, MAP_UNCACHED);
 			if (ret < 0)
 				goto out;
 		} else {
-			ret = __do_memtest(&memtest_used_regions,
+			ret = memtest(&memtest_used_regions,
 					bus_only, MAP_DEFAULT);
 			if (ret < 0)
 				goto out;
@@ -139,6 +166,7 @@ BAREBOX_CMD_HELP_START(memtest)
 BAREBOX_CMD_HELP_TEXT("Options:")
 BAREBOX_CMD_HELP_OPT("-i ITERATIONS", "perform number of iterations (default 1, 0 is endless)")
 BAREBOX_CMD_HELP_OPT("-b", "perform only a test on bus lines")
+BAREBOX_CMD_HELP_OPT("-t", "thorough. test all free areas. If unset, only test biggest free area")
 BAREBOX_CMD_HELP_END
 
 BAREBOX_CMD_START(memtest)
diff --git a/common/memtest.c b/common/memtest.c
index 026fd0d..401b902 100644
--- a/common/memtest.c
+++ b/common/memtest.c
@@ -139,6 +139,22 @@ void mem_test_release_regions(struct list_head *list)
 	}
 }
 
+struct mem_test_resource *mem_test_biggest_region(struct list_head *list)
+{
+	struct mem_test_resource *r, *best = NULL;
+	resource_size_t size = 0;
+
+	list_for_each_entry(r, list, list) {
+		resource_size_t now = resource_size(r->r);
+		if (now > size) {
+			size = now;
+			best = r;
+		}
+	}
+
+	return best;
+}
+
 static void mem_test_report_failure(const char *failure_description,
 				    resource_size_t expected_value,
 				    resource_size_t actual_value,
diff --git a/include/memtest.h b/include/memtest.h
index 3979d65..0100a6c 100644
--- a/include/memtest.h
+++ b/include/memtest.h
@@ -10,6 +10,7 @@ struct mem_test_resource {
 
 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);
-- 
2.6.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 9/9] memtest: Make cached/uncached test configurable
  2015-10-27  8:29 memtest updates Sascha Hauer
                   ` (7 preceding siblings ...)
  2015-10-27  8:30 ` [PATCH 8/9] memtest: By default only test biggest region Sascha Hauer
@ 2015-10-27  8:30 ` Sascha Hauer
  2015-10-27 16:55 ` memtest updates Alexander Aring
  9 siblings, 0 replies; 15+ messages in thread
From: Sascha Hauer @ 2015-10-27  8:30 UTC (permalink / raw)
  To: Barebox List

Add options to explicitly test cached/uncached tests. Without these
options still both cached and uncached is tested if remapping is
supported.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/memtest.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/commands/memtest.c b/commands/memtest.c
index 7853cc5..42bc0b2 100644
--- a/commands/memtest.c
+++ b/commands/memtest.c
@@ -88,10 +88,11 @@ static int do_memtest(int argc, char *argv[])
 	uint32_t i, max_i = 1;
 	struct list_head memtest_used_regions;
 	int (*memtest)(struct list_head *, int, unsigned);
+	int cached = 0, uncached = 0;
 
 	memtest = do_memtest_biggest;
 
-	while ((opt = getopt(argc, argv, "i:bt")) > 0) {
+	while ((opt = getopt(argc, argv, "i:btcu")) > 0) {
 		switch (opt) {
 		case 'i':
 			max_i = simple_strtoul(optarg, NULL, 0);
@@ -102,11 +103,22 @@ static int do_memtest(int argc, char *argv[])
 		case 't':
 			memtest = do_memtest_thorough;
 			break;
+		case 'c':
+			cached = 1;
+			break;
+		case 'u':
+			uncached = 1;
+			break;
 		default:
 			return COMMAND_ERROR_USAGE;
 		}
 	}
 
+	if (!arch_can_remap() && (cached || uncached)) {
+		printf("Cannot map cached or uncached\n");
+		return -EINVAL;
+	}
+
 	if (optind > argc)
 		return COMMAND_ERROR_USAGE;
 
@@ -120,21 +132,23 @@ static int do_memtest(int argc, char *argv[])
 		if (max_i)
 			printf("Start iteration %u of %u.\n", i, max_i);
 
-		if (arch_can_remap()) {
-			/* First do a memtest with caching enabled. */
+		if (cached) {
 			printf("Do memtest with caching enabled.\n");
 			ret = memtest(&memtest_used_regions,
 					bus_only, MAP_CACHED);
 			if (ret < 0)
 				goto out;
+		}
 
-			/* Second do a memtest with caching disabled. */
+		if (uncached) {
 			printf("Do memtest with caching disabled.\n");
 			ret = memtest(&memtest_used_regions,
 					bus_only, MAP_UNCACHED);
 			if (ret < 0)
 				goto out;
-		} else {
+		}
+
+		if (!cached && !uncached) {
 			ret = memtest(&memtest_used_regions,
 					bus_only, MAP_DEFAULT);
 			if (ret < 0)
@@ -166,6 +180,8 @@ BAREBOX_CMD_HELP_START(memtest)
 BAREBOX_CMD_HELP_TEXT("Options:")
 BAREBOX_CMD_HELP_OPT("-i ITERATIONS", "perform number of iterations (default 1, 0 is endless)")
 BAREBOX_CMD_HELP_OPT("-b", "perform only a test on bus lines")
+BAREBOX_CMD_HELP_OPT("-c", "cached. Test using cached memory")
+BAREBOX_CMD_HELP_OPT("-u", "uncached. Test using uncached memory")
 BAREBOX_CMD_HELP_OPT("-t", "thorough. test all free areas. If unset, only test biggest free area")
 BAREBOX_CMD_HELP_END
 
-- 
2.6.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: memtest updates
  2015-10-27  8:29 memtest updates Sascha Hauer
                   ` (8 preceding siblings ...)
  2015-10-27  8:30 ` [PATCH 9/9] memtest: Make cached/uncached test configurable Sascha Hauer
@ 2015-10-27 16:55 ` Alexander Aring
  2015-10-27 17:27   ` Alexander Aring
  2015-10-28  6:17   ` Sascha Hauer
  9 siblings, 2 replies; 15+ messages in thread
From: Alexander Aring @ 2015-10-27 16:55 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List

On Tue, Oct 27, 2015 at 09:29:53AM +0100, Sascha Hauer wrote:
> This series has some updates for the memory test. The output and the
> code are made more compact and some additional options are added. Also
> the remap_range function is reworked.
> 

I currently try to build next with memtest, I got the following issue:

commands/memtest.c: In function 'do_test_one_area':
commands/memtest.c:50:2: error: implicit declaration of function 'mem_test_moving_inversions_pattern' [-Werror=implicit-function-declaration]
  ret = mem_test_moving_inversions_pattern(r->r->start, r->r->end, 0xdeadbeef);

after running grep I realized and there is no
"mem_test_moving_inversions_pattern" function. :-(

Then:

after cutting some words from this function and running grep again, then
I found a "mem_test_moving_inversions" function. :-)

It seems it's a different function and you passed a "0xdeadbeef" there,
otherwise the function fits.

What means 0xdeadbeef here?

Anyway I applied:

diff --git a/commands/memtest.c b/commands/memtest.c
index 88656df..d784a5c 100644
--- a/commands/memtest.c
+++ b/commands/memtest.c
@@ -47,7 +47,7 @@ static int do_test_one_area(struct mem_test_resource *r, int bus_only,
        if (bus_only)
                return 0;
 
-       ret = mem_test_moving_inversions_pattern(r->r->start, r->r->end, 0xdeadbeef);
+       ret = mem_test_moving_inversions(r->r->start, r->r->end);
        if (ret < 0)
                return ret;
        printf("done.\n\n");


and it seems to solve this compiling issue.

- Alex

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: memtest updates
  2015-10-27 16:55 ` memtest updates Alexander Aring
@ 2015-10-27 17:27   ` Alexander Aring
  2015-10-27 17:35     ` Alexander Aring
  2015-10-28  6:17   ` Sascha Hauer
  1 sibling, 1 reply; 15+ messages in thread
From: Alexander Aring @ 2015-10-27 17:27 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List

On Tue, Oct 27, 2015 at 05:54:59PM +0100, Alexander Aring wrote:
> On Tue, Oct 27, 2015 at 09:29:53AM +0100, Sascha Hauer wrote:
> > This series has some updates for the memory test. The output and the
> > code are made more compact and some additional options are added. Also
> > the remap_range function is reworked.
> > 
> 
...
> 
> What means 0xdeadbeef here?

okay, I it's guess the pattern argument which doesn't exist anymore.

I run memtest now with:

memtest -t -u

on the RPi and it seems the first progressbar range of "0/3" - "1/3" runs
faster than the last range of "1/3" - "3/3".

This sounds like that remap_range does not full manipulate the range
of page tables (the range at the start address). Okay we can't full use
the range, because we need to be PAGE_ALIGN, but the whole first range of
"0/3" - "1/3" sounds not correct for me (it's bigger than PAGE_ALIGN).

Maybe everything is correct and the first address room is always a
little bit faster than the others, but I don't think that.

I haven't tried to debug this issue. Can somebody confirm that on an
other arm board?

- Alex

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: memtest updates
  2015-10-27 17:27   ` Alexander Aring
@ 2015-10-27 17:35     ` Alexander Aring
  0 siblings, 0 replies; 15+ messages in thread
From: Alexander Aring @ 2015-10-27 17:35 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List

On Tue, Oct 27, 2015 at 06:27:42PM +0100, Alexander Aring wrote:
> On Tue, Oct 27, 2015 at 05:54:59PM +0100, Alexander Aring wrote:
> > On Tue, Oct 27, 2015 at 09:29:53AM +0100, Sascha Hauer wrote:
> > > This series has some updates for the memory test. The output and the
> > > code are made more compact and some additional options are added. Also
> > > the remap_range function is reworked.
> > > 
> > 
> ...
> > 
> > What means 0xdeadbeef here?
> 
> okay, I it's guess the pattern argument which doesn't exist anymore.
> 
> I run memtest now with:
> 
> memtest -t -u
> 
> on the RPi and it seems the first progressbar range of "0/3" - "1/3" runs
> faster than the last range of "1/3" - "3/3".
> 
> This sounds like that remap_range does not full manipulate the range
> of page tables (the range at the start address). Okay we can't full use
> the range, because we need to be PAGE_ALIGN, but the whole first range of
> "0/3" - "1/3" sounds not correct for me (it's bigger than PAGE_ALIGN).
> 
> Maybe everything is correct and the first address room is always a
> little bit faster than the others, but I don't think that.
> 
> I haven't tried to debug this issue. Can somebody confirm that on an
> other arm board?
> 

okay, false alarm. It's confusing me, we do not always the same
operation in each progressbar step.

We doing in the first part filling some pattern, in second/third part we
doing filling pattern and compare. This is why it takes longer. It just
looks like some area is still cached and the other uncached.

- Alex

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: memtest updates
  2015-10-27 16:55 ` memtest updates Alexander Aring
  2015-10-27 17:27   ` Alexander Aring
@ 2015-10-28  6:17   ` Sascha Hauer
  2015-10-28  9:11     ` Alexander Aring
  1 sibling, 1 reply; 15+ messages in thread
From: Sascha Hauer @ 2015-10-28  6:17 UTC (permalink / raw)
  To: Alexander Aring; +Cc: Barebox List

On Tue, Oct 27, 2015 at 05:55:04PM +0100, Alexander Aring wrote:
> On Tue, Oct 27, 2015 at 09:29:53AM +0100, Sascha Hauer wrote:
> > This series has some updates for the memory test. The output and the
> > code are made more compact and some additional options are added. Also
> > the remap_range function is reworked.
> > 
> 
> I currently try to build next with memtest, I got the following issue:
> 
> commands/memtest.c: In function 'do_test_one_area':
> commands/memtest.c:50:2: error: implicit declaration of function 'mem_test_moving_inversions_pattern' [-Werror=implicit-function-declaration]
>   ret = mem_test_moving_inversions_pattern(r->r->start, r->r->end, 0xdeadbeef);
> 
> after running grep I realized and there is no
> "mem_test_moving_inversions_pattern" function. :-(
> 
> Then:
> 
> after cutting some words from this function and running grep again, then
> I found a "mem_test_moving_inversions" function. :-)
> 
> It seems it's a different function and you passed a "0xdeadbeef" there,
> otherwise the function fits.
> 
> What means 0xdeadbeef here?

For a customer I need a moving inversions test with a fixed pattern
instead of the own address written to the address. That's a leftover
here.

I already fixed that one up.

Sascha


-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: memtest updates
  2015-10-28  6:17   ` Sascha Hauer
@ 2015-10-28  9:11     ` Alexander Aring
  0 siblings, 0 replies; 15+ messages in thread
From: Alexander Aring @ 2015-10-28  9:11 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List

Hi,

On Wed, Oct 28, 2015 at 07:17:55AM +0100, Sascha Hauer wrote:
> On Tue, Oct 27, 2015 at 05:55:04PM +0100, Alexander Aring wrote:
> > On Tue, Oct 27, 2015 at 09:29:53AM +0100, Sascha Hauer wrote:
> > > This series has some updates for the memory test. The output and the
> > > code are made more compact and some additional options are added. Also
> > > the remap_range function is reworked.
> > > 
> > 
> > I currently try to build next with memtest, I got the following issue:
> > 
> > commands/memtest.c: In function 'do_test_one_area':
> > commands/memtest.c:50:2: error: implicit declaration of function 'mem_test_moving_inversions_pattern' [-Werror=implicit-function-declaration]
> >   ret = mem_test_moving_inversions_pattern(r->r->start, r->r->end, 0xdeadbeef);
> > 
> > after running grep I realized and there is no
> > "mem_test_moving_inversions_pattern" function. :-(
> > 
> > Then:
> > 
> > after cutting some words from this function and running grep again, then
> > I found a "mem_test_moving_inversions" function. :-)
> > 
> > It seems it's a different function and you passed a "0xdeadbeef" there,
> > otherwise the function fits.
> > 
> > What means 0xdeadbeef here?
> 
> For a customer I need a moving inversions test with a fixed pattern
> instead of the own address written to the address. That's a leftover
> here.
> 
> I already fixed that one up.
> 

ok, thanks.

I also have some idea to creating a small barebox which do a full
memtest on banks, if the architecture supports it.

E.g. omap which boots from sd card. We have some MLO image. We could
have some switch inside the barebox to build a MLO image which
automatically starts the memtest after setup memory.

I don't know how possible that is and if MLO have the necessary things
inside like "memory bank registration", etc. to make a memory test possible.
Also if everything fits then in the MLO with the memtest command.

Over Kconfig there exists then some switch to enable this behaviour and
also setup the arguments for memtest which should automatically started
inside the MLO. A MLO for memory-testing, something like that.


Just an idea for somebody which wants a "full" memory test.

- Alex

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2015-10-28  9:11 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-27  8:29 memtest updates Sascha Hauer
2015-10-27  8:29 ` [PATCH 1/9] memtest: move request/release regions to common/ Sascha Hauer
2015-10-27  8:29 ` [PATCH 2/9] rework remap_range Sascha Hauer
2015-10-27  8:29 ` [PATCH 3/9] memtest: split tests in separate functions Sascha Hauer
2015-10-27  8:29 ` [PATCH 4/9] memtest: Make output more compact Sascha Hauer
2015-10-27  8:29 ` [PATCH 5/9] memtest: Make comments single line when appropriate Sascha Hauer
2015-10-27  8:29 ` [PATCH 6/9] memtest: move ctrlc check / progress showing into separate function Sascha Hauer
2015-10-27  8:30 ` [PATCH 7/9] memtest: move error handling to end of function Sascha Hauer
2015-10-27  8:30 ` [PATCH 8/9] memtest: By default only test biggest region Sascha Hauer
2015-10-27  8:30 ` [PATCH 9/9] memtest: Make cached/uncached test configurable Sascha Hauer
2015-10-27 16:55 ` memtest updates Alexander Aring
2015-10-27 17:27   ` Alexander Aring
2015-10-27 17:35     ` Alexander Aring
2015-10-28  6:17   ` Sascha Hauer
2015-10-28  9:11     ` Alexander Aring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox