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> |
| 14 | |
| 15 | static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 16 | { |
Albert ARIBAUD | b823fd9 | 2012-10-09 09:28:15 +0000 | [diff] [blame] | 17 | char *s = "dfu"; |
Lukasz Majewski | 6bed7ce | 2013-07-18 13:19:14 +0200 | [diff] [blame] | 18 | int ret, i = 0; |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 19 | |
| 20 | if (argc < 3) |
| 21 | return CMD_RET_USAGE; |
| 22 | |
Lukasz Majewski | 765c5ae | 2013-09-11 14:53:35 +0200 | [diff] [blame] | 23 | ret = dfu_init_env_entities(argv[1], simple_strtoul(argv[2], NULL, 10)); |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 24 | if (ret) |
Lukasz Majewski | 765c5ae | 2013-09-11 14:53:35 +0200 | [diff] [blame] | 25 | return ret; |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 26 | |
Pantelis Antoniou | df93cd9 | 2012-11-30 08:01:08 +0000 | [diff] [blame] | 27 | if (argc > 3 && strcmp(argv[3], "list") == 0) { |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 28 | dfu_show_entities(); |
| 29 | goto done; |
| 30 | } |
| 31 | |
Pantelis Antoniou | ea3e212 | 2012-11-30 08:01:07 +0000 | [diff] [blame] | 32 | #ifdef CONFIG_TRATS |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 33 | board_usb_init(); |
Pantelis Antoniou | ea3e212 | 2012-11-30 08:01:07 +0000 | [diff] [blame] | 34 | #endif |
| 35 | |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 36 | g_dnl_register(s); |
| 37 | while (1) { |
Lukasz Majewski | 6bed7ce | 2013-07-18 13:19:14 +0200 | [diff] [blame] | 38 | if (dfu_reset()) |
| 39 | /* |
| 40 | * This extra number of usb_gadget_handle_interrupts() |
| 41 | * calls is necessary to assure correct transmission |
| 42 | * completion with dfu-util |
| 43 | */ |
| 44 | if (++i == 10) |
| 45 | goto exit; |
| 46 | |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 47 | if (ctrlc()) |
| 48 | goto exit; |
| 49 | |
| 50 | usb_gadget_handle_interrupts(); |
| 51 | } |
| 52 | exit: |
| 53 | g_dnl_unregister(); |
| 54 | done: |
| 55 | dfu_free_entities(); |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 56 | |
Lukasz Majewski | 6bed7ce | 2013-07-18 13:19:14 +0200 | [diff] [blame] | 57 | if (dfu_reset()) |
| 58 | run_command("reset", 0); |
| 59 | |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 60 | return CMD_RET_SUCCESS; |
| 61 | } |
| 62 | |
| 63 | U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu, |
| 64 | "Device Firmware Upgrade", |
| 65 | "<interface> <dev> [list]\n" |
| 66 | " - device firmware upgrade on a device <dev>\n" |
| 67 | " attached to interface <interface>\n" |
| 68 | " [list] - list available alt settings" |
| 69 | ); |