[U-Boot] [PATCH 7/8] arm/davinci: spl - boot device selection

Christian Riesch christian.riesch at omicron.at
Mon Jun 18 22:10:47 CEST 2012


Hi,

On Tuesday, June 12, 2012, Mikhail Kshevetskiy wrote:

> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy at gmail.com<javascript:;>
> >
> ---
>  arch/arm/cpu/arm926ejs/davinci/Makefile          |    5 ++
>  arch/arm/cpu/arm926ejs/davinci/spl.c             |   91
> +++++++++++++++++++---
>  arch/arm/cpu/arm926ejs/davinci/spl_mmc.c         |   37 +++++++++
>  arch/arm/cpu/arm926ejs/davinci/spl_nand.c        |   11 +++
>  arch/arm/cpu/arm926ejs/davinci/spl_spi_flash.c   |   25 ++++++
>  arch/arm/cpu/arm926ejs/davinci/spl_ymodem.c      |   41 ++++++++++
>  arch/arm/include/asm/arch-davinci/davinci_boot.h |   25 ++++++
>  include/configs/cam_enc_4xx.h                    |   12 +--
>  include/configs/da850evm.h                       |   19 +++--
>  include/configs/hawkboard.h                      |   11 +--
>  10 files changed, 247 insertions(+), 30 deletions(-)
>  create mode 100644 arch/arm/cpu/arm926ejs/davinci/spl_mmc.c
>  create mode 100644 arch/arm/cpu/arm926ejs/davinci/spl_nand.c
>  create mode 100644 arch/arm/cpu/arm926ejs/davinci/spl_spi_flash.c
>  create mode 100644 arch/arm/cpu/arm926ejs/davinci/spl_ymodem.c
>  create mode 100644 arch/arm/include/asm/arch-davinci/davinci_boot.h
>
> diff --git a/arch/arm/cpu/arm926ejs/davinci/Makefile
> b/arch/arm/cpu/arm926ejs/davinci/Makefile
> index da7efac..12bd37a 100644
> --- a/arch/arm/cpu/arm926ejs/davinci/Makefile
> +++ b/arch/arm/cpu/arm926ejs/davinci/Makefile
> @@ -40,6 +40,11 @@ ifdef CONFIG_SPL_BUILD
>  COBJS-y        += spl.o
>  COBJS-$(CONFIG_SOC_DM365)      += dm365_lowlevel.o
>  COBJS-$(CONFIG_SOC_DA8XX)      += da850_lowlevel.o
> +
> +COBJS-$(CONFIG_SPL_NAND_SUPPORT)       += spl_nand.o
> +COBJS-$(CONFIG_SPL_SPI_FLASH_SUPPORT)  += spl_spi_flash.o
> +COBJS-$(CONFIG_SPL_YMODEM_SUPPORT)     += spl_ymodem.o
> +COBJS-$(CONFIG_SPL_MMC_SUPPORT)                += spl_mmc.o
>  endif
>
>  SOBJS  = reset.o
> diff --git a/arch/arm/cpu/arm926ejs/davinci/spl.c
> b/arch/arm/cpu/arm926ejs/davinci/spl.c
> index 74632e5..a8c318c 100644
> --- a/arch/arm/cpu/arm926ejs/davinci/spl.c
> +++ b/arch/arm/cpu/arm926ejs/davinci/spl.c
> @@ -25,9 +25,11 @@
>  #include <asm/utils.h>
>  #include <nand.h>
>  #include <asm/arch/dm365_lowlevel.h>
> +#include <asm/arch/davinci_boot.h>
>  #include <ns16550.h>
>  #include <malloc.h>
>  #include <spi_flash.h>
> +#include <linux/compiler.h>
>
>  #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
>
> @@ -72,25 +74,92 @@ void board_init_f(ulong dummy)
>        relocate_code(CONFIG_SPL_STACK, NULL, CONFIG_SPL_TEXT_BASE);
>  }
>
> +u32 davinci_boot_device(void){
> +#ifdef CONFIG_SOC_DA8XX
> +       u32 bootmode = ((*((vu_long*)0x01C14020)) & 0x1F);


You should probably introduce defines for the address and the bitmask. How
about using readl?


> +       switch(bootmode){
> +       case 0x0E:      /* NAND 8  */
> +       case 0x10:      /* NAND 16 */
> +               return BOOT_DEVICE_NAND;
> +       case 0x0A:
> +       case 0x0C:
> +               return BOOT_DEVICE_SPI_FLASH;
> +       case 0x16:      /* UART0 */
> +       case 0x17:      /* UART1 */
> +       case 0x14:      /* UART2 */
> +               return BOOT_DEVICE_UART;
> +       case 0x1C:      /* MMC/SD */
> +               return BOOT_DEVICE_MMC;
> +       default:
> +               return BOOT_DEVICE_NONE;
> +       }


Nice :-)


