public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot]  [RFC] spl: Remove overwrite of relocated malloc limit
@ 2017-01-11 20:19 Andrew F. Davis
  2017-01-12  7:57 ` Lokesh Vutla
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew F. Davis @ 2017-01-11 20:19 UTC (permalink / raw)
  To: u-boot

spl_init on some boards is called after stack and heap relocation, on
some platforms spl_relocate_stack_gd is called to handle setting the
limit to its value CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN when simple
SPL malloc is enabled during relocation. spl_init should then not
re-assign the old pre-relocation limit. Remove this.

Also add some debug statements that can help with find similar
problems.

Signed-off-by: Andrew F. Davis <afd@ti.com>
---
I'm not sure what the real fix should be, probably to clean-up
all this spaghetti code relating to malloc, but for now without
this patch we are stuck with the pre-relocation heap size and
boot with simple malloc is not functional on AM335x-EVM and probably
many other similar boards.

 common/malloc_simple.c | 6 +++++-
 common/spl/spl.c       | 1 -
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/common/malloc_simple.c b/common/malloc_simple.c
index 0f6bcbcc71..611400265b 100644
--- a/common/malloc_simple.c
+++ b/common/malloc_simple.c
@@ -39,10 +39,14 @@ void *memalign_simple(size_t align, size_t bytes)
 
 	addr = ALIGN(gd->malloc_base + gd->malloc_ptr, align);
 	new_ptr = addr + bytes - gd->malloc_base;
-	if (new_ptr > gd->malloc_limit)
+	if (new_ptr > gd->malloc_limit) {
+		debug("space exhausted\n");
 		return NULL;
+	}
+
 	ptr = map_sysmem(addr, bytes);
 	gd->malloc_ptr = ALIGN(new_ptr, sizeof(new_ptr));
+	debug("%lx\n", (ulong)ptr);
 
 	return ptr;
 }
diff --git a/common/spl/spl.c b/common/spl/spl.c
index a76ea3a603..aa75c93fce 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -237,7 +237,6 @@ int spl_init(void)
 #ifdef CONFIG_MALLOC_F_ADDR
 	gd->malloc_base = CONFIG_MALLOC_F_ADDR;
 #endif
-	gd->malloc_limit = CONFIG_SYS_MALLOC_F_LEN;
 	gd->malloc_ptr = 0;
 #endif
 	if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) {
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [U-Boot] [RFC] spl: Remove overwrite of relocated malloc limit
  2017-01-11 20:19 [U-Boot] [RFC] spl: Remove overwrite of relocated malloc limit Andrew F. Davis
@ 2017-01-12  7:57 ` Lokesh Vutla
  0 siblings, 0 replies; 2+ messages in thread
From: Lokesh Vutla @ 2017-01-12  7:57 UTC (permalink / raw)
  To: u-boot



On Thursday 12 January 2017 01:49 AM, Andrew F. Davis wrote:
> spl_init on some boards is called after stack and heap relocation, on
> some platforms spl_relocate_stack_gd is called to handle setting the
> limit to its value CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN when simple
> SPL malloc is enabled during relocation. spl_init should then not
> re-assign the old pre-relocation limit. Remove this.

This will fail for the case if
CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN and CONFIG_SYS_SPL_MALLOC_START is
not defined. i.e. if someone jut use CONFIG_SYS_MALLOC_F for both
board_init_f() and board_init_r().

> 
> Also add some debug statements that can help with find similar
> problems.
> 
> Signed-off-by: Andrew F. Davis <afd@ti.com>
> ---
> I'm not sure what the real fix should be, probably to clean-up
> all this spaghetti code relating to malloc, but for now without
> this patch we are stuck with the pre-relocation heap size and
> boot with simple malloc is not functional on AM335x-EVM and probably
> many other similar boards.
> 
>  common/malloc_simple.c | 6 +++++-
>  common/spl/spl.c       | 1 -
>  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/common/malloc_simple.c b/common/malloc_simple.c
> index 0f6bcbcc71..611400265b 100644
> --- a/common/malloc_simple.c
> +++ b/common/malloc_simple.c
> @@ -39,10 +39,14 @@ void *memalign_simple(size_t align, size_t bytes)
>  
>  	addr = ALIGN(gd->malloc_base + gd->malloc_ptr, align);
>  	new_ptr = addr + bytes - gd->malloc_base;
> -	if (new_ptr > gd->malloc_limit)
> +	if (new_ptr > gd->malloc_limit) {
> +		debug("space exhausted\n");
>  		return NULL;
> +	}
> +
>  	ptr = map_sysmem(addr, bytes);
>  	gd->malloc_ptr = ALIGN(new_ptr, sizeof(new_ptr));
> +	debug("%lx\n", (ulong)ptr);

This can be a separate patch.

>  
>  	return ptr;
>  }
> diff --git a/common/spl/spl.c b/common/spl/spl.c
> index a76ea3a603..aa75c93fce 100644
> --- a/common/spl/spl.c
> +++ b/common/spl/spl.c
> @@ -237,7 +237,6 @@ int spl_init(void)
>  #ifdef CONFIG_MALLOC_F_ADDR
>  	gd->malloc_base = CONFIG_MALLOC_F_ADDR;
>  #endif
> -	gd->malloc_limit = CONFIG_SYS_MALLOC_F_LEN;

IMO this should be guarded with !CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN
instead of removing it.

Thanks and regards,
Lokesh

>  	gd->malloc_ptr = 0;
>  #endif
>  	if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) {
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-01-12  7:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-11 20:19 [U-Boot] [RFC] spl: Remove overwrite of relocated malloc limit Andrew F. Davis
2017-01-12  7:57 ` Lokesh Vutla

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