usb_gadget_sdp.c 1.0 KB

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