blob: 97d00ec5453879c37c40377454bd6aa2807e18bd [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) {
Andre Heider24ccd0c2018-02-15 07:08:55 +010031 pr_err("SDP init failed: %d\n", 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);
Andre Heider24ccd0c2018-02-15 07:08:55 +010037 pr_err("SDP ended\n");
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);