mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Krzysztof Halasa <khc@pm.waw.pl>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] Implement ALTERNATE memory layout.
Date: Tue, 2 Apr 2013 09:20:57 +0200	[thread overview]
Message-ID: <20130402072057.GC20989@pengutronix.de> (raw)
In-Reply-To: <m3ip49gmds.fsf@intrepid.localdomain>

Hi Krzysztof,

The following patch from Jan is probably what you're looking for.

Sascha

8<-----------------------------------------------------------

On AM335x a barebox MLO is placed at the base of the usable SRAM range.
When running without SDRAM, we should be able to pass the SRAM range
to barebox_arm_entry.

First we check if the ends of the memory range lie in the barebox image
and reduce the range in these cases. Then we check if the image splits
the memory range in two and choose to use the larger one.

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
---
 arch/arm/cpu/start.c |   48 +++++++++++++++++++++++++++++++-----------------
 1 file changed, 31 insertions(+), 17 deletions(-)

diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index cd34d9c..fa148c2 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -34,38 +34,52 @@ unsigned long arm_stack_top;
 static noinline __noreturn void __start(uint32_t membase, uint32_t memsize,
 		uint32_t boarddata)
 {
-	unsigned long endmem = membase + memsize;
+	unsigned long memend;
 	unsigned long malloc_start, malloc_end;
 
 	setup_c();
 
-	arm_stack_top = endmem;
-	endmem -= STACK_SIZE; /* Stack */
+	if ((unsigned long)_text <= membase &&
+	    (unsigned long)_end > membase) { /* membase is in barebox */
+		memsize -= (unsigned long)_end - membase;
+		membase = (unsigned long)_end;
+	}
+
+	if ((unsigned long)_text < membase + memsize &&
+	    (unsigned long)_end >= membase + memsize) { /* membase + memsize is in barebox */
+		memsize = (unsigned long)_text - membase;
+	}
+
+	if ((unsigned long)_text > membase &&
+	    (unsigned long)_end < membase + memsize) { /* barebox splits or memory range */
+		unsigned long lowsize = (unsigned long)_text - membase;
+		unsigned long highsize = membase + memsize - (unsigned long)_end;
+		/* use larger range */
+		if (lowsize > highsize) {
+			memsize = lowsize;
+		} else {
+			membase = (unsigned long)_end;
+			memsize = highsize;
+		}
+	}
+
+	arm_stack_top = membase + memsize;
+	memend = membase + memsize - STACK_SIZE; /* Stack */
 
 	if (IS_ENABLED(CONFIG_MMU_EARLY)) {
 
-		endmem &= ~0x3fff;
-		endmem -= SZ_16K; /* ttb */
+		memend &= ~0x3fff;
+		memend -= SZ_16K; /* ttb */
 
 		if (!IS_ENABLED(CONFIG_PBL_IMAGE))
-			mmu_early_enable(membase, memsize, endmem);
+			mmu_early_enable(membase, memsize, memend);
 	}
 
-	if ((unsigned long)_text > membase + memsize ||
-			(unsigned long)_text < membase)
-		/*
-		 * barebox is either outside SDRAM or in another
-		 * memory bank, so we can use the whole bank for
-		 * malloc.
-		 */
-		malloc_end = endmem;
-	else
-		malloc_end = (unsigned long)_text;
-
 	/*
 	 * Maximum malloc space is the Kconfig value if given
 	 * or 64MB.
 	 */
+	malloc_end = memend;
 	if (MALLOC_SIZE > 0) {
 		malloc_start = malloc_end - MALLOC_SIZE;
 		if (malloc_start < membase)
-- 
1.7.10.4


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

  parent reply	other threads:[~2013-04-02  7:20 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-30 11:19 IXP4xx again Krzysztof Halasa
2013-03-30 11:24 ` [PATCH] ARM: XScale processors don't support "clean+invalidate D entry" operation Krzysztof Halasa
2013-03-30 11:25 ` [PATCH] Implement ALTERNATE memory layout Krzysztof Halasa
2013-03-30 12:01   ` Alexander Shiyan
2013-03-30 13:15     ` Krzysztof Halasa
2013-03-30 13:23       ` Re[2]: " Alexander Shiyan
2013-03-30 19:57         ` Krzysztof Halasa
2013-03-30 18:45   ` Antony Pavlov
2013-04-01 18:04   ` Sascha Hauer
2013-04-02  7:20   ` Sascha Hauer [this message]
2013-03-30 11:26 ` [PATCH] ARM: Add support for IXP4xx CPU and for Goramo Multilink router platform Krzysztof Halasa
2013-04-02  6:52   ` Sascha Hauer
2013-04-07 11:42     ` Krzysztof Halasa
2013-04-07 19:54       ` [PATCH] ARM: Support for IXP4xx CPU Krzysztof Halasa
2013-04-08  7:27         ` Jean-Christophe PLAGNIOL-VILLARD
2013-04-14 10:30           ` Krzysztof Halasa
2013-04-14 11:51             ` Jean-Christophe PLAGNIOL-VILLARD
2013-04-07 19:55       ` [PATCH] ARM: Support for IXP4xx hardware Queue Manager Krzysztof Halasa
2013-04-08  7:31         ` Jean-Christophe PLAGNIOL-VILLARD
2013-04-07 19:57       ` [PATCH] ARM: Support for IXP4xx Network Processor Engines (NPEs) Krzysztof Halasa
2013-04-08  7:30         ` Jean-Christophe PLAGNIOL-VILLARD
2013-04-07 19:58       ` [PATCH] ARM: Support for IXP4xx built-in Ethernet interfaces Krzysztof Halasa
2013-04-08  7:29         ` Jean-Christophe PLAGNIOL-VILLARD
2013-04-08  7:56       ` [PATCH] ARM: Add support for IXP4xx CPU and for Goramo Multilink router platform 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=20130402072057.GC20989@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=khc@pm.waw.pl \
    /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