diff options
author | Dan Murphy <dmurphy@ti.com> | 2014-01-16 17:23:30 (GMT) |
---|---|---|
committer | Tom Rini <trini@ti.com> | 2014-01-24 21:59:22 (GMT) |
commit | 8cffe5bd0d601f64eca78d28b8a710ad6ca8edd2 (patch) | |
tree | 17c1cec019810ffc5dcb4a59ab0522cec4c5fdf5 /common | |
parent | 773b5940b5f2fb5d1041c6f4db5796121ccd29c5 (diff) | |
download | u-boot-8cffe5bd0d601f64eca78d28b8a710ad6ca8edd2.tar.xz |
spl: common: Support for USB MSD FAT image loading
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>
Diffstat (limited to 'common')
-rw-r--r-- | common/Makefile | 4 | ||||
-rw-r--r-- | common/spl/Makefile | 1 | ||||
-rw-r--r-- | common/spl/spl.c | 5 | ||||
-rw-r--r-- | common/spl/spl_fat.c | 16 | ||||
-rw-r--r-- | common/spl/spl_usb.c | 58 |
5 files changed, 76 insertions, 8 deletions
diff --git a/common/Makefile b/common/Makefile index d12cba5..4d99ecd 100644 --- a/common/Makefile +++ b/common/Makefile @@ -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 diff --git a/common/spl/Makefile b/common/spl/Makefile index c8d5963..65a1484 100644 --- a/common/spl/Makefile +++ b/common/spl/Makefile @@ -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 diff --git a/common/spl/spl.c b/common/spl/spl.c index da31457..0645cee 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -205,6 +205,11 @@ void board_init_r(gd_t *dummy1, ulong dummy2) 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"); hang(); diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c index 9b40584..1e532d5 100644 --- a/common/spl/spl_fat.c +++ b/common/spl/spl_fat.c @@ -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 index 0000000..53a9043 --- /dev/null +++ b/common/spl/spl_usb.c @@ -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(); + } +} |