Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 1 | /* |
| 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 Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 15 | #include <errno.h> |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 16 | #include <usb.h> |
| 17 | #include <fat.h> |
| 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
| 21 | #ifdef CONFIG_USB_STORAGE |
| 22 | static int usb_stor_curr_dev = -1; /* current device */ |
| 23 | #endif |
| 24 | |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 25 | static int spl_usb_load_image(struct spl_image_info *spl_image, |
| 26 | struct spl_boot_device *bootdev) |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 27 | { |
| 28 | int err; |
Simon Glass | e339475 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 29 | struct blk_desc *stor_dev; |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 30 | |
| 31 | usb_stop(); |
| 32 | err = usb_init(); |
| 33 | if (err) { |
| 34 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
| 35 | printf("%s: usb init failed: err - %d\n", __func__, err); |
| 36 | #endif |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 37 | return err; |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | #ifdef CONFIG_USB_STORAGE |
| 41 | /* try to recognize storage devices immediately */ |
| 42 | usb_stor_curr_dev = usb_stor_scan(1); |
Simon Glass | cf43778 | 2016-05-01 11:36:13 -0600 | [diff] [blame] | 43 | 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] | 44 | if (!stor_dev) |
| 45 | return -ENODEV; |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 46 | #endif |
| 47 | |
| 48 | debug("boot mode - FAT\n"); |
| 49 | |
| 50 | #ifdef CONFIG_SPL_OS_BOOT |
Simon Glass | 3eb382a | 2016-09-24 18:20:15 -0600 | [diff] [blame^] | 51 | if (spl_start_uboot() || |
| 52 | spl_load_image_fat_os(spl_image, stor_dev, |
| 53 | CONFIG_SYS_USB_FAT_BOOT_PARTITION)) |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 54 | #endif |
Simon Glass | 3eb382a | 2016-09-24 18:20:15 -0600 | [diff] [blame^] | 55 | { |
| 56 | err = spl_load_image_fat(spl_image, stor_dev, |
| 57 | CONFIG_SYS_USB_FAT_BOOT_PARTITION, |
| 58 | CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); |
| 59 | } |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 60 | |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 61 | if (err) { |
| 62 | puts("Error loading from USB device\n"); |
| 63 | return err; |
| 64 | } |
| 65 | |
| 66 | return 0; |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 67 | } |
Simon Glass | c43541b | 2016-09-24 18:20:06 -0600 | [diff] [blame] | 68 | SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_USB, spl_usb_load_image); |