blob: a5ec5f46f63300052d4eb9f23f6092f09ebe0c1f [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Sebastian Siewior3aab70a2014-05-05 15:08:10 -05002/*
3 * Copyright 2008 - 2009 Windriver, <www.windriver.com>
4 * Author: Tom Rix <Tom.Rix@windriver.com>
5 *
6 * (C) Copyright 2014 Linaro, Ltd.
7 * Rob Herring <robh@kernel.org>
Sebastian Siewior3aab70a2014-05-05 15:08:10 -05008 */
9#include <common.h>
10#include <command.h>
Simon Glass24b852a2015-11-08 23:47:45 -070011#include <console.h>
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050012#include <g_dnl.h>
Paul Kocialkowski8d2f0032015-06-12 19:57:00 +020013#include <usb.h>
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050014
15static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
16{
Paul Kocialkowski8d2f0032015-06-12 19:57:00 +020017 int controller_index;
18 char *usb_controller;
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050019 int ret;
20
Paul Kocialkowski8d2f0032015-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) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090029 pr_err("USB init failed: %d", ret);
Paul Kocialkowski8d2f0032015-06-12 19:57:00 +020030 return CMD_RET_FAILURE;
31 }
32
Rob Herring267abc62014-12-10 14:43:04 -060033 g_dnl_clear_detach();
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050034 ret = g_dnl_register("usb_dnl_fastboot");
35 if (ret)
36 return ret;
37
Rob Herring7c23bcb2015-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 Kocialkowski8d2f0032015-06-12 19:57:00 +020041 ret = CMD_RET_FAILURE;
42 goto exit;
Rob Herring7c23bcb2015-01-26 15:14:41 -060043 }
44
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050045 while (1) {
Rob Herring267abc62014-12-10 14:43:04 -060046 if (g_dnl_detach())
47 break;
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050048 if (ctrlc())
49 break;
Paul Kocialkowskieca76b72015-05-24 11:41:04 +020050 usb_gadget_handle_interrupts(controller_index);
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050051 }
52
Paul Kocialkowski8d2f0032015-06-12 19:57:00 +020053 ret = CMD_RET_SUCCESS;
54
55exit:
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050056 g_dnl_unregister();
Rob Herring267abc62014-12-10 14:43:04 -060057 g_dnl_clear_detach();
Paul Kocialkowski8d2f0032015-06-12 19:57:00 +020058 board_usb_cleanup(controller_index, USB_INIT_DEVICE);
59
60 return ret;
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050061}
62
63U_BOOT_CMD(
Paul Kocialkowski8d2f0032015-06-12 19:57:00 +020064 fastboot, 2, 1, do_fastboot,
Steve Rae593cbd92014-08-26 11:47:29 -070065 "use USB Fastboot protocol",
Paul Kocialkowski8d2f0032015-06-12 19:57:00 +020066 "<USB_controller>\n"
Steve Rae593cbd92014-08-26 11:47:29 -070067 " - run as a fastboot usb device"
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050068);