[U-Boot] SYS_MALLOC_SIMPLE versus SPL_SYS_MALLOC_SIMPLE?

Robert P. J. Day rpjday at crashcourse.ca
Sat Apr 16 10:58:03 CEST 2016


  (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

-- 

========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================



More information about the U-Boot mailing list