omap-common: add nand spl support
authorSimon Schwarz <simonschwarzcor@googlemail.com>
Wed, 14 Sep 2011 19:29:26 +0000 (15:29 -0400)
committerAlbert ARIBAUD <albert.u.boot@aribaud.net>
Fri, 30 Sep 2011 20:00:54 +0000 (22:00 +0200)
Add NAND support for the new SPL structure.

Signed-off-by: Simon Schwarz <simonschwarzcor@gmail.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>
arch/arm/cpu/armv7/omap-common/spl.c
arch/arm/cpu/armv7/omap3/board.c
arch/arm/include/asm/omap_common.h
include/nand.h

index 1d301f40c627d0164c2c86d55531c7b264e292f3..53d10bf2a57a8074ddf03399d57743e0548c8144 100644 (file)
@@ -26,6 +26,7 @@
 #include <asm/u-boot.h>
 #include <asm/utils.h>
 #include <asm/arch/sys_proto.h>
+#include <nand.h>
 #include <mmc.h>
 #include <fat.h>
 #include <timestamp_autogenerated.h>
@@ -173,7 +174,7 @@ end:
                hang();
        }
 }
-
+static void mmc_load_image(void) __attribute__((unused));
 static void mmc_load_image(void)
 {
        struct mmc *mmc;
@@ -207,12 +208,48 @@ static void mmc_load_image(void)
        }
 }
 
+#ifdef CONFIG_SPL_NAND_SUPPORT
+static void nand_load_image(void) __attribute__ ((unused));
+static void nand_load_image(void)
+{
+       struct image_header *header;
+
+       gpmc_init();
+       nand_init();
+
+       /*use CONFIG_SYS_TEXT_BASE as temporary storage area */
+       header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
+
+#ifdef CONFIG_NAND_ENV_DST
+       nand_spl_load_image(CONFIG_ENV_OFFSET,
+               CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
+       parse_image_header(header);
+       nand_spl_load_image(CONFIG_ENV_OFFSET, image_size,
+               (void *)image_load_addr);
+#ifdef CONFIG_ENV_OFFSET_REDUND
+       nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND,
+               CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
+       parse_image_header(header);
+       nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, image_size,
+               (void *)image_load_addr);
+#endif
+#endif
+       /* Load u-boot */
+       nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
+               CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
+       parse_image_header(header);
+       nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
+               image_size, (void *)image_load_addr);
+       nand_deselect();
+}
+#endif /* CONFIG_SPL_NAND_SUPPORT */
 void jump_to_image_no_args(void)
 {
        typedef void (*image_entry_noargs_t)(void)__attribute__ ((noreturn));
        image_entry_noargs_t image_entry =
                        (image_entry_noargs_t) image_entry_point;
 
+       debug("image entry point: 0x%X\n", image_entry_point);
        image_entry();
 }
 
