Stefan Agner | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * cmd_sdp.c -- sdp command |
| 3 | * |
| 4 | * Copyright (C) 2016 Toradex |
| 5 | * Author: Stefan Agner <stefan.agner@toradex.com> |
| 6 | * |
| 7 | * SPDX-License-Identifier: GPL-2.0+ |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <g_dnl.h> |
| 12 | #include <sdp.h> |
| 13 | #include <usb.h> |
| 14 | |
| 15 | static int do_sdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 16 | { |
| 17 | int ret = CMD_RET_FAILURE; |
| 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); |
| 24 | board_usb_init(controller_index, USB_INIT_DEVICE); |
| 25 | |
| 26 | g_dnl_clear_detach(); |
| 27 | g_dnl_register("usb_dnl_sdp"); |
| 28 | |
| 29 | ret = sdp_init(controller_index); |
| 30 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 31 | pr_err("SDP init failed: %d", ret); |
Stefan Agner | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 32 | goto exit; |
| 33 | } |
| 34 | |
| 35 | /* This command typically does not return but jumps to an image */ |
| 36 | sdp_handle(controller_index); |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 37 | pr_err("SDP ended"); |
Stefan Agner | 2f00569 | 2017-08-16 11:00:53 -0700 | [diff] [blame] | 38 | |
| 39 | exit: |
| 40 | g_dnl_unregister(); |
| 41 | board_usb_cleanup(controller_index, USB_INIT_DEVICE); |
| 42 | |
| 43 | return ret; |
| 44 | } |
| 45 | |
| 46 | U_BOOT_CMD(sdp, 2, 1, do_sdp, |
| 47 | "Serial Downloader Protocol", |
| 48 | "<USB_controller>\n" |
| 49 | " - serial downloader protocol via <USB_controller>\n" |
| 50 | ); |