Commit 05341a87646aceac90a63624fbd5fa620f8dc263
Committed by
Marek Vasut
1 parent
bc5dbcb918
Exists in
v2017.01-smarct4x
and in
25 other branches
common: dfu: saperate the dfu common functionality
The cmd_dfu functionality is been used by both SPL and u-boot, saperating the core dfu functionality moving it to common/dfu.c. Signed-off-by: Ravi Babu <ravibabu@ti.com> Reviewed-by: Tom Rini <trini@konsulko.com>
Showing 4 changed files with 92 additions and 59 deletions Side-by-side Diff
cmd/dfu.c
... | ... | @@ -21,7 +21,6 @@ |
21 | 21 | |
22 | 22 | static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
23 | 23 | { |
24 | - bool dfu_reset = false; | |
25 | 24 | |
26 | 25 | if (argc < 4) |
27 | 26 | return CMD_RET_USAGE; |
... | ... | @@ -30,7 +29,7 @@ |
30 | 29 | char *interface = argv[2]; |
31 | 30 | char *devstring = argv[3]; |
32 | 31 | |
33 | - int ret, i = 0; | |
32 | + int ret; | |
34 | 33 | #ifdef CONFIG_DFU_TFTP |
35 | 34 | unsigned long addr = 0; |
36 | 35 | if (!strcmp(argv[1], "tftp")) { |
37 | 36 | |
38 | 37 | |
39 | 38 | |
... | ... | @@ -52,67 +51,11 @@ |
52 | 51 | } |
53 | 52 | |
54 | 53 | int controller_index = simple_strtoul(usb_controller, NULL, 0); |
55 | - board_usb_init(controller_index, USB_INIT_DEVICE); | |
56 | - g_dnl_clear_detach(); | |
57 | - g_dnl_register("usb_dnl_dfu"); | |
58 | - while (1) { | |
59 | - if (g_dnl_detach()) { | |
60 | - /* | |
61 | - * Check if USB bus reset is performed after detach, | |
62 | - * which indicates that -R switch has been passed to | |
63 | - * dfu-util. In this case reboot the device | |
64 | - */ | |
65 | - if (dfu_usb_get_reset()) { | |
66 | - dfu_reset = true; | |
67 | - goto exit; | |
68 | - } | |
69 | 54 | |
70 | - /* | |
71 | - * This extra number of usb_gadget_handle_interrupts() | |
72 | - * calls is necessary to assure correct transmission | |
73 | - * completion with dfu-util | |
74 | - */ | |
75 | - if (++i == 10000) | |
76 | - goto exit; | |
77 | - } | |
55 | + run_usb_dnl_gadget(controller_index, "usb_dnl_dfu"); | |
78 | 56 | |
79 | - if (ctrlc()) | |
80 | - goto exit; | |
81 | - | |
82 | - if (dfu_get_defer_flush()) { | |
83 | - /* | |
84 | - * Call to usb_gadget_handle_interrupts() is necessary | |
85 | - * to act on ZLP OUT transaction from HOST PC after | |
86 | - * transmitting the whole file. | |
87 | - * | |
88 | - * If this ZLP OUT packet is NAK'ed, the HOST libusb | |
89 | - * function fails after timeout (by default it is set to | |
90 | - * 5 seconds). In such situation the dfu-util program | |
91 | - * exits with error message. | |
92 | - */ | |
93 | - usb_gadget_handle_interrupts(controller_index); | |
94 | - ret = dfu_flush(dfu_get_defer_flush(), NULL, 0, 0); | |
95 | - dfu_set_defer_flush(NULL); | |
96 | - if (ret) { | |
97 | - error("Deferred dfu_flush() failed!"); | |
98 | - goto exit; | |
99 | - } | |
100 | - } | |
101 | - | |
102 | - WATCHDOG_RESET(); | |
103 | - usb_gadget_handle_interrupts(controller_index); | |
104 | - } | |
105 | -exit: | |
106 | - g_dnl_unregister(); | |
107 | - board_usb_cleanup(controller_index, USB_INIT_DEVICE); | |
108 | 57 | done: |
109 | 58 | dfu_free_entities(); |
110 | - | |
111 | - if (dfu_reset) | |
112 | - run_command("reset", 0); | |
113 | - | |
114 | - g_dnl_clear_detach(); | |
115 | - | |
116 | 59 | return ret; |
117 | 60 | } |
118 | 61 |
common/Makefile
... | ... | @@ -89,6 +89,7 @@ |
89 | 89 | endif # !CONFIG_SPL_BUILD |
90 | 90 | |
91 | 91 | ifdef CONFIG_SPL_BUILD |
92 | +obj-$(CONFIG_SPL_DFU_SUPPORT) += dfu.o | |
92 | 93 | obj-$(CONFIG_SPL_DFU_SUPPORT) += cli_hush.o |
93 | 94 | obj-$(CONFIG_SPL_HASH_SUPPORT) += hash.o |
94 | 95 | obj-$(CONFIG_ENV_IS_IN_FLASH) += env_flash.o |
... | ... | @@ -172,6 +173,7 @@ |
172 | 173 | |
173 | 174 | obj-y += cli.o |
174 | 175 | obj-$(CONFIG_CMDLINE) += cli_readline.o |
176 | +obj-$(CONFIG_CMD_DFU) += dfu.o | |
175 | 177 | obj-y += command.o |
176 | 178 | obj-y += s_record.o |
177 | 179 | obj-y += xyzModem.o |
common/dfu.c
1 | +/* | |
2 | + * dfu.c -- dfu command | |
3 | + * | |
4 | + * Copyright (C) 2015 | |
5 | + * Lukasz Majewski <l.majewski@majess.pl> | |
6 | + * | |
7 | + * Copyright (C) 2012 Samsung Electronics | |
8 | + * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com> | |
9 | + * Lukasz Majewski <l.majewski@samsung.com> | |
10 | + * | |
11 | + * SPDX-License-Identifier: GPL-2.0+ | |
12 | + */ | |
13 | + | |
14 | +#include <common.h> | |
15 | +#include <watchdog.h> | |
16 | +#include <dfu.h> | |
17 | +#include <console.h> | |
18 | +#include <g_dnl.h> | |
19 | +#include <usb.h> | |
20 | +#include <net.h> | |
21 | + | |
22 | +int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget) | |
23 | +{ | |
24 | + bool dfu_reset = false; | |
25 | + int ret, i = 0; | |
26 | + | |
27 | + board_usb_init(usbctrl_index, USB_INIT_DEVICE); | |
28 | + g_dnl_clear_detach(); | |
29 | + g_dnl_register(usb_dnl_gadget); | |
30 | + while (1) { | |
31 | + if (g_dnl_detach()) { | |
32 | + /* | |
33 | + * Check if USB bus reset is performed after detach, | |
34 | + * which indicates that -R switch has been passed to | |
35 | + * dfu-util. In this case reboot the device | |
36 | + */ | |
37 | + if (dfu_usb_get_reset()) { | |
38 | + dfu_reset = true; | |
39 | + goto exit; | |
40 | + } | |
41 | + | |
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 == 10000) | |
48 | + goto exit; | |
49 | + } | |
50 | + | |
51 | + if (ctrlc()) | |
52 | + goto exit; | |
53 | + | |
54 | + if (dfu_get_defer_flush()) { | |
55 | + /* | |
56 | + * Call to usb_gadget_handle_interrupts() is necessary | |
57 | + * to act on ZLP OUT transaction from HOST PC after | |
58 | + * transmitting the whole file. | |
59 | + * | |
60 | + * If this ZLP OUT packet is NAK'ed, the HOST libusb | |
61 | + * function fails after timeout (by default it is set to | |
62 | + * 5 seconds). In such situation the dfu-util program | |
63 | + * exits with error message. | |
64 | + */ | |
65 | + usb_gadget_handle_interrupts(usbctrl_index); | |
66 | + ret = dfu_flush(dfu_get_defer_flush(), NULL, 0, 0); | |
67 | + dfu_set_defer_flush(NULL); | |
68 | + if (ret) { | |
69 | + error("Deferred dfu_flush() failed!"); | |
70 | + goto exit; | |
71 | + } | |
72 | + } | |
73 | + | |
74 | + WATCHDOG_RESET(); | |
75 | + usb_gadget_handle_interrupts(usbctrl_index); | |
76 | + } | |
77 | +exit: | |
78 | + g_dnl_unregister(); | |
79 | + board_usb_cleanup(usbctrl_index, USB_INIT_DEVICE); | |
80 | + | |
81 | + if (dfu_reset) | |
82 | + run_command("reset", 0); | |
83 | + | |
84 | + g_dnl_clear_detach(); | |
85 | + | |
86 | + return ret; | |
87 | +} |