blob: 2ead06be9f5acf351f2e24e450ecff683167f6d0 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Agnerd9d661c2017-08-16 11:00:53 -07002/*
3 * cmd_sdp.c -- sdp command
4 *
5 * Copyright (C) 2016 Toradex
6 * Author: Stefan Agner <stefan.agner@toradex.com>
Stefan Agnerd9d661c2017-08-16 11:00:53 -07007 */
8
9#include <common.h>
10#include <g_dnl.h>
11#include <sdp.h>
12#include <usb.h>
13
14static int do_sdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
15{
Sjoerd Simons24d8ab32019-06-04 21:01:55 +020016 int ret;
Stefan Agnerd9d661c2017-08-16 11:00:53 -070017
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);
Jean-Jacques Hiblot585e1992018-11-29 10:52:41 +010023 usb_gadget_initialize(controller_index);
Stefan Agnerd9d661c2017-08-16 11:00:53 -070024
25 g_dnl_clear_detach();
Sjoerd Simons24d8ab32019-06-04 21:01:55 +020026 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 }
Stefan Agnerd9d661c2017-08-16 11:00:53 -070031
32 ret = sdp_init(controller_index);
33 if (ret) {
Andre Heiderb841e972018-02-15 07:08:55 +010034 pr_err("SDP init failed: %d\n", ret);
Stefan Agnerd9d661c2017-08-16 11:00:53 -070035 goto exit;
36 }
37
38 /* This command typically does not return but jumps to an image */
39 sdp_handle(controller_index);
Andre Heiderb841e972018-02-15 07:08:55 +010040 pr_err("SDP ended\n");
Stefan Agnerd9d661c2017-08-16 11:00:53 -070041
42exit:
43 g_dnl_unregister();
Sjoerd Simons24d8ab32019-06-04 21:01:55 +020044exit_register:
Jean-Jacques Hiblot585e1992018-11-29 10:52:41 +010045 usb_gadget_release(controller_index);
Stefan Agnerd9d661c2017-08-16 11:00:53 -070046
Sjoerd Simons24d8ab32019-06-04 21:01:55 +020047 return CMD_RET_FAILURE;
Stefan Agnerd9d661c2017-08-16 11:00:53 -070048}
49
50U_BOOT_CMD(sdp, 2, 1, do_sdp,
51 "Serial Downloader Protocol",
52 "<USB_controller>\n"
53 " - serial downloader protocol via <USB_controller>\n"
54);