cmd: mem: fix range of bitflip test

The bitflip test uses two equal sized memory buffers. This is achieved
by splitting the range of memory into two pieces. The address of the
second buffer, as well as the length of each buffer, were not correctly
calculated. This caused bitflip test to access beyond the end of range.
This patch fixes the pointer arithmetic problem.

A second problem arises because u-boot "mtest" command expects the
ending address to be inclusive. When computing (end - start) this
results in missing 1 byte of the requested length. The bitflip test
expects a count rather than an "ending" address. Thus it fails to test
the last word of the requested range. Fixed by using (end - start + 1).

Added Kconfig option to optionally disable the bitflip test, since it
does add significantly to the time taken for "mtest".

Fixes: 8e434cb705 ("cmd: mem: Add bitflip
memory test to alternate mtest")

Signed-off-by: Ralph Siemsen <ralph.siemsen@linaro.org>
Reviewed-by: Stefan Roese <sr@denx.de>
This commit is contained in:
Ralph Siemsen 2020-09-09 12:10:00 -04:00 committed by Tom Rini
parent e03dd8a05f
commit 9989fb18bd
2 changed files with 28 additions and 5 deletions

View file

@ -777,6 +777,18 @@ config SYS_ALT_MEMTEST
help help
Use a more complete alternative memory test. Use a more complete alternative memory test.
if SYS_ALT_MEMTEST
config SYS_ALT_MEMTEST_BITFLIP
bool "Bitflip test"
default y
help
The alternative memory test includes bitflip test since 2020.07.
The bitflip test significantly increases the overall test time.
Bitflip test can optionally be disabled here.
endif
config SYS_MEMTEST_START config SYS_MEMTEST_START
hex "default start address for mtest" hex "default start address for mtest"
default 0 default 0

View file

@ -985,6 +985,18 @@ static ulong test_bitflip_comparison(volatile unsigned long *bufa,
return errs; return errs;
} }
static ulong mem_test_bitflip(vu_long *buf, ulong start, ulong end)
{
/*
* Split the specified range into two halves.
* Note that mtest range is inclusive of start,end.
* Bitflip test instead uses a count (of 32-bit words).
*/
ulong half_size = (end - start + 1) / 2 / sizeof(unsigned long);
return test_bitflip_comparison(buf, buf + half_size, half_size);
}
static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr, static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr,
vu_long pattern, int iteration) vu_long pattern, int iteration)
{ {
@ -1104,11 +1116,10 @@ static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc,
errs = mem_test_alt(buf, start, end, dummy); errs = mem_test_alt(buf, start, end, dummy);
if (errs == -1UL) if (errs == -1UL)
break; break;
count += errs; if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST_BITFLIP)) {
errs = test_bitflip_comparison(buf, count += errs;
buf + (end - start) / 2, errs = mem_test_bitflip(buf, start, end);
(end - start) / }
sizeof(unsigned long));
} else { } else {
errs = mem_test_quick(buf, start, end, pattern, errs = mem_test_quick(buf, start, end, pattern,
iteration); iteration);