spl_usb.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 <usb.h>
  15. #include <fat.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. #ifdef CONFIG_USB_STORAGE
  18. static int usb_stor_curr_dev = -1; /* current device */
  19. #endif
  20. void spl_usb_load_image(void)
  21. {
  22. int err;
  23. block_dev_desc_t *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. hang();
  31. }
  32. #ifdef CONFIG_USB_STORAGE
  33. /* try to recognize storage devices immediately */
  34. usb_stor_curr_dev = usb_stor_scan(1);
  35. stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
  36. #endif
  37. debug("boot mode - FAT\n");
  38. #ifdef CONFIG_SPL_OS_BOOT
  39. if (spl_start_uboot() || spl_load_image_fat_os(stor_dev,
  40. CONFIG_SYS_USB_FAT_BOOT_PARTITION))
  41. #endif
  42. err = spl_load_image_fat(stor_dev,
  43. CONFIG_SYS_USB_FAT_BOOT_PARTITION,
  44. CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
  45. if (err) {
  46. puts("Error loading USB device\n");
  47. hang();
  48. }
  49. }