@@ -228,10 +265,17 @@ void board_init_r(gd_t *id, ulong dummy)
        boot_device = omap_boot_device();
        debug("boot device - %d\n", boot_device);
        switch (boot_device) {
+#ifdef CONFIG_SPL_MMC_SUPPORT
        case BOOT_DEVICE_MMC1:
        case BOOT_DEVICE_MMC2:
                mmc_load_image();
                break;
+#endif
+#ifdef CONFIG_SPL_NAND_SUPPORT
+       case BOOT_DEVICE_NAND:
+               nand_load_image();
+               break;
+#endif
        default:
                printf("SPL: Un-supported Boot Device - %d!!!\n", boot_device);
                hang();
index 0448bc93ffc442fd4983f5a4f1714e44c20f9545..1b3ef69a99da3a857ed5f74ba11cbbbb0a52838e 100644 (file)
@@ -39,6 +39,7 @@
 #include <asm/cache.h>
 #include <asm/armv7.h>
 #include <asm/arch/gpio.h>
+#include <asm/omap_common.h>
 
 /* Declarations */
 extern omap3_sysinfo sysinfo;
@@ -56,6 +57,41 @@ static const struct gpio_bank gpio_bank_34xx[6] = {
 
 const struct gpio_bank *const omap_gpio_bank = gpio_bank_34xx;
 
+#ifdef CONFIG_SPL_BUILD
+/*
+* We use static variables because global data is not ready yet.
+* Initialized data is available in SPL right from the beginning.
+* We would not typically need to save these parameters in regular
+* U-Boot. This is needed only in SPL at the moment.
+*/
+u32 omap3_boot_device = BOOT_DEVICE_NAND;
+
+/* auto boot mode detection is not possible for OMAP3 - hard code */
+u32 omap_boot_mode(void)
+{
+       switch (omap_boot_device()) {
+       case BOOT_DEVICE_MMC2:
+               return MMCSD_MODE_RAW;
+       case BOOT_DEVICE_MMC1:
+               return MMCSD_MODE_FAT;
+               break;
+       case BOOT_DEVICE_NAND:
+               return NAND_MODE_HW_ECC;
+               break;
+       default:
+               puts("spl: ERROR:  unknown device - can't select boot mode\n");
+               hang();
+       }
+}
+
+u32 omap_boot_device(void)
+{
+       return omap3_boot_device;
+}
+
+#endif /* CONFIG_SPL_BUILD */
+
+
 /******************************************************************************
  * Routine: delay
  * Description: spinning delay to use before udelay works
@@ -197,6 +233,10 @@ void s_init(void)
 
        per_clocks_enable();
 
+#ifdef CONFIG_SPL_BUILD
+       preloader_console_init();
+#endif
+
        if (!in_sdram)
                mem_init();
 }
@@ -245,7 +285,7 @@ void abort(void)
 {
 }
 
-#ifdef CONFIG_NAND_OMAP_GPMC
+#if defined(CONFIG_NAND_OMAP_GPMC) & !defined(CONFIG_SPL_BUILD)
 /******************************************************************************
  * OMAP3 specific command to switch between NAND HW and SW ecc
  *****************************************************************************/
@@ -273,7 +313,7 @@ U_BOOT_CMD(
        "[hw/sw] - Switch between NAND hardware (hw) or software (sw) ecc algorithm"
 );
 
-#endif /* CONFIG_NAND_OMAP_GPMC */
+#endif /* CONFIG_NAND_OMAP_GPMC & !CONFIG_SPL_BUILD */
 
 #ifdef CONFIG_DISPLAY_BOARDINFO
 /**
@@ -410,3 +450,9 @@ void enable_caches(void)
        dcache_enable();
 }
 #endif
+
+void omap_rev_string(char *omap_rev_string)
+{
+       sprintf(omap_rev_string, "OMAP3, sorry revision detection" \
+               " unimplemented");
+}
index d3cb857282ad7b74b62e3b05bb3322a14be74354..015cede2f8ae2e69c56db17b46482a94e60bc7d9 100644 (file)
@@ -37,6 +37,7 @@
 void preloader_console_init(void);
 
 /* Boot device */
+#ifdef CONFIG_OMAP44XX /* OMAP4 */
 #define BOOT_DEVICE_NONE       0
 #define BOOT_DEVICE_XIP                1
 #define BOOT_DEVICE_XIPWAIT    2
@@ -44,13 +45,43 @@ void preloader_console_init(void);
 #define BOOT_DEVICE_ONE_NAND   4
 #define BOOT_DEVICE_MMC1       5
 #define BOOT_DEVICE_MMC2       6
+#elif CONFIG_OMAP34XX /* OMAP3 */
+#define BOOT_DEVICE_NONE       0
+#define BOOT_DEVICE_XIP                1
+#define BOOT_DEVICE_NAND       2
+#define BOOT_DEVICE_ONE_NAND   3
+#define BOOT_DEVICE_MMC2       5 /*emmc*/
+#define BOOT_DEVICE_MMC1       6
+#define BOOT_DEVICE_XIPWAIT    7
+#endif
 
 /* Boot type */
 #define        MMCSD_MODE_UNDEFINED    0
 #define MMCSD_MODE_RAW         1
 #define MMCSD_MODE_FAT         2
+#define NAND_MODE_HW_ECC       3
+
+struct spl_image_info {
+       const char *name;
+       u8 os;
+       u32 load_addr;
+       u32 entry_point;
+       u32 size;
+};
+
+extern struct spl_image_info spl_image;
 
 u32 omap_boot_device(void);
 u32 omap_boot_mode(void);
 
+
+/* SPL common function s*/
+void spl_parse_image_header(const struct image_header *header);
+
+/* NAND SPL functions */
+void spl_nand_load_image(void);
+
+/* MMC SPL functions */
+void spl_mmc_load_image(void);
+
 #endif /* _OMAP_COMMON_H_ */
index 8d94b5cbd7536e4a5492b7cb28d9c6ef34a11534..3c5ef4e3c4ef5a3cecbb8edd3f57f8ad5b859a52 100644 (file)
@@ -132,6 +132,9 @@ int nand_lock( nand_info_t *meminfo, int tight );
 int nand_unlock( nand_info_t *meminfo, ulong start, ulong length );
 int nand_get_lock_status(nand_info_t *meminfo, loff_t offset);
 
+void nand_spl_load_image(loff_t offs, unsigned int size, uchar *dst);
+void nand_deselect(void);
+
 #ifdef CONFIG_SYS_NAND_SELECT_DEVICE
 void board_nand_select_device(struct nand_chip *nand, int chip);
 #endif