Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 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> |
Paul Kocialkowski | d48378f | 2015-06-12 19:57:00 +0200 | [diff] [blame] | 13 | #include <usb.h> |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 14 | |
| 15 | static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
| 16 | { |
Paul Kocialkowski | d48378f | 2015-06-12 19:57:00 +0200 | [diff] [blame] | 17 | int controller_index; |
| 18 | char *usb_controller; |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 19 | int ret; |
| 20 | |
Paul Kocialkowski | d48378f | 2015-06-12 19:57:00 +0200 | [diff] [blame] | 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 | |
Rob Herring | 5aba398 | 2014-12-10 14:43:04 -0600 | [diff] [blame] | 33 | g_dnl_clear_detach(); |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 34 | ret = g_dnl_register("usb_dnl_fastboot"); |
| 35 | if (ret) |
| 36 | return ret; |
| 37 | |
Rob Herring | ce9d8ee | 2015-01-26 15:14:41 -0600 | [diff] [blame] | 38 | if (!g_dnl_board_usb_cable_connected()) { |
| 39 | puts("\rUSB cable not detected.\n" \ |
| 40 | "Command exit.\n"); |
Paul Kocialkowski | d48378f | 2015-06-12 19:57:00 +0200 | [diff] [blame] | 41 | ret = CMD_RET_FAILURE; |
| 42 | goto exit; |
Rob Herring | ce9d8ee | 2015-01-26 15:14:41 -0600 | [diff] [blame] | 43 | } |
| 44 | |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 45 | while (1) { |
Rob Herring | 5aba398 | 2014-12-10 14:43:04 -0600 | [diff] [blame] | 46 | if (g_dnl_detach()) |
| 47 | break; |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 48 | if (ctrlc()) |
| 49 | break; |
Kishon Vijay Abraham I | 4763e16 | 2015-02-23 18:40:23 +0530 | [diff] [blame] | 50 | usb_gadget_handle_interrupts(0); |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 51 | } |
| 52 | |
Paul Kocialkowski | d48378f | 2015-06-12 19:57:00 +0200 | [diff] [blame] | 53 | ret = CMD_RET_SUCCESS; |
| 54 | |
| 55 | exit: |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 56 | g_dnl_unregister(); |
Rob Herring | 5aba398 | 2014-12-10 14:43:04 -0600 | [diff] [blame] | 57 | g_dnl_clear_detach(); |
Paul Kocialkowski | d48378f | 2015-06-12 19:57:00 +0200 | [diff] [blame] | 58 | board_usb_cleanup(controller_index, USB_INIT_DEVICE); |
| 59 | |
| 60 | return ret; |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | U_BOOT_CMD( |
Paul Kocialkowski | d48378f | 2015-06-12 19:57:00 +0200 | [diff] [blame] | 64 | fastboot, 2, 1, do_fastboot, |
Steve Rae | 56ad792 | 2014-08-26 11:47:29 -0700 | [diff] [blame] | 65 | "use USB Fastboot protocol", |
Paul Kocialkowski | d48378f | 2015-06-12 19:57:00 +0200 | [diff] [blame] | 66 | "<USB_controller>\n" |
Steve Rae | 56ad792 | 2014-08-26 11:47:29 -0700 | [diff] [blame] | 67 | " - run as a fastboot usb device" |
Sebastian Siewior | 9d4471e | 2014-05-05 15:08:10 -0500 | [diff] [blame] | 68 | ); |