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

Mikhail Kshevetskiy mikhail.kshevetskiy at gmail.com
Mon Jul 9 05:31:32 CEST 2012


This patch allow us to have a universal spl that detects a boot
device and select a corresponding boot algorithm for main u-boot part
(SOC_DA8XX only)

This patch create copy copy of drivers/mtd/nand/nand_spl_load.c and
drivers/mtd/spi/spi_spl_load.c for the following reasons:
 * avoid jump to main u-boot code just after its loading (required
   for the next patch: spl - add compressed u-boot image support)
 * makes a structure similar to omap3 sources

Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy at gmail.com>
---
Change for v2:
 * fix checkpatch warnings
 * defines for constants
 * use readl() to read a BOOTCFG_REG
 * improve patch description
---
 arch/arm/cpu/arm926ejs/davinci/Makefile          |    5 ++
 arch/arm/cpu/arm926ejs/davinci/spl.c             |   91 +++++++++++++++++++---
 arch/arm/cpu/arm926ejs/davinci/spl_mmc.c         |   39 ++++++++++
 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      |   42 ++++++++++
 arch/arm/include/asm/arch-davinci/davinci_boot.h |   50 ++++++++++++
 include/configs/cam_enc_4xx.h                    |   12 +--
 include/configs/da850evm.h                       |   19 +++--
 include/configs/hawkboard.h                      |   11 +--
 10 files changed, 275 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..50b4bbc 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 = readl(BOOTCFG_REG) & BOOTCFG_REG_DEVICE_MASK;
+	switch (bootmode) {
+	case BOOTCFG_DEVICE_NAND8:
+	case BOOTCFG_DEVICE_NAND16:
+		return BOOT_DEVICE_TYPE_NAND;
+	case BOOTCFG_DEVICE_SPI0_FLASH:
+	case BOOTCFG_DEVICE_SPI1_FLASH:
+		return BOOT_DEVICE_TYPE_SPI_FLASH;
+	case BOOTCFG_DEVICE_UART0:
+	case BOOTCFG_DEVICE_UART1:
+	case BOOTCFG_DEVICE_UART2:
+		return BOOT_DEVICE_TYPE_UART;
+	case BOOTCFG_DEVICE_MMC_OR_SD0:
+		return BOOT_DEVICE_TYPE_MMC;
+	default:
+		return BOOT_DEVICE_TYPE_NONE;
+	}
+#else
+#ifdef
+#endif CONFIG_SPL_NAND_SUPPORT
+	return BOOT_DEVICE_TYPE_NAND;
+#endif
+#ifdef BOOT_DEVICE_SPI_FLASH
+	return BOOT_DEVICE_TYPE_SPI_FLASH;
+#endif
+#ifdef CONFIG_SPL_YMODEM_SUPPORT
+	return BOOT_DEVICE_TYPE_UART;
+#endif
+#ifdef CONFIG_SPL_MMC_SUPPORT
+	return BOOT_DEVICE_TYPE_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_TYPE_NAND:
+		puts("Booting from nand flash ...\n");
+		spl_nand_load_image();
+		break;
+#endif
+#ifdef CONFIG_SPL_SPI_FLASH_SUPPORT
+	case BOOT_DEVICE_TYPE_SPI_FLASH:
+		puts("Booting from spi flash ...\n");
+		spl_spi_flash_load_image();
+		break;
 #endif
+#ifdef CONFIG_SPL_YMODEM_SUPPORT
+	case BOOT_DEVICE_TYPE_UART:
+		puts("Booting from uart ...\n");
+		spl_ymodem_load_image();
+		break;
+#endif
+#ifdef CONFIG_SPL_MMC_SUPPORT
+	case BOOT_DEVICE_TYPE_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..1a551e9
--- /dev/null
+++ b/arch/arm/cpu/arm926ejs/davinci/spl_mmc.c
@@ -0,0 +1,39 @@
+#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);
+}
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..d6fadcd
--- /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);
+	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..b8c4db1
--- /dev/null
+++ b/arch/arm/cpu/arm926ejs/davinci/spl_ymodem.c
@@ -0,0 +1,42 @@
+#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..57afa24
--- /dev/null
+++ b/arch/arm/include/asm/arch-davinci/davinci_boot.h
@@ -0,0 +1,50 @@
+#ifndef	_DAVINCI_BOOT_H_
+#define	_DAVINCI_BOOT_H_
+
+#include <asm/arch/hardware.h>
+
+#define BOOTCFG_REG			(DAVINCI_BOOTCFG_BASE + 0x20)
+#define BOOTCFG_REG_DEVICE_MASK		0x1F
+
+#define BOOTCFG_DEVICE_NOR		0x02
+#define BOOTCFG_DEVICE_NAND8		0x0E
+#define BOOTCFG_DEVICE_NAND16		0x10
+#define BOOTCFG_DEVICE_MMC_OR_SD0	0x1C
+#define BOOTCFG_DEVICE_I2C0_EEPROM	0x00
+#define BOOTCFG_DEVICE_I2C1_EEPROM	0x06
+#define BOOTCFG_DEVICE_I2C0_SLAVE	0x01
+#define BOOTCFG_DEVICE_I2C1_SLAVE	0x07
+#define BOOTCFG_DEVICE_SPI0_EEPROM	0x08
+#define BOOTCFG_DEVICE_SPI1_EEPROM	0x09
+#define BOOTCFG_DEVICE_SPI0_FLASH	0x0A
+#define BOOTCFG_DEVICE_SPI1_FLASH	0x0C
+#define BOOTCFG_DEVICE_SPI0_SLAVE	0x12
+#define BOOTCFG_DEVICE_SPI1_SLAVE	0x13
+#define BOOTCFG_DEVICE_UART0		0x16
+#define BOOTCFG_DEVICE_UART1		0x17
+#define BOOTCFG_DEVICE_UART2		0x14
+#define BOOTCFG_DEVICE_HPI		0x04
+#define BOOTCFG_DEVICE_EMULATION_DEBUG	0x1E
+
+/* Boot device */
+#define BOOT_DEVICE_TYPE_NONE		0
+#define BOOT_DEVICE_TYPE_NAND		1
+#define BOOT_DEVICE_TYPE_SPI_FLASH	2
+#define BOOT_DEVICE_TYPE_UART		3
+#define BOOT_DEVICE_TYPE_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 771ac9c..590f3f8 100644
--- a/include/configs/cam_enc_4xx.h
+++ b/include/configs/cam_enc_4xx.h
@@ -217,18 +217,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 e6adb1f..7a3ec4c 100644
--- a/include/configs/da850evm.h
+++ b/include/configs/da850evm.h
@@ -313,20 +313,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 c6e8859..133fdfb 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.4



More information about the U-Boot mailing list