blob: 1af82e1136656212caa26c327c49dc76e7e70795 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Agner2f005692017-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 Agner2f005692017-08-16 11:00:53 -07007 */
8
9#include <common.h>
Simon Glass09140112020-05-10 11:40:03 -060010#include <command.h>
Stefan Agner2f005692017-08-16 11:00:53 -070011#include <g_dnl.h>
12#include <sdp.h>
13#include <usb.h>
14
Simon Glass09140112020-05-10 11:40:03 -060015static int do_sdp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Stefan Agner2f005692017-08-16 11:00:53 -070016{
Sjoerd Simons25ee9242019-06-04 21:01:55 +020017 int ret;
Stefan Agner2f005692017-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 Hiblota06955a2018-11-29 10:52:41 +010024 usb_gadget_initialize(controller_index);
Stefan Agner2f005692017-08-16 11:00:53 -070025
26 g_dnl_clear_detach();
Sjoerd Simons25ee9242019-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 Agner2f005692017-08-16 11:00:53 -070032
33 ret = sdp_init(controller_index);
34 if (ret) {
Andre Heider24ccd0c2018-02-15 07:08:55 +010035 pr_err("SDP init failed: %d\n", ret);
Stefan Agner2f005692017-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 Heider24ccd0c2018-02-15 07:08:55 +010041 pr_err("SDP ended\n");
Stefan Agner2f005692017-08-16 11:00:53 -070042
43exit:
44 g_dnl_unregister();
Sjoerd Simons25ee9242019-06-04 21:01:55 +020045exit_register:
Jean-Jacques Hiblota06955a2018-11-29 10:52:41 +010046 usb_gadget_release(controller_index);
Stefan Agner2f005692017-08-16 11:00:53 -070047
Sjoerd Simons25ee9242019-06-04 21:01:55 +020048 return CMD_RET_FAILURE;
Stefan Agner2f005692017-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);