Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 2 | /* |
| 3 | * cmd_sdp.c -- sdp command |
| 4 | * |
| 5 | * Copyright (C) 2016 Toradex |
| 6 | * Author: Stefan Agner <stefan.agner@toradex.com> |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 10 | #include <command.h> |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 11 | #include <g_dnl.h> |
| 12 | #include <sdp.h> |
| 13 | #include <usb.h> |
| 14 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 15 | static int do_sdp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 16 | { |
Sjoerd Simons | 24d8ab3 | 2019-06-04 21:01:55 +0200 | [diff] [blame] | 17 | int ret; |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 18 | |
| 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 Hiblot | 585e199 | 2018-11-29 10:52:41 +0100 | [diff] [blame] | 24 | usb_gadget_initialize(controller_index); |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 25 | |
| 26 | g_dnl_clear_detach(); |
Sjoerd Simons | 24d8ab3 | 2019-06-04 21:01:55 +0200 | [diff] [blame] | 27 | 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 Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 32 | |
| 33 | ret = sdp_init(controller_index); |
| 34 | if (ret) { |
Andre Heider | b841e97 | 2018-02-15 07:08:55 +0100 | [diff] [blame] | 35 | pr_err("SDP init failed: %d\n", ret); |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 36 | goto exit; |
| 37 | } |
| 38 | |
| 39 | /* This command typically does not return but jumps to an image */ |
| 40 | sdp_handle(controller_index); |
Andre Heider | b841e97 | 2018-02-15 07:08:55 +0100 | [diff] [blame] | 41 | pr_err("SDP ended\n"); |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 42 | |
| 43 | exit: |
| 44 | g_dnl_unregister(); |
Sjoerd Simons | 24d8ab3 | 2019-06-04 21:01:55 +0200 | [diff] [blame] | 45 | exit_register: |
Jean-Jacques Hiblot | 585e199 | 2018-11-29 10:52:41 +0100 | [diff] [blame] | 46 | usb_gadget_release(controller_index); |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 47 | |
Sjoerd Simons | 24d8ab3 | 2019-06-04 21:01:55 +0200 | [diff] [blame] | 48 | return CMD_RET_FAILURE; |
Stefan Agner | d9d661c | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | U_BOOT_CMD(sdp, 2, 1, do_sdp, |
| 52 | "Serial Downloader Protocol", |
| 53 | "<USB_controller>\n" |
| 54 | " - serial downloader protocol via <USB_controller>\n" |
| 55 | ); |