summaryrefslogtreecommitdiffstats
path: root/common/memtest.c
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2015-05-13 19:54:20 -0700
committerSascha Hauer <s.hauer@pengutronix.de>2015-05-15 07:16:14 +0200
commit6a69d233bdf9d29cf24c0b59d818fd176caf851b (patch)
treeae203cf86082634f8a4612436b7faeba77bfff7b /common/memtest.c
parent6ebc8c603ae3d4a337fe7269661e12b04e960af5 (diff)
downloadbarebox-6a69d233bdf9d29cf24c0b59d818fd176caf851b.tar.gz
common/memtest.c: Refactor mem_test() into three surbroutines
Original mem_test() was rather long an contained code to perform two distinct operations. This patch moves that code into two separate subroutines and converts mem_test into a high level interface that calls the subroutines. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/memtest.c')
-rw-r--r--common/memtest.c105
1 files changed, 68 insertions, 37 deletions
diff --git a/common/memtest.c b/common/memtest.c
index 9eda788..57e2ad9 100644
--- a/common/memtest.c
+++ b/common/memtest.c
@@ -28,35 +28,22 @@
#include <errno.h>
#include <memtest.h>
-static const resource_size_t 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.
- *
- * 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 mem_test_bus_integrity(resource_size_t _start,
+ resource_size_t _end)
{
- volatile resource_size_t *start, *dummy, val, readback, offset,
- offset2, pattern, temp, anti_pattern, num_words;
+ static const resource_size_t 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 */
+ };
+
+ volatile resource_size_t *start, *dummy, num_words, val, readback, offset,
+ offset2, pattern, temp, anti_pattern;
int i;
_start = ALIGN(_start, sizeof(resource_size_t));
@@ -66,7 +53,7 @@ int mem_test(resource_size_t _start,
return -EINVAL;
start = (resource_size_t *)_start;
- /*
+ /*
* Point the dummy to start[1]
*/
dummy = start + 1;
@@ -227,15 +214,25 @@ int mem_test(resource_size_t _start,
start[offset2] = pattern;
}
- /*
- * We tested only the bus if != 0
- * leaving here
- */
- if (bus_only)
- return 0;
+ return 0;
+}
+
+int mem_test_dram(resource_size_t _start,
+ resource_size_t _end)
+{
+ volatile resource_size_t *start, num_words, offset, temp, anti_pattern;
+
+ _start = ALIGN(_start, sizeof(resource_size_t));
+ _end = ALIGN_DOWN(_end, sizeof(resource_size_t)) - 1;
+
+ if (_end <= _start)
+ return -EINVAL;
+
+ 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");
+ "Filling ram with patterns...\n");
/*
* Description: Test the integrity of a physical
@@ -252,16 +249,17 @@ int mem_test(resource_size_t _start,
* Fill memory with a known pattern.
*/
init_progression_bar(num_words);
+
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);
}
-
start[offset] = offset + 1;
}
show_progress(offset);
@@ -326,3 +324,36 @@ int mem_test(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;
+}