Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Agner | 2f00569 | 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 | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <g_dnl.h> |
| 11 | #include <sdp.h> |
| 12 | #include <usb.h> |
| 13 | |
| 14 | static int do_sdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 15 | { |
| 16 | int ret = CMD_RET_FAILURE; |
| 17 | |
| 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); |
| 23 | board_usb_init(controller_index, USB_INIT_DEVICE); |
| 24 | |
| 25 | g_dnl_clear_detach(); |
| 26 | g_dnl_register("usb_dnl_sdp"); |
| 27 | |
| 28 | ret = sdp_init(controller_index); |
| 29 | if (ret) { |
Andre Heider | 24ccd0c | 2018-02-15 07:08:55 +0100 | [diff] [blame] | 30 | pr_err("SDP init failed: %d\n", ret); |
Stefan Agner | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 31 | goto exit; |
| 32 | } |
| 33 | |
| 34 | /* This command typically does not return but jumps to an image */ |
| 35 | sdp_handle(controller_index); |
Andre Heider | 24ccd0c | 2018-02-15 07:08:55 +0100 | [diff] [blame] | 36 | pr_err("SDP ended\n"); |
Stefan Agner | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 37 | |
| 38 | exit: |
| 39 | g_dnl_unregister(); |
| 40 | board_usb_cleanup(controller_index, USB_INIT_DEVICE); |
| 41 | |
| 42 | return ret; |
| 43 | } |
| 44 | |
| 45 | U_BOOT_CMD(sdp, 2, 1, do_sdp, |
| 46 | "Serial Downloader Protocol", |
| 47 | "<USB_controller>\n" |
| 48 | " - serial downloader protocol via <USB_controller>\n" |
| 49 | ); |