This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/PROCESSOR-SDK-AM335X: SPL malloc hangs

Part Number: PROCESSOR-SDK-AM335X

Tool/software: Linux

U-Boot version : U-Boot 2013.07

We have Beaglbone black based custom board.

We have 256MB DDR and 4GB eMMC, 

We will be adding new board with 512MB DDR and 8GB eMMC.

We are planning to place board revision in EEPROM and read the same to decide which board SPL is booting from ( e.g. 256MB or 512MB DDR) and initialize DDR based on board revision

Now I added code in s_init() function of (project specific) board.c and

after adding couple of printfs I figured that function spi_do_alloc_slave in spi.c (U-Boosource/drivers/spi/ ) hangs at

ptr = malloc(size)

I see from board config that

/*
 * 1MB into the SDRAM to allow for SPL's bss at the beginning of SDRAM
 * 64 bytes before this address should be set aside for u-boot.img's
 * header. That is 0x800FFFC0--0x80100000 should not be used for any
 * other needs.
 */
#define CONFIG_SYS_TEXT_BASE		0x80800000
#define CONFIG_SYS_SPL_MALLOC_START	0x80a08000
#define CONFIG_SYS_SPL_MALLOC_SIZE	0x100000

So thinking that malloc start is  in DDR and DDR being not initialized making malloc function to hang.

Then I changed the code as follows,

#include <common.h>
#include <malloc.h>
#include <spi.h>

	static struct spi_slave global_ptr_eeprom;


void *spi_do_alloc_slave(int offset, int size, unsigned int bus,
			 unsigned int cs)
{
	struct spi_slave *slave;
	void *ptr;
	ptr =  &global_ptr_eeprom;

        .. CUT ..

}

and this seem to work

When I see u-boot-spl.map file I see that pointer is in DDR section..

 .bss.global_ptr_eeprom
                0x0000000080a004b4        0xc drivers/spi/libspi.o
                0x0000000080a004c0                . = ALIGN (0x4)
                0x0000000080a004c0                __bss_end = .
Address of section .text set to 0x402f0400

Now it seems to work but  I don't understand how!!

Because now also variable is in DDR and before DDR initialization  how is it working ?

Am I missing something here ?

any suggestion ?

Regards,

Ankur