Skip to contentSkip to conversation

SYS_MALLOC_SIMPLE versus SPL_SYS_MALLOC_SIMPLE?

U-Boot Robert P. J. Day 2 participants 2 messages Apr 16, 2016 – Apr 18, 2016

lore
Share & tools
lore
#0 lore raw

(WARNING: many potentially dumb questions coming this weekend as i
try to put together a u-boot tutorial for some upcoming presentations. please be patient ... )

i had a much longer question about the config option
SYS_MALLOC_SIMPLE until i noticed that it doesn't seem to be defined in a Kconfig file:

  $ grep -rw SYS_MALLOC_SIMPLE *
  common/malloc_simple.c:#if CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE)
  include/exports.h:#if !CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE)
  include/_exports.h:#if !CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE)
  include/malloc.h:#if CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE)
  $

that appears to be the extent of that symbol in the entire u-boot source tree, which is obviously different from:

  $ grep -rw SPL_SYS_MALLOC_SIMPLE *
  arch/arm/Kconfig:	select SPL_SYS_MALLOC_SIMPLE if SUPPORT_SPL
  arch/arm/mach-rockchip/Kconfig:config SPL_SYS_MALLOC_SIMPLE
  Kconfig:config SPL_SYS_MALLOC_SIMPLE
  Kconfig:	depends on SPL_STACK_R && SPL_SYS_MALLOC_SIMPLE
  $

the top-level Kconfig file mentions only the latter:

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.

the header file include/malloc.h proceeds to test the *former*:

  #if CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE)
  #define malloc malloc_simple
  #define realloc realloc_simple
  #define memalign memalign_simple
  static inline void free(void *ptr) {}
  void *calloc(size_t nmemb, size_t size);
  void *memalign_simple(size_t alignment, size_t bytes);
  void *realloc_simple(void *ptr, size_t size);
  #else
  ... snip ...

but (oddly?) common/Makefile includes the conditional compilation:

ifdef CONFIG_SYS_MALLOC_F_LEN (?????)
obj-y += malloc_simple.o
endif

and to top things off, the source file common/malloc_simple.c contains:

  void *malloc_simple(size_t bytes)
  {
  ...
  }

  void *memalign_simple(size_t align, size_t bytes)
  {
  ...
  }

  #if CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE)
  void *calloc(size_t nmemb, size_t elem_size)
  {
  ...
  }
  #endif

at this point, i'm a bit confused as to how all of this malloc_simple stuff hangs together and what the valid Kconfig configurations are.

rday

Signature · 7 lines
========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================
#1 lore raw

Hi,

Quoted 19 lines · Robert P. J. Day

(WARNING: many potentially dumb questions coming this weekend as i
try to put together a u-boot tutorial for some upcoming presentations. please be patient ... )

i had a much longer question about the config option
SYS_MALLOC_SIMPLE until i noticed that it doesn't seem to be defined in a Kconfig file:

   $ grep -rw SYS_MALLOC_SIMPLE *
   common/malloc_simple.c:#if CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE)
   include/exports.h:#if !CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE)
   include/_exports.h:#if !CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE)
   include/malloc.h:#if CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE)
   $

that appears to be the extent of that symbol in the entire u-boot source tree, which is obviously different from:

Quoted 6 lines
   $ grep -rw SPL_SYS_MALLOC_SIMPLE *
   arch/arm/Kconfig:	select SPL_SYS_MALLOC_SIMPLE if SUPPORT_SPL
   arch/arm/mach-rockchip/Kconfig:config SPL_SYS_MALLOC_SIMPLE
   Kconfig:config SPL_SYS_MALLOC_SIMPLE
   Kconfig:	depends on SPL_STACK_R && SPL_SYS_MALLOC_SIMPLE
   $

There is some magic happening somewhere whereby SPL_FOO_BAR Kconfig settings only get set when builind the SPL and they actually get set as FOO_BAR, so the SPL_ prefix is special and tells the u-boot build scripts to only define FOO_BAR when building the SPL, this goes for all SPL_ prefixed Kconfig settings. This all is IIRC.

Regards,

Hans