blob: 1af82e1136656212caa26c327c49dc76e7e70795 [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>
Simon Glassed38aef2020-05-10 11:40:03 -060010#include <command.h>
Stefan Agnerd9d661c2017-08-16 11:00:53 -070011#include <g_dnl.h>
12#include <sdp.h>
13#include <usb.h>
14
Simon Glassed38aef2020-05-10 11:40:03 -060015static int do_sdp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Stefan Agnerd9d661c2017-08-16 11:00:53 -070016{
Sjoerd Simons24d8ab32019-06-04 21:01:55 +020017 int ret;
Stefan Agnerd9d661c2017-08-16 11:00:53 -070018
19 if (argc < 2)
20 return CMD_RET_USAGE;
21
22 char *usb_controller = argv[1];
23 int controller_index = simple_strtoul(usb_controller, NULL, 0);
Jean-Jacques Hiblot585e1992018-11-29 10:52:41 +010024 usb_gadget_initialize(controller_index);
Stefan Agnerd9d661c2017-08-16 11:00:53 -070025
26 g_dnl_clear_detach();
Sjoerd Simons24d8ab32019-06-04 21:01:55 +020027 ret = g_dnl_register("usb_dnl_sdp");
28 if (ret) {
29 pr_err("SDP dnl register failed: %d\n", ret);
30 goto exit_register;
31 }
Stefan Agnerd9d661c2017-08-16 11:00:53 -070032
33 ret = sdp_init(controller_index);
34 if (ret) {
Andre Heiderb841e972018-02-15 07:08:55 +010035 pr_err("SDP init failed: %d\n", ret);
Stefan Agnerd9d661c2017-08-16 11:00:53 -070036 goto exit;
37 }
38
39 /* This command typically does not return but jumps to an image */
40 sdp_handle(controller_index);
Andre Heiderb841e972018-02-15 07:08:55 +010041 pr_err("SDP ended\n");
Stefan Agnerd9d661c2017-08-16 11:00:53 -070042
43exit:
44 g_dnl_unregister();
Sjoerd Simons24d8ab32019-06-04 21:01:55 +020045exit_register:
Jean-Jacques Hiblot585e1992018-11-29 10:52:41 +010046 usb_gadget_release(controller_index);
Stefan Agnerd9d661c2017-08-16 11:00:53 -070047
Sjoerd Simons24d8ab32019-06-04 21:01:55 +020048 return CMD_RET_FAILURE;
Stefan Agnerd9d661c2017-08-16 11:00:53 -070049}
50
51U_BOOT_CMD(sdp, 2, 1, do_sdp,
52 "Serial Downloader Protocol",
53 "<USB_controller>\n"
54 " - serial downloader protocol via <USB_controller>\n"
55);