blob: 68cacbbef6697a815eb4eacdd8fb73b80935f284 [file] [log] [blame]
Heinrich Schuchardt22a50742021-03-05 12:58:37 +01001.. SPDX-License-Identifier: GPL-2.0+
2
3Device Firmware Upgrade (DFU)
4=============================
5
6Overview
7--------
8
9The Device Firmware Upgrade (DFU) allows to download and upload firmware
10to/from U-Boot connected over USB.
11
Michal Simek50fa1182023-05-17 09:17:16 +020012U-Boot follows the Universal Serial Bus Device Class Specification for
Heinrich Schuchardt22a50742021-03-05 12:58:37 +010013Device Firmware Upgrade Version 1.1 the USB forum (DFU v1.1 in www.usb.org).
14
15U-Boot implements this DFU capability (CONFIG_DFU) with the command dfu
16(cmd/dfu.c / CONFIG_CMD_DFU) based on:
17
18- the DFU stack (common/dfu.c and common/spl/spl_dfu.c), based on the
19 USB DFU download gadget (drivers/usb/gadget/f_dfu.c)
20- The access to mediums is done in DFU backends (driver/dfu)
21
22Today the supported DFU backends are:
23
24- MMC (RAW or FAT / EXT2 / EXT3 / EXT4 file system / SKIP / SCRIPT)
25- NAND
26- RAM
27- SF (serial flash)
28- MTD (all MTD device: NAND, SPI-NOR, SPI-NAND,...)
29- virtual
30
31These DFU backends are also used by
32
33- the dfutftp (see README.dfutftp)
34- the thordown command (cmd/thordown.c and gadget/f_thor.c)
35
36The "virtual" backend is a generic DFU backend to support a board specific
37target (for example OTP), only based on the weak functions:
38
39- dfu_write_medium_virt
40- dfu_get_medium_size_virt
41- dfu_read_medium_virt
42
43Configuration Options
44---------------------
45
46The following configuration option are relevant for device firmware upgrade:
47
48* CONFIG_DFU
49* CONFIG_DFU_OVER_USB
50* CONFIG_DFU_MMC
51* CONFIG_DFU_MTD
52* CONFIG_DFU_NAND
53* CONFIG_DFU_RAM
54* CONFIG_DFU_SF
55* CONFIG_DFU_SF_PART
56* CONFIG_DFU_TIMEOUT
57* CONFIG_DFU_VIRTUAL
58* CONFIG_CMD_DFU
59
60Environment variables
61---------------------
62
63The dfu command uses 3 environments variables:
64
65dfu_alt_info
66 The DFU setting for the USB download gadget with a semicolon separated
67 string of information on each alternate::
68
69 dfu_alt_info="<alt1>;<alt2>;....;<altN>"
70
71 When several devices are used, the format is:
72
73 - <interface> <dev>'='alternate list (';' separated)
74 - each interface is separated by '&'::
75
76 dfu_alt_info=\
77 "<interface1> <dev1>=<alt1>;....;<altN>&"\
78 "<interface2> <dev2>=<altN+1>;....;<altM>&"\
79 ...\
80 "<interfaceI> <devI>=<altY+1>;....;<altZ>&"
81
82dfu_bufsiz
83 size of the DFU buffer, when absent, defaults to
84 CONFIG_SYS_DFU_DATA_BUF_SIZE (8 MiB by default)
85
86dfu_hash_algo
87 name of the hash algorithm to use
88
89Commands
90--------
91
92dfu <USB_controller> [<interface> <dev>] list
93 list the alternate device defined in *dfu_alt_info*
94
95dfu <USB_controller> [<interface> <dev>] [<timeout>]
96 start the dfu stack on the USB instance with the selected medium
97 backend and use the *dfu_alt_info* variable to configure the
98 alternate setting and link each one with the medium
99 The dfu command continue until receive a ^C in console or
100 a DFU detach transaction from HOST. If CONFIG_DFU_TIMEOUT option
101 is enabled and <timeout> parameter is present in the command line,
102 the DFU operation will be aborted automatically after <timeout>
103 seconds of waiting remote to initiate DFU session.
104
105The possible values of <interface> are (with <USB controller> = 0 in the dfu
106command example)
107
108mmc
109 for eMMC and SD card::
110
111 dfu 0 mmc <dev>
112
113 each element in *dfu_alt_info* being
114
115 * <name> raw <offset> <size> [mmcpart <num>] raw access to mmc device
Masami Hiramatsud2760f32022-01-31 11:52:46 +0900116 * <name> part <dev> <part_id> [offset <byte>] raw access to partition
117 * <name> fat <dev> <part_id> file in FAT partition
118 * <name> ext4 <dev> <part_id> file in EXT4 partition
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100119 * <name> skip 0 0 ignore flashed data
120 * <name> script 0 0 execute commands in shell
121
122 with
123
124 partid
125 being the GPT or DOS partition index,
126 num
127 being the eMMC hardware partition number.
128
129 A value of environment variable *dfu_alt_info* for eMMC could be::
130
131 u-boot raw 0x3e 0x800 mmcpart 1;bl2 raw 0x1e 0x1d mmcpart 1
132
133 A value of environment variable *dfu_alt_info* for SD card could be::
134
135 u-boot raw 0x80 0x800;uImage ext4 0 2
136
137 If don't want to flash given image file to storage, use "skip" type
138 entity.
139
140 - It can be used to protect flashing wrong image for the specific board.
141 - Especailly, this layout will be useful when thor protocol is used,
142 which performs flashing in batch mode, where more than one file is
143 processed.
144
145 For example, if one makes a single tar file with support for the two
146 boards with u-boot-<board1>.bin and u-boot-<board2>.bin files, one
147 can use it to flash a proper u-boot image on both without a failure::
148
149 u-boot-<board1>.bin raw 0x80 0x800; u-boot-<board2>.bin skip 0 0
150
151 When flashing new system image requires do some more complex things
152 than just writing data to the storage medium, one can use 'script'
153 type. Data written to such entity will be executed as a command list
154 in the u-boot's shell. This for example allows to re-create partition
155 layout and even set new *dfu_alt_info* for the newly created paritions.
156 Such script would look like::
157
158 setenv dfu_alt_info ...
159 setenv mbr_parts ...
160 mbr write ...
161
162 Please note that this means that user will be able to execute any
163 arbitrary commands just like in the u-boot's shell.
164
165nand
166 raw slc nand device::
167
168 dfu 0 nand <dev>
169
170 each element in *dfu_alt_info* being either of
171
Masami Hiramatsud2760f32022-01-31 11:52:46 +0900172 * <name> raw <offset> <size> raw access to nand device
173 * <name> part <dev_id> <part_id> raw access to partition
174 * <name> partubi <dev_id> <part_id> raw access to ubi partition
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100175
176 with
177
Masami Hiramatsud2760f32022-01-31 11:52:46 +0900178 offset
179 is the offset in the nand device (hexadecimal without "0x")
180 size
181 is the size of the access area (hexadecimal without "0x")
182 dev_id
183 is the NAND device index (decimal only)
184 part_id
185 is the NAND partition index (decimal only)
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100186
187ram
188 raw access to ram::
189
190 dfu 0 ram <dev>
191
192 dev
193 is not used for RAM target
194
195 each element in *dfu_alt_info* being::
196
197 <name> ram <offset> <size> raw access to ram
198
Masami Hiramatsud2760f32022-01-31 11:52:46 +0900199 with
200
201 offset
202 is the offset in the ram device (hexadecimal without "0x")
203 size
204 is the size of the access area (hexadecimal without "0x")
205
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100206sf
207 serial flash : NOR::
208
209 cmd: dfu 0 sf <dev>
210
211 each element in *dfu_alt_info* being either of:
212
213 * <name> raw <offset> <size> raw access to sf device
Masami Hiramatsud2760f32022-01-31 11:52:46 +0900214 * <name> part <dev_id> <part_id> raw acces to partition
215 * <name> partubi <dev_id> <part_id> raw acces to ubi partition
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100216
217 with
218
Masami Hiramatsud2760f32022-01-31 11:52:46 +0900219 offset
220 is the offset in the sf device (hexadecimal without "0x")
221 size
222 is the size of the access area (hexadecimal without "0x")
223 dev_id
224 is the sf device index (the device is "nor<dev_id>") (deximal only)
225 part_id
226 is the MTD partition index (decimal only)
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100227
228mtd
229 all MTD device: NAND, SPI-NOR, SPI-NAND,...::
230
231 cmd: dfu 0 mtd <dev>
232
233 with
234
235 dev
236 the mtd identifier as defined in mtd command
237 (nand0, nor0, spi-nand0,...)
238
239 each element in *dfu_alt_info* being either of:
240
Masami Hiramatsud2760f32022-01-31 11:52:46 +0900241 * <name> raw <offset> <size> for raw access to mtd device
242 * <name> part <part_id> for raw access to partition
243 * <name> partubi <part_id> for raw access to ubi partition
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100244
245 with
246
Masami Hiramatsud2760f32022-01-31 11:52:46 +0900247 offset
248 is the offset in the mtd device (hexadecimal without "0x")
249 size
250 is the size of the access area (hexadecimal without "0x")
251 part_id
252 is the MTD partition index (decimal only)
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100253
254virt
255 virtual flash back end for DFU
256
257 ::
258
259 cmd: dfu 0 virt <dev>
260
261 each element in *dfu_alt_info* being:
262
263 * <name>
264
265<interface> and <dev> are absent, the dfu command to use multiple devices::
266
267 cmd: dfu 0 list
268 cmd: dfu 0
269
270*dfu_alt_info* variable provides the list of <interface> <dev> with
271alternate list separated by '&' with the same format for each <alt>::
272
273 mmc <dev>=<alt1>;....;<altN>
274 nand <dev>=<alt1>;....;<altN>
275 ram <dev>=<alt1>;....;<altN>
276 sf <dev>=<alt1>;....;<altN>
277 mtd <dev>=<alt1>;....;<altN>
278 virt <dev>=<alt1>;....;<altN>
279
280Callbacks
281---------
282
283The weak callback functions can be implemented to manage specific behavior
284
285dfu_initiated_callback
286 called when the DFU transaction is started, used to initiase the device
287
288dfu_flush_callback
289 called at the end of the DFU write after DFU manifestation, used to manage
290 the device when DFU transaction is closed
291
292Host tools
293----------
294
295When U-Boot runs the dfu stack, the DFU host tools can be used
296to send/receive firmwares on each configurated alternate.
297
298For example dfu-util is a host side implementation of the DFU 1.1
299specifications(http://dfu-util.sourceforge.net/) which works with U-Boot.
300
301Usage
302-----
303
304Example 1: firmware located in eMMC or SD card, with:
305
306- alternate 1 (alt=1) for SPL partition (GPT partition 1)
307- alternate 2 (alt=2) for U-Boot partition (GPT partition 2)
308
309The U-Boot configuration is::
310
311 U-Boot> env set dfu_alt_info "spl part 0 1;u-boot part 0 2"
312
313 U-Boot> dfu 0 mmc 0 list
314 DFU alt settings list:
315 dev: eMMC alt: 0 name: spl layout: RAW_ADDR
316 dev: eMMC alt: 1 name: u-boot layout: RAW_ADDR
317
318 Boot> dfu 0 mmc 0
319
320On the Host side:
321
322list the available alternate setting::
323
324 $> dfu-util -l
325 dfu-util 0.9
326
327 Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
328 Copyright 2010-2016 Tormod Volden and Stefan Schmidt
329 This program is Free Software and has ABSOLUTELY NO WARRANTY
330 Please report bugs to http://sourceforge.net/p/dfu-util/tickets/
331
332 Found DFU: [0483:5720] ver=0200, devnum=45, cfg=1, intf=0, path="3-1.3.1", \
333 alt=1, name="u-boot", serial="003A00203438510D36383238"
334 Found DFU: [0483:5720] ver=0200, devnum=45, cfg=1, intf=0, path="3-1.3.1", \
335 alt=0, name="spl", serial="003A00203438510D36383238"
336
337 To download to U-Boot, use -D option
338
339 $> dfu-util -a 0 -D u-boot-spl.bin
340 $> dfu-util -a 1 -D u-boot.bin
341
342 To upload from U-Boot, use -U option
343
344 $> dfu-util -a 0 -U u-boot-spl.bin
345 $> dfu-util -a 1 -U u-boot.bin
346
347 To request a DFU detach and reset the USB connection:
348 $> dfu-util -a 0 -e -R
349
350
351Example 2: firmware located in NOR (sf) and NAND, with:
352
353- alternate 1 (alt=1) for SPL partition (NOR GPT partition 1)
354- alternate 2 (alt=2) for U-Boot partition (NOR GPT partition 2)
355- alternate 3 (alt=3) for U-Boot-env partition (NOR GPT partition 3)
356- alternate 4 (alt=4) for UBI partition (NAND GPT partition 1)
357
358::
359
360 U-Boot> env set dfu_alt_info \
361 "sf 0:0:10000000:0=spl part 0 1;u-boot part 0 2; \
362 u-boot-env part 0 3&nand 0=UBI partubi 0,1"
363
364 U-Boot> dfu 0 list
365
366 DFU alt settings list:
367 dev: SF alt: 0 name: spl layout: RAW_ADDR
368 dev: SF alt: 1 name: ssbl layout: RAW_ADDR
369 dev: SF alt: 2 name: u-boot-env layout: RAW_ADDR
370 dev: NAND alt: 3 name: UBI layout: RAW_ADDR
371
372 U-Boot> dfu 0
373
374::
375
376 $> dfu-util -l
377 Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
378 intf=0, alt=3, name="UBI", serial="002700333338511934383330"
379 Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
380 intf=0, alt=2, name="u-boot-env", serial="002700333338511934383330"
381 Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
382 intf=0, alt=1, name="u-boot", serial="002700333338511934383330"
383 Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
384 intf=0, alt=0, name="spl", serial="002700333338511934383330"
385
386Same example with MTD backend
387
388::
389
390 U-Boot> env set dfu_alt_info \
391 "mtd nor0=spl part 1;u-boot part 2;u-boot-env part 3&"\
392 "mtd nand0=UBI partubi 1"
393
394 U-Boot> dfu 0 list
395 using id 'nor0,0'
396 using id 'nor0,1'
397 using id 'nor0,2'
398 using id 'nand0,0'
399 DFU alt settings list:
400 dev: MTD alt: 0 name: spl layout: RAW_ADDR
401 dev: MTD alt: 1 name: u-boot layout: RAW_ADDR
402 dev: MTD alt: 2 name: u-boot-env layout: RAW_ADDR
403 dev: MTD alt: 3 name: UBI layout: RAW_ADDR
404
405Example 3
406
407firmware located in SD Card (mmc) and virtual partition on OTP and PMIC not
408volatile memory
409
410- alternate 1 (alt=1) for scard
411- alternate 2 (alt=2) for OTP (virtual)
412- alternate 3 (alt=3) for PMIC NVM (virtual)
413
414::
415
416 U-Boot> env set dfu_alt_info \
417 "mmc 0=sdcard raw 0 0x100000&"\
418 "virt 0=otp" \
419 "virt 1=pmic"
420
421::
422
423 U-Boot> dfu 0 list
424 DFU alt settings list:
425 dev: eMMC alt: 0 name: sdcard layout: RAW_ADDR
426 dev: VIRT alt: 1 name: otp layout: RAW_ADDR
427 dev: VIRT alt: 2 name: pmic layout: RAW_ADDR