README.dfu 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. # SPDX-License-Identifier: GPL-2.0+
  2. Device Firmware Upgrade (DFU)
  3. Overview:
  4. The Device Firmware Upgrade (DFU) allows to download and upload firmware
  5. to/from U-Boot connected over USB.
  6. U-boot follows the Universal Serial Bus Device Class Specification for
  7. Device Firmware Upgrade Version 1.1 the USB forum (DFU v1.1 in www.usb.org).
  8. U-Boot implements this DFU capability (CONFIG_DFU) with the command dfu
  9. (cmd/dfu.c / CONFIG_CMD_DFU) based on:
  10. - the DFU stack (common/dfu.c and common/spl/spl_dfu.c), based on the
  11. USB DFU download gadget (drivers/usb/gadget/f_dfu.c)
  12. - The access to mediums is done in DFU backends (driver/dfu)
  13. Today the supported DFU backends are:
  14. - MMC (RAW or FAT / EXT2 / EXT3 / EXT4 file system)
  15. - NAND
  16. - RAM
  17. - SF (serial flash)
  18. - MTD (all MTD device: NAND, SPI-NOR, SPI-NAND,...)
  19. - virtual
  20. These DFU backends are also used by
  21. - the dfutftp (see README.dfutftp)
  22. - the thordown command (cmd/thordown.c and gadget/f_thor.c)
  23. The "virtual" backend is a generic DFU backend to support a board specific
  24. target (for example OTP), only based on the weak functions:
  25. - dfu_write_medium_virt
  26. - dfu_get_medium_size_virt
  27. - dfu_read_medium_virt
  28. Configuration Options:
  29. CONFIG_DFU
  30. CONFIG_DFU_OVER_USB
  31. CONFIG_DFU_MMC
  32. CONFIG_DFU_MTD
  33. CONFIG_DFU_NAND
  34. CONFIG_DFU_RAM
  35. CONFIG_DFU_SF
  36. CONFIG_DFU_SF_PART
  37. CONFIG_DFU_TIMEOUT
  38. CONFIG_DFU_VIRTUAL
  39. CONFIG_CMD_DFU
  40. Environment variables:
  41. the dfu command uses 3 environments variables:
  42. "dfu_alt_info" : the DFU setting for the USB download gadget with a semicolon
  43. separated string of information on each alternate:
  44. dfu_alt_info="<alt1>;<alt2>;....;<altN>"
  45. when several devices are used, the format is:
  46. - <interface> <dev>'='alternate list (';' separated)
  47. - each interface is separated by '&'
  48. dfu_alt_info=\
  49. "<interface1> <dev1>=<alt1>;....;<altN>&"\
  50. "<interface2> <dev2>=<altN+1>;....;<altM>&"\
  51. ...\
  52. "<interfaceI> <devI>=<altY+1>;....;<altZ>&"
  53. "dfu_bufsiz" : size of the DFU buffer, when absent, use
  54. CONFIG_SYS_DFU_DATA_BUF_SIZE (8 MiB by default)
  55. "dfu_hash_algo" : name of the hash algorithm to use
  56. Commands:
  57. dfu <USB_controller> [<interface> <dev>] list
  58. list the alternate device defined in "dfu_alt_info"
  59. dfu <USB_controller> [<interface> <dev>] [<timeout>]
  60. start the dfu stack on the USB instance with the selected medium
  61. backend and use the "dfu_alt_info" variable to configure the
  62. alternate setting and link each one with the medium
  63. The dfu command continue until receive a ^C in console or
  64. a DFU detach transaction from HOST. If CONFIG_DFU_TIMEOUT option
  65. is enabled and <timeout> parameter is present in the command line,
  66. the DFU operation will be aborted automatically after <timeout>
  67. seconds of waiting remote to initiate DFU session.
  68. The possible values of <interface> are :
  69. (with <USB controller> = 0 in the dfu command example)
  70. "mmc" (for eMMC and SD card)
  71. cmd: dfu 0 mmc <dev>
  72. each element in "dfu_alt_info" =
  73. <name> raw <offset> <size> [mmcpart <num>] raw access to mmc device
  74. <name> part <dev> <part_id> [mmcpart <num>] raw access to partition
  75. <name> fat <dev> <part_id> [mmcpart <num>] file in FAT partition
  76. <name> ext4 <dev> <part_id> [mmcpart <num>] file in EXT4 partition
  77. with <partid> being the GPT or DOS partition index,
  78. with <num> being the eMMC hardware partition number.
  79. A value of environment variable dfu_alt_info for eMMC could be:
  80. "u-boot raw 0x3e 0x800 mmcpart 1;bl2 raw 0x1e 0x1d mmcpart 1"
  81. A value of environment variable dfu_alt_info for SD card could be:
  82. "u-boot raw 0x80 0x800;uImage ext4 0 2"
  83. "nand" (raw slc nand device)
  84. cmd: dfu 0 nand <dev>
  85. each element in "dfu_alt_info" =
  86. <name> raw <offset> <size> raw access to mmc device
  87. <name> part <dev> <part_id> raw acces to partition
  88. <name> partubi <dev> <part_id> raw acces to ubi partition
  89. with <partid> is the MTD partition index
  90. "ram"
  91. cmd: dfu 0 ram <dev>
  92. (<dev> is not used for RAM target)
  93. each element in "dfu_alt_info" =
  94. <name> ram <offset> <size> raw access to ram
  95. "sf" (serial flash : NOR)
  96. cmd: dfu 0 sf <dev>
  97. each element in "dfu_alt_info" =
  98. <name> raw <offset> <size> raw access to sf device
  99. <name> part <dev> <part_id> raw acces to partition
  100. <name> partubi <dev> <part_id> raw acces to ubi partition
  101. with <partid> is the MTD partition index
  102. "mtd" (all MTD device: NAND, SPI-NOR, SPI-NAND,...)
  103. cmd: dfu 0 mtd <dev>
  104. with <dev> the mtd identifier as defined in mtd command
  105. (nand0, nor0, spi-nand0,...)
  106. each element in "dfu_alt_info" =
  107. <name> raw <offset> <size> raw access to mtd device
  108. <name> part <dev> <part_id> raw acces to partition
  109. <name> partubi <dev> <part_id> raw acces to ubi partition
  110. with <partid> is the MTD partition index
  111. "virt"
  112. cmd: dfu 0 virt <dev>
  113. each element in "dfu_alt_info" =
  114. <name>
  115. <interface> and <dev> are absent:
  116. the dfu command to use multiple devices
  117. cmd: dfu 0 list
  118. cmd: dfu 0
  119. "dfu_alt_info" variable provides the list of <interface> <dev> with
  120. alternate list separated by '&' with the same format for each <alt>
  121. mmc <dev>=<alt1>;....;<altN>
  122. nand <dev>=<alt1>;....;<altN>
  123. ram <dev>=<alt1>;....;<altN>
  124. sf <dev>=<alt1>;....;<altN>
  125. mtd <dev>=<alt1>;....;<altN>
  126. virt <dev>=<alt1>;....;<altN>
  127. Callbacks:
  128. The weak callback functions can be implemented to manage specific behavior
  129. - dfu_initiated_callback : called when the DFU transaction is started,
  130. used to initiase the device
  131. - dfu_flush_callback : called at the end of the DFU write after DFU
  132. manifestation, used to manage the device when
  133. DFU transaction is closed
  134. Host tools:
  135. When U-Boot runs the dfu stack, the DFU host tools can be used
  136. to send/receive firmwares on each configurated alternate.
  137. For example dfu-util is a host side implementation of the DFU 1.1
  138. specifications(http://dfu-util.sourceforge.net/) which works with U-Boot.
  139. Usage:
  140. Example 1: firmware located in eMMC or SD card, with:
  141. - alternate 1 (alt=1) for SPL partition (GPT partition 1)
  142. - alternate 2 (alt=2) for U-Boot partition (GPT partition 2)
  143. The U-Boot configuration is:
  144. U-Boot> env set dfu_alt_info "spl part 0 1;u-boot part 0 2"
  145. U-Boot> dfu 0 mmc 0 list
  146. DFU alt settings list:
  147. dev: eMMC alt: 0 name: spl layout: RAW_ADDR
  148. dev: eMMC alt: 1 name: u-boot layout: RAW_ADDR
  149. Boot> dfu 0 mmc 0
  150. On the Host side:
  151. list the available alternate setting:
  152. $> dfu-util -l
  153. dfu-util 0.9
  154. Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
  155. Copyright 2010-2016 Tormod Volden and Stefan Schmidt
  156. This program is Free Software and has ABSOLUTELY NO WARRANTY
  157. Please report bugs to http://sourceforge.net/p/dfu-util/tickets/
  158. Found DFU: [0483:5720] ver=0200, devnum=45, cfg=1, intf=0, path="3-1.3.1", \
  159. alt=1, name="u-boot", serial="003A00203438510D36383238"
  160. Found DFU: [0483:5720] ver=0200, devnum=45, cfg=1, intf=0, path="3-1.3.1", \
  161. alt=0, name="spl", serial="003A00203438510D36383238"
  162. To download to U-Boot, use -D option
  163. $> dfu-util -a 0 -D u-boot-spl.bin
  164. $> dfu-util -a 1 -D u-boot.bin
  165. To upload from U-Boot, use -U option
  166. $> dfu-util -a 0 -U u-boot-spl.bin
  167. $> dfu-util -a 1 -U u-boot.bin
  168. To request a DFU detach and reset the USB connection:
  169. $> dfu-util -a 0 -e -R
  170. Example 2: firmware located in NOR (sf) and NAND, with:
  171. - alternate 1 (alt=1) for SPL partition (NOR GPT partition 1)
  172. - alternate 2 (alt=2) for U-Boot partition (NOR GPT partition 2)
  173. - alternate 3 (alt=3) for U-Boot-env partition (NOR GPT partition 3)
  174. - alternate 4 (alt=4) for UBI partition (NAND GPT partition 1)
  175. U-Boot> env set dfu_alt_info \
  176. "sf 0:0:10000000:0=spl part 0 1;u-boot part 0 2; \
  177. u-boot-env part 0 3&nand 0=UBI partubi 0,1"
  178. U-Boot> dfu 0 list
  179. DFU alt settings list:
  180. dev: SF alt: 0 name: spl layout: RAW_ADDR
  181. dev: SF alt: 1 name: ssbl layout: RAW_ADDR
  182. dev: SF alt: 2 name: u-boot-env layout: RAW_ADDR
  183. dev: NAND alt: 3 name: UBI layout: RAW_ADDR
  184. U-Boot> dfu 0
  185. $> dfu-util -l
  186. Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
  187. intf=0, alt=3, name="UBI", serial="002700333338511934383330"
  188. Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
  189. intf=0, alt=2, name="u-boot-env", serial="002700333338511934383330"
  190. Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
  191. intf=0, alt=1, name="u-boot", serial="002700333338511934383330"
  192. Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
  193. intf=0, alt=0, name="spl", serial="002700333338511934383330"
  194. Same example with MTD backend
  195. U-Boot> env set dfu_alt_info \
  196. "mtd nor0=spl part 1;u-boot part 2;u-boot-env part 3&"\
  197. "mtd nand0=UBI partubi 1"
  198. U-Boot> dfu 0 list
  199. using id 'nor0,0'
  200. using id 'nor0,1'
  201. using id 'nor0,2'
  202. using id 'nand0,0'
  203. DFU alt settings list:
  204. dev: MTD alt: 0 name: spl layout: RAW_ADDR
  205. dev: MTD alt: 1 name: u-boot layout: RAW_ADDR
  206. dev: MTD alt: 2 name: u-boot-env layout: RAW_ADDR
  207. dev: MTD alt: 3 name: UBI layout: RAW_ADDR
  208. Example 3: firmware located in SD Card (mmc) and virtual partition on
  209. OTP and PMIC not volatile memory
  210. - alternate 1 (alt=1) for scard
  211. - alternate 2 (alt=2) for OTP (virtual)
  212. - alternate 3 (alt=3) for PMIC NVM (virtual)
  213. U-Boot> env set dfu_alt_info \
  214. "mmc 0=sdcard raw 0 0x100000&"\
  215. "virt 0=otp" \
  216. "virt 1=pmic"
  217. U-Boot> dfu 0 list
  218. DFU alt settings list:
  219. dev: eMMC alt: 0 name: sdcard layout: RAW_ADDR
  220. dev: VIRT alt: 1 name: otp layout: RAW_ADDR
  221. dev: VIRT alt: 2 name: pmic layout: RAW_ADDR