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