SPL: DFU Support in SPL
Subsystems (2)
v3 cover SPL: DFU Support in SPL
Traditionally the DFU support is available only as part 2nd stage boot loader(u-boot) and DFU is not supported in SPL.
The SPL-DFU feature is useful for boards which does not have MMC/SD, ethernet boot mechanism to boot the board and only has USB inteface.
This patch add DFU support in SPL with RAM memory device support to load and execute u-boot from PC over USB interface. And then leverage full functional feature of DFU in u-boot to flash boot inital binary images to factory or bare-metal boards to memory devices like SPI, eMMC, MMC/SD card using USB interface.
As a reference, refer to application note [3] on SPL-DFU support based on 2014.07 u-boot.
Steps to build SPL-DFU/RAM:
This SPL-DFU support can be enabled through Menuconfig->Boot Images->Enable SPL-DFU support
1) Soc ROMcode loads the u-boot-spl.bin(+DFU) to IRAM from PC host via usb interface and execute DFU.
2) Then load u-boot.img to RAM using dfu-util from PC-host with -R switch to boot u-boot.
#sudo dfu-util -c 1 -i 0 -a 0 -D u-boot.img -R
Note:
On latest mainline u-boot usb fails,
need patch [4],[5] to test dfu.
Tested on dra7xx SoCs family.
[1] is EVM console output with SPL-DFU/RAM enabled.
[2] is ubuntu host console output.
references:
[1] http://pastebin.ubuntu.com/21264490/
[2] http://pastebin.ubuntu.com/21264638/
[3] http://www.ti.com/lit/an/sprac33/sprac33.pdf
[4] https://patchwork.ozlabs.org/patch/651146/
[5] http://pastebin.ubuntu.com/21264233/
v3 changes:
- minor v2 review comments fixed.
- Kconfig SPL/DFU selection made generic.
- unselect CONFIG_CMD_BOOTD for SPL
v1/v2 changes :
- support for DFU RAM device only .
- removed support for other SPI flash devices
- SPL+DFU loads and execute u-boot and leaverage u-boot dfu functionality to flash binaries to SPI, eMMC etc.
- saperated the common dfu code used by SPL and u-boot to common/dfu.c
Ravi Babu (5):
spl: dfu: add dfu support in SPL
common: dfu: saperate the dfu common functionality
spl: dfu: adding dfu support functions for SPL-DFU
dra7x: boot: add dfu bootmode support
dra7x: configs: enable SPL-DFU support
Kconfig | 27 ++++++++ arch/arm/cpu/armv7/omap-common/boot-common.c | 5 ++ arch/arm/include/asm/arch-omap5/spl.h | 2 +- cmd/dfu.c | 61 +----------------- common/Makefile | 3 + common/dfu.c | 87 ++++++++++++++++++++++++++ common/spl/Makefile | 1 + common/spl/spl.c | 10 ++- common/spl/spl_dfu.c | 57 +++++++++++++++++ include/configs/dra7xx_evm.h | 20 +++++- include/configs/ti_omap5_common.h | 2 - include/g_dnl.h | 1 + include/spl.h | 8 +++ scripts/Makefile.spl | 4 ++ 14 files changed, 224 insertions(+), 64 deletions(-) create mode 100644 common/dfu.c create mode 100644 common/spl/spl_dfu.c
Signature · 1 line
1.7.9.5
RFC PATCH v3 1/5 spl: dfu: add dfu support in SPL
Traditionally the DFU support is available only as part 2nd stage boot loader(u-boot) and DFU is not supported in SPL.
The SPL-DFU feature is useful for boards which does not have MMC/SD, ethernet boot mechanism to boot the board and only has USB inteface.
This patch add DFU support in SPL with RAM memory device support to load and execute u-boot. And then leverage full functionality DFU in u-boot to flash boot inital binary images to factory or bare-metal boards to memory devices like SPI, eMMC, MMC/SD card using USB interface.
This SPL-DFU support can be enabled through Menuconfig->Boot Images->Enable SPL-DFU support
--- Kconfig | 27 +++++++++++++++++++++++++++ common/Makefile | 1 + scripts/Makefile.spl | 4 ++++ 3 files changed, 32 insertions(+)
Kconfig +27 -0
@@ -336,6 +336,33 @@ config SPL_FIT_IMAGE_POST_PROCESS injected into the FIT creation (i.e. the blobs would have been pre- processed before being added to the FIT image). +config SPL_DFU_SUPPORT + bool "Enable SPL with DFU to load binaries to memory device" + depends on USB + help + Currently the SPL does not have capability to load the + binaries or boot images to boot devices like ram,eMMC,SPI,etc. + This feature enables the DFU (Device Firmware Upgarde) in SPL with + RAM memory device support. The ROM code will load and execute + the SPL built with dfu. The user can load binaries (u-boot/kernel) to + selected device partition from host-pc using dfu-utils. + This feature will be useful to flash the binaries to factory + or bare-metal boards using USB interface. + +choice + bool "DFU device selection" + depends on SPL_DFU_SUPPORT + +config SPL_DFU_RAM + bool "RAM device" + depends on SPL_DFU_SUPPORT + help + select RAM/DDR memory device for loading binary images + (u-boot/kernel) to the selected device partition using + DFU and execute the u-boot/kernel from RAM. + +endchoice + config SYS_CLK_FREQ depends on ARC || ARCH_SUNXI int "CPU clock frequency"
common/Makefile +1 -0
@@ -87,6 +87,7 @@ obj-$(CONFIG_USB_KEYBOARD) += usb_kbd.o endif # !CONFIG_SPL_BUILD ifdef CONFIG_SPL_BUILD +obj-$(CONFIG_SPL_DFU_SUPPORT) += cli_hush.o obj-$(CONFIG_SPL_HASH_SUPPORT) += hash.o obj-$(CONFIG_ENV_IS_IN_FLASH) += env_flash.o obj-$(CONFIG_SPL_YMODEM_SUPPORT) += xyzModem.o
scripts/Makefile.spl +4 -0
@@ -57,6 +57,10 @@ libs-y += common/init/ libs-$(CONFIG_SPL_LIBCOMMON_SUPPORT) += common/ cmd/ libs-$(CONFIG_SPL_LIBDISK_SUPPORT) += disk/ libs-y += drivers/ +libs-$(CONFIG_SPL_DFU_SUPPORT) += drivers/dfu/ +libs-$(CONFIG_SPL_DFU_SUPPORT) += drivers/usb/gadget/ +libs-$(CONFIG_SPL_DFU_SUPPORT) += drivers/usb/gadget/udc/ +libs-$(CONFIG_SPL_DFU_SUPPORT) += drivers/usb/dwc3/ libs-y += dts/ libs-y += fs/ libs-$(CONFIG_SPL_LIBGENERIC_SUPPORT) += lib/
Signature · 1 line
1.7.9.5
RFC PATCH v3 2/5 common: dfu: saperate the dfu common functionality
In reply to Ravi BabuThe cmd_dfu functionality is been used by both SPL and u-boot, saperating the core dfu functionality moving it to common/dfu.c.
--- cmd/dfu.c | 61 ++------------------------------------ common/Makefile | 2 ++ common/dfu.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/g_dnl.h | 1 + 4 files changed, 92 insertions(+), 59 deletions(-) create mode 100644 common/dfu.c
cmd/dfu.c +2 -59
@@ -21,7 +21,6 @@static int do_dfu (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) { -bool dfu_reset = false;if (argc <4 )return CMD_RET_USAGE ;
@@ -30,7 +29,7 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])char *interface = argv[2 ];char *devstring = argv[3 ]; -int ret, i =0 ; +int ret;#ifdef CONFIG_DFU_TFTP unsigned long addr =0 ;if (!strcmp (argv[1 ],"tftp" )) {
@@ -52,67 +51,11 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) }int controller_index =simple_strtoul (usb_controller,NULL ,0 ); -board_usb_init (controller_index,USB_INIT_DEVICE ); -g_dnl_clear_detach (); -g_dnl_register ("usb_dnl_dfu" ); -while (1 ) { -if (g_dnl_detach ()) { -/* -* Check if USB bus reset is performed after detach, -* which indicates that -R switch has been passed to -* dfu-util. In this case reboot the device -*/ -if (dfu_usb_get_reset ()) { - dfu_reset = true; - goto exit; - } -/* -* This extra number of usb_gadget_handle_interrupts() -* calls is necessary to assure correct transmission -* completion with dfu-util -*/ -if (++i ==10000 ) - goto exit; - } +run_usb_dnl_gadget (controller_index,"usb_dnl_dfu" ); -if (ctrlc ()) - goto exit; - -if (dfu_get_defer_flush ()) { -/* -* Call to usb_gadget_handle_interrupts() is necessary -* to act on ZLP OUT transaction from HOST PC after -* transmitting the whole file. -* -* If this ZLP OUT packet is NAK'ed, the HOST libusb -* function fails after timeout (by default it is set to -* 5 seconds). In such situation the dfu-util program -* exits with error message. -*/ -usb_gadget_handle_interrupts (controller_index); - ret =dfu_flush (dfu_get_defer_flush (),NULL ,0 ,0 ); -dfu_set_defer_flush (NULL ); -if (ret) { -error ("Deferred dfu_flush() failed!" ); - goto exit; - } - } - -WATCHDOG_RESET (); -usb_gadget_handle_interrupts (controller_index); - } -exit: -g_dnl_unregister (); -board_usb_cleanup (controller_index,USB_INIT_DEVICE ); done:dfu_free_entities (); - -if (dfu_reset) -run_command ("reset" ,0 ); - -g_dnl_clear_detach (); -return ret; }
common/Makefile +2 -0
@@ -87,6 +87,7 @@ obj-$(CONFIG_USB_KEYBOARD) += usb_kbd.o endif # !CONFIG_SPL_BUILD ifdef CONFIG_SPL_BUILD +obj-$(CONFIG_SPL_DFU_SUPPORT) += dfu.o obj-$(CONFIG_SPL_DFU_SUPPORT) += cli_hush.o obj-$(CONFIG_SPL_HASH_SUPPORT) += hash.o obj-$(CONFIG_ENV_IS_IN_FLASH) += env_flash.o
@@ -160,6 +161,7 @@ obj-$(CONFIG_CMDLINE) += cli_simple.o obj-y += cli.o obj-$(CONFIG_CMDLINE) += cli_readline.o +obj-$(CONFIG_CMD_DFU) += dfu.o obj-y += command.o obj-y += s_record.o obj-y += xyzModem.o
common/dfu.c new file +87 -0
87 lines not on this page · raw message
include/g_dnl.h +1 -0
@@ -43,5 +43,6 @@ void g_dnl_set_serialnumber(char *);bool g_dnl_detach (void );void g_dnl_trigger_detach (void );void g_dnl_clear_detach (void ); +int run_usb_dnl_gadget (int usbctrl_index,char *usb_dnl_gadget);#endif /* __G_DOWNLOAD_H_ */
Signature · 1 line
1.7.9.5
RFC PATCH v3 3/5 spl: dfu: adding dfu support functions for SPL-DFU
In reply to Ravi BabuAdding support functions to run dfu spl commands.
--- common/spl/Makefile | 1 + common/spl/spl_dfu.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/spl.h | 8 +++++++ 3 files changed, 66 insertions(+) create mode 100644 common/spl/spl_dfu.c
common/spl/Makefile +1 -0
@@ -24,4 +24,5 @@ obj-$(CONFIG_SPL_USB_SUPPORT) += spl_usb.o obj-$(CONFIG_SPL_FAT_SUPPORT) += spl_fat.o obj-$(CONFIG_SPL_EXT_SUPPORT) += spl_ext.o obj-$(CONFIG_SPL_SATA_SUPPORT) += spl_sata.o +obj-$(CONFIG_SPL_DFU_SUPPORT) += spl_dfu.o endif
common/spl/spl_dfu.c new file +57 -0
57 lines not on this page · raw message
include/spl.h +8 -0
@@ -144,4 +144,12 @@ void spl_board_init(void);*/ bool spl_was_boot_source (void ); +/** +* spl_dfu_cmd- run dfu command with chosen mmc device interface +* @param usb_index - usb controller number +* @param mmc_dev - mmc device nubmer +* +* @return 0 on success, otherwise error code +*/ +int spl_dfu_cmd (int usbctrl,char *dfu_alt_info,char *interface,char *devstr);#endif
Signature · 1 line
1.7.9.5
RFC PATCH v3 4/5 dra7x: boot: add dfu bootmode support
In reply to Ravi BabuThis patch enables the DFU boot mode support
for dra7x platform.
--- arch/arm/cpu/armv7/omap-common/boot-common.c | 5 +++++ arch/arm/include/asm/arch-omap5/spl.h | 2 +- common/spl/spl.c | 10 +++++++++- 3 files changed, 15 insertions(+), 2 deletions(-)
arch/arm/cpu/armv7/omap-common/boot-common.c +5 -0
@@ -91,6 +91,11 @@ void save_omap_boot_params(void) sys_boot_device =1 ;break ;#endif +#if defined(BOOT_DEVICE_DFU ) && !defined(CONFIG_SPL_DFU_SUPPORT ) +case BOOT_DEVICE_DFU : + sys_boot_device =1 ; +break ; +#endif }if (sys_boot_device) {
arch/arm/include/asm/arch-omap5/spl.h +1 -1
@@ -20,7 +20,7 @@#define BOOT_DEVICE_QSPI_1 0x0A#define BOOT_DEVICE_QSPI_4 0x0B#define BOOT_DEVICE_UART 0x43 -#define BOOT_DEVICE_USB 0x45 +#define BOOT_DEVICE_DFU 0x45#define MMC_BOOT_DEVICES_START BOOT_DEVICE_MMC1#define MMC_BOOT_DEVICES_END BOOT_DEVICE_MMC2_2
common/spl/spl.c +9 -1
@@ -171,7 +171,7 @@ __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)# define CONFIG_SPL_LOAD_FIT_ADDRESS 0#endif -#ifdef CONFIG_SPL_RAM_DEVICE +#if defined(CONFIG_SPL_RAM_DEVICE ) || defined(CONFIG_SPL_DFU_SUPPORT )static ulong spl_ram_load_read (struct spl_load_info *load,ulong sector,ulong count,void *buf) {
@@ -309,6 +309,9 @@ struct boot_device_name boot_name_table[] = { #ifdef CONFIG_SPL_USB_SUPPORT { BOOT_DEVICE_USB, "USB" }, #endif +#ifdef CONFIG_SPL_DFU_SUPPORT + { BOOT_DEVICE_DFU, "USB DFU" }, +#endif #ifdef CONFIG_SPL_SATA_SUPPORT { BOOT_DEVICE_SATA, "SATA" }, #endif
@@ -395,6 +398,11 @@ static int spl_load_image(u32 boot_device)case BOOT_DEVICE_USB :return spl_usb_load_image ();#endif +#ifdef CONFIG_SPL_DFU_SUPPORT +case BOOT_DEVICE_DFU : +spl_dfu_cmd (0 ,"dfu_alt_info_ram" ,"ram" ,"0" ); +return spl_ram_load_image (); +#endif #ifdef CONFIG_SPL_SATA_SUPPORT case BOOT_DEVICE_SATA :return spl_sata_load_image ();
Signature · 1 line
1.7.9.5
RFC PATCH v3 5/5 dra7x: configs: enable SPL-DFU support
In reply to Ravi BabuThis patch enables the SPL-DFU support for
dra7x platform.
--- include/configs/dra7xx_evm.h | 20 +++++++++++++++++++- include/configs/ti_omap5_common.h | 2 -- 2 files changed, 19 insertions(+), 3 deletions(-)
include/configs/dra7xx_evm.h +19 -1
@@ -133,6 +133,23 @@#define CONFIG_FASTBOOT_FLASH_MMC_DEV 1#endif +#ifdef CONFIG_SPL_BUILD +#undef CONFIG_CMD_BOOTD +#ifdef CONFIG_SPL_DFU_SUPPORT +#define CONFIG_SPL_LOAD_FIT_ADDRESS 0x80200000 +#define CONFIG_SPL_ENV_SUPPORT +#define CONFIG_SPL_HASH_SUPPORT +#define DFU_ALT_INFO_RAM \ + "dfu_alt_info_ram=" \ + "kernel ram 0x80200000 0x4000000;" \ + "fdt ram 0x80f80000 0x80000;" \ + "ramdisk ram 0x81000000 0x4000000\0" +#define DFUARGS \ + "dfu_bufsiz=0x10000\0" \ + DFU_ALT_INFO_RAM +#endif +#endif +#include <configs/ti_omap5_common.h> /* Enhance our eMMC support / experience. */
@@ -222,9 +239,10 @@#define CONFIG_USB_FUNCTION_DFU #define CONFIG_DFU_RAM +#ifndef CONFIG_SPL_BUILD #define CONFIG_DFU_MMC -#define CONFIG_DFU_RAM #define CONFIG_DFU_SF +#endif /* SATA */ #define CONFIG_BOARD_LATE_INIT
include/configs/ti_omap5_common.h +0 -2
@@ -66,7 +66,6 @@#define DFUARGS #endif -#ifndef CONFIG_SPL_BUILD #define CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG #define CONFIG_EXTRA_ENV_SETTINGS \ DEFAULT_LINUX_BOOT_ENV \
@@ -130,7 +129,6 @@"setenv mmcroot /dev/mmcblk0p2 rw; " \"run mmcboot;" \"" -#endif /* * SPL related defines. The Public RAM memory map the ROM defines the
Signature · 1 line
1.7.9.5