omap: add MMC and FAT support to SPL
authorAneesh V <aneesh@ti.com>
Thu, 21 Jul 2011 13:10:27 +0000 (09:10 -0400)
committerU-Boot <uboot@aari01-12.(none)>
Wed, 3 Aug 2011 10:49:20 +0000 (12:49 +0200)
- Add MMC raw and FAT mode boot support for OMAP
- Provide a means by which parameters passed by ROM-code
  can be saved in u-boot.
- Save boot mode related information passed by OMAP4 ROM-code
  and use it to determine where to load the u-boot from
- Assumes that the image has a mkimage header. Gets the
  payload size and load address from this header. If the
  header is not detected assume u-boot.bin as payload

Signed-off-by: Aneesh V <aneesh@ti.com>
Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>
arch/arm/cpu/armv7/cpu.c
arch/arm/cpu/armv7/omap-common/spl.c
arch/arm/cpu/armv7/omap4/board.c
arch/arm/cpu/armv7/omap4/lowlevel_init.S
arch/arm/cpu/armv7/start.S
arch/arm/include/asm/arch-omap4/omap4.h
arch/arm/include/asm/omap_common.h
include/configs/omap4_panda.h
include/configs/omap4_sdp4430.h

index def9ced64faffdf744f65f673ee8002cb8c8c40f..091e3e0842d5506b2b6351a404ee06e8cb75d594 100644 (file)
 #include <asm/cache.h>
 #include <asm/armv7.h>
 
