From patchwork Thu Mar 5 06:21:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roese X-Patchwork-Id: 243212 List-Id: U-Boot discussion From: sr at denx.de (Stefan Roese) Date: Thu, 5 Mar 2020 07:21:29 +0100 Subject: [PATCH 1/4] cmd: mem: Correctly count the errors in mtest Message-ID: <20200305062132.22932-1-sr@denx.de> This patch changes mtest to correctly count the overall errors and print them even in the abort (Ctrl-C) case. Signed-off-by: Stefan Roese --- cmd/mem.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/cmd/mem.c b/cmd/mem.c index 6d54f19527..9367278aa8 100644 --- a/cmd/mem.c +++ b/cmd/mem.c @@ -871,7 +871,7 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, ulong start, end; vu_long *buf, *dummy; ulong iteration_limit = 0; - int ret; + ulong count = 0; ulong errs = 0; /* number of errors, or -1 if interrupted */ ulong pattern = 0; int iteration; @@ -929,6 +929,7 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, } if (errs == -1UL) break; + count += errs; } /* @@ -947,14 +948,10 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, if (errs == -1UL) { /* Memory test was aborted - write a newline to finish off */ putc('\n'); - ret = 1; - } else { - printf("Tested %d iteration(s) with %lu errors.\n", - iteration, errs); - ret = errs != 0; } + printf("Tested %d iteration(s) with %lu errors.\n", iteration, count); - return ret; + return errs != 0; } #endif /* CONFIG_CMD_MEMTEST */ From patchwork Thu Mar 5 06:21:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roese X-Patchwork-Id: 243213 List-Id: U-Boot discussion From: sr at denx.de (Stefan Roese) Date: Thu, 5 Mar 2020 07:21:30 +0100 Subject: [PATCH 2/4] cmd: mem: Drop eldk-4.2 workaround and use cast in unmap_sysmem() In-Reply-To: <20200305062132.22932-1-sr@denx.de> References: <20200305062132.22932-1-sr@denx.de> Message-ID: <20200305062132.22932-2-sr@denx.de> Use a cast instead of the "eldk-4.2" workaround for unmap_sysmem(). Signed-off-by: Stefan Roese --- cmd/mem.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/cmd/mem.c b/cmd/mem.c index 9367278aa8..f519adaee2 100644 --- a/cmd/mem.c +++ b/cmd/mem.c @@ -932,18 +932,8 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, count += errs; } - /* - * Work-around for eldk-4.2 which gives this warning if we try to - * case in the unmap_sysmem() call: - * warning: initialization discards qualifiers from pointer target type - */ - { - void *vbuf = (void *)buf; - void *vdummy = (void *)dummy; - - unmap_sysmem(vbuf); - unmap_sysmem(vdummy); - } + unmap_sysmem((void *)buf); + unmap_sysmem((void *)dummy); if (errs == -1UL) { /* Memory test was aborted - write a newline to finish off */ From patchwork Thu Mar 5 06:21:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roese X-Patchwork-Id: 243214 List-Id: U-Boot discussion From: sr at denx.de (Stefan Roese) Date: Thu, 5 Mar 2020 07:21:31 +0100 Subject: [PATCH 3/4] cmd: mem: Use IS_ENABLED instead of alt_test variable In-Reply-To: <20200305062132.22932-1-sr@denx.de> References: <20200305062132.22932-1-sr@denx.de> Message-ID: <20200305062132.22932-3-sr@denx.de> This patch uses the IS_ENABLED() macro to check, which mtest variant is enabled. Signed-off-by: Stefan Roese --- cmd/mem.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/cmd/mem.c b/cmd/mem.c index f519adaee2..2ccc7032ad 100644 --- a/cmd/mem.c +++ b/cmd/mem.c @@ -875,11 +875,6 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, ulong errs = 0; /* number of errors, or -1 if interrupted */ ulong pattern = 0; int iteration; -#if defined(CONFIG_SYS_ALT_MEMTEST) - const int alt_test = 1; -#else - const int alt_test = 0; -#endif start = CONFIG_SYS_MEMTEST_START; end = CONFIG_SYS_MEMTEST_END; @@ -921,7 +916,7 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, printf("Iteration: %6d\r", iteration + 1); debug("\n"); - if (alt_test) { + if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) { errs = mem_test_alt(buf, start, end, dummy); } else { errs = mem_test_quick(buf, start, end, pattern, From patchwork Thu Mar 5 06:21:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roese X-Patchwork-Id: 243215 List-Id: U-Boot discussion From: sr at denx.de (Stefan Roese) Date: Thu, 5 Mar 2020 07:21:32 +0100 Subject: [PATCH 4/4] cmd: mem: Add bitflip memory test to alternate mtest In-Reply-To: <20200305062132.22932-1-sr@denx.de> References: <20200305062132.22932-1-sr@denx.de> Message-ID: <20200305062132.22932-4-sr@denx.de> This additional bitflip memory test is inspired by the bitflip test in memtester v4.3.0. It show some errors on some problematic GARDENA MT7688 based boards. The other memory tests usually don't show any errors here. Signed-off-by: Stefan Roese --- cmd/mem.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/cmd/mem.c b/cmd/mem.c index 2ccc7032ad..0bfb6081e7 100644 --- a/cmd/mem.c +++ b/cmd/mem.c @@ -801,6 +801,59 @@ static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr, return errs; } +static int compare_regions(volatile unsigned long *bufa, + volatile unsigned long *bufb, size_t count) +{ + volatile unsigned long *p1 = bufa; + volatile unsigned long *p2 = bufb; + int errs = 0; + size_t i; + + for (i = 0; i < count; i++, p1++, p2++) { + if (*p1 != *p2) { + printf("FAILURE: 0x%08lx != 0x%08lx (delta=0x%08lx -> bit %ld) at offset 0x%08lx\n", + (unsigned long)*p1, (unsigned long)*p2, + *p1 ^ *p2, __ffs(*p1 ^ *p2), + (unsigned long)(i * sizeof(unsigned long))); + errs++; + } + } + + return errs; +} + +static ulong test_bitflip_comparison(volatile unsigned long *bufa, + volatile unsigned long *bufb, size_t count) +{ + volatile unsigned long *p1 = bufa; + volatile unsigned long *p2 = bufb; + unsigned int j, k; + unsigned long q; + size_t i; + int max; + int errs = 0; + + max = sizeof(unsigned long) * 8; + for (k = 0; k < max; k++) { + q = 0x00000001L << k; + for (j = 0; j < 8; j++) { + WATCHDOG_RESET(); + q = ~q; + p1 = (volatile unsigned long *)bufa; + p2 = (volatile unsigned long *)bufb; + for (i = 0; i < count; i++) + *p1++ = *p2++ = (i % 2) == 0 ? q : ~q; + + errs += compare_regions(bufa, bufb, count); + } + + if (ctrlc()) + return -1UL; + } + + return errs; +} + static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr, vu_long pattern, int iteration) { @@ -918,6 +971,13 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, debug("\n"); if (IS_ENABLED(CONFIG_SYS_ALT_MEMTEST)) { errs = mem_test_alt(buf, start, end, dummy); + if (errs == -1UL) + break; + count += errs; + errs = test_bitflip_comparison(buf, + buf + (end - start) / 2, + (end - start) / + sizeof(unsigned long)); } else { errs = mem_test_quick(buf, start, end, pattern, iteration);