spl_usb.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include <common.h>
  12. #include <spl.h>
  13. #include <asm/u-boot.h>
  14. #include <errno.h>
  15. #include <usb.h>
  16. #include <fat.h>
  17. DECLARE_GLOBAL_DATA_PTR;
  18. #ifdef CONFIG_USB_STORAGE
  19. static int usb_stor_curr_dev = -1; /* current device */
  20. #endif
  21. static int spl_usb_load_image(struct spl_image_info *spl_image,
  22. struct spl_boot_device *bootdev)
  23. {
  24. int err;
  25. struct blk_desc *stor_dev;
  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
  32. return err;
  33. }
  34. #ifdef CONFIG_USB_STORAGE
  35. /* try to recognize storage devices immediately */
  36. usb_stor_curr_dev = usb_stor_scan(1);
  37. stor_dev = blk_get_devnum_by_type(IF_TYPE_USB, usb_stor_curr_dev);
  38. if (!stor_dev)
  39. return -ENODEV;
  40. #endif
  41. debug("boot mode - FAT\n");
  42. #ifdef CONFIG_SPL_OS_BOOT
  43. if (spl_start_uboot() ||
  44. spl_load_image_fat_os(spl_image, stor_dev,
  45. CONFIG_SYS_USB_FAT_BOOT_PARTITION))
  46. #endif
  47. {
  48. err = spl_load_image_fat(spl_image, stor_dev,
  49. CONFIG_SYS_USB_FAT_BOOT_PARTITION,
  50. CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
  51. }
  52. if (err) {
  53. puts("Error loading from USB device\n");
  54. return err;
  55. }
  56. return 0;
  57. }
  58. SPL_LOAD_IMAGE_METHOD("USB", 0, BOOT_DEVICE_USB, spl_usb_load_image);