spl_usb.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. int spl_usb_load_image(void)
  22. {
  23. int err;
  24. block_dev_desc_t *stor_dev;
  25. usb_stop();
  26. err = usb_init();
  27. if (err) {
  28. #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
  29. printf("%s: usb init failed: err - %d\n", __func__, err);
  30. #endif
  31. return err;
  32. }
  33. #ifdef CONFIG_USB_STORAGE
  34. /* try to recognize storage devices immediately */
  35. usb_stor_curr_dev = usb_stor_scan(1);
  36. stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
  37. if (!stor_dev)
  38. return -ENODEV;
  39. #endif
  40. debug("boot mode - FAT\n");
  41. #ifdef CONFIG_SPL_OS_BOOT
  42. if (spl_start_uboot() || spl_load_image_fat_os(stor_dev,
  43. CONFIG_SYS_USB_FAT_BOOT_PARTITION))
  44. #endif
  45. err = spl_load_image_fat(stor_dev,
  46. CONFIG_SYS_USB_FAT_BOOT_PARTITION,
  47. CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
  48. if (err) {
  49. puts("Error loading from USB device\n");
  50. return err;
  51. }
  52. return 0;
  53. }