Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 1 | /* |
| 2 | * cmd_dfu.c -- dfu command |
| 3 | * |
| 4 | * Copyright (C) 2012 Samsung Electronics |
| 5 | * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com> |
| 6 | * Lukasz Majewski <l.majewski@samsung.com> |
| 7 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 12 | #include <dfu.h> |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 13 | #include <g_dnl.h> |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 14 | #include <usb.h> |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 15 | |
| 16 | static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 17 | { |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 18 | if (argc < 4) |
| 19 | return CMD_RET_USAGE; |
| 20 | |
| 21 | char *usb_controller = argv[1]; |
| 22 | char *interface = argv[2]; |
| 23 | char *devstring = argv[3]; |
| 24 | |
Lukasz Majewski | 6bed7ce | 2013-07-18 13:19:14 +0200 | [diff] [blame] | 25 | int ret, i = 0; |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 26 | |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 27 | ret = dfu_init_env_entities(interface, simple_strtoul(devstring, |
| 28 | NULL, 10)); |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 29 | if (ret) |
Stephen Warren | afb8e71 | 2014-06-10 10:06:41 -0600 | [diff] [blame] | 30 | goto done; |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 31 | |
Stephen Warren | afb8e71 | 2014-06-10 10:06:41 -0600 | [diff] [blame] | 32 | ret = CMD_RET_SUCCESS; |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 33 | if (argc > 4 && strcmp(argv[4], "list") == 0) { |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 34 | dfu_show_entities(); |
| 35 | goto done; |
| 36 | } |
| 37 | |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 38 | int controller_index = simple_strtoul(usb_controller, NULL, 0); |
| 39 | board_usb_init(controller_index, USB_INIT_DEVICE); |
Pantelis Antoniou | ea3e212 | 2012-11-30 08:01:07 +0000 | [diff] [blame] | 40 | |
Mateusz Zalega | c4d0e85 | 2014-04-28 21:13:28 +0200 | [diff] [blame] | 41 | g_dnl_register("usb_dnl_dfu"); |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 42 | while (1) { |
Lukasz Majewski | 6bed7ce | 2013-07-18 13:19:14 +0200 | [diff] [blame] | 43 | if (dfu_reset()) |
| 44 | /* |
| 45 | * This extra number of usb_gadget_handle_interrupts() |
| 46 | * calls is necessary to assure correct transmission |
| 47 | * completion with dfu-util |
| 48 | */ |
| 49 | if (++i == 10) |
| 50 | goto exit; |
| 51 | |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 52 | if (ctrlc()) |
| 53 | goto exit; |
| 54 | |
| 55 | usb_gadget_handle_interrupts(); |
| 56 | } |
| 57 | exit: |
| 58 | g_dnl_unregister(); |
| 59 | done: |
| 60 | dfu_free_entities(); |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 61 | |
Lukasz Majewski | 6bed7ce | 2013-07-18 13:19:14 +0200 | [diff] [blame] | 62 | if (dfu_reset()) |
| 63 | run_command("reset", 0); |
| 64 | |
Stephen Warren | afb8e71 | 2014-06-10 10:06:41 -0600 | [diff] [blame] | 65 | return ret; |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu, |
| 69 | "Device Firmware Upgrade", |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 70 | "<USB_controller> <interface> <dev> [list]\n" |
| 71 | " - device firmware upgrade via <USB_controller>\n" |
| 72 | " on device <dev>, attached to interface\n" |
| 73 | " <interface>\n" |
| 74 | " [list] - list available alt settings\n" |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 75 | ); |