2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-01-16 17:23:30 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2014
|
|
|
|
* Texas Instruments, <www.ti.com>
|
|
|
|
*
|
|
|
|
* Dan Murphy <dmurphy@ti.com>
|
|
|
|
*
|
|
|
|
* Derived work from spl_mmc.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2014-01-16 17:23:30 +00:00
|
|
|
#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>
|
|
|
|
|
|
|
|
static int usb_stor_curr_dev = -1; /* current device */
|
|
|
|
|
2020-08-03 06:05:04 +00:00
|
|
|
int spl_usb_load(struct spl_image_info *spl_image,
|
|
|
|
struct spl_boot_device *bootdev, int partition,
|
|
|
|
const char *filename)
|
2014-01-16 17:23:30 +00:00
|
|
|
{
|
2020-08-03 06:05:05 +00:00
|
|
|
int err = 0;
|
2016-02-29 22:25:34 +00:00
|
|
|
struct blk_desc *stor_dev;
|
2020-08-03 06:05:05 +00:00
|
|
|
static bool usb_init_pending = true;
|
|
|
|
|
|
|
|
if (usb_init_pending) {
|
|
|
|
usb_stop();
|
|
|
|
err = usb_init();
|
|
|
|
usb_init_pending = false;
|
|
|
|
}
|
2014-01-16 17:23:30 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* try to recognize storage devices immediately */
|
|
|
|
usb_stor_curr_dev = usb_stor_scan(1);
|
2022-09-17 15:00:09 +00:00
|
|
|
stor_dev = blk_get_devnum_by_uclass_id(UCLASS_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
|
|
|
|
|
|
|
debug("boot mode - FAT\n");
|
|
|
|
|
2021-10-31 03:03:48 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OS_BOOT)
|
2016-09-25 00:20:15 +00:00
|
|
|
if (spl_start_uboot() ||
|
2022-01-14 13:31:38 +00:00
|
|
|
spl_load_image_fat_os(spl_image, bootdev, stor_dev, partition))
|
2014-01-16 17:23:30 +00:00
|
|
|
#endif
|
2016-09-25 00:20:15 +00:00
|
|
|
{
|
2022-01-14 13:31:38 +00:00
|
|
|
err = spl_load_image_fat(spl_image, bootdev, stor_dev, partition, filename);
|
2016-09-25 00:20:15 +00:00
|
|
|
}
|
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
|
|
|
}
|
2020-08-03 06:05:04 +00:00
|
|
|
|
|
|
|
static int spl_usb_load_image(struct spl_image_info *spl_image,
|
|
|
|
struct spl_boot_device *bootdev)
|
|
|
|
{
|
|
|
|
return spl_usb_load(spl_image, bootdev,
|
|
|
|
CONFIG_SYS_USB_FAT_BOOT_PARTITION,
|
|
|
|
CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
|
|
|
|
}
|
2016-11-30 22:30:50 +00:00
|
|
|
SPL_LOAD_IMAGE_METHOD("USB", 0, BOOT_DEVICE_USB, spl_usb_load_image);
|