mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Maxime Ripard <maxime.ripard@free-electrons.com>
To: barebox@lists.infradead.org
Subject: [PATCH 1/2] memsize: Make get_ram_size RAM proof
Date: Tue, 26 Feb 2013 17:55:41 +0100	[thread overview]
Message-ID: <1361897742-3454-2-git-send-email-maxime.ripard@free-electrons.com> (raw)
In-Reply-To: <1361897742-3454-1-git-send-email-maxime.ripard@free-electrons.com>

get_ram_size cannot be used when running from RAM at the moment, even
though it backs up the memory cells it modifies, since it can also
modify the get_ram_size function itself.

Avoid testing the memory area where barebox is loaded at to prevent this
problem. If the memory supposed to host barebox is not working, we'll
have plenty of other problems anyway.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
---
 common/memsize.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/common/memsize.c b/common/memsize.c
index d149e41..1d00984 100644
--- a/common/memsize.c
+++ b/common/memsize.c
@@ -19,6 +19,9 @@
 
 #include <common.h>
 #include <config.h>
+
+#include <asm-generic/sections.h>
+
 #if defined (__PPC__) && !defined (__SANDBOX__)
 /*
  * At least on G2 PowerPC cores, sequential accesses to non-existent
@@ -45,6 +48,15 @@ long get_ram_size(volatile long *base, long maxsize)
 
 	for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
 		addr = base + cnt;	/* pointer arith! */
+
+		/*
+		 * If we run get_ram_size from RAM, avoid poking into
+		 * the Barebox code, and if the RAM at these address
+		 * doesn't work, we will have trouble anyway...
+		 */
+		if (addr > (long*)_text && addr < (long*)__bss_stop)
+			continue;
+
 		sync ();
 		save[i++] = *addr;
 		sync ();
@@ -65,6 +77,9 @@ long get_ram_size(volatile long *base, long maxsize)
 		*addr = save[i];
 		for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
 			addr  = base + cnt;
+			if (addr > (long*)_text && addr < (long*)__bss_stop)
+				continue;
+
 			sync ();
 			*addr = save[--i];
 		}
@@ -73,6 +88,9 @@ long get_ram_size(volatile long *base, long maxsize)
 
 	for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
 		addr = base + cnt;	/* pointer arith! */
+		if (addr > (long*)_text && addr < (long*)__bss_stop)
+			continue;
+
 		val = *addr;
 		*addr = save[--i];
 		if (val != ~cnt) {
@@ -81,6 +99,9 @@ long get_ram_size(volatile long *base, long maxsize)
 			 */
 			for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
 				addr  = base + cnt;
+				if (addr > (long*)_text && addr < (long*)__bss_stop)
+					continue;
+
 				*addr = save[--i];
 			}
 			return (size);
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2013-02-26 16:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-26 16:55 [PATCHv2 0/2] cfa10036: Retrieve RAM size at runtime Maxime Ripard
2013-02-26 16:55 ` Maxime Ripard [this message]
2013-03-04  8:02   ` [PATCH 1/2] memsize: Make get_ram_size RAM proof Sascha Hauer
2013-03-07 13:52     ` Maxime Ripard
2013-03-07 14:10       ` Juergen Beisert
2013-03-07 14:26         ` Maxime Ripard
2013-02-26 16:55 ` [PATCH 2/2] cfa10036: Retrieve the RAM size at runtime Maxime Ripard
2013-02-27  8:03 ` [PATCHv2 0/2] cfa10036: Retrieve " Sascha Hauer

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=1361897742-3454-2-git-send-email-maxime.ripard@free-electrons.com \
    --to=maxime.ripard@free-electrons.com \
    --cc=barebox@lists.infradead.org \
    /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