From patchwork Wed Dec 26 18:57:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 208189 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 38E722C007C for ; Thu, 27 Dec 2012 05:59:13 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 469784A09E; Wed, 26 Dec 2012 19:59:10 +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 7GmFcVHsjY26; Wed, 26 Dec 2012 19:59:10 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 75D634A0AB; Wed, 26 Dec 2012 19:58:39 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 179804A08A for ; Wed, 26 Dec 2012 19:57:42 +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 BObw0iCCE3KS for ; Wed, 26 Dec 2012 19:57:40 +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-vc0-f202.google.com (mail-vc0-f202.google.com [209.85.220.202]) by theia.denx.de (Postfix) with ESMTPS id 8BCB34A08D for ; Wed, 26 Dec 2012 19:57:32 +0100 (CET) Received: by mail-vc0-f202.google.com with SMTP id m8so927244vcd.1 for ; Wed, 26 Dec 2012 10:57:31 -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=7eXmxIm9GKov7+ndujoG22i9RqBpstNOdn7BNSTDYMw=; b=C+JHOrxyVa+BCugSghOpYHkTf/pW9BoyoOO5EpfzjActY1fEnEujLN9Hll13mwFuwe hRnK+TOSmA1JaMISitt2Clmxb93plEUFgr3Jgx7b0q8W11WiMP80Zsf2okfuJxk8pEI9 rQp6S6pyGecxgTjGBCcrOnDPLXMuxc/8Hob+8rwcVyWmAyhVGXmRRxL4MqDJwsV1bmWD sqrmKuldKEUd5lXrRzQgnzdF5YmgshXtgQJ37cf/2jkY1ELhpp3CL5KggwkNGGP96dHb coz3S+Maq5TLQKWVfLzw+I/CT9drc2H5F/gvfoL0vOwbQrjShlb5Bi+J5b1KVjeOZXhb 0r6g== X-Received: by 10.236.150.97 with SMTP id y61mr12898288yhj.25.1356548251372; Wed, 26 Dec 2012 10:57:31 -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 i27si2351713yhe.4.2012.12.26.10.57.31 (version=TLSv1/SSLv3 cipher=AES128-SHA); Wed, 26 Dec 2012 10:57:31 -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 36D1982004A; Wed, 26 Dec 2012 10:57:31 -0800 (PST) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id BE5A0161045; Wed, 26 Dec 2012 10:57:30 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Date: Wed, 26 Dec 2012 10:57:00 -0800 Message-Id: <1356548233-5570-8-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: ALoCoQnpFrh4gRenxIeJ9gjZJxZxC2AWt2gphiAidMIe7rZx8xb4UVkNgnzcODHOrecat/mMfD4xlizhUQzHpXy8hdlJjK00hcCS2737+M2XRlUPlnV9irixFqyXm2WKHT+OdQ8YJc8B4l0je4ni21vszhxuuaxMOr7JHirk+e3tvUJus8ZYfzOKyPgJVSP5+O55n+iRO0p5 Cc: Tom Rini , Joe Hershberger , Kumar Gala Subject: [U-Boot] [PATCH 07/20] Use common mtest iteration counting 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 The iteration code is the same for each version of the memory test, so pull it out into the common function. Signed-off-by: Simon Glass --- common/cmd_mem.c | 123 ++++++++++++++++++++++++++---------------------------- 1 files changed, 59 insertions(+), 64 deletions(-) diff --git a/common/cmd_mem.c b/common/cmd_mem.c index 36ac6f4..41c1e70 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -621,11 +621,9 @@ int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } #endif /* CONFIG_LOOPW */ -static int mem_test_alt(vu_long *start, vu_long *end, - int iteration_limit) +static ulong mem_test_alt(vu_long *start, vu_long *end) { vu_long *addr; - int iterations = 1; ulong errs = 0; ulong val, readback; int j; @@ -652,27 +650,6 @@ static int mem_test_alt(vu_long *start, vu_long *end, 0xaaaaaaaa, /* alternating 1/0 */ }; - printf("Testing %08x ... %08x:\n", (uint)(uintptr_t)start, - (uint)(uintptr_t)end); - debug("%s:%d: start 0x%p end 0x%p\n", - __func__, __LINE__, start, end); - - for (;;) { - if (ctrlc()) { - putc('\n'); - return 1; - } - - if (iteration_limit && iterations > iteration_limit) { - printf("Tested %d iteration(s) with %lu errors.\n", - iterations-1, errs); - return errs != 0; - } - - printf("Iteration: %6d\r", iterations); - debug("\n"); - iterations++; - /* * Data line test: write a pattern to the first * location, write the 1's complement to a 'parking' @@ -705,7 +682,7 @@ static int mem_test_alt(vu_long *start, vu_long *end, errs++; if (ctrlc()) { putc('\n'); - return 1; + return -1; } } *addr = ~val; @@ -718,7 +695,7 @@ static int mem_test_alt(vu_long *start, vu_long *end, errs++; if (ctrlc()) { putc('\n'); - return 1; + return -1; } } } @@ -786,7 +763,7 @@ static int mem_test_alt(vu_long *start, vu_long *end, errs++; if (ctrlc()) { putc('\n'); - return 1; + return -1; } } } @@ -808,7 +785,7 @@ static int mem_test_alt(vu_long *start, vu_long *end, errs++; if (ctrlc()) { putc('\n'); - return 1; + return -1; } } } @@ -850,7 +827,7 @@ static int mem_test_alt(vu_long *start, vu_long *end, errs++; if (ctrlc()) { putc('\n'); - return 1; + return -1; } } @@ -872,37 +849,38 @@ static int mem_test_alt(vu_long *start, vu_long *end, errs++; if (ctrlc()) { putc('\n'); - return 1; + return -1; } } start[offset] = 0; } - } + + return 0; } -static int mem_test_quick(vu_long *start, vu_long *end, - int iteration_limit, vu_long pattern) +static ulong mem_test_quick(vu_long *start, vu_long *end, vu_long pattern, + int iteration) { vu_long *addr; - int iterations = 1; ulong errs = 0; ulong incr; ulong val, readback; + /* Alternate the pattern */ incr = 1; - for (;;) { - if (ctrlc()) { - putc('\n'); - return 1; - } - - if (iteration_limit && iterations > iteration_limit) { - printf("Tested %d iteration(s) with %lu errors.\n", - iterations-1, errs); - return errs != 0; - } - ++iterations; - + if (iteration & 1) { + incr = -incr; + /* + * Flip the pattern each time to make lots of zeros and + * then, the next time, lots of ones. We decrement + * the "negative" patterns and increment the "positive" + * patterns to preserve this feature. + */ + if (pattern & 0x80000000) + pattern = -pattern; /* complement & increment */ + else + pattern = ~pattern; + } printf("\rPattern %08lX Writing..." "%12s" "\b\b\b\b\b\b\b\b\b\b", @@ -926,24 +904,13 @@ static int mem_test_quick(vu_long *start, vu_long *end, errs++; if (ctrlc()) { putc('\n'); - return 1; + return -1; } } val += incr; } - /* - * Flip the pattern each time to make lots of zeros and - * then, the next time, lots of ones. We decrement - * the "negative" patterns and increment the "positive" - * patterns to preserve this feature. - */ - if (pattern & 0x80000000) - pattern = -pattern; /* complement & increment */ - else - pattern = ~pattern; - incr = -incr; - } + return 0; } /* @@ -957,7 +924,9 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, vu_long *start, *end; int iteration_limit; int ret; + ulong errs = 0; /* number of errors, or -1 if interrupted */ ulong pattern; + int iteration; #if defined(CONFIG_SYS_ALT_MEMTEST) const int alt_test = 1; #else @@ -984,10 +953,36 @@ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, 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); + printf("Testing %08x ... %08x:\n", (uint)(uintptr_t)start, + (uint)(uintptr_t)end); + debug("%s:%d: start 0x%p end 0x%p\n", + __func__, __LINE__, start, end); + + for (iteration = 0; + !iteration_limit || iteration < iteration_limit; + iteration++) { + if (ctrlc()) { + putc('\n'); + errs = -1UL; + break; + } + + 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 (errs == -1UL) { + /* Memory test was aborted */ + ret = 1; + } else { + printf("Tested %d iteration(s) with %lu errors.\n", + iteration, errs); + ret = errs != 0; + } return ret; /* not reached */ }