+void save_boot_params_default(u32 r0, u32 r1, u32 r2, u32 r3)
+{
+}
+
+void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3)
+       __attribute__((weak, alias("save_boot_params_default")));
+
 int cleanup_before_linux(void)
 {
        /*
index b2015431e3258e18c8059881bec1ce2c63b3a11d..d1776522b7fa5d00e936eb07f9050a547baeffe6 100644 (file)
  */
 #include <common.h>
 #include <asm/u-boot.h>
+#include <asm/utils.h>
 #include <asm/arch/sys_proto.h>
+#include <mmc.h>
+#include <fat.h>
 #include <timestamp_autogenerated.h>
 #include <version_autogenerated.h>
+#include <asm/omap_common.h>
+#include <asm/arch/mmc_host_def.h>
+#include <i2c.h>
+#include <image.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
 /* Define global data structure pointer to it*/
 static gd_t gdata __attribute__ ((section(".data")));
 static bd_t bdata __attribute__ ((section(".data")));
+static const char *image_name;
+static u8 image_os;
+static u32 image_load_addr;
+static u32 image_entry_point;
+static u32 image_size;
 
 inline void hang(void)
 {
@@ -53,10 +65,188 @@ void board_init_f(ulong dummy)
        relocate_code(CONFIG_SPL_STACK, &gdata, CONFIG_SPL_TEXT_BASE);
 }
 
+#ifdef CONFIG_GENERIC_MMC
+int board_mmc_init(bd_t *bis)
+{
+       switch (omap_boot_device()) {
+       case BOOT_DEVICE_MMC1:
+               omap_mmc_init(0);
+               break;
+       case BOOT_DEVICE_MMC2:
+               omap_mmc_init(1);
+               break;
+       }
+       return 0;
+}
+#endif
+
+static void parse_image_header(const struct image_header *header)
+{
+       u32 header_size = sizeof(struct image_header);
+
+       if (__be32_to_cpu(header->ih_magic) == IH_MAGIC) {
+               image_size = __be32_to_cpu(header->ih_size) + header_size;
+               image_entry_point = __be32_to_cpu(header->ih_load);
+               /* Load including the header */
+               image_load_addr = image_entry_point - header_size;
+               image_os = header->ih_os;
+               image_name = (const char *)&header->ih_name;
+               debug("spl: payload image: %s load addr: 0x%x size: %d\n",
+                       image_name, image_load_addr, image_size);
+       } else {
+               /* Signature not found - assume u-boot.bin */
+               printf("mkimage signature not found - ih_magic = %x\n",
+                       header->ih_magic);
+               puts("Assuming u-boot.bin ..\n");
+               /* Let's assume U-Boot will not be more than 200 KB */
+               image_size = 200 * 1024;
+               image_entry_point = CONFIG_SYS_TEXT_BASE;
+               image_load_addr = CONFIG_SYS_TEXT_BASE;
+               image_os = IH_OS_U_BOOT;
+               image_name = "U-Boot";
+       }
+}
+
+static void mmc_load_image_raw(struct mmc *mmc)
+{
+       u32 image_size_sectors, err;
+       const struct image_header *header;
+
+       header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
+                                               sizeof(struct image_header));
+
+       /* read image header to find the image size & load address */
+       err = mmc->block_dev.block_read(0,
+                       CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR, 1,
+                       (void *)header);
+
+       if (err <= 0)
+               goto end;
+
+       parse_image_header(header);
+
+       /* convert size to sectors - round up */
+       image_size_sectors = (image_size + MMCSD_SECTOR_SIZE - 1) /
+                               MMCSD_SECTOR_SIZE;
+
+       /* Read the header too to avoid extra memcpy */
+       err = mmc->block_dev.block_read(0,
+                       CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR,
+                       image_size_sectors, (void *)image_load_addr);
+
+end:
+       if (err <= 0) {
+               printf("spl: mmc blk read err - %d\n", err);
+               hang();
+       }
+}
+
+static void mmc_load_image_fat(struct mmc *mmc)
+{
+       s32 err;
+       struct image_header *header;
+
+       header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
+                                               sizeof(struct image_header));
+
+       err = fat_register_device(&mmc->block_dev,
+                               CONFIG_SYS_MMC_SD_FAT_BOOT_PARTITION);
+       if (err) {
+               printf("spl: fat register err - %d\n", err);
+               hang();
+       }
+
+       err = file_fat_read(CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME,
+                               (u8 *)header, sizeof(struct image_header));
+       if (err <= 0)
+               goto end;
+
+       parse_image_header(header);
+
+       err = file_fat_read(CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME,
+                               (u8 *)image_load_addr, 0);
+
+end:
+       if (err <= 0) {
+               printf("spl: error reading image %s, err - %d\n",
+                       CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME, err);
+               hang();
+       }
+}
+
+static void mmc_load_image(void)
+{
+       struct mmc *mmc;
+       int err;
+       u32 boot_mode;
+
+       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();
+       }
+
+       err = mmc_init(mmc);
+       if (err) {
+               printf("spl: mmc init failed: err - %d\n", err);
+               hang();
+       }
+
+       boot_mode = omap_boot_mode();
+       if (boot_mode == MMCSD_MODE_RAW) {
+               debug("boot mode - RAW\n");
+               mmc_load_image_raw(mmc);
+       } else if (boot_mode == MMCSD_MODE_FAT) {
+               debug("boot mode - FAT\n");
+               mmc_load_image_fat(mmc);
+       } else {
+               puts("spl: wrong MMC boot mode\n");
+               hang();
+       }
+}
+
+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;
+
+       image_entry();
+}
+
+void jump_to_image_no_args(void) __attribute__ ((noreturn));
 void board_init_r(gd_t *id, ulong dummy)
 {
-       for (;;)
-               ;
+       u32 boot_device;
+       debug(">>spl:board_init_r()\n");
+
+       timer_init();
+       i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
+
+       boot_device = omap_boot_device();
+       debug("boot device - %d\n", boot_device);
+       switch (boot_device) {
+       case BOOT_DEVICE_MMC1:
+       case BOOT_DEVICE_MMC2:
+               mmc_load_image();
+               break;
+       default:
+               printf("SPL: Un-supported Boot Device - %d!!!\n", boot_device);
+               hang();
+               break;
+       }
+
+       switch (image_os) {
+       case IH_OS_U_BOOT:
+               debug("Jumping to U-Boot\n");
+               jump_to_image_no_args();
+               break;
+       default:
+               puts("Unsupported OS image.. Jumping nevertheless..\n");
+               jump_to_image_no_args();
+       }
 }
 
 void preloader_console_init(void)
index 54dd509194735f1610b8a0a1a2fe3c2e25119c53..2e5739a1dd505ccabc552bee36a35121d4bc2c99 100644 (file)
@@ -39,6 +39,27 @@ DECLARE_GLOBAL_DATA_PTR;
 
 u32 *const omap4_revision = (u32 *)OMAP4_SRAM_SCRATCH_OMAP4_REV;
 
