spl_sdp.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2016 Toradex
  4. * Author: Stefan Agner <stefan.agner@toradex.com>
  5. */
  6. #include <common.h>
  7. #include <spl.h>
  8. #include <usb.h>
  9. #include <g_dnl.h>
  10. #include <sdp.h>
  11. static int spl_sdp_load_image(struct spl_image_info *spl_image,
  12. struct spl_boot_device *bootdev)
  13. {
  14. int ret;
  15. const int controller_index = CONFIG_SPL_SDP_USB_DEV;
  16. usb_gadget_initialize(controller_index);
  17. g_dnl_clear_detach();
  18. ret = g_dnl_register("usb_dnl_sdp");
  19. if (ret) {
  20. pr_err("SDP dnl register failed: %d\n", ret);
  21. return ret;
  22. }
  23. ret = sdp_init(controller_index);
  24. if (ret) {
  25. pr_err("SDP init failed: %d\n", ret);
  26. return -ENODEV;
  27. }
  28. /*
  29. * This command either loads a legacy image, jumps and never returns,
  30. * or it loads a FIT image and returns it to be handled by the SPL
  31. * code.
  32. */
  33. ret = spl_sdp_handle(controller_index, spl_image);
  34. debug("SDP ended\n");
  35. usb_gadget_release(controller_index);
  36. return ret;
  37. }
  38. SPL_LOAD_IMAGE_METHOD("USB SDP", 0, BOOT_DEVICE_BOARD, spl_sdp_load_image);