usb_gadget_sdp.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * cmd_sdp.c -- sdp command
  4. *
  5. * Copyright (C) 2016 Toradex
  6. * Author: Stefan Agner <stefan.agner@toradex.com>
  7. */
  8. #include <common.h>
  9. #include <g_dnl.h>
  10. #include <sdp.h>
  11. #include <usb.h>
  12. static int do_sdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  13. {
  14. int ret = CMD_RET_FAILURE;
  15. if (argc < 2)
  16. return CMD_RET_USAGE;
  17. char *usb_controller = argv[1];
  18. int controller_index = simple_strtoul(usb_controller, NULL, 0);
  19. board_usb_init(controller_index, USB_INIT_DEVICE);
  20. g_dnl_clear_detach();
  21. g_dnl_register("usb_dnl_sdp");
  22. ret = sdp_init(controller_index);
  23. if (ret) {
  24. pr_err("SDP init failed: %d\n", ret);
  25. goto exit;
  26. }
  27. /* This command typically does not return but jumps to an image */
  28. sdp_handle(controller_index);
  29. pr_err("SDP ended\n");
  30. exit:
  31. g_dnl_unregister();
  32. board_usb_cleanup(controller_index, USB_INIT_DEVICE);
  33. return ret;
  34. }
  35. U_BOOT_CMD(sdp, 2, 1, do_sdp,
  36. "Serial Downloader Protocol",
  37. "<USB_controller>\n"
  38. " - serial downloader protocol via <USB_controller>\n"
  39. );