blob: a5ec5f46f63300052d4eb9f23f6092f09ebe0c1f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Sebastian Siewior9d4471e2014-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 Siewior9d4471e2014-05-05 15:08:10 -05008 */
9#include <common.h>
10#include <command.h>
Simon Glassa73bda42015-11-08 23:47:45 -070011#include <console.h>
Sebastian Siewior9d4471e2014-05-05 15:08:10 -050012#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) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090029 pr_err("USB init failed: %d", ret);
Paul Kocialkowskid48378f2015-06-12 19:57:00 +020030 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);