mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* Re: [PATCH 2/6] memory: fix regions calculation
       [not found] ` <1346745947-7199-3-git-send-email-a.aring@phytec.de>
@ 2012-09-04 20:39   ` Sascha Hauer
  0 siblings, 0 replies; only message in thread
From: Sascha Hauer @ 2012-09-04 20:39 UTC (permalink / raw)
  To: Alexander Aring; +Cc: barebox

On Tue, Sep 04, 2012 at 10:05:43AM +0200, Alexander Aring wrote:
> 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;


> index 80b62e9..c85aae1 100644
> --- a/arch/arm/lib/arm.c
> +++ b/arch/arm/lib/arm.c
> @@ -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.

>  	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)

>  	request_sdram_region("barebox",
>  			(unsigned long)&_stext,
>  			(unsigned long)&_etext -
> -			(unsigned long)&_stext + 1);
> +			(unsigned long)&_stext);

This change is correct.

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

>  #ifdef STACK_BASE
>  	request_sdram_region("stack", STACK_BASE, STACK_SIZE);
>  #endif
> diff --git a/common/startup.c b/common/startup.c
> index abd1b77..0fa2dab 100644
> --- a/common/startup.c
> +++ b/common/startup.c
> @@ -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.

>  
>  	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

-- 
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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2012-09-04 20:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1346745947-7199-1-git-send-email-a.aring@phytec.de>
     [not found] ` <1346745947-7199-3-git-send-email-a.aring@phytec.de>
2012-09-04 20:39   ` [PATCH 2/6] memory: fix regions calculation Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox