9
0
Fork 0

Merge branch 'for-next/memtest'

This commit is contained in:
Sascha Hauer 2015-06-09 09:26:43 +02:00
commit 65aa032d11
1 changed files with 113 additions and 65 deletions

View File

@ -28,35 +28,33 @@
#include <errno.h> #include <errno.h>
#include <memtest.h> #include <memtest.h>
static const resource_size_t bitpattern[] = { static void mem_test_report_failure(const char *failure_description,
0x00000001, /* single bit */ resource_size_t expected_value,
0x00000003, /* two adjacent bits */ resource_size_t actual_value,
0x00000007, /* three adjacent bits */ volatile resource_size_t *address)
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)
{ {
volatile resource_size_t *start, *dummy, val, readback, offset, printf("FAILURE (%s): "
offset2, pattern, temp, anti_pattern, num_words; "expected 0x%08x, actual 0x%08x at address 0x%08x.\n",
failure_description, expected_value, actual_value,
(resource_size_t)address);
}
int mem_test_bus_integrity(resource_size_t _start,
resource_size_t _end)
{
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; int i;
_start = ALIGN(_start, sizeof(resource_size_t)); _start = ALIGN(_start, sizeof(resource_size_t));
@ -66,7 +64,7 @@ int mem_test(resource_size_t _start,
return -EINVAL; return -EINVAL;
start = (resource_size_t *)_start; start = (resource_size_t *)_start;
/* /*
* Point the dummy to start[1] * Point the dummy to start[1]
*/ */
dummy = start + 1; dummy = start + 1;
@ -91,8 +89,7 @@ int mem_test(resource_size_t _start,
* '0's and '0' bits through a field of '1's (i.e. * '0's and '0' bits through a field of '1's (i.e.
* pattern and ~pattern). * pattern and ~pattern).
*/ */
for (i = 0; i < ARRAY_SIZE(bitpattern)/ for (i = 0; i < ARRAY_SIZE(bitpattern); i++) {
sizeof(resource_size_t); i++) {
val = bitpattern[i]; val = bitpattern[i];
for (; val != 0; val <<= 1) { for (; val != 0; val <<= 1) {
@ -101,9 +98,8 @@ int mem_test(resource_size_t _start,
*dummy = ~val; *dummy = ~val;
readback = *start; readback = *start;
if (readback != val) { if (readback != val) {
printf("FAILURE (data line): " mem_test_report_failure("data line",
"expected 0x%08x, actual 0x%08x at address 0x%08x.\n", val, readback, start);
val, readback, (resource_size_t)start);
return -EIO; return -EIO;
} }
@ -111,10 +107,8 @@ int mem_test(resource_size_t _start,
*dummy = val; *dummy = val;
readback = *start; readback = *start;
if (readback != ~val) { if (readback != ~val) {
printf("FAILURE (data line): " mem_test_report_failure("data line",
"Is 0x%08x, should be 0x%08x at address 0x%08x.\n", ~val, readback, start);
readback,
~val, (resource_size_t)start);
return -EIO; return -EIO;
} }
} }
@ -171,6 +165,15 @@ int mem_test(resource_size_t _start,
for (offset = 1; offset <= num_words; offset <<= 1) for (offset = 1; offset <= num_words; offset <<= 1)
start[offset] = pattern; start[offset] = pattern;
/*
* Now write anti-pattern at offset 0. If during the previous
* step one of the address lines got stuck high this
* operation would result in a memory cell at power-of-two
* offset being set to anti-pattern which hopefully would be
* detected byt the loop that follows.
*/
start[0] = anti_pattern;
printf("Check for address bits stuck high.\n"); printf("Check for address bits stuck high.\n");
/* /*
@ -179,15 +182,17 @@ int mem_test(resource_size_t _start,
for (offset = 1; offset <= num_words; offset <<= 1) { for (offset = 1; offset <= num_words; offset <<= 1) {
temp = start[offset]; temp = start[offset];
if (temp != pattern) { if (temp != pattern) {
printf("FAILURE: Address bit " mem_test_report_failure("address bit stuck high",
"stuck high @ 0x%08x:" pattern, temp, &start[offset]);
" expected 0x%08x, actual 0x%08x.\n",
(resource_size_t)&start[offset],
pattern, temp);
return -EIO; return -EIO;
} }
} }
/*
Restore original value
*/
start[0] = pattern;
printf("Check for address bits stuck " printf("Check for address bits stuck "
"low or shorted.\n"); "low or shorted.\n");
@ -197,31 +202,40 @@ int mem_test(resource_size_t _start,
for (offset2 = 1; offset2 <= num_words; offset2 <<= 1) { for (offset2 = 1; offset2 <= num_words; offset2 <<= 1) {
start[offset2] = anti_pattern; start[offset2] = anti_pattern;
for (offset = 1; offset <= num_words; offset <<= 1) { for (offset = 0; offset <= num_words;
offset = (offset) ? offset << 1 : 1) {
temp = start[offset]; temp = start[offset];
if ((temp != pattern) && if ((temp != pattern) &&
(offset != offset2)) { (offset != offset2)) {
printf("FAILURE: Address bit stuck" mem_test_report_failure(
" low or shorted @" "address bit stuck low or shorted",
" 0x%08x: expected 0x%08x, actual 0x%08x.\n", pattern, temp, &start[offset]);
(resource_size_t)&start[offset],
pattern, temp);
return -EIO; return -EIO;
} }
} }
start[offset2] = pattern; start[offset2] = pattern;
} }
/* return 0;
* We tested only the bus if != 0 }
* leaving here
*/ int mem_test_dram(resource_size_t _start,
if (bus_only) resource_size_t _end)
return 0; {
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" 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 * Description: Test the integrity of a physical
@ -238,16 +252,17 @@ int mem_test(resource_size_t _start,
* Fill memory with a known pattern. * Fill memory with a known pattern.
*/ */
init_progression_bar(num_words); init_progression_bar(num_words);
for (offset = 0; offset < num_words; offset++) { 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 (!(offset & (SZ_4K - 1))) {
if (ctrlc()) if (ctrlc())
return -EINTR; return -EINTR;
show_progress(offset); show_progress(offset);
} }
start[offset] = offset + 1; start[offset] = offset + 1;
} }
show_progress(offset); show_progress(offset);
@ -266,10 +281,10 @@ int mem_test(resource_size_t _start,
temp = start[offset]; temp = start[offset];
if (temp != (offset + 1)) { if (temp != (offset + 1)) {
printf("\nFAILURE (read/write) @ 0x%08x:" printf("\n");
" expected 0x%08x, actual 0x%08x.\n", mem_test_report_failure("read/write",
(resource_size_t)&start[offset], (offset + 1),
(offset + 1), temp); temp, &start[offset]);
return -EIO; return -EIO;
} }
@ -294,10 +309,10 @@ int mem_test(resource_size_t _start,
temp = start[offset]; temp = start[offset];
if (temp != anti_pattern) { if (temp != anti_pattern) {
printf("\nFAILURE (read/write): @ 0x%08x:" printf("\n");
" expected 0x%08x, actual 0x%08x.\n", mem_test_report_failure("read/write",
(resource_size_t)&start[offset], anti_pattern,
anti_pattern, temp); temp, &start[offset]);
return -EIO; return -EIO;
} }
@ -312,3 +327,36 @@ int mem_test(resource_size_t _start,
return 0; 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;
}