From: Minkyu Kang <mk7.kang@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] memsize: get correct memory size
Date: Wed, 18 Nov 2009 14:02:54 +0900 [thread overview]
Message-ID: <4B037FFE.8030804@samsung.com> (raw)
In some case, saved address and compared address are different. (e.g: 80M)
So, it can be get wrong memory size.
This patch fix the such problem, and fix style problems also.
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>
---
common/memsize.c | 77 +++++++++++++++++++++++++++++++++---------------------
1 files changed, 47 insertions(+), 30 deletions(-)
diff --git a/common/memsize.c b/common/memsize.c
index 6c275c9..57c3cd7 100644
--- a/common/memsize.c
+++ b/common/memsize.c
@@ -44,51 +44,68 @@ long get_ram_size(volatile long *base, long maxsize)
long cnt;
long val;
long size;
+ long max = maxsize / sizeof(long);
int i = 0;
- for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
+ for (cnt = 1; cnt < max; cnt <<= 1) {
addr = base + cnt; /* pointer arith! */
- sync ();
- save[i++] = *addr;
- sync ();
+ sync();
+ save[++i] = *addr;
+ sync();
*addr = ~cnt;
}
+ addr = base + max - 1;
+ sync();
+ save[++i] = *addr;
+ sync();
+ *addr = ~max;
+
addr = base;
- sync ();
- save[i] = *addr;
- sync ();
+ sync();
+ save[0] = *addr;
+ sync();
*addr = 0;
+ sync();
- sync ();
- 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);
+ val = *addr;
+ if (val != 0) {
+ i = 0;
+ cnt = 1;
+ size = 0;
+ goto restore;
}
- for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
+ i = 0;
+ for (cnt = 1; cnt < max; cnt <<= 1) {
addr = base + cnt; /* pointer arith! */
val = *addr;
- *addr = save[--i];
+ *addr = save[++i];
if (val != ~cnt) {
- size = cnt * sizeof (long);
- /* Restore the original data before leaving the function.
- */
- for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
- addr = base + cnt;
- *addr = save[--i];
- }
- return (size);
+ size = cnt * sizeof(long);
+ cnt <<= 1;
+ goto restore;
}
}
- return (maxsize);
+ addr = base + max - 1;
+ val = *addr;
+ *addr = save[++i];
+ if (val != ~max)
+ maxsize = (cnt >> 1) * sizeof(long);
+
+ return maxsize;
+
+restore:
+ /* Restore the original data before leaving the function. */
+ for (; cnt < max; cnt <<= 1) {
+ addr = base + cnt;
+ sync();
+ *addr = save[++i];
+ }
+ addr = base;
+ sync();
+ *addr = save[0];
+
+ return size;
}
--
1.5.4.3
next reply other threads:[~2009-11-18 5:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-18 5:02 Minkyu Kang [this message]
2009-11-23 7:04 ` [U-Boot] [PATCH] memsize: get correct memory size Minkyu Kang
2009-11-23 18:37 ` Wolfgang Denk
2009-11-24 4:40 ` Minkyu Kang
2009-11-24 22:08 ` Wolfgang Denk
2009-11-25 2:00 ` Minkyu Kang
2009-11-25 16:30 ` Wolfgang Denk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4B037FFE.8030804@samsung.com \
--to=mk7.kang@samsung.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox