[U-Boot-Users] problem of malloc return 0

朱洪亮 aspirefhaha at gmail.com
Thu Jun 21 10:20:07 CEST 2007


Hi
    i am new to uboot,
    I am porting uboot to lpc2220 on my board,and when run at env_relocate()
in start_armboot(void), i get sometrouble.

/**** code from lib_arm/board.c  ***/
void env_relocate (void)
{
    DEBUGF ("%s[%d] offset = 0x%lx\n", __FUNCTION__,__LINE__,
        gd->reloc_off);

#ifdef CONFIG_AMIGAONEG3SE
    enable_nvram();
#endif

#ifdef ENV_IS_EMBEDDED
    /*
     * The environment buffer is embedded with the text segment,
     * just relocate the environment pointer
     */
    env_ptr = (env_t *)((ulong)env_ptr + gd->reloc_off);
    DEBUGF ("%s[%d] embedded ENV at %p\n", __FUNCTION__,__LINE__,env_ptr);
#else
    /*
     * We must allocate a buffer for the environment
     */
    env_ptr = (env_t *)malloc (CFG_ENV_SIZE);
    DEBUGF ("%s[%d] malloced ENV at %p\n", __FUNCTION__,__LINE__,env_ptr);
#endif
/* ******   code end   *******/

after the code "env_ptr = (env_t *)malloc (CFG_ENV_SIZE)"  the  env_ptr is
0x0;
i change the toolchain from arm-linux to arm-elf and the return value is
also 0x0,so what should i do if i want to initial for malloc,
and I don't know why we call mem_malloc_init,

/********  code from lib_arm/borad.c   ***/
static ulong mem_malloc_start = 0;
static ulong mem_malloc_end = 0;
static ulong mem_malloc_brk = 0;

static
void mem_malloc_init (ulong dest_addr)
{
    mem_malloc_start = dest_addr;
    mem_malloc_end = dest_addr + CFG_MALLOC_LEN;
    mem_malloc_brk = mem_malloc_start;

    memset ((void *) mem_malloc_start, 0,
            mem_malloc_end - mem_malloc_start);
}
/********* **/

the variables are all static, does it have any relation with malloc();
and I find there is a function malloc_bin_reloc in dlmalloc.c , and the
change the "static mbinptr av_[NAV * 2 + 2] " with the gd->reloc_off,what i
should set the gd->reloc_off if there are something relation,the code below

/***** code from common/dlmalloc.c  ****/
void malloc_bin_reloc (void)
{
    unsigned long *p = (unsigned long *)(&av_[2]);
    int i;
    for (i=2; i<(sizeof(av_)/sizeof(mbinptr)); ++i) {
        *p++ += gd->reloc_off;
    }
}
/***** code end ****/

looking for some help,thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.denx.de/pipermail/u-boot/attachments/20070621/6b1cdb2a/attachment.htm 


More information about the U-Boot mailing list