Commit b6bfb6ff9a2173d5e0e5506b95631aa49396c468

Authored by Simon Glass
1 parent e9fc058314

Add a simple version of memalign()

This is used when the full malloc() is not available.

Signed-off-by: Simon Glass <sjg@chromium.org>

Showing 1 changed file with 14 additions and 0 deletions Side-by-side Diff

common/malloc_simple.c
... ... @@ -26,6 +26,20 @@
26 26 return ptr;
27 27 }
28 28  
  29 +void *memalign_simple(size_t align, size_t bytes)
  30 +{
  31 + ulong addr, new_ptr;
  32 + void *ptr;
  33 +
  34 + addr = ALIGN(gd->malloc_base + gd->malloc_ptr, bytes);
  35 + new_ptr = addr + bytes;
  36 + if (new_ptr > gd->malloc_limit)
  37 + return NULL;
  38 + ptr = map_sysmem(addr, bytes);
  39 + gd->malloc_ptr = ALIGN(new_ptr, sizeof(new_ptr));
  40 + return ptr;
  41 +}
  42 +
29 43 #ifdef CONFIG_SYS_MALLOC_SIMPLE
30 44 void *calloc(size_t nmemb, size_t elem_size)
31 45 {