]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
2f005695 SA |
2 | /* |
3 | * cmd_sdp.c -- sdp command | |
4 | * | |
5 | * Copyright (C) 2016 Toradex | |
6 | * Author: Stefan Agner <[email protected]> | |
2f005695 SA |
7 | */ |
8 | ||
09140113 | 9 | #include <command.h> |
2f005695 SA |
10 | #include <g_dnl.h> |
11 | #include <sdp.h> | |
12 | #include <usb.h> | |
1e94b46f | 13 | #include <linux/printk.h> |
2f005695 | 14 | |
09140113 | 15 | static int do_sdp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
2f005695 | 16 | { |
37fb7cb7 | 17 | int controller_index; |
6b84acc9 | 18 | struct udevice *udc; |
25ee9246 | 19 | int ret; |
2f005695 SA |
20 | |
21 | if (argc < 2) | |
22 | return CMD_RET_USAGE; | |
23 | ||
37fb7cb7 | 24 | controller_index = simple_strtoul(argv[1], NULL, 0); |
6b84acc9 MV |
25 | ret = udc_device_get_by_index(controller_index, &udc); |
26 | if (ret) | |
27 | return ret; | |
2f005695 SA |
28 | |
29 | g_dnl_clear_detach(); | |
25ee9246 SS |
30 | ret = g_dnl_register("usb_dnl_sdp"); |
31 | if (ret) { | |
32 | pr_err("SDP dnl register failed: %d\n", ret); | |
33 | goto exit_register; | |
34 | } | |
2f005695 | 35 | |
6b84acc9 | 36 | ret = sdp_init(udc); |
2f005695 | 37 | if (ret) { |
24ccd0c8 | 38 | pr_err("SDP init failed: %d\n", ret); |
2f005695 SA |
39 | goto exit; |
40 | } | |
41 | ||
42 | /* This command typically does not return but jumps to an image */ | |
6b84acc9 | 43 | sdp_handle(udc); |
24ccd0c8 | 44 | pr_err("SDP ended\n"); |
2f005695 SA |
45 | |
46 | exit: | |
47 | g_dnl_unregister(); | |
25ee9246 | 48 | exit_register: |
6b84acc9 | 49 | udc_device_put(udc); |
2f005695 | 50 | |
25ee9246 | 51 | return CMD_RET_FAILURE; |
2f005695 SA |
52 | } |
53 | ||
54 | U_BOOT_CMD(sdp, 2, 1, do_sdp, | |
55 | "Serial Downloader Protocol", | |
56 | "<USB_controller>\n" | |
57 | " - serial downloader protocol via <USB_controller>\n" | |
58 | ); |