]> git.sur5r.net Git - u-boot/commitdiff
spl: common: Support for USB MSD FAT image loading
authorDan Murphy <dmurphy@ti.com>
Thu, 16 Jan 2014 17:23:30 +0000 (11:23 -0600)
committerTom Rini <trini@ti.com>
Fri, 24 Jan 2014 21:59:22 +0000 (16:59 -0500)
Add SPL support to be able to detect a USB Mass Storage device
connected to a USB host.  Once a USB Mass storage device is detected
the SPL will load the u-boot.img from a FAT partition to target address.

Signed-off-by: Dan Murphy <dmurphy@ti.com>
arch/arm/include/asm/arch-am33xx/spl.h
common/Makefile
common/spl/Makefile
common/spl/spl.c
common/spl/spl_fat.c
common/spl/spl_usb.c [new file with mode: 0644]
include/spl.h
spl/Makefile

index 5cd1e95257a87441359ed421e71fd0f8888149ba..2df4114580dadd3ef6e71b6bcdfefdb9bac24961 100644 (file)
@@ -19,6 +19,7 @@
 #define BOOT_DEVICE_MMC1       7
 #define BOOT_DEVICE_MMC2       8
 #define BOOT_DEVICE_SPI                10
+#define BOOT_DEVICE_USB     13
 #define BOOT_DEVICE_UART       65
 #define BOOT_DEVICE_CPGMAC     71
 #else
 #endif
 #define BOOT_DEVICE_MMC2_2      0xFF
 
-#if defined(CONFIG_AM33XX) || defined(CONFIG_AM43XX)
-#define MMC_BOOT_DEVICES_START BOOT_DEVICE_MMC1
-#define MMC_BOOT_DEVICES_END   BOOT_DEVICE_MMC2
+#if defined(CONFIG_AM33XX)
+#define MMC_BOOT_DEVICES_START BOOT_DEVICE_MMC1
+#define MMC_BOOT_DEVICES_END   BOOT_DEVICE_MMC2
+#elif defined(CONFIG_AM43XX)
+#define MMC_BOOT_DEVICES_START BOOT_DEVICE_MMC1
+#ifdef CONFIG_SPL_USB_SUPPORT
+#define MMC_BOOT_DEVICES_END   BOOT_DEVICE_USB
+#else
+#define MMC_BOOT_DEVICES_END   BOOT_DEVICE_MMC2
+#endif
 #elif defined(CONFIG_TI81XX)
 #define MMC_BOOT_DEVICES_START BOOT_DEVICE_MMC2
 #define MMC_BOOT_DEVICES_END   BOOT_DEVICE_MMC1
index d12cba5bf0d9b5392b67217253bd50c191b5d17b..4d99ecd6168cb32f61c872f453cf1ef7cc16ffcc 100644 (file)
@@ -197,6 +197,10 @@ obj-$(CONFIG_SPL_NET_SUPPORT) += miiphyutil.o
 obj-$(CONFIG_SPL_ENV_SUPPORT) += env_attr.o
 obj-$(CONFIG_SPL_ENV_SUPPORT) += env_flags.o
 obj-$(CONFIG_SPL_ENV_SUPPORT) += env_callback.o
+ifdef CONFIG_SPL_USB_HOST_SUPPORT
+obj-$(CONFIG_SPL_USB_SUPPORT) += usb.o usb_hub.o
+obj-$(CONFIG_USB_STORAGE) += usb_storage.o
+endif
 ifneq ($(CONFIG_SPL_NET_SUPPORT),y)
 obj-$(CONFIG_ENV_IS_NOWHERE) += env_nowhere.o
 obj-$(CONFIG_ENV_IS_IN_MMC) += env_mmc.o
index c8d5963df797489c1950faf08ed2921a7410efe0..65a1484fc4e48fc6016e57c385778837599add63 100644 (file)
@@ -16,5 +16,6 @@ obj-$(CONFIG_SPL_NAND_SUPPORT) += spl_nand.o
 obj-$(CONFIG_SPL_ONENAND_SUPPORT) += spl_onenand.o
 obj-$(CONFIG_SPL_NET_SUPPORT) += spl_net.o
 obj-$(CONFIG_SPL_MMC_SUPPORT) += spl_mmc.o
+obj-$(CONFIG_SPL_USB_SUPPORT) += spl_usb.o
 obj-$(CONFIG_SPL_FAT_SUPPORT) += spl_fat.o
 endif
index da31457d5f06d6ab192ffedf1ed82974d688459c..0645cee789ff8640f12ab69de458b1cd91013eef 100644 (file)
@@ -204,6 +204,11 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
        case BOOT_DEVICE_USBETH:
                spl_net_load_image("usb_ether");
                break;
+#endif
+#ifdef CONFIG_SPL_USB_SUPPORT
+       case BOOT_DEVICE_USB:
+               spl_usb_load_image();
+               break;
 #endif
        default:
                debug("SPL: Un-supported Boot Device\n");
