Commit 05341a87646aceac90a63624fbd5fa620f8dc263

Authored by B, Ravi
Committed by Marek Vasut
1 parent bc5dbcb918

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 Inline Diff

1 /* 1 /*
2 * cmd_dfu.c -- dfu command 2 * cmd_dfu.c -- dfu command
3 * 3 *
4 * Copyright (C) 2015 4 * Copyright (C) 2015
5 * Lukasz Majewski <l.majewski@majess.pl> 5 * Lukasz Majewski <l.majewski@majess.pl>
6 * 6 *
7 * Copyright (C) 2012 Samsung Electronics 7 * Copyright (C) 2012 Samsung Electronics
8 * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com> 8 * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
9 * Lukasz Majewski <l.majewski@samsung.com> 9 * Lukasz Majewski <l.majewski@samsung.com>
10 * 10 *
11 * SPDX-License-Identifier: GPL-2.0+ 11 * SPDX-License-Identifier: GPL-2.0+
12 */ 12 */
13 13
14 #include <common.h> 14 #include <common.h>
15 #include <watchdog.h> 15 #include <watchdog.h>
16 #include <dfu.h> 16 #include <dfu.h>
17 #include <console.h> 17 #include <console.h>
18 #include <g_dnl.h> 18 #include <g_dnl.h>
19 #include <usb.h> 19 #include <usb.h>
20 #include <net.h> 20 #include <net.h>
21 21
22 static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 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 if (argc < 4) 25 if (argc < 4)
27 return CMD_RET_USAGE; 26 return CMD_RET_USAGE;
28 27
29 char *usb_controller = argv[1]; 28 char *usb_controller = argv[1];
30 char *interface = argv[2]; 29 char *interface = argv[2];
31 char *devstring = argv[3]; 30 char *devstring = argv[3];
32 31
33 int ret, i = 0; 32 int ret;
34 #ifdef CONFIG_DFU_TFTP 33 #ifdef CONFIG_DFU_TFTP
35 unsigned long addr = 0; 34 unsigned long addr = 0;
36 if (!strcmp(argv[1], "tftp")) { 35 if (!strcmp(argv[1], "tftp")) {
37 if (argc == 5) 36 if (argc == 5)
38 addr = simple_strtoul(argv[4], NULL, 0); 37 addr = simple_strtoul(argv[4], NULL, 0);
39 38
40 return update_tftp(addr, interface, devstring); 39 return update_tftp(addr, interface, devstring);
41 } 40 }
42 #endif 41 #endif
43 42
44 ret = dfu_init_env_entities(interface, devstring); 43 ret = dfu_init_env_entities(interface, devstring);
45 if (ret) 44 if (ret)
46 goto done; 45 goto done;
47 46
48 ret = CMD_RET_SUCCESS; 47 ret = CMD_RET_SUCCESS;
49 if (argc > 4 && strcmp(argv[4], "list") == 0) { 48 if (argc > 4 && strcmp(argv[4], "list") == 0) {
50 dfu_show_entities(); 49 dfu_show_entities();
51 goto done; 50 goto done;
52 } 51 }
53 52
54 int controller_index = simple_strtoul(usb_controller, NULL, 0); 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 /* 55 run_usb_dnl_gadget(controller_index, "usb_dnl_dfu");
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 }
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 done: 57 done:
109 dfu_free_entities(); 58 dfu_free_entities();
110
111 if (dfu_reset)
112 run_command("reset", 0);
113
114 g_dnl_clear_detach();
115
116 return ret; 59 return ret;
117 } 60 }
118 61
119 U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu, 62 U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
120 "Device Firmware Upgrade", 63 "Device Firmware Upgrade",
121 "<USB_controller> <interface> <dev> [list]\n" 64 "<USB_controller> <interface> <dev> [list]\n"
122 " - device firmware upgrade via <USB_controller>\n" 65 " - device firmware upgrade via <USB_controller>\n"
123 " on device <dev>, attached to interface\n" 66 " on device <dev>, attached to interface\n"
124 " <interface>\n" 67 " <interface>\n"
125 " [list] - list available alt settings\n" 68 " [list] - list available alt settings\n"
126 #ifdef CONFIG_DFU_TFTP 69 #ifdef CONFIG_DFU_TFTP
127 "dfu tftp <interface> <dev> [<addr>]\n" 70 "dfu tftp <interface> <dev> [<addr>]\n"
128 " - device firmware upgrade via TFTP\n" 71 " - device firmware upgrade via TFTP\n"
129 " on device <dev>, attached to interface\n" 72 " on device <dev>, attached to interface\n"
130 " <interface>\n" 73 " <interface>\n"
131 " [<addr>] - address where FIT image has been stored\n" 74 " [<addr>] - address where FIT image has been stored\n"
132 #endif 75 #endif
133 ); 76 );
134 77
1 # 1 #
2 # (C) Copyright 2004-2006 2 # (C) Copyright 2004-2006
3 # Wolfgang Denk, DENX Software Engineering, wd@denx.de. 3 # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 # 4 #
5 # SPDX-License-Identifier: GPL-2.0+ 5 # SPDX-License-Identifier: GPL-2.0+
6 # 6 #
7 7
8 # core 8 # core
9 ifndef CONFIG_SPL_BUILD 9 ifndef CONFIG_SPL_BUILD
10 obj-y += init/ 10 obj-y += init/
11 obj-y += main.o 11 obj-y += main.o
12 obj-y += exports.o 12 obj-y += exports.o
13 obj-y += hash.o 13 obj-y += hash.o
14 obj-$(CONFIG_HUSH_PARSER) += cli_hush.o 14 obj-$(CONFIG_HUSH_PARSER) += cli_hush.o
15 obj-$(CONFIG_AUTOBOOT) += autoboot.o 15 obj-$(CONFIG_AUTOBOOT) += autoboot.o
16 16
17 # This option is not just y/n - it can have a numeric value 17 # This option is not just y/n - it can have a numeric value
18 ifdef CONFIG_BOOT_RETRY_TIME 18 ifdef CONFIG_BOOT_RETRY_TIME
19 obj-y += bootretry.o 19 obj-y += bootretry.o
20 endif 20 endif
21 21
22 # boards 22 # boards
23 obj-y += board_f.o 23 obj-y += board_f.o
24 obj-y += board_r.o 24 obj-y += board_r.o
25 obj-$(CONFIG_DISPLAY_BOARDINFO) += board_info.o 25 obj-$(CONFIG_DISPLAY_BOARDINFO) += board_info.o
26 obj-$(CONFIG_DISPLAY_BOARDINFO_LATE) += board_info.o 26 obj-$(CONFIG_DISPLAY_BOARDINFO_LATE) += board_info.o
27 27
28 obj-$(CONFIG_CMD_BOOTM) += bootm.o bootm_os.o 28 obj-$(CONFIG_CMD_BOOTM) += bootm.o bootm_os.o
29 obj-$(CONFIG_CMD_BOOTZ) += bootm.o bootm_os.o 29 obj-$(CONFIG_CMD_BOOTZ) += bootm.o bootm_os.o
30 obj-$(CONFIG_CMD_BOOTI) += bootm.o bootm_os.o 30 obj-$(CONFIG_CMD_BOOTI) += bootm.o bootm_os.o
31 31
32 # environment 32 # environment
33 obj-y += env_attr.o 33 obj-y += env_attr.o
34 obj-y += env_callback.o 34 obj-y += env_callback.o
35 obj-y += env_flags.o 35 obj-y += env_flags.o
36 obj-$(CONFIG_ENV_IS_IN_DATAFLASH) += env_dataflash.o 36 obj-$(CONFIG_ENV_IS_IN_DATAFLASH) += env_dataflash.o
37 obj-$(CONFIG_ENV_IS_IN_EEPROM) += env_eeprom.o 37 obj-$(CONFIG_ENV_IS_IN_EEPROM) += env_eeprom.o
38 extra-$(CONFIG_ENV_IS_EMBEDDED) += env_embedded.o 38 extra-$(CONFIG_ENV_IS_EMBEDDED) += env_embedded.o
39 obj-$(CONFIG_ENV_IS_IN_EEPROM) += env_embedded.o 39 obj-$(CONFIG_ENV_IS_IN_EEPROM) += env_embedded.o
40 extra-$(CONFIG_ENV_IS_IN_FLASH) += env_embedded.o 40 extra-$(CONFIG_ENV_IS_IN_FLASH) += env_embedded.o
41 obj-$(CONFIG_ENV_IS_IN_NVRAM) += env_embedded.o 41 obj-$(CONFIG_ENV_IS_IN_NVRAM) += env_embedded.o
42 obj-$(CONFIG_ENV_IS_IN_FLASH) += env_flash.o 42 obj-$(CONFIG_ENV_IS_IN_FLASH) += env_flash.o
43 obj-$(CONFIG_ENV_IS_IN_MMC) += env_mmc.o 43 obj-$(CONFIG_ENV_IS_IN_MMC) += env_mmc.o
44 obj-$(CONFIG_ENV_IS_IN_FAT) += env_fat.o 44 obj-$(CONFIG_ENV_IS_IN_FAT) += env_fat.o
45 obj-$(CONFIG_ENV_IS_IN_EXT4) += env_ext4.o 45 obj-$(CONFIG_ENV_IS_IN_EXT4) += env_ext4.o
46 obj-$(CONFIG_ENV_IS_IN_NAND) += env_nand.o 46 obj-$(CONFIG_ENV_IS_IN_NAND) += env_nand.o
47 obj-$(CONFIG_ENV_IS_IN_NVRAM) += env_nvram.o 47 obj-$(CONFIG_ENV_IS_IN_NVRAM) += env_nvram.o
48 obj-$(CONFIG_ENV_IS_IN_ONENAND) += env_onenand.o 48 obj-$(CONFIG_ENV_IS_IN_ONENAND) += env_onenand.o
49 obj-$(CONFIG_ENV_IS_IN_SATA) += env_sata.o 49 obj-$(CONFIG_ENV_IS_IN_SATA) += env_sata.o
50 obj-$(CONFIG_ENV_IS_IN_SPI_FLASH) += env_sf.o 50 obj-$(CONFIG_ENV_IS_IN_SPI_FLASH) += env_sf.o
51 obj-$(CONFIG_ENV_IS_IN_REMOTE) += env_remote.o 51 obj-$(CONFIG_ENV_IS_IN_REMOTE) += env_remote.o
52 obj-$(CONFIG_ENV_IS_IN_UBI) += env_ubi.o 52 obj-$(CONFIG_ENV_IS_IN_UBI) += env_ubi.o
53 obj-$(CONFIG_ENV_IS_NOWHERE) += env_nowhere.o 53 obj-$(CONFIG_ENV_IS_NOWHERE) += env_nowhere.o
54 54
55 obj-$(CONFIG_CMD_BEDBUG) += bedbug.o 55 obj-$(CONFIG_CMD_BEDBUG) += bedbug.o
56 obj-$(CONFIG_$(SPL_)OF_LIBFDT) += fdt_support.o 56 obj-$(CONFIG_$(SPL_)OF_LIBFDT) += fdt_support.o
57 57
58 obj-$(CONFIG_MII) += miiphyutil.o 58 obj-$(CONFIG_MII) += miiphyutil.o
59 obj-$(CONFIG_CMD_MII) += miiphyutil.o 59 obj-$(CONFIG_CMD_MII) += miiphyutil.o
60 obj-$(CONFIG_PHYLIB) += miiphyutil.o 60 obj-$(CONFIG_PHYLIB) += miiphyutil.o
61 61
62 ifdef CONFIG_CMD_USB 62 ifdef CONFIG_CMD_USB
63 obj-y += usb.o usb_hub.o 63 obj-y += usb.o usb_hub.o
64 obj-$(CONFIG_USB_STORAGE) += usb_storage.o 64 obj-$(CONFIG_USB_STORAGE) += usb_storage.o
65 endif 65 endif
66 66
67 # others 67 # others
68 obj-$(CONFIG_BOOTSTAGE) += bootstage.o 68 obj-$(CONFIG_BOOTSTAGE) += bootstage.o
69 obj-$(CONFIG_CONSOLE_MUX) += iomux.o 69 obj-$(CONFIG_CONSOLE_MUX) += iomux.o
70 obj-y += flash.o 70 obj-y += flash.o
71 obj-$(CONFIG_CMD_KGDB) += kgdb.o kgdb_stubs.o 71 obj-$(CONFIG_CMD_KGDB) += kgdb.o kgdb_stubs.o
72 obj-$(CONFIG_I2C_EDID) += edid.o 72 obj-$(CONFIG_I2C_EDID) += edid.o
73 obj-$(CONFIG_KALLSYMS) += kallsyms.o 73 obj-$(CONFIG_KALLSYMS) += kallsyms.o
74 obj-y += splash.o 74 obj-y += splash.o
75 obj-$(CONFIG_SPLASH_SOURCE) += splash_source.o 75 obj-$(CONFIG_SPLASH_SOURCE) += splash_source.o
76 ifndef CONFIG_DM_VIDEO 76 ifndef CONFIG_DM_VIDEO
77 obj-$(CONFIG_LCD) += lcd.o lcd_console.o 77 obj-$(CONFIG_LCD) += lcd.o lcd_console.o
78 endif 78 endif
79 obj-$(CONFIG_LCD_ROTATION) += lcd_console_rotation.o 79 obj-$(CONFIG_LCD_ROTATION) += lcd_console_rotation.o
80 obj-$(CONFIG_LCD_DT_SIMPLEFB) += lcd_simplefb.o 80 obj-$(CONFIG_LCD_DT_SIMPLEFB) += lcd_simplefb.o
81 obj-$(CONFIG_LYNXKDI) += lynxkdi.o 81 obj-$(CONFIG_LYNXKDI) += lynxkdi.o
82 obj-$(CONFIG_MENU) += menu.o 82 obj-$(CONFIG_MENU) += menu.o
83 obj-$(CONFIG_CMD_SATA) += sata.o 83 obj-$(CONFIG_CMD_SATA) += sata.o
84 obj-$(CONFIG_SCSI) += scsi.o 84 obj-$(CONFIG_SCSI) += scsi.o
85 obj-$(CONFIG_UPDATE_TFTP) += update.o 85 obj-$(CONFIG_UPDATE_TFTP) += update.o
86 obj-$(CONFIG_DFU_TFTP) += update.o 86 obj-$(CONFIG_DFU_TFTP) += update.o
87 obj-$(CONFIG_USB_KEYBOARD) += usb_kbd.o 87 obj-$(CONFIG_USB_KEYBOARD) += usb_kbd.o
88 88
89 endif # !CONFIG_SPL_BUILD 89 endif # !CONFIG_SPL_BUILD
90 90
91 ifdef CONFIG_SPL_BUILD 91 ifdef CONFIG_SPL_BUILD
92 obj-$(CONFIG_SPL_DFU_SUPPORT) += dfu.o
92 obj-$(CONFIG_SPL_DFU_SUPPORT) += cli_hush.o 93 obj-$(CONFIG_SPL_DFU_SUPPORT) += cli_hush.o
93 obj-$(CONFIG_SPL_HASH_SUPPORT) += hash.o 94 obj-$(CONFIG_SPL_HASH_SUPPORT) += hash.o
94 obj-$(CONFIG_ENV_IS_IN_FLASH) += env_flash.o 95 obj-$(CONFIG_ENV_IS_IN_FLASH) += env_flash.o
95 obj-$(CONFIG_SPL_YMODEM_SUPPORT) += xyzModem.o 96 obj-$(CONFIG_SPL_YMODEM_SUPPORT) += xyzModem.o
96 obj-$(CONFIG_SPL_NET_SUPPORT) += miiphyutil.o 97 obj-$(CONFIG_SPL_NET_SUPPORT) += miiphyutil.o
97 obj-$(CONFIG_SPL_OF_TRANSLATE) += fdt_support.o 98 obj-$(CONFIG_SPL_OF_TRANSLATE) += fdt_support.o
98 ifdef CONFIG_SPL_USB_HOST_SUPPORT 99 ifdef CONFIG_SPL_USB_HOST_SUPPORT
99 obj-$(CONFIG_SPL_USB_SUPPORT) += usb.o usb_hub.o 100 obj-$(CONFIG_SPL_USB_SUPPORT) += usb.o usb_hub.o
100 obj-$(CONFIG_USB_STORAGE) += usb_storage.o 101 obj-$(CONFIG_USB_STORAGE) += usb_storage.o
101 endif 102 endif
102 # environment 103 # environment
103 ifdef CONFIG_TPL_BUILD 104 ifdef CONFIG_TPL_BUILD
104 obj-$(CONFIG_TPL_ENV_SUPPORT) += env_attr.o 105 obj-$(CONFIG_TPL_ENV_SUPPORT) += env_attr.o
105 obj-$(CONFIG_TPL_ENV_SUPPORT) += env_flags.o 106 obj-$(CONFIG_TPL_ENV_SUPPORT) += env_flags.o
106 obj-$(CONFIG_TPL_ENV_SUPPORT) += env_callback.o 107 obj-$(CONFIG_TPL_ENV_SUPPORT) += env_callback.o
107 else 108 else
108 obj-$(CONFIG_SPL_ENV_SUPPORT) += env_attr.o 109 obj-$(CONFIG_SPL_ENV_SUPPORT) += env_attr.o
109 obj-$(CONFIG_SPL_ENV_SUPPORT) += env_flags.o 110 obj-$(CONFIG_SPL_ENV_SUPPORT) += env_flags.o
110 obj-$(CONFIG_SPL_ENV_SUPPORT) += env_callback.o 111 obj-$(CONFIG_SPL_ENV_SUPPORT) += env_callback.o
111 endif 112 endif
112 ifneq ($(CONFIG_TPL_ENV_SUPPORT)$(CONFIG_SPL_ENV_SUPPORT),) 113 ifneq ($(CONFIG_TPL_ENV_SUPPORT)$(CONFIG_SPL_ENV_SUPPORT),)
113 obj-$(CONFIG_ENV_IS_NOWHERE) += env_nowhere.o 114 obj-$(CONFIG_ENV_IS_NOWHERE) += env_nowhere.o
114 obj-$(CONFIG_ENV_IS_IN_MMC) += env_mmc.o 115 obj-$(CONFIG_ENV_IS_IN_MMC) += env_mmc.o
115 obj-$(CONFIG_ENV_IS_IN_FAT) += env_fat.o 116 obj-$(CONFIG_ENV_IS_IN_FAT) += env_fat.o
116 obj-$(CONFIG_ENV_IS_IN_EXT4) += env_ext4.o 117 obj-$(CONFIG_ENV_IS_IN_EXT4) += env_ext4.o
117 obj-$(CONFIG_ENV_IS_IN_NAND) += env_nand.o 118 obj-$(CONFIG_ENV_IS_IN_NAND) += env_nand.o
118 obj-$(CONFIG_ENV_IS_IN_SPI_FLASH) += env_sf.o 119 obj-$(CONFIG_ENV_IS_IN_SPI_FLASH) += env_sf.o
119 obj-$(CONFIG_ENV_IS_IN_FLASH) += env_flash.o 120 obj-$(CONFIG_ENV_IS_IN_FLASH) += env_flash.o
120 endif 121 endif
121 ifdef CONFIG_SPL_SATA_SUPPORT 122 ifdef CONFIG_SPL_SATA_SUPPORT
122 obj-$(CONFIG_SCSI) += scsi.o 123 obj-$(CONFIG_SCSI) += scsi.o
123 endif 124 endif
124 endif 125 endif
125 #environment 126 #environment
126 obj-y += env_common.o 127 obj-y += env_common.o
127 #others 128 #others
128 obj-$(CONFIG_DDR_SPD) += ddr_spd.o 129 obj-$(CONFIG_DDR_SPD) += ddr_spd.o
129 obj-$(CONFIG_SPD_EEPROM) += ddr_spd.o 130 obj-$(CONFIG_SPD_EEPROM) += ddr_spd.o
130 obj-$(CONFIG_HWCONFIG) += hwconfig.o 131 obj-$(CONFIG_HWCONFIG) += hwconfig.o
131 obj-$(CONFIG_BOUNCE_BUFFER) += bouncebuf.o 132 obj-$(CONFIG_BOUNCE_BUFFER) += bouncebuf.o
132 ifdef CONFIG_SPL_BUILD 133 ifdef CONFIG_SPL_BUILD
133 ifdef CONFIG_TPL_BUILD 134 ifdef CONFIG_TPL_BUILD
134 obj-$(CONFIG_TPL_SERIAL_SUPPORT) += console.o 135 obj-$(CONFIG_TPL_SERIAL_SUPPORT) += console.o
135 else 136 else
136 obj-$(CONFIG_SPL_SERIAL_SUPPORT) += console.o 137 obj-$(CONFIG_SPL_SERIAL_SUPPORT) += console.o
137 endif 138 endif
138 else 139 else
139 obj-y += console.o 140 obj-y += console.o
140 endif 141 endif
141 obj-$(CONFIG_CROS_EC) += cros_ec.o 142 obj-$(CONFIG_CROS_EC) += cros_ec.o
142 obj-y += dlmalloc.o 143 obj-y += dlmalloc.o
143 ifdef CONFIG_SYS_MALLOC_F_LEN 144 ifdef CONFIG_SYS_MALLOC_F_LEN
144 obj-y += malloc_simple.o 145 obj-y += malloc_simple.o
145 endif 146 endif
146 obj-$(CONFIG_CMD_IDE) += ide.o 147 obj-$(CONFIG_CMD_IDE) += ide.o
147 obj-y += image.o 148 obj-y += image.o
148 obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o 149 obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o
149 obj-$(CONFIG_$(SPL_)OF_LIBFDT) += image-fdt.o 150 obj-$(CONFIG_$(SPL_)OF_LIBFDT) += image-fdt.o
150 obj-$(CONFIG_$(SPL_)FIT) += image-fit.o 151 obj-$(CONFIG_$(SPL_)FIT) += image-fit.o
151 obj-$(CONFIG_$(SPL_)FIT_SIGNATURE) += image-sig.o 152 obj-$(CONFIG_$(SPL_)FIT_SIGNATURE) += image-sig.o
152 obj-$(CONFIG_IO_TRACE) += iotrace.o 153 obj-$(CONFIG_IO_TRACE) += iotrace.o
153 obj-y += memsize.o 154 obj-y += memsize.o
154 obj-y += stdio.o 155 obj-y += stdio.o
155 156
156 # This option is not just y/n - it can have a numeric value 157 # This option is not just y/n - it can have a numeric value
157 ifdef CONFIG_FASTBOOT_FLASH 158 ifdef CONFIG_FASTBOOT_FLASH
158 obj-y += image-sparse.o 159 obj-y += image-sparse.o
159 ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV 160 ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
160 obj-y += fb_mmc.o 161 obj-y += fb_mmc.o
161 endif 162 endif
162 ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV 163 ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV
163 obj-y += fb_nand.o 164 obj-y += fb_nand.o
164 endif 165 endif
165 endif 166 endif
166 167
167 ifdef CONFIG_CMD_EEPROM_LAYOUT 168 ifdef CONFIG_CMD_EEPROM_LAYOUT
168 obj-y += eeprom/eeprom_field.o eeprom/eeprom_layout.o 169 obj-y += eeprom/eeprom_field.o eeprom/eeprom_layout.o
169 endif 170 endif
170 # We always have this since drivers/ddr/fs/interactive.c needs it 171 # We always have this since drivers/ddr/fs/interactive.c needs it
171 obj-$(CONFIG_CMDLINE) += cli_simple.o 172 obj-$(CONFIG_CMDLINE) += cli_simple.o
172 173
173 obj-y += cli.o 174 obj-y += cli.o
174 obj-$(CONFIG_CMDLINE) += cli_readline.o 175 obj-$(CONFIG_CMDLINE) += cli_readline.o
176 obj-$(CONFIG_CMD_DFU) += dfu.o
175 obj-y += command.o 177 obj-y += command.o
176 obj-y += s_record.o 178 obj-y += s_record.o
177 obj-y += xyzModem.o 179 obj-y += xyzModem.o
178 180
179 CFLAGS_env_embedded.o := -Wa,--no-warn -DENV_CRC=$(shell tools/envcrc 2>/dev/null) 181 CFLAGS_env_embedded.o := -Wa,--no-warn -DENV_CRC=$(shell tools/envcrc 2>/dev/null)
180 182
File was created 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 }
88
1 /* 1 /*
2 * Copyright (C) 2012 Samsung Electronics 2 * Copyright (C) 2012 Samsung Electronics
3 * Lukasz Majewski <l.majewski@samsung.com> 3 * Lukasz Majewski <l.majewski@samsung.com>
4 * 4 *
5 * SPDX-License-Identifier: GPL-2.0+ 5 * SPDX-License-Identifier: GPL-2.0+
6 */ 6 */
7 7
8 #ifndef __G_DOWNLOAD_H_ 8 #ifndef __G_DOWNLOAD_H_
9 #define __G_DOWNLOAD_H_ 9 #define __G_DOWNLOAD_H_
10 10
11 #include <linux/usb/ch9.h> 11 #include <linux/usb/ch9.h>
12 #include <linux/usb/gadget.h> 12 #include <linux/usb/gadget.h>
13 #include <linux/usb/composite.h> 13 #include <linux/usb/composite.h>
14 #include <linker_lists.h> 14 #include <linker_lists.h>
15 15
16 /* 16 /*
17 * @usb_fname: unescaped USB function name 17 * @usb_fname: unescaped USB function name
18 * @callback_ptr: bind callback, one per function name 18 * @callback_ptr: bind callback, one per function name
19 */ 19 */
20 #define DECLARE_GADGET_BIND_CALLBACK(usb_fname, callback_ptr) \ 20 #define DECLARE_GADGET_BIND_CALLBACK(usb_fname, callback_ptr) \
21 ll_entry_declare(struct g_dnl_bind_callback, \ 21 ll_entry_declare(struct g_dnl_bind_callback, \
22 __usb_function_name_##usb_fname, \ 22 __usb_function_name_##usb_fname, \
23 g_dnl_bind_callbacks) = { \ 23 g_dnl_bind_callbacks) = { \
24 .usb_function_name = #usb_fname, \ 24 .usb_function_name = #usb_fname, \
25 .fptr = callback_ptr \ 25 .fptr = callback_ptr \
26 } 26 }
27 27
28 typedef int (*g_dnl_bind_callback_f)(struct usb_configuration *); 28 typedef int (*g_dnl_bind_callback_f)(struct usb_configuration *);
29 29
30 /* used in Gadget downloader callback linker list */ 30 /* used in Gadget downloader callback linker list */
31 struct g_dnl_bind_callback { 31 struct g_dnl_bind_callback {
32 const char *usb_function_name; 32 const char *usb_function_name;
33 g_dnl_bind_callback_f fptr; 33 g_dnl_bind_callback_f fptr;
34 }; 34 };
35 35
36 int g_dnl_bind_fixup(struct usb_device_descriptor *, const char *); 36 int g_dnl_bind_fixup(struct usb_device_descriptor *, const char *);
37 int g_dnl_get_board_bcd_device_number(int gcnum); 37 int g_dnl_get_board_bcd_device_number(int gcnum);
38 int g_dnl_board_usb_cable_connected(void); 38 int g_dnl_board_usb_cable_connected(void);
39 int g_dnl_register(const char *s); 39 int g_dnl_register(const char *s);
40 void g_dnl_unregister(void); 40 void g_dnl_unregister(void);
41 void g_dnl_set_serialnumber(char *); 41 void g_dnl_set_serialnumber(char *);
42 42
43 bool g_dnl_detach(void); 43 bool g_dnl_detach(void);
44 void g_dnl_trigger_detach(void); 44 void g_dnl_trigger_detach(void);
45 void g_dnl_clear_detach(void); 45 void g_dnl_clear_detach(void);
46 int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget);
46 47
47 #endif /* __G_DOWNLOAD_H_ */ 48 #endif /* __G_DOWNLOAD_H_ */
48 49