spl_usb.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2014
  4. * Texas Instruments, <www.ti.com>
  5. *
  6. * Dan Murphy <dmurphy@ti.com>
  7. *
  8. * Derived work from spl_mmc.c
  9. */
  10. #include <common.h>
  11. #include <spl.h>
  12. #include <asm/u-boot.h>
  13. #include <errno.h>
  14. #include <usb.h>
  15. #include <fat.h>
  16. static int usb_stor_curr_dev = -1; /* current device */
  17. static int spl_usb_load_image(struct spl_image_info *spl_image,
  18. struct spl_boot_device *bootdev)
  19. {
  20. int err;
  21. struct blk_desc *stor_dev;
  22. usb_stop();
  23. err = usb_init();
  24. if (err) {
  25. #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
  26. printf("%s: usb init failed: err - %d\n", __func__, err);
  27. #endif
  28. return err;
  29. }
  30. /* try to recognize storage devices immediately */
  31. usb_stor_curr_dev = usb_stor_scan(1);
  32. stor_dev = blk_get_devnum_by_type(IF_TYPE_USB, usb_stor_curr_dev);
  33. if (!stor_dev)
  34. return -ENODEV;
  35. debug("boot mode - FAT\n");
  36. #ifdef CONFIG_SPL_OS_BOOT
  37. if (spl_start_uboot() ||
  38. spl_load_image_fat_os(spl_image, stor_dev,
  39. CONFIG_SYS_USB_FAT_BOOT_PARTITION))
  40. #endif
  41. {
  42. err = spl_load_image_fat(spl_image, stor_dev,
  43. CONFIG_SYS_USB_FAT_BOOT_PARTITION,
  44. CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
  45. }
  46. if (err) {
  47. puts("Error loading from USB device\n");
  48. return err;
  49. }
  50. return 0;
  51. }
  52. SPL_LOAD_IMAGE_METHOD("USB", 0, BOOT_DEVICE_USB, spl_usb_load_image);