From 321179eec565d4ddcd3daff18357a658cf823bef Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 14 Oct 2019 09:27:59 +0200 Subject: doc: dfu: Add dfu documentation Add documentation for dfu stack and "dfu" command. Reviewed-by: Lukasz Majewski Signed-off-by: Patrick Delaunay --- doc/README.dfu | 144 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 doc/README.dfu (limited to 'doc') diff --git a/doc/README.dfu b/doc/README.dfu new file mode 100644 index 0000000..f5344e2 --- /dev/null +++ b/doc/README.dfu @@ -0,0 +1,144 @@ +# SPDX-License-Identifier: GPL-2.0+ + +Device Firmware Upgrade (DFU) + +Overview: + + The Device Firmware Upgrade (DFU) allows to download and upload firmware + to/from U-Boot connected over USB. + + U-boot follows the Universal Serial Bus Device Class Specification for + Device Firmware Upgrade Version 1.1 the USB forum (DFU v1.1 in www.usb.org). + + U-Boot implements this DFU capability (CONFIG_DFU) with the command dfu + (cmd/dfu.c / CONFIG_CMD_DFU) based on: + - the DFU stack (common/dfu.c and common/spl/spl_dfu.c), based on the + USB DFU download gadget (drivers/usb/gadget/f_dfu.c) + - The access to mediums is done in DFU backends (driver/dfu) + + Today the supported DFU backends are: + - MMC (RAW or FAT / EXT2 / EXT3 / EXT4 file system) + - NAND + - RAM + - SF (serial flash) + + These DFU backends are also used by + - the dfutftp (see README.dfutftp) + - the thordown command (cmd/thordown.c and gadget/f_thor.c) + +Configuration Options: + CONFIG_DFU + CONFIG_DFU_OVER_USB + CONFIG_DFU_MMC + CONFIG_DFU_NAND + CONFIG_DFU_RAM + CONFIG_DFU_SF + CONFIG_CMD_DFU + +Environment variables: + the dfu command use 3 environments variables: + "dfu_alt_info" : the DFU setting for the USB download gadget with a comma + separated string of information on each alternate: + dfu_alt_info=";;....;" + + "dfu_bufsiz" : size of the DFU buffer, when absent, use + CONFIG_SYS_DFU_DATA_BUF_SIZE (8MiB by default) + + "dfu_hash_algo" : name of the hash algorithm to use + +Commands: + dfu list + list the alternate device defined in "dfu_alt_info" + + dfu + start the dfu stack on the USB instance with the selected medium + backend and use the "dfu_alt_info" variable to configure the + alternate setting and link each one with the medium + The dfu command continue until receive a ^C in console or + a DFU detach transaction from HOST. + + The possible values of are : + (with = 0 in the dfu command example) + + "mmc" (for eMMC and SD card) + cmd: dfu 0 mmc + each element in "dfu_alt_info" = + raw raw access to mmc device + part raw acces to partition + fat file in FAT partition + ext4 file in EXT4 partition + + with is the GPT or DOS partition index + + "nand" (raw slc nand device) + cmd: dfu 0 nand + each element in "dfu_alt_info" = + raw raw access to mmc device + part raw acces to partition + partubi raw acces to ubi partition + + with is the MTD partition index + + "ram" + cmd: dfu 0 ram + ( is not used for RAM target) + each element in "dfu_alt_info" = + ram raw access to ram + + "sf" (serial flash : NOR) + cmd: dfu 0 sf + each element in "dfu_alt_info" = + ram raw access to sf device + +Host tools: + When U-Boot runs the dfu stack, the DFU host tools can be used + to send/receive firmwares on each configurated alternate. + + For example dfu-util is a host side implementation of the DFU 1.1 + specifications(http://dfu-util.sourceforge.net/) which works with U-Boot. + +Usage: + Example for firmware located in eMMC or SD card, with: + - alternate 1 (alt=1) for SPL partition (GPT partition 1) + - alternate 2 (alt=2) for U-Boot partition (GPT partition 2) + + The U-Boot configuration is: + + U-Boot> env set dfu_alt_info "spl part 0 1;u-boot part 0 2" + + U-Boot> dfu 0 mmc 0 list + DFU alt settings list: + dev: eMMC alt: 0 name: spl layout: RAW_ADDR + dev: eMMC alt: 1 name: u-boot layout: RAW_ADDR + + Boot> dfu 0 mmc 0 + + On the Host side: + + list the available alternate setting: + + $> dfu-util -l + dfu-util 0.9 + + Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc. + Copyright 2010-2016 Tormod Volden and Stefan Schmidt + This program is Free Software and has ABSOLUTELY NO WARRANTY + Please report bugs to http://sourceforge.net/p/dfu-util/tickets/ + + Found DFU: [0483:5720] ver=0200, devnum=45, cfg=1, intf=0, path="3-1.3.1", \ + alt=1, name="u-boot", serial="003A00203438510D36383238" + Found DFU: [0483:5720] ver=0200, devnum=45, cfg=1, intf=0, path="3-1.3.1", \ + alt=0, name="spl", serial="003A00203438510D36383238" + + To download to U-Boot, use -D option + + $> dfu-util -a 0 -D u-boot-spl.bin + $> dfu-util -a 1 -D u-boot.bin + + To upload from U-Boot, use -U option + + $> dfu-util -a 0 -U u-boot-spl.bin + $> dfu-util -a 1 -U u-boot.bin + + To request a DFU detach and reset the USB connection: + $> dfu-util -a 0 -e -R -- cgit v1.1 From cb986ba0fe4692a9d21a193c4ca9db460df77364 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 14 Oct 2019 09:28:00 +0200 Subject: dfu: sf: add partition support for nor backend Copy the partition support from NAND backend to SF, support part and partubi option. In case of ubi partition, erase the rest of the partition as it is mandatory for UBI. The added code is under compilation flag CONFIG_DFU_SF_PART activated by default. for example: U-Boot> env set dfu_alt_info "spl part 0 1;\ u-boot part 0 2;u-boot-env part 0 3;UBI partubi 0 4" U-Boot> dfu 0 sf 0:0:10000000:0 Signed-off-by: Patrick Delaunay --- doc/README.dfu | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'doc') diff --git a/doc/README.dfu b/doc/README.dfu index f5344e2..7a2b5f1 100644 --- a/doc/README.dfu +++ b/doc/README.dfu @@ -33,6 +33,7 @@ Configuration Options: CONFIG_DFU_NAND CONFIG_DFU_RAM CONFIG_DFU_SF + CONFIG_DFU_SF_PART CONFIG_CMD_DFU Environment variables: @@ -89,6 +90,10 @@ Commands: cmd: dfu 0 sf each element in "dfu_alt_info" = ram raw access to sf device + part raw acces to partition + partubi raw acces to ubi partition + + with is the MTD partition index Host tools: When U-Boot runs the dfu stack, the DFU host tools can be used -- cgit v1.1 From febabe3ed4f422a39e461ba4c2aff5f0fde6e4d2 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 14 Oct 2019 09:28:02 +0200 Subject: dfu: allow to manage DFU on several devices Add support of DFU for several interface/device with one command. The format for "dfu_alt_info" in this case is : - '='alternate list (';' separated) - each interface is separated by '&' The previous behavior is always supported. One example for NOR (bootloaders) + NAND (rootfs in UBI): U-Boot> env set dfu_alt_info \ "sf 0:0:10000000:0=spl part 0 1;u-boot part 0 2; \ u-boot-env part 0 3&nand 0=UBI partubi 0,3" U-Boot> dfu 0 list DFU alt settings list: dev: SF alt: 0 name: spl layout: RAW_ADDR dev: SF alt: 1 name: ssbl layout: RAW_ADDR dev: SF alt: 2 name: u-boot-env layout: RAW_ADDR dev: NAND alt: 3 name: UBI layout: RAW_ADDR U-Boot> dfu 0 $> dfu-util -l Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\ intf=0, alt=3, name="UBI", serial="002700333338511934383330" Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\ intf=0, alt=2, name="u-boot-env", serial="002700333338511934383330" Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\ intf=0, alt=1, name="u-boot", serial="002700333338511934383330" Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\ intf=0, alt=0, name="spl", serial="002700333338511934383330" Signed-off-by: Patrick Delaunay --- doc/README.dfu | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) (limited to 'doc') diff --git a/doc/README.dfu b/doc/README.dfu index 7a2b5f1..d1ef7e4 100644 --- a/doc/README.dfu +++ b/doc/README.dfu @@ -42,16 +42,25 @@ Environment variables: separated string of information on each alternate: dfu_alt_info=";;....;" + when only several device are used, the format is: + - '='alternate list (';' separated) + - each interface is separated by '&' + dfu_alt_info=\ + " =;....;&"\ + " =;....;&"\ + ...\ + " =;....;&" + "dfu_bufsiz" : size of the DFU buffer, when absent, use CONFIG_SYS_DFU_DATA_BUF_SIZE (8MiB by default) "dfu_hash_algo" : name of the hash algorithm to use Commands: - dfu list + dfu [ ] list list the alternate device defined in "dfu_alt_info" - dfu + dfu [ ] start the dfu stack on the USB instance with the selected medium backend and use the "dfu_alt_info" variable to configure the alternate setting and link each one with the medium @@ -95,6 +104,18 @@ Commands: with is the MTD partition index + and are absent: + the dfu command to use multiple devices + cmd: dfu 0 list + cmd: dfu 0 + "dfu_alt_info" variable provides the list of with + alternate list separated by '&' with the same format for each + mmc =;....; + nand =;....; + ram =;....; + sf =;....; + + Host tools: When U-Boot runs the dfu stack, the DFU host tools can be used to send/receive firmwares on each configurated alternate. @@ -103,7 +124,7 @@ Host tools: specifications(http://dfu-util.sourceforge.net/) which works with U-Boot. Usage: - Example for firmware located in eMMC or SD card, with: + Example 1: firmware located in eMMC or SD card, with: - alternate 1 (alt=1) for SPL partition (GPT partition 1) - alternate 2 (alt=2) for U-Boot partition (GPT partition 2) @@ -147,3 +168,34 @@ Usage: To request a DFU detach and reset the USB connection: $> dfu-util -a 0 -e -R + + + Example 2: firmware located in NOR (sf) and NAND, with: + - alternate 1 (alt=1) for SPL partition (NOR GPT partition 1) + - alternate 2 (alt=2) for U-Boot partition (NOR GPT partition 2) + - alternate 3 (alt=3) for U-Boot-env partition (NOR GPT partition 3) + - alternate 4 (alt=4) for UBI partition (NAND GPT partition 1) + + U-Boot> env set dfu_alt_info \ + "sf 0:0:10000000:0=spl part 0 1;u-boot part 0 2; \ + u-boot-env part 0 3&nand 0=UBI partubi 0,1" + + U-Boot> dfu 0 list + + DFU alt settings list: + dev: SF alt: 0 name: spl layout: RAW_ADDR + dev: SF alt: 1 name: ssbl layout: RAW_ADDR + dev: SF alt: 2 name: u-boot-env layout: RAW_ADDR + dev: NAND alt: 3 name: UBI layout: RAW_ADDR + + U-Boot> dfu 0 + + $> dfu-util -l + Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\ + intf=0, alt=3, name="UBI", serial="002700333338511934383330" + Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\ + intf=0, alt=2, name="u-boot-env", serial="002700333338511934383330" + Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\ + intf=0, alt=1, name="u-boot", serial="002700333338511934383330" + Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\ + intf=0, alt=0, name="spl", serial="002700333338511934383330" -- cgit v1.1 From 6015af28ee6d44d6c7b21f3844c90df9239f66f4 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 14 Oct 2019 09:28:04 +0200 Subject: dfu: add backend for MTD device Add DFU backend for MTD device: allow to read and write on all MTD device (NAND, SPI-NOR, SPI-NAND,...) For example : > set dfu_alt_info "nand_raw raw 0x0 0x100000" > dfu 0 mtd nand0 This MTD backend provides the same level than dfu nand backend for NAND and dfu sf backend for SPI-NOR; So it can replace booth of them but it also add support of spi-nand. > set dfu_alt_info "nand_raw raw 0x0 0x100000" > dfu 0 mtd spi-nand0 The backend code is based on the "mtd" command introduced by commit 5db66b3aee6f ("cmd: mtd: add 'mtd' command") Signed-off-by: Patrick Delaunay --- doc/README.dfu | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'doc') diff --git a/doc/README.dfu b/doc/README.dfu index d1ef7e4..96bced3 100644 --- a/doc/README.dfu +++ b/doc/README.dfu @@ -21,6 +21,7 @@ Overview: - NAND - RAM - SF (serial flash) + - MTD (all MTD device: NAND, SPI-NOR, SPI-NAND,...) These DFU backends are also used by - the dfutftp (see README.dfutftp) @@ -30,6 +31,7 @@ Configuration Options: CONFIG_DFU CONFIG_DFU_OVER_USB CONFIG_DFU_MMC + CONFIG_DFU_MTD CONFIG_DFU_NAND CONFIG_DFU_RAM CONFIG_DFU_SF @@ -104,6 +106,13 @@ Commands: with is the MTD partition index + "mtd" (all MTD device: NAND, SPI-NOR, SPI-NAND,...) + cmd: dfu 0 mtd + with the mtd identifier as defined in mtd command + (nand0, nor0, spi-nand0,...) + each element in "dfu_alt_info" = + raw raw access to mtd device + and are absent: the dfu command to use multiple devices cmd: dfu 0 list @@ -114,6 +123,7 @@ Commands: nand =;....; ram =;....; sf =;....; + mtd =;....; Host tools: -- cgit v1.1 From d5640f700d0413059b39cdd621c9401ef90d08fa Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 14 Oct 2019 09:28:05 +0200 Subject: dfu: add partition support for MTD backend Add the support of MTD partition for the MTD backend. The expected dfu_alt_info for one alternate on the mtd device : part partubi "partubi" also erase up to the end of the partition after write operation. For example: dfu_alt_info = "spl part 1;u-boot part 2; UBI partubi 3" U-Boot> dfu 0 mtd nand0 Acked-by: Lukasz Majewski Signed-off-by: Patrick Delaunay --- doc/README.dfu | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'doc') diff --git a/doc/README.dfu b/doc/README.dfu index 96bced3..92a7695 100644 --- a/doc/README.dfu +++ b/doc/README.dfu @@ -112,6 +112,10 @@ Commands: (nand0, nor0, spi-nand0,...) each element in "dfu_alt_info" = raw raw access to mtd device + part raw acces to partition + partubi raw acces to ubi partition + + with is the MTD partition index and are absent: the dfu command to use multiple devices @@ -209,3 +213,20 @@ Usage: intf=0, alt=1, name="u-boot", serial="002700333338511934383330" Found DFU: [0483:5720] ver=9999, devnum=96, cfg=1,\ intf=0, alt=0, name="spl", serial="002700333338511934383330" + + Same example with MTD backend + + U-Boot> env set dfu_alt_info \ + "mtd nor0=spl part 1;u-boot part 2;u-boot-env part 3&"\ + "mtd nand0=UBI partubi 1" + + U-Boot> dfu 0 list + using id 'nor0,0' + using id 'nor0,1' + using id 'nor0,2' + using id 'nand0,0' + DFU alt settings list: + dev: MTD alt: 0 name: spl layout: RAW_ADDR + dev: MTD alt: 1 name: u-boot layout: RAW_ADDR + dev: MTD alt: 2 name: u-boot-env layout: RAW_ADDR + dev: MTD alt: 3 name: UBI layout: RAW_ADDR -- cgit v1.1 From ec44cace4b8d23556924550fe76bf2744eb91144 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 14 Oct 2019 09:28:06 +0200 Subject: dfu: add DFU virtual backend Add a virtual DFU backend to allow board specific read and write (for OTP update for example). Acked-by: Lukasz Majewski Signed-off-by: Patrick Delaunay --- doc/README.dfu | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'doc') diff --git a/doc/README.dfu b/doc/README.dfu index 92a7695..43a6f31 100644 --- a/doc/README.dfu +++ b/doc/README.dfu @@ -22,11 +22,18 @@ Overview: - RAM - SF (serial flash) - MTD (all MTD device: NAND, SPI-NOR, SPI-NAND,...) + - virtual These DFU backends are also used by - the dfutftp (see README.dfutftp) - the thordown command (cmd/thordown.c and gadget/f_thor.c) + The "virtual" backend is a generic DFU backend to support a board specific + target (for example OTP), only based on the weak functions: + - dfu_write_medium_virt + - dfu_get_medium_size_virt + - dfu_read_medium_virt + Configuration Options: CONFIG_DFU CONFIG_DFU_OVER_USB @@ -36,6 +43,7 @@ Configuration Options: CONFIG_DFU_RAM CONFIG_DFU_SF CONFIG_DFU_SF_PART + CONFIG_DFU_VIRTUAL CONFIG_CMD_DFU Environment variables: @@ -117,6 +125,11 @@ Commands: with is the MTD partition index + "virt" + cmd: dfu 0 virt + each element in "dfu_alt_info" = + + and are absent: the dfu command to use multiple devices cmd: dfu 0 list @@ -128,7 +141,7 @@ Commands: ram =;....; sf =;....; mtd =;....; - + virt =;....; Host tools: When U-Boot runs the dfu stack, the DFU host tools can be used @@ -230,3 +243,20 @@ Usage: dev: MTD alt: 1 name: u-boot layout: RAW_ADDR dev: MTD alt: 2 name: u-boot-env layout: RAW_ADDR dev: MTD alt: 3 name: UBI layout: RAW_ADDR + + Example 3: firmware located in SD Card (mmc) and virtual partition on + OTP and PMIC not volatile memory + - alternate 1 (alt=1) for scard + - alternate 2 (alt=2) for OTP (virtual) + - alternate 3 (alt=3) for PMIC NVM (virtual) + + U-Boot> env set dfu_alt_info \ + "mmc 0=sdcard raw 0 0x100000&"\ + "virt 0=otp" \ + "virt 1=pmic" + + U-Boot> dfu 0 list + DFU alt settings list: + dev: eMMC alt: 0 name: sdcard layout: RAW_ADDR + dev: VIRT alt: 1 name: otp layout: RAW_ADDR + dev: VIRT alt: 2 name: pmic layout: RAW_ADDR -- cgit v1.1 From 067c13c70bfb99d25979b989870ed39eab34659a Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 14 Oct 2019 09:28:07 +0200 Subject: dfu: add callback for flush and initiated operation Add weak callback to allow board specific behavior - flush - initiated This patch prepare usage of DFU back end for communication with STM32CubeProgrammer on stm32mp1 platform with stm32prog command. Signed-off-by: Patrick Delaunay --- doc/README.dfu | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'doc') diff --git a/doc/README.dfu b/doc/README.dfu index 43a6f31..558d347 100644 --- a/doc/README.dfu +++ b/doc/README.dfu @@ -143,6 +143,14 @@ Commands: mtd =;....; virt =;....; +Callbacks: + The weak callback functions can be implemented to manage specific behavior + - dfu_initiated_callback : called when the DFU transaction is started, + used to initiase the device + - dfu_flush_callback : called at the end of the DFU write after DFU + manifestation, used to manage the device when + DFU transaction is closed + Host tools: When U-Boot runs the dfu stack, the DFU host tools can be used to send/receive firmwares on each configurated alternate. -- cgit v1.1