[U-Boot] [PATCH v2 1/2] malloc_simple: Add Kconfig option for using only malloc_simple in the SPL

common/dlmalloc.c is quite big, both in .text and .data usage, therefor on some boards the SPL is build to use only malloc_simple.c and not the dlmalloc.c code. This is done in various include/configs/foo.h with the following construct:
#ifdef CONFIG_SPL_BUILD #define CONFIG_SYS_MALLOC_SIMPLE #endif
This commit introduces a SPL_MALLOC_SIMPLE Kconfig bool which allows selecting this functionality through Kconfig instead.
Signed-off-by: Hans de Goede hdegoede@redhat.com --- Changes in v2: -Fix commit message wrt quoting lines starting with a # -Rename Kconfig option from SPL_MALLOC_SIMPLE to SPL_SYS_MALLOC_SIMPLE -Simplify the ifdef checks to #if CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE) --- Kconfig | 10 ++++++++++ common/malloc_simple.c | 2 +- include/_exports.h | 2 +- include/exports.h | 2 +- include/malloc.h | 2 +- 5 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/Kconfig b/Kconfig index 05a34f7..7770743 100644 --- a/Kconfig +++ b/Kconfig @@ -114,6 +114,16 @@ config SPL help If you want to build SPL as well as the normal image, say Y.
+config SPL_SYS_MALLOC_SIMPLE + bool + depends on SPL + prompt "Only use malloc_simple functions in the spl" + help + Say Y here to only use the *_simple malloc functions from + malloc_simple.c, rather then using the versions from dlmalloc.c + this will make the SPL binary smaller at the cost of more heap + usage as the *_simple malloc functions do not re-use free-ed mem. + config SPL_STACK_R depends on SPL bool "Enable SDRAM location for SPL stack" diff --git a/common/malloc_simple.c b/common/malloc_simple.c index c745863..9bf1fed 100644 --- a/common/malloc_simple.c +++ b/common/malloc_simple.c @@ -40,7 +40,7 @@ void *memalign_simple(size_t align, size_t bytes) return ptr; }
-#ifdef CONFIG_SYS_MALLOC_SIMPLE +#if CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE) void *calloc(size_t nmemb, size_t elem_size) { size_t size = nmemb * elem_size; diff --git a/include/_exports.h b/include/_exports.h index 74a882a..11beeb2 100644 --- a/include/_exports.h +++ b/include/_exports.h @@ -23,7 +23,7 @@ EXPORT_FUNC(dummy, void, free_hdlr, void) #endif EXPORT_FUNC(malloc, void *, malloc, size_t) -#ifndef CONFIG_SYS_MALLOC_SIMPLE +#if !CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE) EXPORT_FUNC(free, void, free, void *) #endif EXPORT_FUNC(udelay, void, udelay, unsigned long) diff --git a/include/exports.h b/include/exports.h index a3e0469..deef8fb 100644 --- a/include/exports.h +++ b/include/exports.h @@ -19,7 +19,7 @@ int printf(const char* fmt, ...); void install_hdlr(int, interrupt_handler_t, void*); void free_hdlr(int); void *malloc(size_t); -#ifndef CONFIG_SYS_MALLOC_SIMPLE +#if !CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE) void free(void*); #endif void __udelay(unsigned long); diff --git a/include/malloc.h b/include/malloc.h index f4da9e6..f20e4d3 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -872,7 +872,7 @@ extern Void_t* sbrk();
#else
-#ifdef CONFIG_SYS_MALLOC_SIMPLE +#if CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE) #define malloc malloc_simple #define realloc realloc_simple #define memalign memalign_simple

