blob: c8d82318957940ec7d97155fdd66acdde6aefab5 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dan Murphycb367e12014-01-16 11:23:30 -06002/*
3 * (C) Copyright 2014
4 * Texas Instruments, <www.ti.com>
5 *
6 * Dan Murphy <dmurphy@ti.com>
7 *
Dan Murphycb367e12014-01-16 11:23:30 -06008 * Derived work from spl_mmc.c
9 */
10
11#include <common.h>
12#include <spl.h>
13#include <asm/u-boot.h>
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020014#include <errno.h>
Dan Murphycb367e12014-01-16 11:23:30 -060015#include <usb.h>
16#include <fat.h>
17
Dan Murphycb367e12014-01-16 11:23:30 -060018#ifdef CONFIG_USB_STORAGE
19static int usb_stor_curr_dev = -1; /* current device */
20#endif
21
Simon Glassee306792016-09-24 18:20:13 -060022static int spl_usb_load_image(struct spl_image_info *spl_image,
23 struct spl_boot_device *bootdev)
Dan Murphycb367e12014-01-16 11:23:30 -060024{
25 int err;
Simon Glasse3394752016-02-29 15:25:34 -070026 struct blk_desc *stor_dev;
Dan Murphycb367e12014-01-16 11:23:30 -060027
28 usb_stop();
29 err = usb_init();
30 if (err) {
31#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
32 printf("%s: usb init failed: err - %d\n", __func__, err);
33#endif
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020034 return err;
Dan Murphycb367e12014-01-16 11:23:30 -060035 }
36
37#ifdef CONFIG_USB_STORAGE
38 /* try to recognize storage devices immediately */
39 usb_stor_curr_dev = usb_stor_scan(1);
Simon Glasscf437782016-05-01 11:36:13 -060040 stor_dev = blk_get_devnum_by_type(IF_TYPE_USB, usb_stor_curr_dev);
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020041 if (!stor_dev)
42 return -ENODEV;
Dan Murphycb367e12014-01-16 11:23:30 -060043#endif
44
45 debug("boot mode - FAT\n");
46
47#ifdef CONFIG_SPL_OS_BOOT
Simon Glass3eb382a2016-09-24 18:20:15 -060048 if (spl_start_uboot() ||
49 spl_load_image_fat_os(spl_image, stor_dev,
50 CONFIG_SYS_USB_FAT_BOOT_PARTITION))
Dan Murphycb367e12014-01-16 11:23:30 -060051#endif
Simon Glass3eb382a2016-09-24 18:20:15 -060052 {
53 err = spl_load_image_fat(spl_image, stor_dev,
54 CONFIG_SYS_USB_FAT_BOOT_PARTITION,
55 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
56 }
Dan Murphycb367e12014-01-16 11:23:30 -060057
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020058 if (err) {
59 puts("Error loading from USB device\n");
60 return err;
61 }
62
63 return 0;
Dan Murphycb367e12014-01-16 11:23:30 -060064}
Simon Glass4fc1f252016-11-30 15:30:50 -070065SPL_LOAD_IMAGE_METHOD("USB", 0, BOOT_DEVICE_USB, spl_usb_load_image);