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