blob: b9d1c8c02bd9c0c51976271f80c9d98bcd5ef4e1 [file] [log] [blame]
Sebastian Siewior9d4471e2014-05-05 15:08:10 -05001/*
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>
Paul Kocialkowskid48378f2015-06-12 19:57:00 +020013#include <usb.h>
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050014
15static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
16{
Paul Kocialkowskid48378f2015-06-12 19:57:00 +020017 int controller_index;
18 char *usb_controller;
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050019 int ret;
20
Paul Kocialkowskid48378f2015-06-12 19:57:00 +020021 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
Rob Herring5aba3982014-12-10 14:43:04 -060033 g_dnl_clear_detach();
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050034 ret = g_dnl_register("usb_dnl_fastboot");
35 if (ret)
36 return ret;
37
Rob Herringce9d8ee2015-01-26 15:14:41 -060038 if (!g_dnl_board_usb_cable_connected()) {
39 puts("\rUSB cable not detected.\n" \
40 "Command exit.\n");
Paul Kocialkowskid48378f2015-06-12 19:57:00 +020041 ret = CMD_RET_FAILURE;
42 goto exit;
Rob Herringce9d8ee2015-01-26 15:14:41 -060043 }
44
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050045 while (1) {
Rob Herring5aba3982014-12-10 14:43:04 -060046 if (g_dnl_detach())
47 break;
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050048 if (ctrlc())
49 break;
Paul Kocialkowski6b9f7282015-05-24 11:41:04 +020050 usb_gadget_handle_interrupts(controller_index);
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050051 }
52
Paul Kocialkowskid48378f2015-06-12 19:57:00 +020053 ret = CMD_RET_SUCCESS;
54
55exit:
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050056 g_dnl_unregister();
Rob Herring5aba3982014-12-10 14:43:04 -060057 g_dnl_clear_detach();
Paul Kocialkowskid48378f2015-06-12 19:57:00 +020058 board_usb_cleanup(controller_index, USB_INIT_DEVICE);
59
60 return ret;
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050061}
62
63U_BOOT_CMD(
Paul Kocialkowskid48378f2015-06-12 19:57:00 +020064 fastboot, 2, 1, do_fastboot,
Steve Rae56ad7922014-08-26 11:47:29 -070065 "use USB Fastboot protocol",
Paul Kocialkowskid48378f2015-06-12 19:57:00 +020066 "<USB_controller>\n"
Steve Rae56ad7922014-08-26 11:47:29 -070067 " - run as a fastboot usb device"
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050068);