Merge branch 'master' of https://source.denx.de/u-boot/custodians/u-boot-sh
[u-boot.git] / cmd / usb_gadget_sdp.c
blob39259a3b09253cb643f26f4f2f98c79745fbff62
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * cmd_sdp.c -- sdp command
5 * Copyright (C) 2016 Toradex
6 * Author: Stefan Agner <stefan.agner@toradex.com>
7 */
9 #include <command.h>
10 #include <g_dnl.h>
11 #include <sdp.h>
12 #include <usb.h>
13 #include <linux/printk.h>
15 static int do_sdp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
17 int controller_index;
18 struct udevice *udc;
19 int ret;
21 if (argc < 2)
22 return CMD_RET_USAGE;
24 controller_index = simple_strtoul(argv[1], NULL, 0);
25 ret = udc_device_get_by_index(controller_index, &udc);
26 if (ret)
27 return ret;
29 g_dnl_clear_detach();
30 ret = g_dnl_register("usb_dnl_sdp");
31 if (ret) {
32 pr_err("SDP dnl register failed: %d\n", ret);
33 goto exit_register;
36 ret = sdp_init(udc);
37 if (ret) {
38 pr_err("SDP init failed: %d\n", ret);
39 goto exit;
42 /* This command typically does not return but jumps to an image */
43 sdp_handle(udc);
44 pr_err("SDP ended\n");
46 exit:
47 g_dnl_unregister();
48 exit_register:
49 udc_device_put(udc);
51 return CMD_RET_FAILURE;
54 U_BOOT_CMD(sdp, 2, 1, do_sdp,
55 "Serial Downloader Protocol",
56 "<USB_controller>\n"
57 " - serial downloader protocol via <USB_controller>\n"