]>
Commit | Line | Data |
---|---|---|
a006a5de ŁM |
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 | * | |
1a459660 | 8 | * SPDX-License-Identifier: GPL-2.0+ |
a006a5de ŁM |
9 | */ |
10 | ||
11 | #include <common.h> | |
a006a5de | 12 | #include <dfu.h> |
a006a5de | 13 | #include <g_dnl.h> |
16297cfb | 14 | #include <usb.h> |
a006a5de ŁM |
15 | |
16 | static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | |
17 | { | |
1cc03c5c ŁM |
18 | bool dfu_reset = false; |
19 | ||
16297cfb MZ |
20 | if (argc < 4) |
21 | return CMD_RET_USAGE; | |
22 | ||
23 | char *usb_controller = argv[1]; | |
24 | char *interface = argv[2]; | |
25 | char *devstring = argv[3]; | |
26 | ||
6bed7ce5 | 27 | int ret, i = 0; |
a006a5de | 28 | |
dd64827e | 29 | ret = dfu_init_env_entities(interface, devstring); |
a006a5de | 30 | if (ret) |
afb8e71c | 31 | goto done; |
a006a5de | 32 | |
afb8e71c | 33 | ret = CMD_RET_SUCCESS; |
16297cfb | 34 | if (argc > 4 && strcmp(argv[4], "list") == 0) { |
a006a5de ŁM |
35 | dfu_show_entities(); |
36 | goto done; | |
37 | } | |
38 | ||
16297cfb MZ |
39 | int controller_index = simple_strtoul(usb_controller, NULL, 0); |
40 | board_usb_init(controller_index, USB_INIT_DEVICE); | |
fe1b28c9 | 41 | g_dnl_clear_detach(); |
c4d0e856 | 42 | g_dnl_register("usb_dnl_dfu"); |
a006a5de | 43 | while (1) { |
fe1b28c9 | 44 | if (g_dnl_detach()) { |
1cc03c5c ŁM |
45 | /* |
46 | * Check if USB bus reset is performed after detach, | |
47 | * which indicates that -R switch has been passed to | |
48 | * dfu-util. In this case reboot the device | |
49 | */ | |
50 | if (dfu_usb_get_reset()) { | |
51 | dfu_reset = true; | |
52 | goto exit; | |
53 | } | |
54 | ||
6bed7ce5 ŁM |
55 | /* |
56 | * This extra number of usb_gadget_handle_interrupts() | |
57 | * calls is necessary to assure correct transmission | |
58 | * completion with dfu-util | |
59 | */ | |
1cc03c5c | 60 | if (++i == 10000) |
6bed7ce5 | 61 | goto exit; |
1cc03c5c | 62 | } |
6bed7ce5 | 63 | |
a006a5de ŁM |
64 | if (ctrlc()) |
65 | goto exit; | |
66 | ||
67 | usb_gadget_handle_interrupts(); | |
68 | } | |
69 | exit: | |
70 | g_dnl_unregister(); | |
71 | done: | |
72 | dfu_free_entities(); | |
a006a5de | 73 | |
1cc03c5c | 74 | if (dfu_reset) |
6bed7ce5 ŁM |
75 | run_command("reset", 0); |
76 | ||
fe1b28c9 | 77 | g_dnl_clear_detach(); |
1cc03c5c | 78 | |
afb8e71c | 79 | return ret; |
a006a5de ŁM |
80 | } |
81 | ||
82 | U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu, | |
83 | "Device Firmware Upgrade", | |
16297cfb MZ |
84 | "<USB_controller> <interface> <dev> [list]\n" |
85 | " - device firmware upgrade via <USB_controller>\n" | |
86 | " on device <dev>, attached to interface\n" | |
87 | " <interface>\n" | |
88 | " [list] - list available alt settings\n" | |
a006a5de | 89 | ); |