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