+#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 omap4_boot_device = BOOT_DEVICE_MMC1;
+u32 omap4_boot_mode = MMCSD_MODE_FAT;
+
+u32 omap_boot_device(void)
+{
+       return omap4_boot_device;
+}
+
+u32 omap_boot_mode(void)
+{
+       return omap4_boot_mode;
+}
+#endif
+
 void do_set_mux(u32 base, struct pad_conf_entry const *array, int size)
 {
        int i;
index 6abfbbaa13115362b189595030d14e2bd98d98bb..91525ecd466c241209ea88cb90dd4c22140f8d5e 100644 (file)
  */
 
 #include <asm/arch/omap4.h>
+#ifdef CONFIG_SPL_BUILD
+.global save_boot_params
+save_boot_params:
+       /*
+        * See if the rom code passed pointer is valid:
+        * It is not valid if it is not in non-secure SRAM
+        * This may happen if you are booting with the help of
+        * debugger
+        */
+       ldr     r2, =NON_SECURE_SRAM_START
+       cmp     r2, r0
+       bgt     1f
+       ldr     r2, =NON_SECURE_SRAM_END
+       cmp     r2, r0
+       blt     1f
+
+       /* Store the boot device in omap4_boot_device */
+       ldr     r2, [r0, #BOOT_DEVICE_OFFSET]   @ r1 <- value of boot device
+       and     r2, #BOOT_DEVICE_MASK
+       ldr     r3, =omap4_boot_device
+       str     r2, [r3]                        @ omap4_boot_device <- r1
+
+       /* Store the boot mode (raw/FAT) in omap4_boot_mode */
+       ldr     r2, [r0, #DEV_DESC_PTR_OFFSET]  @ get the device descriptor ptr
+       ldr     r2, [r2, #DEV_DATA_PTR_OFFSET]  @ get the pDeviceData ptr
+       ldr     r2, [r2, #BOOT_MODE_OFFSET]     @ get the boot mode
+       ldr     r3, =omap4_boot_mode
+       str     r2, [r3]
+1:
+       bx      lr
+#endif
 
 .globl lowlevel_init
 lowlevel_init:
index 02a25354e926a15dd5ed453d91174b03dae29cbf..db8e9d2f189523b3c3151b890a63550c3693ebd6 100644 (file)
@@ -134,6 +134,7 @@ IRQ_STACK_START_IN:
  */
 
 reset:
+       bl      save_boot_params
        /*
         * set the cpu to SVC32 mode
         */
index a8dbedb45d489dc666bc605b62f41ef80ec77da8..563544fb010612ccbb3c6aa085769d3c77ed8e5e 100644 (file)
@@ -144,4 +144,12 @@ struct s32ktimer {
 #define OMAP4430_ES2_2 0x44300220
 #define OMAP4430_ES2_3 0x44300230
 
+/* ROM code defines */
+/* Boot device */
+#define BOOT_DEVICE_MASK       0xFF
+#define BOOT_DEVICE_OFFSET     0x8
+#define DEV_DESC_PTR_OFFSET    0x4
+#define DEV_DATA_PTR_OFFSET    0x18
+#define BOOT_MODE_OFFSET       0x8
+
 #endif
index 69d53d2c7299a402442bb57e6db55e40939a9ae3..d3cb857282ad7b74b62e3b05bb3322a14be74354 100644 (file)
 
 void preloader_console_init(void);
 
+/* Boot device */
+#define BOOT_DEVICE_NONE       0
+#define BOOT_DEVICE_XIP                1
+#define BOOT_DEVICE_XIPWAIT    2
+#define BOOT_DEVICE_NAND       3
+#define BOOT_DEVICE_ONE_NAND   4
+#define BOOT_DEVICE_MMC1       5
+#define BOOT_DEVICE_MMC2       6
+
+/* Boot type */
+#define        MMCSD_MODE_UNDEFINED    0
+#define MMCSD_MODE_RAW         1
+#define MMCSD_MODE_FAT         2
+
+u32 omap_boot_device(void);
+u32 omap_boot_mode(void);
+
 #endif /* _OMAP_COMMON_H_ */
index 1112362b3231304dc95b5874751f29e336cbb212..f6f283a73524ddc18ece7f015defc22d934ed6ef 100644 (file)
 #define CONFIG_SPL_BSS_START_ADDR      0x80000000
 #define CONFIG_SPL_BSS_MAX_SIZE                0x80000         /* 512 KB */
 
+#define CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR        0x300 /* address 0x60000 */
+#define CONFIG_SYS_U_BOOT_MAX_SIZE_SECTORS     0x200 /* 256 KB */
+#define CONFIG_SYS_MMC_SD_FAT_BOOT_PARTITION   1
+#define CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME       "u-boot.img"
+
 #define CONFIG_SPL_LIBCOMMON_SUPPORT
 #define CONFIG_SPL_LIBDISK_SUPPORT
 #define CONFIG_SPL_I2C_SUPPORT
index 6a6be9e9b853cdff637f73ff97f2f0abe80511b1..346763d722bcc29888d1200c830a5fb896add0bd 100644 (file)
 #define CONFIG_SPL_BSS_START_ADDR      0x80000000
 #define CONFIG_SPL_BSS_MAX_SIZE                0x80000         /* 512 KB */
 
+#define CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR        0x300 /* address 0x60000 */
+#define CONFIG_SYS_U_BOOT_MAX_SIZE_SECTORS     0x200 /* 256 KB */
+#define CONFIG_SYS_MMC_SD_FAT_BOOT_PARTITION   1
+#define CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME       "u-boot.img"
+
 #define CONFIG_SPL_LIBCOMMON_SUPPORT
 #define CONFIG_SPL_LIBDISK_SUPPORT
 #define CONFIG_SPL_I2C_SUPPORT