]>
Commit | Line | Data |
---|---|---|
3aab70af SS |
1 | /* |
2 | * Copyright 2008 - 2009 Windriver, <www.windriver.com> | |
3 | * Author: Tom Rix <Tom.Rix@windriver.com> | |
4 | * | |
5 | * (C) Copyright 2014 Linaro, Ltd. | |
6 | * Rob Herring <robh@kernel.org> | |
7 | * | |
8 | * SPDX-License-Identifier: GPL-2.0+ | |
9 | */ | |
10 | #include <common.h> | |
11 | #include <command.h> | |
24b852a7 | 12 | #include <console.h> |
3aab70af | 13 | #include <g_dnl.h> |
8d2f0039 | 14 | #include <usb.h> |
3aab70af SS |
15 | |
16 | static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) | |
17 | { | |
8d2f0039 PK |
18 | int controller_index; |
19 | char *usb_controller; | |
3aab70af SS |
20 | int ret; |
21 | ||
8d2f0039 PK |
22 | if (argc < 2) |
23 | return CMD_RET_USAGE; | |
24 | ||
25 | usb_controller = argv[1]; | |
26 | controller_index = simple_strtoul(usb_controller, NULL, 0); | |
27 | ||
28 | ret = board_usb_init(controller_index, USB_INIT_DEVICE); | |
29 | if (ret) { | |
30 | error("USB init failed: %d", ret); | |
31 | return CMD_RET_FAILURE; | |
32 | } | |
33 | ||
267abc62 | 34 | g_dnl_clear_detach(); |
3aab70af SS |
35 | ret = g_dnl_register("usb_dnl_fastboot"); |
36 | if (ret) | |
37 | return ret; | |
38 | ||
7c23bcb9 RH |
39 | if (!g_dnl_board_usb_cable_connected()) { |
40 | puts("\rUSB cable not detected.\n" \ | |
41 | "Command exit.\n"); | |
8d2f0039 PK |
42 | ret = CMD_RET_FAILURE; |
43 | goto exit; | |
7c23bcb9 RH |
44 | } |
45 | ||
3aab70af | 46 | while (1) { |
267abc62 RH |
47 | if (g_dnl_detach()) |
48 | break; | |
3aab70af SS |
49 | if (ctrlc()) |
50 | break; | |
eca76b74 | 51 | usb_gadget_handle_interrupts(controller_index); |
3aab70af SS |
52 | } |
53 | ||
8d2f0039 PK |
54 | ret = CMD_RET_SUCCESS; |
55 | ||
56 | exit: | |
3aab70af | 57 | g_dnl_unregister(); |
267abc62 | 58 | g_dnl_clear_detach(); |
8d2f0039 PK |
59 | board_usb_cleanup(controller_index, USB_INIT_DEVICE); |
60 | ||
61 | return ret; | |
3aab70af SS |
62 | } |
63 | ||
64 | U_BOOT_CMD( | |
8d2f0039 | 65 | fastboot, 2, 1, do_fastboot, |
593cbd93 | 66 | "use USB Fastboot protocol", |
8d2f0039 | 67 | "<USB_controller>\n" |
593cbd93 | 68 | " - run as a fastboot usb device" |
3aab70af | 69 | ); |