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