malloc_simple uses a part of the stack as heap, initially it uses SYS_MALLOC_F_LEN bytes which typically is quite small as the initial stacks sits in SRAM and we do not have that much SRAM to work with.
When DRAM becomes available we may switch the stack from SRAM to DRAM to give use more room. This commit adds support for also switching to a new bigger malloc_simple heap located in the new stack.
Note that this requires spl_init to be called before spl_relocate_stack_gd which in practice means that spl_init must be called from board_init_f.
Signed-off-by: Hans de Goede hdegoede@redhat.com Reviewed-by: Tom Rini trini@konsulko.com --- Changes in v2: -Adjust for SPL_MALLOC_SIMPLE to SPL_SYS_MALLOC_SIMPLE rename --- Kconfig | 10 ++++++++++ common/spl/spl.c | 12 ++++++++++++ 2 files changed, 22 insertions(+)
diff --git a/Kconfig b/Kconfig index 7770743..5ed5b66 100644 --- a/Kconfig +++ b/Kconfig @@ -142,6 +142,16 @@ config SPL_STACK_R_ADDR Specify the address in SDRAM for the SPL stack. This will be set up before board_init_r() is called.
+config SPL_STACK_R_MALLOC_SIMPLE_LEN + depends on SPL_STACK_R && SPL_SYS_MALLOC_SIMPLE + hex "Size of malloc_simple heap after switching to DRAM SPL stack" + default 0x100000 + help + Specify the amount of the stack to use as memory pool for + malloc_simple after switching the stack to DRAM. This may be set + to give board_init_r() a larger heap then the initial heap in + SRAM which is limited to SYS_MALLOC_F_LEN bytes. + config TPL bool depends on SPL && SUPPORT_TPL diff --git a/common/spl/spl.c b/common/spl/spl.c index b09a626..4b319d6 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -347,6 +347,18 @@ ulong spl_relocate_stack_gd(void) memcpy(new_gd, (void *)gd, sizeof(gd_t)); gd = new_gd;
+#ifdef CONFIG_SPL_SYS_MALLOC_SIMPLE + if (CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN) { + if (!(gd->flags & GD_FLG_SPL_INIT)) + panic("spl_init must be called before heap reloc"); + + ptr -= CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN; + gd->malloc_base = ptr; + gd->malloc_limit = CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN; + gd->malloc_ptr = 0; + } +#endif + return ptr; #else return 0;

On 22 September 2015 at 11:25, Hans de Goede hdegoede@redhat.com wrote:
malloc_simple uses a part of the stack as heap, initially it uses SYS_MALLOC_F_LEN bytes which typically is quite small as the initial stacks sits in SRAM and we do not have that much SRAM to work with.
When DRAM becomes available we may switch the stack from SRAM to DRAM to give use more room. This commit adds support for also switching to a new bigger malloc_simple heap located in the new stack.
Note that this requires spl_init to be called before spl_relocate_stack_gd which in practice means that spl_init must be called from board_init_f.
Signed-off-by: Hans de Goede hdegoede@redhat.com Reviewed-by: Tom Rini trini@konsulko.com
Changes in v2:
-Adjust for SPL_MALLOC_SIMPLE to SPL_SYS_MALLOC_SIMPLE rename
Kconfig | 10 ++++++++++ common/spl/spl.c | 12 ++++++++++++ 2 files changed, 22 insertions(+)
Acked-by: Simon Glass sjg@chromium.org

On 22 September 2015 at 11:25, Hans de Goede hdegoede@redhat.com wrote:
common/dlmalloc.c is quite big, both in .text and .data usage, therefor on some boards the SPL is build to use only malloc_simple.c and not the dlmalloc.c code. This is done in various include/configs/foo.h with the following construct:
#ifdef CONFIG_SPL_BUILD #define CONFIG_SYS_MALLOC_SIMPLE #endif
This commit introduces a SPL_MALLOC_SIMPLE Kconfig bool which allows selecting this functionality through Kconfig instead.
Signed-off-by: Hans de Goede hdegoede@redhat.com
Changes in v2: -Fix commit message wrt quoting lines starting with a # -Rename Kconfig option from SPL_MALLOC_SIMPLE to SPL_SYS_MALLOC_SIMPLE
-Simplify the ifdef checks to #if CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE)
Kconfig | 10 ++++++++++ common/malloc_simple.c | 2 +- include/_exports.h | 2 +- include/exports.h | 2 +- include/malloc.h | 2 +- 5 files changed, 14 insertions(+), 4 deletions(-)
Acked-by: Simon Glass sjg@chromium.org
participants (2)
-
Hans de Goede
-
Simon Glass