Skip to contentSkip to conversation

memory: fix regions calculation

PATCH Sascha Hauer 1 participant 1 message Sep 4, 2012 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 9 lines · Alexander Aring

Fix calculation of regions.

Previous end address and next start address of two chained regions are the same in a linkerscript.
We need the same behaviour for mem_malloc_init.

When we add the region to the regions tree we calculate -1 to the end address.

Most of this patch is wrong. The following is always true:

end = start + size - 1

The problem we have is that in the linker scripts we have

_text = .;
*(.text*)
_etext = .;

Here _etext is *not* the end but the next free address.

So we have to calculate text size for the above example as:

text_size = _etext - _text;

arch/arm/lib/arm.c line 10

Quoted 9 lines

index 80b62e9..c85aae1 100644

arch/arm/lib/arm.c +1 -1
@@ -7,7 +7,7 @@
 static int arm_mem_malloc_init(void)
 {
 	mem_malloc_init((void *)MALLOC_BASE,
-			(void *)(MALLOC_BASE + MALLOC_SIZE - 1));
+			(void *)(MALLOC_BASE + MALLOC_SIZE));

So this patch is wrong.

arch/arm/lib/arm.c line 13

Quoted 4 lines
arch/arm/lib/arm.c +1 -1
 	request_sdram_region("malloc space",
 			malloc_start,
-			malloc_end - malloc_start + 1);
+			malloc_end - malloc_start);

This is also wrong (and also all changes above this)

arch/arm/lib/arm.c

Quoted 5 lines
arch/arm/lib/arm.c +1 -1
 	request_sdram_region("barebox",
 			(unsigned long)&_stext,
 			(unsigned long)&_etext -
-			(unsigned long)&_stext + 1);
+			(unsigned long)&_stext);

This change is correct.

arch/arm/lib/arm.c

Quoted 5 lines
arch/arm/lib/arm.c +1 -1
 	request_sdram_region("bss",
 			(unsigned long)&__bss_start,
 			(unsigned long)&__bss_stop -
-			(unsigned long)&__bss_start + 1);
+			(unsigned long)&__bss_start);

This change is also correct.

Quoted 8 lines

#ifdef STACK_BASE

arch/arm/lib/arm.c +0 -0
 	request_sdram_region("stack", STACK_BASE, STACK_SIZE);
 #endif
common/startup.c +0 -0
index abd1b77..0fa2dab 100644

common/startup.c extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[], · line 51

Quoted 7 lines
common/startup.c +2 -2
@@ -47,8 +47,8 @@ extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
 static void display_meminfo(void)
 {
 	ulong mstart = mem_malloc_start();
-	ulong mend   = mem_malloc_end();
-	ulong msize  = mend - mstart + 1;
+	ulong mend   = mem_malloc_end() - 1;
+	ulong msize  = mend - mstart;

This change is wrong.

common/startup.c static void display_meminfo(void) · line 59

Quoted 9 lines
common/startup.c +1 -1
 	debug("barebox code: 0x%p -> 0x%p\n", _stext, _etext);
 	debug("bss segment:  0x%p -> 0x%p\n", __bss_start, __bss_stop);
@@ -56,7 +56,7 @@ static void display_meminfo(void)
 		mstart, mend, size_human_readable(msize));
 #ifdef CONFIG_ARM
 	printf("Stack space : 0x%08x -> 0x%08x (size %s)\n",
-		STACK_BASE, STACK_BASE + STACK_SIZE,
+		STACK_BASE, STACK_BASE + STACK_SIZE - 1,

This change is correct.

Sascha

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox