blob: 8adcca592d586aa9cbfabe14caab3e99f77a4d73 [file] [log] [blame]
Sebastian Siewior3aab70a2014-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>
Simon Glass24b852a2015-11-08 23:47:45 -070012#include <console.h>
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050013#include <g_dnl.h>
Paul Kocialkowski8d2f0032015-06-12 19:57:00 +020014#include <usb.h>
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050015
16static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
17{
Paul Kocialkowski8d2f0032015-06-12 19:57:00 +020018 int controller_index;
19 char *usb_controller;
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050020 int ret;
21
Paul Kocialkowski8d2f0032015-06-12 19:57:00 +020022 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) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090030 pr_err("USB init failed: %d", ret);
Paul Kocialkowski8d2f0032015-06-12 19:57:00 +020031 return CMD_RET_FAILURE;
32 }
33
Rob Herring267abc62014-12-10 14:43:04 -060034 g_dnl_clear_detach();
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050035 ret = g_dnl_register("usb_dnl_fastboot");
36 if (ret)
37 return ret;
38
Rob Herring7c23bcb2015-01-26 15:14:41 -060039 if (!g_dnl_board_usb_cable_connected()) {
40 puts("\rUSB cable not detected.\n" \
41 "Command exit.\n");
Paul Kocialkowski8d2f0032015-06-12 19:57:00 +020042 ret = CMD_RET_FAILURE;
43 goto exit;
Rob Herring7c23bcb2015-01-26 15:14:41 -060044 }
45
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050046 while (1) {
Rob Herring267abc62014-12-10 14:43:04 -060047 if (g_dnl_detach())
48 break;
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050049 if (ctrlc())
50 break;
Paul Kocialkowskieca76b72015-05-24 11:41:04 +020051 usb_gadget_handle_interrupts(controller_index);
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050052 }
53
Paul Kocialkowski8d2f0032015-06-12 19:57:00 +020054 ret = CMD_RET_SUCCESS;
55
56exit:
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050057 g_dnl_unregister();
Rob Herring267abc62014-12-10 14:43:04 -060058 g_dnl_clear_detach();
Paul Kocialkowski8d2f0032015-06-12 19:57:00 +020059 board_usb_cleanup(controller_index, USB_INIT_DEVICE);
60
61 return ret;
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050062}
63
64U_BOOT_CMD(
Paul Kocialkowski8d2f0032015-06-12 19:57:00 +020065 fastboot, 2, 1, do_fastboot,
Steve Rae593cbd92014-08-26 11:47:29 -070066 "use USB Fastboot protocol",
Paul Kocialkowski8d2f0032015-06-12 19:57:00 +020067 "<USB_controller>\n"
Steve Rae593cbd92014-08-26 11:47:29 -070068 " - run as a fastboot usb device"
Sebastian Siewior3aab70a2014-05-05 15:08:10 -050069);