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