2014-01-16 17:23:30 +00:00
|
|
|
/*
|
|
|
|
* (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>
|
2015-11-08 15:11:49 +00:00
|
|
|
#include <errno.h>
|
2014-01-16 17:23:30 +00:00
|
|
|
#include <usb.h>
|
|
|
|
#include <fat.h>
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
#ifdef CONFIG_USB_STORAGE
|
|
|
|
static int usb_stor_curr_dev = -1; /* current device */
|
|
|
|
#endif
|
|
|
|
|
2016-09-25 00:19:57 +00:00
|
|
|
int spl_usb_load_image(struct spl_boot_device *bootdev)
|
2014-01-16 17:23:30 +00:00
|
|
|
{
|
|
|
|
int err;
|
2016-02-29 22:25:34 +00:00
|
|
|
struct blk_desc *stor_dev;
|
2014-01-16 17:23:30 +00:00
|
|
|
|
|
|
|
usb_stop();
|
|
|
|
err = usb_init();
|
|
|
|
if (err) {
|
|
|
|
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
|
|
|
|
printf("%s: usb init failed: err - %d\n", __func__, err);
|
|
|
|
#endif
|
2015-11-08 15:11:49 +00:00
|
|
|
return err;
|
2014-01-16 17:23:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_USB_STORAGE
|
|
|
|
/* try to recognize storage devices immediately */
|
|
|
|
usb_stor_curr_dev = usb_stor_scan(1);
|
2016-05-01 17:36:13 +00:00
|
|
|
stor_dev = blk_get_devnum_by_type(IF_TYPE_USB, usb_stor_curr_dev);
|
2015-11-08 15:11:49 +00:00
|
|
|
if (!stor_dev)
|
|
|
|
return -ENODEV;
|
2014-01-16 17:23:30 +00:00
|
|
|
#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,
|
2014-10-15 15:53:11 +00:00
|
|
|
CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
|
2014-01-16 17:23:30 +00:00
|
|
|
|
2015-11-08 15:11:49 +00:00
|
|
|
if (err) {
|
|
|
|
puts("Error loading from USB device\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2014-01-16 17:23:30 +00:00
|
|
|
}
|