mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-20 22:21:41 +00:00
Split out the memory tests into separate functions
Half of the code is currently hidden behind an #ifdef. Move the two memory tests into their own functions and use the compiler to eliminate the unused code. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
0628ab8ec5
commit
c9638f50fb
1 changed files with 116 additions and 101 deletions
127
common/cmd_mem.c
127
common/cmd_mem.c
|
@ -626,22 +626,14 @@ int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_LOOPW */
|
#endif /* CONFIG_LOOPW */
|
||||||
|
|
||||||
/*
|
static int mem_test_alt(vu_long *start, vu_long *end,
|
||||||
* Perform a memory test. A more complete alternative test can be
|
int iteration_limit)
|
||||||
* configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
|
|
||||||
* interrupted by ctrl-c or by a failure of one of the sub-tests.
|
|
||||||
*/
|
|
||||||
static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
|
|
||||||
char * const argv[])
|
|
||||||
{
|
{
|
||||||
vu_long *addr, *start, *end;
|
vu_long *addr;
|
||||||
ulong val;
|
|
||||||
ulong readback;
|
|
||||||
ulong errs = 0;
|
|
||||||
int iterations = 1;
|
int iterations = 1;
|
||||||
int iteration_limit;
|
ulong errs = 0;
|
||||||
|
ulong val, readback;
|
||||||
#if defined(CONFIG_SYS_ALT_MEMTEST)
|
int j;
|
||||||
vu_long len;
|
vu_long len;
|
||||||
vu_long offset;
|
vu_long offset;
|
||||||
vu_long test_offset;
|
vu_long test_offset;
|
||||||
|
@ -654,8 +646,6 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
|
||||||
#else
|
#else
|
||||||
vu_long *dummy = NULL; /* yes, this is address 0x0, not NULL */
|
vu_long *dummy = NULL; /* yes, this is address 0x0, not NULL */
|
||||||
#endif
|
#endif
|
||||||
int j;
|
|
||||||
|
|
||||||
static const ulong bitpattern[] = {
|
static const ulong bitpattern[] = {
|
||||||
0x00000001, /* single bit */
|
0x00000001, /* single bit */
|
||||||
0x00000003, /* two adjacent bits */
|
0x00000003, /* two adjacent bits */
|
||||||
|
@ -666,35 +656,11 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
|
||||||
0x00000055, /* four non-adjacent bits */
|
0x00000055, /* four non-adjacent bits */
|
||||||
0xaaaaaaaa, /* alternating 1/0 */
|
0xaaaaaaaa, /* alternating 1/0 */
|
||||||
};
|
};
|
||||||
#else
|
|
||||||
ulong incr;
|
|
||||||
ulong pattern;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (argc > 1)
|
printf("Testing %08x ... %08x:\n", (uint)(uintptr_t)start,
|
||||||
start = (ulong *)simple_strtoul(argv[1], NULL, 16);
|
(uint)(uintptr_t)end);
|
||||||
else
|
|
||||||
start = (ulong *)CONFIG_SYS_MEMTEST_START;
|
|
||||||
|
|
||||||
if (argc > 2)
|
|
||||||
end = (ulong *)simple_strtoul(argv[2], NULL, 16);
|
|
||||||
else
|
|
||||||
end = (ulong *)(CONFIG_SYS_MEMTEST_END);
|
|
||||||
|
|
||||||
if (argc > 3)
|
|
||||||
pattern = (ulong)simple_strtoul(argv[3], NULL, 16);
|
|
||||||
else
|
|
||||||
pattern = 0;
|
|
||||||
|
|
||||||
if (argc > 4)
|
|
||||||
iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16);
|
|
||||||
else
|
|
||||||
iteration_limit = 0;
|
|
||||||
|
|
||||||
#if defined(CONFIG_SYS_ALT_MEMTEST)
|
|
||||||
printf ("Testing %08x ... %08x:\n", (uint)start, (uint)end);
|
|
||||||
debug("%s:%d: start 0x%p end 0x%p\n",
|
debug("%s:%d: start 0x%p end 0x%p\n",
|
||||||
__FUNCTION__, __LINE__, start, end);
|
__func__, __LINE__, start, end);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (ctrlc()) {
|
if (ctrlc()) {
|
||||||
|
@ -702,7 +668,6 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (iteration_limit && iterations > iteration_limit) {
|
if (iteration_limit && iterations > iteration_limit) {
|
||||||
printf("Tested %d iteration(s) with %lu errors.\n",
|
printf("Tested %d iteration(s) with %lu errors.\n",
|
||||||
iterations-1, errs);
|
iterations-1, errs);
|
||||||
|
@ -731,11 +696,12 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
|
||||||
* pattern and ~pattern).
|
* pattern and ~pattern).
|
||||||
*/
|
*/
|
||||||
addr = start;
|
addr = start;
|
||||||
for (j = 0; j < sizeof(bitpattern)/sizeof(bitpattern[0]); j++) {
|
for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]);
|
||||||
|
j++) {
|
||||||
val = bitpattern[j];
|
val = bitpattern[j];
|
||||||
for (; val != 0; val <<= 1) {
|
for (; val != 0; val <<= 1) {
|
||||||
*addr = val;
|
*addr = val;
|
||||||
*dummy = ~val; /* clear the test data off of the bus */
|
*dummy = ~val; /* clear the test data off the bus */
|
||||||
readback = *addr;
|
readback = *addr;
|
||||||
if(readback != val) {
|
if(readback != val) {
|
||||||
printf("FAILURE (data line): "
|
printf("FAILURE (data line): "
|
||||||
|
@ -802,15 +768,13 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
|
||||||
anti_pattern = (vu_long) 0x55555555;
|
anti_pattern = (vu_long) 0x55555555;
|
||||||
|
|
||||||
debug("%s:%d: length = 0x%.8lx\n",
|
debug("%s:%d: length = 0x%.8lx\n",
|
||||||
__FUNCTION__, __LINE__,
|
__func__, __LINE__, len);
|
||||||
len);
|
|
||||||
/*
|
/*
|
||||||
* Write the default pattern at each of the
|
* Write the default pattern at each of the
|
||||||
* power-of-two offsets.
|
* power-of-two offsets.
|
||||||
*/
|
*/
|
||||||
for (offset = 1; offset < len; offset <<= 1) {
|
for (offset = 1; offset < len; offset <<= 1)
|
||||||
start[offset] = pattern;
|
start[offset] = pattern;
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for address bits stuck high.
|
* Check for address bits stuck high.
|
||||||
|
@ -919,8 +883,17 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
|
||||||
start[offset] = 0;
|
start[offset] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int mem_test_quick(vu_long *start, vu_long *end,
|
||||||
|
int iteration_limit, vu_long pattern)
|
||||||
|
{
|
||||||
|
vu_long *addr;
|
||||||
|
int iterations = 1;
|
||||||
|
ulong errs = 0;
|
||||||
|
ulong incr;
|
||||||
|
ulong val, readback;
|
||||||
|
|
||||||
#else /* The original, quickie test */
|
|
||||||
incr = 1;
|
incr = 1;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (ctrlc()) {
|
if (ctrlc()) {
|
||||||
|
@ -970,16 +943,58 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
|
||||||
* the "negative" patterns and increment the "positive"
|
* the "negative" patterns and increment the "positive"
|
||||||
* patterns to preserve this feature.
|
* patterns to preserve this feature.
|
||||||
*/
|
*/
|
||||||
if(pattern & 0x80000000) {
|
if (pattern & 0x80000000)
|
||||||
pattern = -pattern; /* complement & increment */
|
pattern = -pattern; /* complement & increment */
|
||||||
}
|
else
|
||||||
else {
|
|
||||||
pattern = ~pattern;
|
pattern = ~pattern;
|
||||||
}
|
|
||||||
incr = -incr;
|
incr = -incr;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Perform a memory test. A more complete alternative test can be
|
||||||
|
* configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until
|
||||||
|
* interrupted by ctrl-c or by a failure of one of the sub-tests.
|
||||||
|
*/
|
||||||
|
static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc,
|
||||||
|
char * const argv[])
|
||||||
|
{
|
||||||
|
vu_long *start, *end;
|
||||||
|
int iteration_limit;
|
||||||
|
int ret;
|
||||||
|
ulong pattern;
|
||||||
|
#if defined(CONFIG_SYS_ALT_MEMTEST)
|
||||||
|
const int alt_test = 1;
|
||||||
|
#else
|
||||||
|
const int alt_test = 0;
|
||||||
#endif
|
#endif
|
||||||
return 0; /* not reached */
|
|
||||||
|
if (argc > 1)
|
||||||
|
start = (ulong *)simple_strtoul(argv[1], NULL, 16);
|
||||||
|
else
|
||||||
|
start = (ulong *)CONFIG_SYS_MEMTEST_START;
|
||||||
|
|
||||||
|
if (argc > 2)
|
||||||
|
end = (ulong *)simple_strtoul(argv[2], NULL, 16);
|
||||||
|
else
|
||||||
|
end = (ulong *)(CONFIG_SYS_MEMTEST_END);
|
||||||
|
|
||||||
|
if (argc > 3)
|
||||||
|
pattern = (ulong)simple_strtoul(argv[3], NULL, 16);
|
||||||
|
else
|
||||||
|
pattern = 0;
|
||||||
|
|
||||||
|
if (argc > 4)
|
||||||
|
iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16);
|
||||||
|
else
|
||||||
|
iteration_limit = 0;
|
||||||
|
|
||||||
|
if (alt_test)
|
||||||
|
ret = mem_test_alt(start, end, iteration_limit);
|
||||||
|
else
|
||||||
|
ret = mem_test_quick(start, end, iteration_limit, pattern);
|
||||||
|
|
||||||
|
return ret; /* not reached */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue