]> git.sur5r.net Git - u-boot/blob - common/spl/spl_usb.c
spl: Pass spl_image as a parameter to load_image() methods
[u-boot] / common / spl / spl_usb.c
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>
15 #include <errno.h>
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
25 static int spl_usb_load_image(struct spl_image_info *spl_image,
26                               struct spl_boot_device *bootdev)
27 {
28         int err;
29         struct blk_desc *stor_dev;
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
37                 return err;
38         }
39
40 #ifdef CONFIG_USB_STORAGE
41         /* try to recognize storage devices immediately */
42         usb_stor_curr_dev = usb_stor_scan(1);
43         stor_dev = blk_get_devnum_by_type(IF_TYPE_USB, usb_stor_curr_dev);
44         if (!stor_dev)
45                 return -ENODEV;
46 #endif
47
48         debug("boot mode - FAT\n");
49
50 #ifdef CONFIG_SPL_OS_BOOT
51                 if (spl_start_uboot() || spl_load_image_fat_os(stor_dev,
52                                                                 CONFIG_SYS_USB_FAT_BOOT_PARTITION))
53 #endif
54                 err = spl_load_image_fat(stor_dev,
55                                 CONFIG_SYS_USB_FAT_BOOT_PARTITION,
56                                 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
57
58         if (err) {
59                 puts("Error loading from USB device\n");
60                 return err;
61         }
62
63         return 0;
64 }
65 SPL_LOAD_IMAGE_METHOD(0, BOOT_DEVICE_USB, spl_usb_load_image);