From patchwork Wed Dec 26 18:57:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 208203 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 247182C007C for ; Thu, 27 Dec 2012 06:02:00 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 40CF34A189; Wed, 26 Dec 2012 20:01:34 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FBxDcvahTAUP; Wed, 26 Dec 2012 20:01:33 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 206214A0B3; Wed, 26 Dec 2012 19:58:54 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 81C424A08E for ; Wed, 26 Dec 2012 19:57:56 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Y4av0Z6vYgt8 for ; Wed, 26 Dec 2012 19:57:55 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-gh0-f202.google.com (mail-gh0-f202.google.com [209.85.160.202]) by theia.denx.de (Postfix) with ESMTPS id 482784A0AF for ; Wed, 26 Dec 2012 19:57:36 +0100 (CET) Received: by mail-gh0-f202.google.com with SMTP id z10so615294ghb.5 for ; Wed, 26 Dec 2012 10:57:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=P3o5HG3Y8bLAcvds83ZKR0jyaalPANIu04BXG/oh/io=; b=ZlQU4QNZxLU48+Z2t+2K8qjr2+jui5lLSXiACptOiWN4Df/XfCjmCTl0b7s4hvFirD qL1bCcyMnpUHnHtJT0uuQm/69Chj/F4UxfzpzVtb3oDeLfkq8iUpLZf5IVEMk6JmdNtc jqpY2GqrVy3KttXKao5jIZRJd85WUSUZnuQmhinv++tyFMAGVWN1kMNoJ3xBt1R09ibe njz1CVc8Gv05nlKYkzSIlnUJ0/C44l4Al0CHKMTAFySEdABTGv5jtRbNaxsjSZYg5T/I k0sxiykrU4H/X0KH5Ur3ungwEJF2nonM+hHIWqBot8J6Xvr0zkq66aIfQoi5NHgwm6H3 YH6Q== X-Received: by 10.236.158.168 with SMTP id q28mr12737848yhk.20.1356548252177; Wed, 26 Dec 2012 10:57:32 -0800 (PST) Received: from wpzn4.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id l20si2352386yhi.2.2012.12.26.10.57.32 (version=TLSv1/SSLv3 cipher=AES128-SHA); Wed, 26 Dec 2012 10:57:32 -0800 (PST) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.73.79]) by wpzn4.hot.corp.google.com (Postfix) with ESMTP id 088B682004A; Wed, 26 Dec 2012 10:57:32 -0800 (PST) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id DD55D161045; Wed, 26 Dec 2012 10:57:31 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Date: Wed, 26 Dec 2012 10:57:12 -0800 Message-Id: <1356548233-5570-20-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1356548233-5570-1-git-send-email-sjg@chromium.org> References: <1356548233-5570-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQn4NLhzJJhAfbm4P/twT+7huF16TnLnJ2VLLdO+b8VbW72Uy/eUyMBWuJWGjR7Ukf7Q8wx1UT8gPheIFO0wIu7xZXOTBP4obYsTip+604sI1vMhru3YZqz29mXwnqbDoO5rgER0AtOrNXcd0himaPuOC+LAi9zQH+QvqYOKpH3jxTX6ejBVGnMdLCtoGrO1CxNdaxc0 Cc: Tom Rini , Joe Hershberger , Kumar Gala Subject: [U-Boot] [PATCH 19/20] sandbox: Update mtest to fix crashes X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Use map_sysmem() in the memory tester so that it works as expected on sandbox. Signed-off-by: Simon Glass --- common/cmd_mem.c | 97 +++++++++++++++++++++++++++++------------------------- 1 files changed, 52 insertions(+), 45 deletions(-) diff --git a/common/cmd_mem.c b/common/cmd_mem.c index f83acdf..1bbe166 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -626,21 +626,19 @@ int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } #endif /* CONFIG_LOOPW */ -static ulong mem_test_alt(ulong start_addr, ulong end_addr) +static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr, + vu_long *dummy) { - vu_long *start, *end; vu_long *addr; ulong errs = 0; ulong val, readback; int j; - vu_long len; vu_long offset; vu_long test_offset; vu_long pattern; vu_long temp; vu_long anti_pattern; vu_long num_words; - vu_long *dummy = (vu_long *)CONFIG_SYS_MEMTEST_SCRATCH; static const ulong bitpattern[] = { 0x00000001, /* single bit */ 0x00000003, /* two adjacent bits */ @@ -652,8 +650,7 @@ static ulong mem_test_alt(ulong start_addr, ulong end_addr) 0xaaaaaaaa, /* alternating 1/0 */ }; - start = (vu_long *)start_addr; - end = (vu_long *)end_addr; + num_words = (end_addr - start_addr) / sizeof(vu_long); /* * Data line test: write a pattern to the first @@ -672,11 +669,11 @@ static ulong mem_test_alt(ulong start_addr, ulong end_addr) * '0's and '0' bits through a field of '1's (i.e. * pattern and ~pattern). */ - addr = start; + addr = buf; for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) { val = bitpattern[j]; for (; val != 0; val <<= 1) { - *addr = val; + *addr = val; *dummy = ~val; /* clear the test data off the bus */ readback = *addr; if (readback != val) { @@ -735,58 +732,56 @@ static ulong mem_test_alt(ulong start_addr, ulong end_addr) * * Returns: 0 if the test succeeds, 1 if the test fails. */ - len = (end_addr - start_addr) / sizeof(vu_long); pattern = (vu_long) 0xaaaaaaaa; anti_pattern = (vu_long) 0x55555555; - debug("%s:%d: length = 0x%.8lx\n", - __func__, __LINE__, len); + debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words); /* * Write the default pattern at each of the * power-of-two offsets. */ - for (offset = 1; offset < len; offset <<= 1) - start[offset] = pattern; + for (offset = 1; offset < num_words; offset <<= 1) + addr[offset] = pattern; /* * Check for address bits stuck high. */ test_offset = 0; - start[test_offset] = anti_pattern; + addr[test_offset] = anti_pattern; - for (offset = 1; offset < len; offset <<= 1) { - temp = start[offset]; + for (offset = 1; offset < num_words; offset <<= 1) { + temp = addr[offset]; if (temp != pattern) { printf("\nFAILURE: Address bit stuck high @ 0x%.8lx:" " expected 0x%.8lx, actual 0x%.8lx\n", - (ulong)&start[offset], pattern, temp); + start_addr + offset, pattern, temp); errs++; if (ctrlc()) return -1; } } - start[test_offset] = pattern; + addr[test_offset] = pattern; WATCHDOG_RESET(); /* * Check for addr bits stuck low or shorted. */ - for (test_offset = 1; test_offset < len; test_offset <<= 1) { - start[test_offset] = anti_pattern; + for (test_offset = 1; test_offset < num_words; test_offset <<= 1) { + addr[test_offset] = anti_pattern; - for (offset = 1; offset < len; offset <<= 1) { - temp = start[offset]; + for (offset = 1; offset < num_words; offset <<= 1) { + temp = addr[offset]; if ((temp != pattern) && (offset != test_offset)) { printf("\nFAILURE: Address bit stuck low or" " shorted @ 0x%.8lx: expected 0x%.8lx," " actual 0x%.8lx\n", - (ulong)&start[offset], pattern, temp); + start_addr + offset, pattern, temp); errs++; if (ctrlc()) return -1; } } - start[test_offset] = pattern; + addr[test_offset] = pattern; } /* @@ -801,14 +796,14 @@ static ulong mem_test_alt(ulong start_addr, ulong end_addr) * * Returns: 0 if the test succeeds, 1 if the test fails. */ - num_words = ((ulong)end - (ulong)start)/sizeof(vu_long) + 1; + num_words++; /* * Fill memory with a known pattern. */ for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { WATCHDOG_RESET(); - start[offset] = pattern; + addr[offset] = pattern; } /* @@ -816,18 +811,18 @@ static ulong mem_test_alt(ulong start_addr, ulong end_addr) */ for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { WATCHDOG_RESET(); - temp = start[offset]; + temp = addr[offset]; if (temp != pattern) { printf("\nFAILURE (read/write) @ 0x%.8lx:" " expected 0x%.8lx, actual 0x%.8lx)\n", - (ulong)&start[offset], pattern, temp); + start_addr + offset, pattern, temp); errs++; if (ctrlc()) return -1; } anti_pattern = ~pattern; - start[offset] = anti_pattern; + addr[offset] = anti_pattern; } /* @@ -836,28 +831,28 @@ static ulong mem_test_alt(ulong start_addr, ulong end_addr) for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) { WATCHDOG_RESET(); anti_pattern = ~pattern; - temp = start[offset]; + temp = addr[offset]; if (temp != anti_pattern) { printf("\nFAILURE (read/write): @ 0x%.8lx:" " expected 0x%.8lx, actual 0x%.8lx)\n", - (ulong)&start[offset], anti_pattern, temp); + start_addr + offset, anti_pattern, temp); errs++; if (ctrlc()) return -1; } - start[offset] = 0; + addr[offset] = 0; } return 0; } -static ulong mem_test_quick(ulong start_addr, ulong end_addr, vu_long pattern, - int iteration) +static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr, + vu_long pattern, int iteration) { - vu_long *start, *end; + vu_long *end; vu_long *addr; ulong errs = 0; - ulong incr; + ulong incr, length; ulong val, readback; /* Alternate the pattern */ @@ -875,14 +870,14 @@ static ulong mem_test_quick(ulong start_addr, ulong end_addr, vu_long pattern, else pattern = ~pattern; } - start = (vu_long *)start_addr; - end = (vu_long *)end_addr; + length = (end_addr - start_addr) / sizeof(ulong); + end = buf + length; printf("\rPattern %08lX Writing..." "%12s" "\b\b\b\b\b\b\b\b\b\b", pattern, ""); - for (addr = start, val = pattern; addr < end; addr++) { + for (addr = buf, val = pattern; addr < end; addr++) { WATCHDOG_RESET(); *addr = val; val += incr; @@ -890,13 +885,16 @@ static ulong mem_test_quick(ulong start_addr, ulong end_addr, vu_long pattern, puts("Reading..."); - for (addr = start, val = pattern; addr < end; addr++) { + for (addr = buf, val = pattern; addr < end; addr++) { WATCHDOG_RESET(); readback = *addr; if (readback != val) { + ulong offset = addr - buf; + printf("\nMem error @ 0x%08X: " "found %08lX, expected %08lX\n", - (uint)(uintptr_t)addr, readback, val); + (uint)(uintptr_t)(start_addr + offset), + readback, val); errs++; if (ctrlc()) return -1; @@ -916,6 +914,7 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { ulong start, end; + vu_long *buf, *dummy; int iteration_limit; int ret; ulong errs = 0; /* number of errors, or -1 if interrupted */ @@ -951,6 +950,8 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__, start, end); + buf = map_sysmem(start, end - start); + dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long)); for (iteration = 0; !iteration_limit || iteration < iteration_limit; iteration++) { @@ -961,11 +962,17 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, printf("Iteration: %6d\r", iteration + 1); debug("\n"); - if (alt_test) - errs = mem_test_alt(start, end); - else - errs = mem_test_quick(start, end, pattern, iteration); + if (alt_test) { + errs = mem_test_alt(buf, start, end, dummy); + } else { + errs = mem_test_quick(buf, start, end, pattern, + iteration); + } + if (errs == -1UL) + break; } + unmap_sysmem((void *)buf); + unmap_sysmem((void *)dummy); if (errs == -1UL) { /* Memory test was aborted - write a newline to finish off */