[U-Boot] Using spi_alloc_slave() from SPL

Stefano Babic sbabic at denx.de
Thu Aug 6 15:38:48 CEST 2015


Hi Fabio,

On 06/08/2015 15:25, Fabio Estevam wrote:
> Hi,
> 
> I am trying to use spi_flash_probe() inside SPL on a custom mx6 board.
> 
> The idea is to read some parameters from the SPI NOR flash and configure
> the DDR accordingly.
> 
> This is similar to what gw_ventana_spl.c does, but it reads from i2c
> eeprom instead of SPI NOR.
> 
> Here are the changes just to illustrate the problem:
> 
> --- a/board/freescale/mx6sabresd/mx6sabresd.c
> +++ b/board/freescale/mx6sabresd/mx6sabresd.c
> @@ -692,6 +692,19 @@ int checkboard(void)
>  #ifdef CONFIG_SPL_BUILD
>  #include <spl.h>
>  #include <libfdt.h>
> +#include <spi_flash.h>
> +#include <spi.h>
> +
> +static int read_spi_flash(void)
> +{
> +       struct spi_flash *spi;
> +       char buf[2];
> +
> +       spi = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
> +                             CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
> +       return spi_flash_read(spi, 0, 2, buf);
> +}
> 
>  const struct mx6dq_iomux_ddr_regs mx6_ddr_ioregs = {
>         .dram_sdclk_0 =  0x00020030,
> @@ -837,6 +850,8 @@ void board_init_f(ulong dummy)
>         /* UART clocks enabled and gd valid - init serial console */
>         preloader_console_init();
> 
> +       read_spi_flash();
> +
>         /* DDR initialization */
>         spl_dram_init();
> 
> diff --git a/include/configs/mx6sabresd.h b/include/configs/mx6sabresd.h
> index 41162ca..f5dfaf7 100644
> --- a/include/configs/mx6sabresd.h
> +++ b/include/configs/mx6sabresd.h
> @@ -12,6 +12,10 @@
>  #ifdef CONFIG_SPL
>  #define CONFIG_SPL_LIBCOMMON_SUPPORT
>  #define CONFIG_SPL_MMC_SUPPORT
> +#define CONFIG_SPL_SPI_SUPPORT
> +#define CONFIG_SPL_SPI_FLASH_SUPPORT
> +#define CONFIG_SYS_SPI_U_BOOT_OFFS     (64 * 1024)
> +#define CONFIG_SPL_SPI_LOAD
>  #include "imx6_spl.h"
>  #endif
> 
> @@ -35,6 +39,12 @@
>  #define CONFIG_SYS_MMC_ENV_DEV         1       /* SDHC3 */
>  #endif
> 
> +#define CONFIG_ENV_SECT_SIZE           (64 * 1024)
> +#define CONFIG_ENV_SPI_BUS             CONFIG_SF_DEFAULT_BUS
> +#define CONFIG_ENV_SPI_CS              CONFIG_SF_DEFAULT_CS
> +#define CONFIG_ENV_SPI_MODE            CONFIG_SF_DEFAULT_MODE
> +#define CONFIG_ENV_SPI_MAX_HZ          CONFIG_SF_DEFAULT_SPEED
> +
>  #define CONFIG_CMD_PCI
>  #ifdef CONFIG_CMD_PCI
>  #define CONFIG_PCI
> 


> The when I run it:
> 
> U-Boot SPL 2015.07-08202-g6dcdca1-dirty (Aug 06 2015 - 10:18:33)
> mxc_spi: SPI Slave not allocated !
> 
> spi_flash_probe() ---> spi_setup_slave() ----> spi_alloc_slave() which
> fails on mxc_spi.c

Right - if I remember well, spi_alloc requires a full functional malloc,
and then fails.

> 
> As read_spi_flash() is called prior to the DDR initialization,
> spi_alloc_slave() fails.
> 
> Is there a way to avoid calling spi_alloc_slave() in the SPL case?
>
> Any ideas on how to fix this?

There is the possibility to set a malloc area inside SPL:

CONFIG_SYS_SPL_MALLOC_START
CONFIG_SYS_SPL_MALLOC_SIZE

you do not need a lot of space, and you can try to put it inside the IRAM.

This should guarantee that spi_alloc_slave() works.

Best regards,
Stefano


-- 
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================


More information about the U-Boot mailing list