mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2025-08-07 15:56:59 +02:00
common: Tidy up how malloc() is inited
The call to malloc() is a bit strange. The naming of the arguments suggests that an address is passed, but in fact it is a pointer, at least in the board_init_r() function and SPL equivalent. Update it to work as described. Add a function comment as well. Note that this does adjustment does not extend into the malloc() implementation itself, apart from changing mem_malloc_init(), since there are lots of casts and pointers and integers are used interchangeably. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Tom Rini <trini@konsulko.com> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
This commit is contained in:
parent
09f5be613a
commit
41fecdc94e
@ -204,8 +204,7 @@ static int initr_malloc(void)
|
|||||||
*/
|
*/
|
||||||
start = gd->relocaddr - TOTAL_MALLOC_LEN;
|
start = gd->relocaddr - TOTAL_MALLOC_LEN;
|
||||||
gd_set_malloc_start(start);
|
gd_set_malloc_start(start);
|
||||||
mem_malloc_init((ulong)map_sysmem(start, TOTAL_MALLOC_LEN),
|
mem_malloc_init(start, TOTAL_MALLOC_LEN);
|
||||||
TOTAL_MALLOC_LEN);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
#include <asm/global_data.h>
|
#include <asm/global_data.h>
|
||||||
|
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
#include <mapmem.h>
|
||||||
|
#include <string.h>
|
||||||
#include <asm/io.h>
|
#include <asm/io.h>
|
||||||
#include <valgrind/memcheck.h>
|
#include <valgrind/memcheck.h>
|
||||||
|
|
||||||
@ -598,9 +600,9 @@ void *sbrk(ptrdiff_t increment)
|
|||||||
|
|
||||||
void mem_malloc_init(ulong start, ulong size)
|
void mem_malloc_init(ulong start, ulong size)
|
||||||
{
|
{
|
||||||
mem_malloc_start = start;
|
mem_malloc_start = (ulong)map_sysmem(start, size);
|
||||||
mem_malloc_end = start + size;
|
mem_malloc_end = mem_malloc_start + size;
|
||||||
mem_malloc_brk = start;
|
mem_malloc_brk = mem_malloc_start;
|
||||||
|
|
||||||
#ifdef CONFIG_SYS_MALLOC_DEFAULT_TO_INIT
|
#ifdef CONFIG_SYS_MALLOC_DEFAULT_TO_INIT
|
||||||
malloc_init();
|
malloc_init();
|
||||||
|
@ -678,9 +678,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
|
|||||||
spl_set_bd();
|
spl_set_bd();
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_SPL_SYS_MALLOC)) {
|
if (IS_ENABLED(CONFIG_SPL_SYS_MALLOC)) {
|
||||||
mem_malloc_init((ulong)map_sysmem(SPL_SYS_MALLOC_START,
|
mem_malloc_init(SPL_SYS_MALLOC_START, SPL_SYS_MALLOC_SIZE);
|
||||||
SPL_SYS_MALLOC_SIZE),
|
|
||||||
SPL_SYS_MALLOC_SIZE);
|
|
||||||
gd->flags |= GD_FLG_FULL_MALLOC_INIT;
|
gd->flags |= GD_FLG_FULL_MALLOC_INIT;
|
||||||
}
|
}
|
||||||
if (!(gd->flags & GD_FLG_SPL_INIT)) {
|
if (!(gd->flags & GD_FLG_SPL_INIT)) {
|
||||||
|
@ -981,6 +981,14 @@ extern ulong mem_malloc_start;
|
|||||||
extern ulong mem_malloc_end;
|
extern ulong mem_malloc_end;
|
||||||
extern ulong mem_malloc_brk;
|
extern ulong mem_malloc_brk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mem_malloc_init() - Set up the malloc() pool
|
||||||
|
*
|
||||||
|
* Sets the region of memory to be used for all future calls to malloc(), etc.
|
||||||
|
*
|
||||||
|
* @start: Start address
|
||||||
|
* @size: Size in bytes
|
||||||
|
*/
|
||||||
void mem_malloc_init(ulong start, ulong size);
|
void mem_malloc_init(ulong start, ulong size);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
Loading…
Reference in New Issue
Block a user