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