index 9b405840082f77abdcd225c01dc2096a97bb13a4..1e532d5963e0e0ef84bbf3a90809c9b0aafc982d 100644 (file)
@@ -28,7 +28,7 @@ static int spl_register_fat_device(block_dev_desc_t *block_dev, int partition)
        err = fat_register_device(block_dev, partition);
        if (err) {
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
-               printf("spl: fat register err - %d\n", err);
+               printf("%s: fat register err - %d\n", __func__, err);
 #endif
                hang();
        }
@@ -46,7 +46,7 @@ int spl_load_image_fat(block_dev_desc_t *block_dev,
        struct image_header *header;
 
        err = spl_register_fat_device(block_dev, partition);
-       if (err <= 0)
+       if (err)
                goto end;
 
        header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
@@ -63,8 +63,8 @@ int spl_load_image_fat(block_dev_desc_t *block_dev,
 end:
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
        if (err <= 0)
-               printf("spl: error reading image %s, err - %d\n",
-                      filename, err);
+               printf("%s: error reading image %s, err - %d\n",
+                      __func__, filename, err);
 #endif
 
        return (err <= 0);
@@ -76,15 +76,15 @@ int spl_load_image_fat_os(block_dev_desc_t *block_dev, int partition)
        int err;
 
        err = spl_register_fat_device(block_dev, partition);
-       if (err <= 0)
-               return -1;
+       if (err)
+               return err;
 
        err = file_fat_read(CONFIG_SPL_FAT_LOAD_ARGS_NAME,
                            (void *)CONFIG_SYS_SPL_ARGS_ADDR, 0);
        if (err <= 0) {
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
-               printf("spl: error reading image %s, err - %d\n",
-                      CONFIG_SPL_FAT_LOAD_ARGS_NAME, err);
+               printf("%s: error reading image %s, err - %d\n",
+                      __func__, CONFIG_SPL_FAT_LOAD_ARGS_NAME, err);
 #endif
                return -1;
        }
diff --git a/common/spl/spl_usb.c b/common/spl/spl_usb.c
new file mode 100644 (file)
index 0000000..53a9043
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * (C) Copyright 2014
+ * Texas Instruments, <www.ti.com>
+ *
+ * Dan Murphy <dmurphy@ti.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ *
+ * Derived work from spl_mmc.c
+ */
+
+#include <common.h>
+#include <spl.h>
+#include <asm/u-boot.h>
+#include <usb.h>
+#include <fat.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#ifdef CONFIG_USB_STORAGE
+static int usb_stor_curr_dev = -1; /* current device */
+#endif
+
+void spl_usb_load_image(void)
+{
+       int err;
+       block_dev_desc_t *stor_dev;
+
+       usb_stop();
+       err = usb_init();
+       if (err) {
+#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
+               printf("%s: usb init failed: err - %d\n", __func__, err);
+#endif
+               hang();
+       }
+
+#ifdef CONFIG_USB_STORAGE
+       /* try to recognize storage devices immediately */
+       usb_stor_curr_dev = usb_stor_scan(1);
+       stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
+#endif
+
+       debug("boot mode - FAT\n");
+
+#ifdef CONFIG_SPL_OS_BOOT
+               if (spl_start_uboot() || spl_load_image_fat_os(stor_dev,
+                                                               CONFIG_SYS_USB_FAT_BOOT_PARTITION))
+#endif
+               err = spl_load_image_fat(stor_dev,
+                               CONFIG_SYS_USB_FAT_BOOT_PARTITION,
+                               CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME);
+
+               if (err) {
+                       puts("Error loading USB device\n");
+                       hang();
+               }
+}
index cd5cd26501ca8706b13408a8481b50e5da7b0f3b..5e248561f13791ade05d69dea96f5315410cb20c 100644 (file)
@@ -61,6 +61,9 @@ void spl_spi_load_image(void);
 /* Ethernet SPL functions */
 void spl_net_load_image(const char *device);
 
+/* USB SPL functions */
+void spl_usb_load_image(void);
+
 /* SPL FAT image functions */
 int spl_load_image_fat(block_dev_desc_t *block_dev, int partition, const char *filename);
 int spl_load_image_fat_os(block_dev_desc_t *block_dev, int partition);
index ceb425b6bcfd1955f9a12e11d16e424b0cc1452a..4143e3810cd4340eae32b155307cbe24975e77f1 100644 (file)
@@ -83,6 +83,8 @@ LIBS-$(CONFIG_SPL_USBETH_SUPPORT) += drivers/net/phy/
 LIBS-$(CONFIG_SPL_MUSB_NEW_SUPPORT) += drivers/usb/musb-new/
 LIBS-$(CONFIG_SPL_USBETH_SUPPORT) += drivers/usb/gadget/
 LIBS-$(CONFIG_SPL_WATCHDOG_SUPPORT) += drivers/watchdog/
+LIBS-$(CONFIG_SPL_USB_HOST_SUPPORT) += drivers/usb/host/
+LIBS-$(CONFIG_OMAP_USB_PHY) += drivers/usb/phy/
 
 ifneq (,$(CONFIG_MX23)$(CONFIG_MX35)$(filter $(SOC), mx25 mx27 mx5 mx6 mx31 mx35))
 LIBS-y += arch/$(ARCH)/imx-common/