README.dfu 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 use 3 environments variables:
  42. "dfu_alt_info" : the DFU setting for the USB download gadget with a comma
  43. separated string of information on each alternate:
  44. dfu_alt_info="<alt1>;<alt2>;....;<altN>"
  45. when only several device 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 (8MiB 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> raw access to mmc device
  74. <name> part <dev> <part_id> raw acces to partition
  75. <name> fat <dev> <part_id> file in FAT partition
  76. <name> ext4 <dev> <part_id> file in EXT4 partition
  77. with <partid> is the GPT or DOS partition index
  78. "nand" (raw slc nand device)
  79. cmd: dfu 0 nand <dev>
  80. each element in "dfu_alt_info" =
  81. <name> raw <offset> <size> raw access to mmc device
  82. <name> part <dev> <part_id> raw acces to partition
  83. <name> partubi <dev> <part_id> raw acces to ubi partition
  84. with <partid> is the MTD partition index
  85. "ram"
  86. cmd: dfu 0 ram <dev>
  87. (<dev> is not used for RAM target)
  88. each element in "dfu_alt_info" =
  89. <name> ram <offset> <size> raw access to ram
  90. "sf" (serial flash : NOR)
  91. cmd: dfu 0 sf <dev>
  92. each element in "dfu_alt_info" =
  93. <name> ram <offset> <size> raw access to sf device
  94. <name> part <dev> <part_id> raw acces to partition
  95. <name> partubi <dev> <part_id> raw acces to ubi partition
  96. with <partid> is the MTD partition index
  97. "mtd" (all MTD device: NAND, SPI-NOR, SPI-NAND,...)
  98. cmd: dfu 0 mtd <dev>
  99. with <dev> the mtd identifier as defined in mtd command
  100. (nand0, nor0, spi-nand0,...)
  101. each element in "dfu_alt_info" =
  102. <name> raw <offset> <size> raw access to mtd device
  103. <name> part <dev> <part_id> raw acces to partition
  104. <name> partubi <dev> <part_id> raw acces to ubi partition
  105. with <partid> is the MTD partition index
  106. "virt"
  107. cmd: dfu 0 virt <dev>
  108. each element in "dfu_alt_info" =
  109. <name>
  110. <interface> and <dev> are absent:
  111. the dfu command to use multiple devices
  112. cmd: dfu 0 list
  113. cmd: dfu 0
  114. "dfu_alt_info" variable provides the list of <interface> <dev> with
  115. alternate list separated by '&' with the same format for each <alt>
  116. mmc <dev>=<alt1>;....;<altN>
  117. nand <dev>=<alt1>;....;<altN>
  118. ram <dev>=<alt1>;....;<altN>
  119. sf <dev>=<alt1>;....;<altN>
  120. mtd <dev>=<alt1>;....;<altN>
  121. virt <dev>=<alt1>;....;<altN>
  122. Callbacks:
  123. The weak callback functions can be implemented to manage specific behavior
  124. - dfu_initiated_callback : called when the DFU transaction is started,
  125. used to initiase the device
  126. - dfu_flush_callback : called at the end of the DFU write after DFU
  127. manifestation, used to manage the device when
  128. DFU transaction is closed
  129. Host tools:
  130. When U-Boot runs the dfu stack, the DFU host tools can be used
  131. to send/receive firmwares on each configurated alternate.
  132. For example dfu-util is a host side implementation of the DFU 1.1
  133. specifications(http://dfu-util.sourceforge.net/) which works with U-Boot.
  134. Usage:
  135. Example 1: firmware located in eMMC or SD card, with:
  136. - alternate 1 (alt=1) for SPL partition (GPT partition 1)
  137. - alternate 2 (alt=2) for U-Boot partition (GPT partition 2)
  138. The U-Boot configuration is:
  139. U-Boot> env set dfu_alt_info "spl part 0 1;u-boot part 0 2"
  140. U-Boot> dfu 0 mmc 0 list
  141. DFU alt settings list:
  142. dev: eMMC alt: 0 name: spl layout: RAW_ADDR
  143. dev: eMMC alt: 1 name: u-boot layout: RAW_ADDR
  144. Boot> dfu 0 mmc 0
  145. On the Host side:
  146. list the available alternate setting:
  147. $> dfu-util -l
  148. dfu-util 0.9
  149. Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
  150. Copyright 2010-2016 Tormod Volden and Stefan Schmidt
  151. This program is Free Software and has ABSOLUTELY NO WARRANTY
  152. Please report bugs to http://sourceforge.net/p/dfu-util/tickets/
  153. Found DFU: [0483:5720] ver=0200, devnum=45, cfg=1, intf=0, path="3-1.3.1", \
  154. alt=1, name="u-boot", serial="003A00203438510D36383238"
  155. Found DFU: [0483:5720] ver=0200, devnum=45, cfg=1, intf=0, path="3-1.3.1", \
  156. alt=0, name="spl", serial="003A00203438510D36383238"
  157. To download to U-Boot, use -D option
  158. $> dfu-util -a 0 -D u-boot-spl.bin
  159. $> dfu-util -a 1 -D u-boot.bin
  160. To upload from U-Boot, use -U option
  161. $> dfu-util -a 0 -U u-boot-spl.bin
  162. $> dfu-util -a 1 -U u-boot.bin
  163. To request a DFU detach and reset the USB connection:
  164. $> dfu-util -a 0 -e -R
  165. Example 2: firmware located in NOR (sf) and NAND, with:
  166. - alternate 1 (alt=1) for SPL partition (NOR GPT partition 1)
  167. - alternate 2 (alt=2) for U-Boot partition (NOR GPT partition 2)
  168. - alternate 3 (alt=3) for U-Boot-env partition (NOR GPT partition 3)
  169. - alternate 4 (alt=4) for UBI partition (NAND GPT partition 1)
  170. U-Boot> env set dfu_alt_info \
  171. "sf 0:0:10000000:0=spl part 0 1;u-boot part 0 2; \
  172. u-boot-env part 0 3&nand 0=UBI partubi 0,1"
  173. U-Boot> dfu 0 list
  174. DFU alt settings list:
  175. dev: SF alt: 0 name: spl layout: RAW_ADDR
  176. dev: SF alt: 1 name: ssbl layout: RAW_ADDR
  177. dev: SF alt: 2 name: u-boot-env layout: RAW_ADDR
  178. dev: NAND alt: 3 name: UBI layout: RAW_ADDR
  179. U-Boot> dfu 0
  180. $> dfu-util -l
  181. Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
  182. intf=0, alt=3, name="UBI", serial="002700333338511934383330"
  183. Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
  184. intf=0, alt=2, name="u-boot-env", serial="002700333338511934383330"
  185. Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
  186. intf=0, alt=1, name="u-boot", serial="002700333338511934383330"
  187. Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\
  188. intf=0, alt=0, name="spl", serial="002700333338511934383330"
  189. Same example with MTD backend
  190. U-Boot> env set dfu_alt_info \
  191. "mtd nor0=spl part 1;u-boot part 2;u-boot-env part 3&"\
  192. "mtd nand0=UBI partubi 1"
  193. U-Boot> dfu 0 list
  194. using id 'nor0,0'
  195. using id 'nor0,1'
  196. using id 'nor0,2'
  197. using id 'nand0,0'
  198. DFU alt settings list:
  199. dev: MTD alt: 0 name: spl layout: RAW_ADDR
  200. dev: MTD alt: 1 name: u-boot layout: RAW_ADDR
  201. dev: MTD alt: 2 name: u-boot-env layout: RAW_ADDR
  202. dev: MTD alt: 3 name: UBI layout: RAW_ADDR
  203. Example 3: firmware located in SD Card (mmc) and virtual partition on
  204. OTP and PMIC not volatile memory
  205. - alternate 1 (alt=1) for scard
  206. - alternate 2 (alt=2) for OTP (virtual)
  207. - alternate 3 (alt=3) for PMIC NVM (virtual)
  208. U-Boot> env set dfu_alt_info \
  209. "mmc 0=sdcard raw 0 0x100000&"\
  210. "virt 0=otp" \
  211. "virt 1=pmic"
  212. U-Boot> dfu 0 list
  213. DFU alt settings list:
  214. dev: eMMC alt: 0 name: sdcard layout: RAW_ADDR
  215. dev: VIRT alt: 1 name: otp layout: RAW_ADDR
  216. dev: VIRT alt: 2 name: pmic layout: RAW_ADDR