From patchwork Tue Feb 9 21:38:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 581078 X-Patchwork-Delegate: trini@ti.com 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 27052140321 for ; Wed, 10 Feb 2016 08:38:55 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9C9A0A7506; Tue, 9 Feb 2016 22:38:53 +0100 (CET) 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 SH1--o3DiH4M; Tue, 9 Feb 2016 22:38:53 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1D36BA7498; Tue, 9 Feb 2016 22:38:53 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D7CDDA7498 for ; Tue, 9 Feb 2016 22:38:50 +0100 (CET) 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 DvbbKG4tHo2Z for ; Tue, 9 Feb 2016 22:38:50 +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 mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by theia.denx.de (Postfix) with ESMTPS id 8864FA745C for ; Tue, 9 Feb 2016 22:38:46 +0100 (CET) Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 06BF6A147A; Tue, 9 Feb 2016 21:38:45 +0000 (UTC) Received: from localhost.localdomain.com (vpn1-6-238.ams2.redhat.com [10.36.6.238]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u19LcfDf016627; Tue, 9 Feb 2016 16:38:42 -0500 From: Hans de Goede To: Tom Rini , =?UTF-8?q?Eddy=20Petri=C8=99or?= Date: Tue, 9 Feb 2016 22:38:31 +0100 Message-Id: <1455053911-7530-1-git-send-email-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Cc: Ian Campbell , u-boot@lists.denx.de Subject: [U-Boot] [PATCH] Revert "common/memsize.c: Simplify RAM size detection" X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This commit breaks bootup on sunxi boards, the get stuck when running the main u-boot binary at: CPU: Allwinner H3 (SUN8I) I2C: ready DRAM: This reverts commit 8e7cba048baae68ee0916a8f52b4304277328d5e. Signed-off-by: Hans de Goede --- common/memsize.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/common/memsize.c b/common/memsize.c index 5c0d279..0fb9ba5 100644 --- a/common/memsize.c +++ b/common/memsize.c @@ -33,28 +33,38 @@ long get_ram_size(long *base, long maxsize) long size; int i = 0; - for (cnt = (maxsize / sizeof(long)) >> 1; cnt >= 0; cnt >>= 1) { + for (cnt = (maxsize / sizeof(long)) >> 1; cnt > 0; cnt >>= 1) { addr = base + cnt; /* pointer arith! */ sync(); - save[i] = *addr; + save[i++] = *addr; sync(); - if (cnt) { - i++; - *addr = ~cnt; - } else { - *addr = 0; - } + *addr = ~cnt; } + addr = base; + sync(); + save[i] = *addr; + sync(); + *addr = 0; + sync(); - cnt = 0; - do { + if ((val = *addr) != 0) { + /* Restore the original data before leaving the function. */ + sync(); + *addr = save[i]; + for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) { + addr = base + cnt; + sync(); + *addr = save[--i]; + } + return (0); + } + + for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) { addr = base + cnt; /* pointer arith! */ val = *addr; - *addr = save[i--]; - sync(); - if (((cnt == 0) && (val != 0)) || - ((cnt != 0) && (val != ~cnt))) { + *addr = save[--i]; + if (val != ~cnt) { size = cnt * sizeof(long); /* * Restore the original data @@ -64,16 +74,11 @@ long get_ram_size(long *base, long maxsize) cnt < maxsize / sizeof(long); cnt <<= 1) { addr = base + cnt; - *addr = save[i--]; + *addr = save[--i]; } return (size); } - - if (cnt) - cnt = cnt << 1; - else - cnt = 1; - } while (cnt < maxsize / sizeof(long)); + } return (maxsize); }