spl_usb.c 1.5 KB

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