> +#else
> +#ifdef
> +#endif CONFIG_SPL_NAND_SUPPORT
> +       return BOOT_DEVICE_NAND;
> +#endif
> +#ifdef BOOT_DEVICE_SPI_FLASH
> +       return BOOT_DEVICE_SPI_FLASH;
> +#endif
> +#ifdef CONFIG_SPL_YMODEM_SUPPORT
> +       return BOOT_DEVICE_UART;
> +#endif
> +#ifdef CONFIG_SPL_MMC_SUPPORT
> +       return BOOT_DEVICE_MMC;
> +#endif
> +}
> +
>  void board_init_r(gd_t *id, ulong dummy)
>  {
> -#ifdef CONFIG_SPL_NAND_LOAD
> -       nand_init();
> -       puts("Nand boot...\n");
> -       nand_boot();
> -#endif
> -#ifdef CONFIG_SPL_SPI_LOAD
> -       mem_malloc_init(CONFIG_SYS_TEXT_BASE - CONFIG_SYS_MALLOC_LEN,
> -                       CONFIG_SYS_MALLOC_LEN);
> +       u32 boot_device;
> +       void (*uboot)(void) __noreturn;
> +
> +       mem_malloc_init(CONFIG_SYS_SPL_MALLOC_START,
> +                       CONFIG_SYS_SPL_MALLOC_SIZE);
>
>        gd = &gdata;
>        gd->bd = &bdata;
>        gd->flags |= GD_FLG_RELOC;
> +#ifdef CONFIG_SPL_SERIAL_SUPPORT
>        gd->baudrate = CONFIG_BAUDRATE;
> -       serial_init();          /* serial communications setup */
> +       serial_init();
>        gd->have_console = 1;
> +#endif
>
> -       puts("SPI boot...\n");
> -       spi_boot();
> +       boot_device = davinci_boot_device();
> +       debug("boot device - %d\n", boot_device);
> +       switch (boot_device) {
> +#ifdef CONFIG_SPL_NAND_SUPPORT
> +       case BOOT_DEVICE_NAND:
> +               puts("Booting from nand flash ...\n");
> +               spl_nand_load_image();
> +               break;
> +#endif
> +#ifdef CONFIG_SPL_SPI_FLASH_SUPPORT
> +       case BOOT_DEVICE_SPI_FLASH:
> +               puts("Booting from spi flash ...\n");
> +               spl_spi_flash_load_image();
> +               break;
>  #endif
> +#ifdef CONFIG_SPL_YMODEM_SUPPORT
> +       case BOOT_DEVICE_UART:
> +               puts("Booting from uart ...\n");
> +               spl_ymodem_load_image();
> +               break;
> +#endif
> +#ifdef CONFIG_SPL_MMC_SUPPORT
> +       case BOOT_DEVICE_MMC:
> +               puts("Booting from mmc/sd card...\n");
> +               spl_mmc_load_image();
> +               break;
> +#endif
> +       default:
> +               printf("SPL: Un-supported Boot Device - %d!!!\n",
> boot_device);
> +               hang();
> +               break;
> +       }
> +
> +       puts("Jump to U-Boot image...\n");
> +       uboot = (void *) CONFIG_SYS_TEXT_BASE;
> +       (*uboot)();
>  }
> diff --git a/arch/arm/cpu/arm926ejs/davinci/spl_mmc.c
> b/arch/arm/cpu/arm926ejs/davinci/spl_mmc.c
> new file mode 100644
> index 0000000..520ecd1
> --- /dev/null
> +++ b/arch/arm/cpu/arm926ejs/davinci/spl_mmc.c
> @@ -0,0 +1,37 @@
> +#include <common.h>
> +#include <asm/u-boot.h>
> +#include <asm/utils.h>
> +#include <mmc.h>
> +#include <asm/arch/sdmmc_defs.h>
> +
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +void spl_mmc_load_image(void)
> +{
> +       int ret;
> +       struct mmc *mmc;
> +
> +       mmc_initialize(gd->bd);
> +       /* We register only one device. So, the dev id is always 0 */
> +       mmc = find_mmc_device(0);
> +       if (!mmc) {
> +               puts("spl: mmc device not found!!\n");
> +               hang();
> +       }
> +
> +       ret = mmc_init(mmc);
> +       if (ret) {
> +               printf("spl: mmc init failed: err - %d\n", ret);
> +               hang();
> +       }
> +
> +       ret = mmc->block_dev.block_read(0,
> CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR,
> +                                       CONFIG_SYS_U_BOOT_MAX_SIZE_SECTORS,
> +                                       (void *) CONFIG_SYS_TEXT_BASE);
> +       if (ret < 0) {
> +               printf("spl: mmc blk read err - %d\n", ret);
> +               hang();
> +       }
> +
> +       debug("Loaded %d sectors from SD/MMC card\n",
> CONFIG_SYS_U_BOOT_MAX_SIZE_SECTORS);
> +}
> diff --git a/arch/arm/cpu/arm926ejs/davinci/spl_nand.c
> b/arch/arm/cpu/arm926ejs/davinci/spl_nand.c
> new file mode 100644
> index 0000000..bad1e8f
> --- /dev/null
> +++ b/arch/arm/cpu/arm926ejs/davinci/spl_nand.c
> @@ -0,0 +1,11 @@
> +#include <common.h>
> +#include <nand.h>
> +
> +void spl_nand_load_image(void)
> +{
> +       nand_init();
> +       nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
> +                       CONFIG_SYS_NAND_U_BOOT_SIZE,
> +                       (void *) CONFIG_SYS_TEXT_BASE);
> +       debug("Loaded %d bytes from NAND flash\n",
> CONFIG_SYS_NAND_U_BOOT_SIZE);



