blob: 5aac10bd573c8cbd0361a286a816511192f134db [file] [log] [blame]
Dan Murphycb367e12014-01-16 11:23:30 -06001/*
2 * (C) Copyright 2014
3 * Texas Instruments, <www.ti.com>
4 *
5 * Dan Murphy <dmurphy@ti.com>
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 *
9 * Derived work from spl_mmc.c
10 */
11
12#include <common.h>
13#include <spl.h>
14#include <asm/u-boot.h>
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020015#include <errno.h>
Dan Murphycb367e12014-01-16 11:23:30 -060016#include <usb.h>
17#include <fat.h>
18
Dan Murphycb367e12014-01-16 11:23:30 -060019#ifdef CONFIG_USB_STORAGE
20static int usb_stor_curr_dev = -1; /* current device */
21#endif
22
Simon Glassee306792016-09-24 18:20:13 -060023static int spl_usb_load_image(struct spl_image_info *spl_image,
24 struct spl_boot_device *bootdev)
Dan Murphycb367e12014-01-16 11:23:30 -060025{
26 int err;
Simon Glasse3394752016-02-29 15:25:34 -070027 struct blk_desc *stor_dev;
Dan Murphycb367e12014-01-16 11:23:30 -060028
29 usb_stop();
30 err = usb_init();
31 if (err) {
32#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
33 printf("%s: usb init failed: err - %d\n", __func__, err);
34#endif
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020035 return err;
Dan Murphycb367e12014-01-16 11:23:30 -060036 }
37
38#ifdef CONFIG_USB_STORAGE
39 /* try to recognize storage devices immediately */
40 usb_stor_curr_dev = usb_stor_scan(1);
Simon Glasscf437782016-05-01 11:36:13 -060041 stor_dev = blk_get_devnum_by_type(IF_TYPE_USB, usb_stor_curr_dev);
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020042 if (!stor_dev)
43 return -ENODEV;
Dan Murphycb367e12014-01-16 11:23:30 -060044#endif
45
46 debug("boot mode - FAT\n");
47
48#ifdef CONFIG_SPL_OS_BOOT
Simon Glass3eb382a2016-09-24 18:20:15 -060049 if (spl_start_uboot() ||
50 spl_load_image_fat_os(spl_image, stor_dev,
51 CONFIG_SYS_USB_FAT_BOOT_PARTITION))
Dan Murphycb367e12014-01-16 11:23:30 -060052#endif
Simon Glass3eb382a2016-09-24 18:20:15 -060053 {
54 err = spl_load_image_fat(spl_image, stor_dev,
55 CONFIG_SYS_USB_FAT_BOOT_PARTITION,
56 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
57 }
Dan Murphycb367e12014-01-16 11:23:30 -060058
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020059 if (err) {
60 puts("Error loading from USB device\n");
61 return err;
62 }
63
64 return 0;
Dan Murphycb367e12014-01-16 11:23:30 -060065}
Simon Glass4fc1f252016-11-30 15:30:50 -070066SPL_LOAD_IMAGE_METHOD("USB", 0, BOOT_DEVICE_USB, spl_usb_load_image);