usb_gadget_sdp.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 <command.h>
  10. #include <g_dnl.h>
  11. #include <sdp.h>
  12. #include <usb.h>
  13. static int do_sdp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
  14. {
  15. int ret;
  16. if (argc < 2)
  17. return CMD_RET_USAGE;
  18. char *usb_controller = argv[1];
  19. int controller_index = simple_strtoul(usb_controller, NULL, 0);
  20. usb_gadget_initialize(controller_index);
  21. g_dnl_clear_detach();
  22. ret = g_dnl_register("usb_dnl_sdp");
  23. if (ret) {
  24. pr_err("SDP dnl register failed: %d\n", ret);
  25. goto exit_register;
  26. }
  27. ret = sdp_init(controller_index);
  28. if (ret) {
  29. pr_err("SDP init failed: %d\n", ret);
  30. goto exit;
  31. }
  32. /* This command typically does not return but jumps to an image */
  33. sdp_handle(controller_index);
  34. pr_err("SDP ended\n");
  35. exit:
  36. g_dnl_unregister();
  37. exit_register:
  38. usb_gadget_release(controller_index);
  39. return CMD_RET_FAILURE;
  40. }
  41. U_BOOT_CMD(sdp, 2, 1, do_sdp,
  42. "Serial Downloader Protocol",
  43. "<USB_controller>\n"
  44. " - serial downloader protocol via <USB_controller>\n"
  45. );