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 | |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 25 | int spl_usb_load_image(void) |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 26 | { |
| 27 | int err; |
| 28 | block_dev_desc_t *stor_dev; |
| 29 | |
| 30 | usb_stop(); |
| 31 | err = usb_init(); |
| 32 | if (err) { |
| 33 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
| 34 | printf("%s: usb init failed: err - %d\n", __func__, err); |
| 35 | #endif |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 36 | return err; |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | #ifdef CONFIG_USB_STORAGE |
| 40 | /* try to recognize storage devices immediately */ |
| 41 | usb_stor_curr_dev = usb_stor_scan(1); |
| 42 | stor_dev = usb_stor_get_dev(usb_stor_curr_dev); |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 43 | if (!stor_dev) |
| 44 | return -ENODEV; |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 45 | #endif |
| 46 | |
| 47 | debug("boot mode - FAT\n"); |
| 48 | |
| 49 | #ifdef CONFIG_SPL_OS_BOOT |
| 50 | if (spl_start_uboot() || spl_load_image_fat_os(stor_dev, |
| 51 | CONFIG_SYS_USB_FAT_BOOT_PARTITION)) |
| 52 | #endif |
| 53 | err = spl_load_image_fat(stor_dev, |
| 54 | CONFIG_SYS_USB_FAT_BOOT_PARTITION, |
Guillaume GARDET | 602a16c | 2014-10-15 17:53:11 +0200 | [diff] [blame] | 55 | CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 56 | |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 57 | if (err) { |
| 58 | puts("Error loading from USB device\n"); |
| 59 | return err; |
| 60 | } |
| 61 | |
| 62 | return 0; |
Dan Murphy | cb367e1 | 2014-01-16 11:23:30 -0600 | [diff] [blame] | 63 | } |