]> git.ipfire.org Git - people/ms/u-boot.git/blame - common/cmd_fastboot.c
dfu: command: Extend "dfu" command to handle receiving data via TFTP
[people/ms/u-boot.git] / common / cmd_fastboot.c
CommitLineData
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>
12#include <g_dnl.h>
8d2f0039 13#include <usb.h>
3aab70af
SS
14
15static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
16{
8d2f0039
PK
17 int controller_index;
18 char *usb_controller;
3aab70af
SS
19 int ret;
20
8d2f0039
PK
21 if (argc < 2)
22 return CMD_RET_USAGE;
23
24 usb_controller = argv[1];
25 controller_index = simple_strtoul(usb_controller, NULL, 0);
26
27 ret = board_usb_init(controller_index, USB_INIT_DEVICE);
28 if (ret) {
29 error("USB init failed: %d", ret);
30 return CMD_RET_FAILURE;
31 }
32
267abc62 33 g_dnl_clear_detach();
3aab70af
SS
34 ret = g_dnl_register("usb_dnl_fastboot");
35 if (ret)
36 return ret;
37
7c23bcb9
RH
38 if (!g_dnl_board_usb_cable_connected()) {
39 puts("\rUSB cable not detected.\n" \
40 "Command exit.\n");
8d2f0039
PK
41 ret = CMD_RET_FAILURE;
42 goto exit;
7c23bcb9
RH
43 }
44
3aab70af 45 while (1) {
267abc62
RH
46 if (g_dnl_detach())
47 break;
3aab70af
SS
48 if (ctrlc())
49 break;
eca76b74 50 usb_gadget_handle_interrupts(controller_index);
3aab70af
SS
51 }
52
8d2f0039
PK
53 ret = CMD_RET_SUCCESS;
54
55exit:
3aab70af 56 g_dnl_unregister();
267abc62 57 g_dnl_clear_detach();
8d2f0039
PK
58 board_usb_cleanup(controller_index, USB_INIT_DEVICE);
59
60 return ret;
3aab70af
SS
61}
62
63U_BOOT_CMD(
8d2f0039 64 fastboot, 2, 1, do_fastboot,
593cbd93 65 "use USB Fastboot protocol",
8d2f0039 66 "<USB_controller>\n"
593cbd93 67 " - run as a fastboot usb device"
3aab70af 68);