Why not use the code from drivers/mtd/nand/nand_spl_load.c?

+}
> diff --git a/arch/arm/cpu/arm926ejs/davinci/spl_spi_flash.c
> b/arch/arm/cpu/arm926ejs/davinci/spl_spi_flash.c
> new file mode 100644
> index 0000000..2d5b045
> --- /dev/null
> +++ b/arch/arm/cpu/arm926ejs/davinci/spl_spi_flash.c
> @@ -0,0 +1,25 @@
> +#include <common.h>
> +#include <spi_flash.h>
> +
> +void spl_spi_flash_load_image(void)
> +{
> +       int ret;
> +       struct spi_flash *flash;
> +
> +       flash = spi_flash_probe(CONFIG_SPL_SPI_BUS, CONFIG_SPL_SPI_CS,
> +                               CONFIG_SF_DEFAULT_SPEED, SPI_MODE_3);
> +       if (!flash) {
> +               puts("spl: spi flash probe failed.\n");
> +               hang();
> +       }
> +
> +       ret = spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS,
> +                            CONFIG_SYS_SPI_U_BOOT_SIZE,
> +                            (void *) CONFIG_SYS_TEXT_BASE);


This duplicates the code in drivers/mtd/spi/spi_spl_load.c.


> +       if (ret < 0) {
> +               printf("spl: spi flash read err - %d\n", ret);
> +               hang();
> +       }
> +
> +       debug("Loaded %d bytes from SPI flash\n",
> CONFIG_SYS_SPI_U_BOOT_SIZE);
> +}
> diff --git a/arch/arm/cpu/arm926ejs/davinci/spl_ymodem.c
> b/arch/arm/cpu/arm926ejs/davinci/spl_ymodem.c
> new file mode 100644
> index 0000000..be6786b
> --- /dev/null
> +++ b/arch/arm/cpu/arm926ejs/davinci/spl_ymodem.c
> @@ -0,0 +1,41 @@
> +#include <common.h>
> +#include <xyzModem.h>
> +#include <asm/u-boot.h>
> +#include <asm/utils.h>
> +
> +#define BUF_SIZE 1024
> +
> +static int getcymodem(void) {
> +       if (tstc())
> +               return (getc());
> +       return -1;
> +}
> +
> +void spl_ymodem_load_image(void)
> +{
> +       int size;
> +       int err;
> +       int res;
> +       connection_info_t info;
> +       ulong store_addr = ~0;
> +
> +       size = 0;
> +       info.mode = xyzModem_ymodem;
> +       res = xyzModem_stream_open (&info, &err);
> +       if (!res) {
> +               store_addr = CONFIG_SYS_TEXT_BASE;
> +               while ((res =
> +                       xyzModem_stream_read ((char*)store_addr, 1024,
> &err)) > 0) {
> +                       store_addr += res;
> +                       size += res;
> +               }
> +       } else {
> +               printf("spl: ymodem err - %s\n", xyzModem_error(err));
> +               hang();
> +       }
> +
> +       xyzModem_stream_close (&err);
> +       xyzModem_stream_terminate (false, &getcymodem);
> +
> +       debug("Loaded %d bytes from UART\n", size);
> +}
> diff --git a/arch/arm/include/asm/arch-davinci/davinci_boot.h
> b/arch/arm/include/asm/arch-davinci/davinci_boot.h
> new file mode 100644
> index 0000000..5d553ee
> --- /dev/null
> +++ b/arch/arm/include/asm/arch-davinci/davinci_boot.h
> @@ -0,0 +1,25 @@
> +#ifndef        _DAVINCI_BOOT_H_
> +#define        _DAVINCI_BOOT_H_
> +
> +/* Boot device */
> +#define BOOT_DEVICE_NONE        0
> +#define BOOT_DEVICE_NAND        1
> +#define BOOT_DEVICE_SPI_FLASH   2
> +#define BOOT_DEVICE_UART        3
> +#define BOOT_DEVICE_MMC         4
> +
> +u32 davinci_boot_device(void);
> +
> +/* NAND SPL functions */
> +void spl_nand_load_image(void);
> +
> +/* SPI FLASH SPL functions */
> +void spl_spi_flash_load_image(void);
> +
> +/* YMODEM SPL functions */
> +void spl_ymodem_load_image(void);
> +
> +/* MMC SPL functions */
> +void spl_mmc_load_image(void);
> +
> +#endif /* _DAVINCI_BOOT_H_ */
> diff --git a/include/configs/cam_enc_4xx.h b/include/configs/cam_enc_4xx.h
> index 71faf1c..58dde89 100644
> --- a/include/configs/cam_enc_4xx.h
> +++ b/include/configs/cam_enc_4xx.h
> @@ -219,18 +219,18 @@
>
>  /* Defines for SPL */
>  #define CONFIG_SPL
> +#define CONFIG_SPL_LDSCRIPT            "$(BOARDDIR)/u-boot-spl.lds"
> +#define CONFIG_SPL_STACK               (0x00010000 + 0x7f00)
> +#define CONFIG_SPL_TEXT_BASE           0x00000020
> /*CONFIG_SYS_SRAM_START*/
> +#define CONFIG_SYS_SPL_MALLOC_START    (CONFIG_SYS_TEXT_BASE -
> CONFIG_SYS_MALLOC_LEN)
> +#define CONFIG_SYS_SPL_MALLOC_SIZE     CONFIG_SYS_MALLOC_LEN
> +#define CONFIG_SPL_MAX_SIZE            12320
>  #define CONFIG_SPL_LIBGENERIC_SUPPORT
>  #define CONFIG_SPL_NAND_SUPPORT
>  #define CONFIG_SPL_NAND_SIMPLE
> -#define CONFIG_SPL_NAND_LOAD
>  #define CONFIG_SYS_NAND_HW_ECC_OOBFIRST
>  #define CONFIG_SPL_SERIAL_SUPPORT
>  #define CONFIG_SPL_POST_MEM_SUPPORT
> -#define CONFIG_SPL_LDSCRIPT            "$(BOARDDIR)/u-boot-spl.lds"
> -#define CONFIG_SPL_STACK               (0x00010000 + 0x7f00)
> -
> -#define CONFIG_SPL_TEXT_BASE           0x00000020
> /*CONFIG_SYS_SRAM_START*/
> -#define CONFIG_SPL_MAX_SIZE            12320
>
>  #ifndef CONFIG_SPL_BUILD
>  #define CONFIG_SYS_TEXT_BASE           0x81080000
> diff --git a/include/configs/da850evm.h b/include/configs/da850evm.h
> index 989472b..e027fe7 100644
> --- a/include/configs/da850evm.h
> +++ b/include/configs/da850evm.h
> @@ -315,20 +315,23 @@
>
>  /* defines for SPL */
>  #define CONFIG_SPL
> +#define CONFIG_SPL_LDSCRIPT
>  "board/$(BOARDDIR)/u-boot-spl-da850evm.lds"
> +#define CONFIG_SPL_STACK               0x8001ff00
> +#define CONFIG_SPL_TEXT_BASE           0x80000000
> +#define CONFIG_SYS_SPL_MALLOC_START    (CONFIG_SYS_TEXT_BASE -
> CONFIG_SYS_MALLOC_LEN)
> +#define CONFIG_SYS_SPL_MALLOC_SIZE     CONFIG_SYS_MALLOC_LEN
> +#define CONFIG_SPL_MAX_SIZE            32768
> +#define CONFIG_SPL_LIBCOMMON_SUPPORT
> +#define CONFIG_SPL_LIBGENERIC_SUPPORT
>  #define CONFIG_SPL_SPI_SUPPORT
>  #define CONFIG_SPL_SPI_FLASH_SUPPORT
> -#define CONFIG_SPL_SPI_LOAD
>  #define CONFIG_SPL_SPI_BUS 0
>  #define CONFIG_SPL_SPI_CS 0
> -#define CONFIG_SPL_SERIAL_SUPPORT
> -#define CONFIG_SPL_LIBCOMMON_SUPPORT
> -#define CONFIG_SPL_LIBGENERIC_SUPPORT
> -#define CONFIG_SPL_LDSCRIPT    "board/$(BOARDDIR)/u-boot-spl-da850evm.lds"
> -#define CONFIG_SPL_STACK       0x8001ff00
> -#define CONFIG_SPL_TEXT_BASE   0x80000000
> -#define CONFIG_SPL_MAX_SIZE    32768
>  #define CONFIG_SYS_SPI_U_BOOT_OFFS     0x8000
>  #define CONFIG_SYS_SPI_U_BOOT_SIZE     0x30000
> +#define CONFIG_SPL_SERIAL_SUPPORT
> +#define CONFIG_SPL_YMODEM_SUPPORT
> +
>
>  /* additions for new relocation code, must added to all boards */
>  #define CONFIG_SYS_SDRAM_BASE          0xc0000000
> diff --git a/include/configs/hawkboard.h b/include/configs/hawkboard.h
> index 6d2d4fb..a3b8d5d 100644
> --- a/include/configs/hawkboard.h
> +++ b/include/configs/hawkboard.h
> @@ -59,14 +59,15 @@
>
>  /* Spl */
>  #define CONFIG_SPL
> -#define CONFIG_SPL_NAND_SUPPORT
> -#define CONFIG_SPL_NAND_SIMPLE
> -#define CONFIG_SPL_NAND_LOAD
> -#define CONFIG_SPL_LIBGENERIC_SUPPORT  /* for udelay and __div64_32 for
> NAND */
> -#define CONFIG_SPL_SERIAL_SUPPORT
>  #define CONFIG_SPL_LDSCRIPT
>  "board/$(BOARDDIR)/u-boot-spl-hawk.lds"
>  #define CONFIG_SPL_TEXT_BASE           0xc1080000
>  #define CONFIG_SPL_STACK               CONFIG_SYS_INIT_SP_ADDR
> +#define CONFIG_SYS_SPL_MALLOC_START    (CONFIG_SYS_TEXT_BASE -
> CONFIG_SYS_MALLOC_LEN)
> +#define CONFIG_SYS_SPL_MALLOC_SIZE     CONFIG_SYS_MALLOC_LEN
> +#define CONFIG_SPL_LIBGENERIC_SUPPORT  /* for udelay and __div64_32 for
> NAND */
> +#define CONFIG_SPL_NAND_SUPPORT
> +#define CONFIG_SPL_NAND_SIMPLE
> +#define CONFIG_SPL_SERIAL_SUPPORT
>
>  /*
>  * Memory Info
> --
> 1.7.10
>
> Regards, Christian

> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de <javascript:;>
> http://lists.denx.de/mailman/listinfo/u-boot
>


More information about the U-Boot mailing list