[U-Boot] [PATCH 1/3] malloc_simple: Allow malloc_simple to be used with non stack RAM

Simon Glass sjg at chromium.org
Tue Aug 18 03:59:51 CEST 2015


Hi Hans,

On 17 August 2015 at 10:08, Hans de Goede <hdegoede at redhat.com> wrote:
> Before this patch malloc_simple would always allocate a chunk of RAM from
> the stack. This commit adds a CONFIG_SYS_MALLOC_F_BASE define, which when
> set directly specifies the memory address to use for the heap with
> malloc_simple.
>
> Signed-off-by: Hans de Goede <hdegoede at redhat.com>
> Reviewed-by: Simon Glass <sjg at chromium.org>
> ---
>  arch/arm/lib/crt0.S | 2 +-
>  common/board_f.c    | 4 ++++
>  common/dlmalloc.c   | 4 ++++
>  common/spl/spl.c    | 3 +++
>  4 files changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm/lib/crt0.S b/arch/arm/lib/crt0.S
> index afd4f10..5e6619f 100644
> --- a/arch/arm/lib/crt0.S
> +++ b/arch/arm/lib/crt0.S
> @@ -96,7 +96,7 @@ clr_gd:
>         strlo   r0, [r1]                /* clear 32-bit GD word */
>         addlo   r1, r1, #4              /* move to next */
>         blo     clr_gd
> -#if defined(CONFIG_SYS_MALLOC_F_LEN)
> +#if defined(CONFIG_SYS_MALLOC_F_LEN) && !defined(CONFIG_SYS_MALLOC_F_BASE)
>         sub     sp, sp, #CONFIG_SYS_MALLOC_F_LEN
>         str     sp, [r9, #GD_MALLOC_BASE]
>  #endif
> diff --git a/common/board_f.c b/common/board_f.c
> index c959774..7f3b96f 100644
> --- a/common/board_f.c
> +++ b/common/board_f.c
> @@ -1050,9 +1050,13 @@ ulong board_init_f_mem(ulong top)
>         arch_setup_gd(gd_ptr);
>
>  #ifdef CONFIG_SYS_MALLOC_F_LEN
> +#if defined(CONFIG_SYS_MALLOC_F_BASE)
> +       gd->malloc_base = CONFIG_SYS_MALLOC_F_BASE;
> +#else
>         top -= CONFIG_SYS_MALLOC_F_LEN;
>         gd->malloc_base = top;
>  #endif
> +#endif
>
>         return top;
>  }
> diff --git a/common/dlmalloc.c b/common/dlmalloc.c
> index b5bb051..9b14033 100644
> --- a/common/dlmalloc.c
> +++ b/common/dlmalloc.c
> @@ -3264,7 +3264,11 @@ int mALLOPt(param_number, value) int param_number; int value;
>  int initf_malloc(void)
>  {
>  #ifdef CONFIG_SYS_MALLOC_F_LEN
> +#if defined(CONFIG_SYS_MALLOC_F_BASE)
> +       gd->malloc_base = CONFIG_SYS_MALLOC_F_BASE;
> +#else
>         assert(gd->malloc_base);        /* Set up by crt0.S */
> +#endif
>         gd->malloc_limit = CONFIG_SYS_MALLOC_F_LEN;
>         gd->malloc_ptr = 0;
>  #endif
> diff --git a/common/spl/spl.c b/common/spl/spl.c
> index 94b01da..811452b 100644
> --- a/common/spl/spl.c
> +++ b/common/spl/spl.c
> @@ -156,6 +156,9 @@ int spl_init(void)
>  #if defined(CONFIG_SYS_MALLOC_F_LEN)
>         gd->malloc_limit = CONFIG_SYS_MALLOC_F_LEN;
>         gd->malloc_ptr = 0;
> +#if defined(CONFIG_SYS_MALLOC_F_BASE)
> +       gd->malloc_base = CONFIG_SYS_MALLOC_F_BASE;
> +#endif
>  #endif
>         if (IS_ENABLED(CONFIG_OF_CONTROL) &&
>                         !IS_ENABLED(CONFIG_SPL_DISABLE_OF_CONTROL)) {
> --
> 2.4.3
>

Why does this save memory?

In general we should move away from hard-coding specific addresses I
think, and just work out the memory from a single address, subtracting
space for each area we need.

Regards,
Simon


More information about the U-Boot mailing list