Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2014 |
| 4 | * Texas Instruments, <www.ti.com> |
| 5 | * |
| 6 | * Dan Murphy <dmurphy@ti.com> |
| 7 | * |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 8 | * Derived work from spl_mmc.c |
| 9 | */ |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <spl.h> |
| 13 | #include <asm/u-boot.h> |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 14 | #include <errno.h> |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 15 | #include <usb.h> |
| 16 | #include <fat.h> |
| 17 | |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 18 | static int usb_stor_curr_dev = -1; /* current device */ |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 19 | |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 20 | static int spl_usb_load_image(struct spl_image_info *spl_image, |
| 21 | struct spl_boot_device *bootdev) |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 22 | { |
| 23 | int err; |
Simon Glass | e339475 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 24 | struct blk_desc *stor_dev; |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 25 | |
| 26 | usb_stop(); |
| 27 | err = usb_init(); |
| 28 | if (err) { |
| 29 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
| 30 | printf("%s: usb init failed: err - %d\n", __func__, err); |
| 31 | #endif |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 32 | return err; |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 33 | } |
| 34 | |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 35 | /* try to recognize storage devices immediately */ |
| 36 | usb_stor_curr_dev = usb_stor_scan(1); |
Simon Glass | cf43778 | 2016-05-01 11:36:13 -0600 | [diff] [blame] | 37 | stor_dev = blk_get_devnum_by_type(IF_TYPE_USB, usb_stor_curr_dev); |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 38 | if (!stor_dev) |
| 39 | return -ENODEV; |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 40 | |
| 41 | debug("boot mode - FAT\n"); |
| 42 | |
| 43 | #ifdef CONFIG_SPL_OS_BOOT |
Simon Glass | 3eb382a | 2016-09-24 18:20:15 -0600 | [diff] [blame] | 44 | if (spl_start_uboot() || |
| 45 | spl_load_image_fat_os(spl_image, stor_dev, |
| 46 | CONFIG_SYS_USB_FAT_BOOT_PARTITION)) |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 47 | #endif |
Simon Glass | 3eb382a | 2016-09-24 18:20:15 -0600 | [diff] [blame] | 48 | { |
| 49 | err = spl_load_image_fat(spl_image, stor_dev, |
| 50 | CONFIG_SYS_USB_FAT_BOOT_PARTITION, |
| 51 | CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); |
| 52 | } |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 53 | |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 54 | if (err) { |
| 55 | puts("Error loading from USB device\n"); |
| 56 | return err; |
| 57 | } |
| 58 | |
| 59 | return 0; |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 60 | } |
Simon Glass | 4fc1f25 | 2016-11-30 15:30:50 -0700 | [diff] [blame] | 61 | SPL_LOAD_IMAGE_METHOD("USB", 0, BOOT_DEVICE_USB, spl_usb_load_image); |