summaryrefslogtreecommitdiffstats
path: root/patches/barebox-2013.04.0/0001-arm-start-improve-memory-layout-calculation.patch
blob: 8c6854d3188554b21332dfcd35094082ab9847d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
From d7df89aff4ba68d8bb57cbf6145c5cd5f201f704 Mon Sep 17 00:00:00 2001
From: Jan Luebbe <jlu@pengutronix.de>
Date: Fri, 15 Mar 2013 12:40:55 +0100
Subject: [PATCH 1/8] arm: start: improve memory layout calculation

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.8.2.rc2