blob: ae4d73c1250d02eb082d65ea687c2d6ad663412e [file] [log] [blame]
Stefan Agner2f005692017-08-16 11:00:53 -07001/*
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
15static 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 Yamada9b643e32017-09-16 14:10:41 +090031 pr_err("SDP init failed: %d", ret);
Stefan Agner2f005692017-08-16 11:00:53 -070032 goto exit;
33 }
34
35 /* This command typically does not return but jumps to an image */
36 sdp_handle(controller_index);
Masahiro Yamada9b643e32017-09-16 14:10:41 +090037 pr_err("SDP ended");
Stefan Agner2f005692017-08-16 11:00:53 -070038
39exit:
40 g_dnl_unregister();
41 board_usb_cleanup(controller_index, USB_INIT_DEVICE);
42
43 return ret;
44}
45
46U_BOOT_CMD(sdp, 2, 1, do_sdp,
47 "Serial Downloader Protocol",
48 "<USB_controller>\n"
49 " - serial downloader protocol via <USB_controller>\n"
50);