blob: af805514b267288b086855b95fd945af67b45ee5 [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
Mattijs Korpershoek28874012024-01-03 09:00:04 +01009Device Firmware Upgrade (DFU) enables the download and upload of firmware
10to/from U-Boot while connected over USB.
Heinrich Schuchardt22a50742021-03-05 12:58:37 +010011
Michal Simek50fa1182023-05-17 09:17:16 +020012U-Boot follows the Universal Serial Bus Device Class Specification for
Mattijs Korpershoek28874012024-01-03 09:00:04 +010013Device Firmware Upgrade Version 1.1 from the USB forum (DFU v1.1 in www.usb.org).
Heinrich Schuchardt22a50742021-03-05 12:58:37 +010014
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)
Caleb Connollyc49e09b2024-10-12 15:57:17 +020025- SCSI (UFS, RAW partition, FAT / EXT2 / EXT3 / EXT4 file system / SKIP / SCRIPT)
Heinrich Schuchardt22a50742021-03-05 12:58:37 +010026- NAND
27- RAM
28- SF (serial flash)
29- MTD (all MTD device: NAND, SPI-NOR, SPI-NAND,...)
30- virtual
31
32These DFU backends are also used by
33
34- the dfutftp (see README.dfutftp)
35- the thordown command (cmd/thordown.c and gadget/f_thor.c)
36
37The "virtual" backend is a generic DFU backend to support a board specific
38target (for example OTP), only based on the weak functions:
39
40- dfu_write_medium_virt
41- dfu_get_medium_size_virt
42- dfu_read_medium_virt
43
44Configuration Options
45---------------------
46
Mattijs Korpershoek28874012024-01-03 09:00:04 +010047The following configuration options are relevant to device firmware upgrade:
Heinrich Schuchardt22a50742021-03-05 12:58:37 +010048
49* CONFIG_DFU
50* CONFIG_DFU_OVER_USB
51* CONFIG_DFU_MMC
52* CONFIG_DFU_MTD
53* CONFIG_DFU_NAND
54* CONFIG_DFU_RAM
Caleb Connollyc49e09b2024-10-12 15:57:17 +020055* CONFIG_DFU_SCSI
Heinrich Schuchardt22a50742021-03-05 12:58:37 +010056* CONFIG_DFU_SF
57* CONFIG_DFU_SF_PART
58* CONFIG_DFU_TIMEOUT
59* CONFIG_DFU_VIRTUAL
60* CONFIG_CMD_DFU
61
62Environment variables
63---------------------
64
Mattijs Korpershoek28874012024-01-03 09:00:04 +010065The dfu command uses 3 environment variables:
Heinrich Schuchardt22a50742021-03-05 12:58:37 +010066
67dfu_alt_info
68 The DFU setting for the USB download gadget with a semicolon separated
69 string of information on each alternate::
70
71 dfu_alt_info="<alt1>;<alt2>;....;<altN>"
72
73 When several devices are used, the format is:
74
75 - <interface> <dev>'='alternate list (';' separated)
76 - each interface is separated by '&'::
77
78 dfu_alt_info=\
79 "<interface1> <dev1>=<alt1>;....;<altN>&"\
80 "<interface2> <dev2>=<altN+1>;....;<altM>&"\
81 ...\
82 "<interfaceI> <devI>=<altY+1>;....;<altZ>&"
83
84dfu_bufsiz
85 size of the DFU buffer, when absent, defaults to
86 CONFIG_SYS_DFU_DATA_BUF_SIZE (8 MiB by default)
87
88dfu_hash_algo
89 name of the hash algorithm to use
90
91Commands
92--------
93
94dfu <USB_controller> [<interface> <dev>] list
Mattijs Korpershoek28874012024-01-03 09:00:04 +010095 List the alternate device defined in *dfu_alt_info*.
Heinrich Schuchardt22a50742021-03-05 12:58:37 +010096
97dfu <USB_controller> [<interface> <dev>] [<timeout>]
Mattijs Korpershoek28874012024-01-03 09:00:04 +010098 Start the dfu stack on the USB instance with the selected medium
Heinrich Schuchardt22a50742021-03-05 12:58:37 +010099 backend and use the *dfu_alt_info* variable to configure the
Mattijs Korpershoek28874012024-01-03 09:00:04 +0100100 alternate setting and link each one with the medium.
101 The dfu command continues until it receives a ^C in the console or
102 a DFU detach transaction from the HOST. If the CONFIG_DFU_TIMEOUT option
103 is enabled and a <timeout> parameter is present in the command line,
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100104 the DFU operation will be aborted automatically after <timeout>
Mattijs Korpershoek28874012024-01-03 09:00:04 +0100105 seconds of waiting for the remote to initiate a DFU session.
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100106
107The possible values of <interface> are (with <USB controller> = 0 in the dfu
108command example)
109
110mmc
111 for eMMC and SD card::
112
113 dfu 0 mmc <dev>
114
115 each element in *dfu_alt_info* being
116
117 * <name> raw <offset> <size> [mmcpart <num>] raw access to mmc device
Masami Hiramatsud2760f32022-01-31 11:52:46 +0900118 * <name> part <dev> <part_id> [offset <byte>] raw access to partition
119 * <name> fat <dev> <part_id> file in FAT partition
120 * <name> ext4 <dev> <part_id> file in EXT4 partition
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100121 * <name> skip 0 0 ignore flashed data
122 * <name> script 0 0 execute commands in shell
123
124 with
125
Marek Vasut3ed7faf2023-10-29 23:37:22 +0100126 offset
127 is the offset in the device (hexadecimal without "0x")
128 size
129 is the size of the access area (hexadecimal without "0x")
130 or 0 which means whole device
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100131 partid
132 being the GPT or DOS partition index,
133 num
134 being the eMMC hardware partition number.
135
136 A value of environment variable *dfu_alt_info* for eMMC could be::
137
138 u-boot raw 0x3e 0x800 mmcpart 1;bl2 raw 0x1e 0x1d mmcpart 1
139
140 A value of environment variable *dfu_alt_info* for SD card could be::
141
142 u-boot raw 0x80 0x800;uImage ext4 0 2
143
Mattijs Korpershoek28874012024-01-03 09:00:04 +0100144 If you don't want to flash the given image file to storage, use the "skip"
145 type entity.
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100146
Mattijs Korpershoek28874012024-01-03 09:00:04 +0100147 - It can be used to protect from flashing the wrong image for the specific board.
148 - Especially, this layout will be useful when the thor protocol is used,
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100149 which performs flashing in batch mode, where more than one file is
150 processed.
151
152 For example, if one makes a single tar file with support for the two
153 boards with u-boot-<board1>.bin and u-boot-<board2>.bin files, one
154 can use it to flash a proper u-boot image on both without a failure::
155
156 u-boot-<board1>.bin raw 0x80 0x800; u-boot-<board2>.bin skip 0 0
157
Mattijs Korpershoek28874012024-01-03 09:00:04 +0100158 When flashing a new system image requires you to do some more complex
159 things than just writing data to the storage medium, one can use 'script'
160 type. Data written to such an entity will be executed as a command list
161 in the u-boot's shell. This for example allows you to re-create a partition
162 layout and even set a new *dfu_alt_info* for the newly created partitions.
163 Such a script would look like::
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100164
165 setenv dfu_alt_info ...
166 setenv mbr_parts ...
167 mbr write ...
168
Mattijs Korpershoek28874012024-01-03 09:00:04 +0100169 Please note that this means the user will be able to execute any
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100170 arbitrary commands just like in the u-boot's shell.
171
Caleb Connollyc49e09b2024-10-12 15:57:17 +0200172scsi
173 for UFS storage::
174
175 dfu 0 scsi <dev>
176
177 each element in *dfu_alt_info* being
178
179 * <name> raw <offset> <size> raw access to SCSI LUN
180 * <name> part <part_id> raw access to partition
181 * <name> fat <part_id> file in FAT partition
182 * <name> ext4 <part_id> file in EXT4 partition
183 * <name> skip 0 0 ignore flashed data
184 * <name> script 0 0 execute commands in shell
185
186 with
187
188 size
189 is the size of the access area (hexadecimal without "0x")
190 or 0 which means whole device
191 partid
192 is the GPT or DOS partition index.
193 dev
194 is the SCSI LU (Logical Unit) index (decimal only)
195
196 A value of environment variable *dfu_alt_info* for UFS could be::
197
198 u-boot part 4;bl2 raw 0x1e 0x1d
199
200 See mmc section above for details on the skip and script types.
201
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100202nand
203 raw slc nand device::
204
205 dfu 0 nand <dev>
206
207 each element in *dfu_alt_info* being either of
208
Masami Hiramatsud2760f32022-01-31 11:52:46 +0900209 * <name> raw <offset> <size> raw access to nand device
210 * <name> part <dev_id> <part_id> raw access to partition
211 * <name> partubi <dev_id> <part_id> raw access to ubi partition
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100212
213 with
214
Masami Hiramatsud2760f32022-01-31 11:52:46 +0900215 offset
216 is the offset in the nand device (hexadecimal without "0x")
217 size
218 is the size of the access area (hexadecimal without "0x")
219 dev_id
220 is the NAND device index (decimal only)
221 part_id
222 is the NAND partition index (decimal only)
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100223
224ram
225 raw access to ram::
226
227 dfu 0 ram <dev>
228
229 dev
230 is not used for RAM target
231
232 each element in *dfu_alt_info* being::
233
234 <name> ram <offset> <size> raw access to ram
235
Masami Hiramatsud2760f32022-01-31 11:52:46 +0900236 with
237
238 offset
239 is the offset in the ram device (hexadecimal without "0x")
240 size
241 is the size of the access area (hexadecimal without "0x")
242
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100243sf
244 serial flash : NOR::
245
246 cmd: dfu 0 sf <dev>
247
248 each element in *dfu_alt_info* being either of:
249
250 * <name> raw <offset> <size> raw access to sf device
Mattijs Korpershoek28874012024-01-03 09:00:04 +0100251 * <name> part <dev_id> <part_id> raw access to partition
252 * <name> partubi <dev_id> <part_id> raw access to ubi partition
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100253
254 with
255
Masami Hiramatsud2760f32022-01-31 11:52:46 +0900256 offset
257 is the offset in the sf device (hexadecimal without "0x")
258 size
259 is the size of the access area (hexadecimal without "0x")
260 dev_id
261 is the sf device index (the device is "nor<dev_id>") (deximal only)
262 part_id
263 is the MTD partition index (decimal only)
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100264
265mtd
266 all MTD device: NAND, SPI-NOR, SPI-NAND,...::
267
268 cmd: dfu 0 mtd <dev>
269
270 with
271
272 dev
273 the mtd identifier as defined in mtd command
274 (nand0, nor0, spi-nand0,...)
275
276 each element in *dfu_alt_info* being either of:
277
Masami Hiramatsud2760f32022-01-31 11:52:46 +0900278 * <name> raw <offset> <size> for raw access to mtd device
279 * <name> part <part_id> for raw access to partition
280 * <name> partubi <part_id> for raw access to ubi partition
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100281
282 with
283
Masami Hiramatsud2760f32022-01-31 11:52:46 +0900284 offset
285 is the offset in the mtd device (hexadecimal without "0x")
286 size
287 is the size of the access area (hexadecimal without "0x")
288 part_id
289 is the MTD partition index (decimal only)
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100290
291virt
292 virtual flash back end for DFU
293
294 ::
295
296 cmd: dfu 0 virt <dev>
297
298 each element in *dfu_alt_info* being:
299
300 * <name>
301
302<interface> and <dev> are absent, the dfu command to use multiple devices::
303
304 cmd: dfu 0 list
305 cmd: dfu 0
306
307*dfu_alt_info* variable provides the list of <interface> <dev> with
308alternate list separated by '&' with the same format for each <alt>::
309
310 mmc <dev>=<alt1>;....;<altN>
311 nand <dev>=<alt1>;....;<altN>
312 ram <dev>=<alt1>;....;<altN>
Caleb Connollyc49e09b2024-10-12 15:57:17 +0200313 scsi <dev>=<alt1>;....;<altN>
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100314 sf <dev>=<alt1>;....;<altN>
315 mtd <dev>=<alt1>;....;<altN>
316 virt <dev>=<alt1>;....;<altN>
317
318Callbacks
319---------
320
321The weak callback functions can be implemented to manage specific behavior
322
323dfu_initiated_callback
Mattijs Korpershoek28874012024-01-03 09:00:04 +0100324 called when the DFU transaction is started, used to initialize the device
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100325
326dfu_flush_callback
327 called at the end of the DFU write after DFU manifestation, used to manage
Mattijs Korpershoek28874012024-01-03 09:00:04 +0100328 the device when the DFU transaction is closed
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100329
330Host tools
331----------
332
333When U-Boot runs the dfu stack, the DFU host tools can be used
Mattijs Korpershoek28874012024-01-03 09:00:04 +0100334to send/receive firmware images on each configured alternate.
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100335
336For example dfu-util is a host side implementation of the DFU 1.1
337specifications(http://dfu-util.sourceforge.net/) which works with U-Boot.
338
339Usage
340-----
341
342Example 1: firmware located in eMMC or SD card, with:
343
344- alternate 1 (alt=1) for SPL partition (GPT partition 1)
345- alternate 2 (alt=2) for U-Boot partition (GPT partition 2)
346
347The U-Boot configuration is::
348
349 U-Boot> env set dfu_alt_info "spl part 0 1;u-boot part 0 2"
350
351 U-Boot> dfu 0 mmc 0 list
352 DFU alt settings list:
353 dev: eMMC alt: 0 name: spl layout: RAW_ADDR
354 dev: eMMC alt: 1 name: u-boot layout: RAW_ADDR
355
356 Boot> dfu 0 mmc 0
357
358On the Host side:
359
360list the available alternate setting::
361
362 $> dfu-util -l
363 dfu-util 0.9
364
365 Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
366 Copyright 2010-2016 Tormod Volden and Stefan Schmidt
367 This program is Free Software and has ABSOLUTELY NO WARRANTY
368 Please report bugs to http://sourceforge.net/p/dfu-util/tickets/
369
370 Found DFU: [0483:5720] ver=0200, devnum=45, cfg=1, intf=0, path="3-1.3.1", \
371 alt=1, name="u-boot", serial="003A00203438510D36383238"
372 Found DFU: [0483:5720] ver=0200, devnum=45, cfg=1, intf=0, path="3-1.3.1", \
373 alt=0, name="spl", serial="003A00203438510D36383238"
374
375 To download to U-Boot, use -D option
376
377 $> dfu-util -a 0 -D u-boot-spl.bin
378 $> dfu-util -a 1 -D u-boot.bin
379
380 To upload from U-Boot, use -U option
381
382 $> dfu-util -a 0 -U u-boot-spl.bin
383 $> dfu-util -a 1 -U u-boot.bin
384
385 To request a DFU detach and reset the USB connection:
386 $> dfu-util -a 0 -e -R
387
388
389Example 2: firmware located in NOR (sf) and NAND, with:
390
391- alternate 1 (alt=1) for SPL partition (NOR GPT partition 1)
392- alternate 2 (alt=2) for U-Boot partition (NOR GPT partition 2)
393- alternate 3 (alt=3) for U-Boot-env partition (NOR GPT partition 3)
394- alternate 4 (alt=4) for UBI partition (NAND GPT partition 1)
395
396::
397
398 U-Boot> env set dfu_alt_info \
399 "sf 0:0:10000000:0=spl part 0 1;u-boot part 0 2; \
400 u-boot-env part 0 3&nand 0=UBI partubi 0,1"
401
402 U-Boot> dfu 0 list
403
404 DFU alt settings list:
405 dev: SF alt: 0 name: spl layout: RAW_ADDR
406 dev: SF alt: 1 name: ssbl layout: RAW_ADDR
407 dev: SF alt: 2 name: u-boot-env layout: RAW_ADDR
408 dev: NAND alt: 3 name: UBI layout: RAW_ADDR
409
410 U-Boot> dfu 0
411
412::
413
414 $> dfu-util -l
415 Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
416 intf=0, alt=3, name="UBI", serial="002700333338511934383330"
417 Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
418 intf=0, alt=2, name="u-boot-env", serial="002700333338511934383330"
419 Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
420 intf=0, alt=1, name="u-boot", serial="002700333338511934383330"
421 Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
422 intf=0, alt=0, name="spl", serial="002700333338511934383330"
423
424Same example with MTD backend
425
426::
427
428 U-Boot> env set dfu_alt_info \
429 "mtd nor0=spl part 1;u-boot part 2;u-boot-env part 3&"\
430 "mtd nand0=UBI partubi 1"
431
432 U-Boot> dfu 0 list
433 using id 'nor0,0'
434 using id 'nor0,1'
435 using id 'nor0,2'
436 using id 'nand0,0'
437 DFU alt settings list:
438 dev: MTD alt: 0 name: spl layout: RAW_ADDR
439 dev: MTD alt: 1 name: u-boot layout: RAW_ADDR
440 dev: MTD alt: 2 name: u-boot-env layout: RAW_ADDR
441 dev: MTD alt: 3 name: UBI layout: RAW_ADDR
442
443Example 3
444
Mattijs Korpershoek28874012024-01-03 09:00:04 +0100445firmware located in SD Card (mmc) and virtual partition on OTP and PMIC
446non-volatile memory
Heinrich Schuchardt22a50742021-03-05 12:58:37 +0100447
448- alternate 1 (alt=1) for scard
449- alternate 2 (alt=2) for OTP (virtual)
450- alternate 3 (alt=3) for PMIC NVM (virtual)
451
452::
453
454 U-Boot> env set dfu_alt_info \
455 "mmc 0=sdcard raw 0 0x100000&"\
456 "virt 0=otp" \
457 "virt 1=pmic"
458
459::
460
461 U-Boot> dfu 0 list
462 DFU alt settings list:
463 dev: eMMC alt: 0 name: sdcard layout: RAW_ADDR
464 dev: VIRT alt: 1 name: otp layout: RAW_ADDR
465 dev: VIRT alt: 2 name: pmic layout: RAW_ADDR