dfu: Drop unused prototype of dfu_trigger_reset()
PATCH v2 1/4 dfu: Drop unused prototype of dfu_trigger_reset()
After the commit 1cc03c5c53c0 ("dfu: Provide means to find difference between dfu-util -e and -R") the dangling ptototype appeared. Remove it here.
--- include/dfu.h | 1 - 1 file changed, 1 deletion(-)
include/dfu.h +0 -1
@@ -171,7 +171,6 @@ const char *dfu_get_dev_type(enum dfu_device_type t);const char *dfu_get_layout (enum dfu_layout l);struct dfu_entity *dfu_get_entity (int alt);char *dfu_extract_token (char ** e,int *n); -void dfu_trigger_reset (void );int dfu_get_alt (char *name);int dfu_init_env_entities (char *interface,char *devstr);unsigned char *dfu_get_buf (struct dfu_entity *dfu);
Signature · 1 line
2.24.0
PATCH v2 2/4 dfu: Refactor do_dfu() to handle optional argument
In the future we may utilize optional argument in 'dfu' command line. As a preparation for this, refactor do_dfu().
--- cmd/dfu.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
cmd/dfu.c +10 -7
@@ -30,22 +30,25 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])#if defined(CONFIG_DFU_OVER_USB ) || defined(CONFIG_DFU_OVER_TFTP )char *interface =NULL ;char *devstring =NULL ; +#if defined(CONFIG_DFU_OVER_TFTP ) +unsigned long value =0 ; +#endif if (argc >=4 ) { interface = argv[2 ]; devstring = argv[3 ]; } + +#if defined(CONFIG_DFU_OVER_TFTP ) +if (argc ==5 || argc ==3 ) + value =simple_strtoul (argv[argc -1 ],NULL ,0 ); +#endif #endif int ret =0 ;#ifdef CONFIG_DFU_OVER_TFTP -unsigned long addr =0 ; -if (!strcmp (argv[1 ],"tftp" )) { -if (argc ==5 || argc ==3 ) - addr =simple_strtoul (argv[argc -1 ],NULL ,0 ); - -return update_tftp (addr, interface, devstring); - } +if (!strcmp (argv[1 ],"tftp" )) +return update_tftp (value, interface, devstring);#endif #ifdef CONFIG_DFU_OVER_USB ret =dfu_init_env_entities (interface, devstring);
Signature · 1 line
2.24.0
PATCH v2 2/4 dfu: Refactor do_dfu() to handle optional argument
Quoted 9 lines · Andy Shevchenko
In the future we may utilize optional argument in 'dfu' command line. As a preparation for this, refactor
do_dfu().Signed-off-by Andy Shevchenko <[email protected]>Acked-by Lukasz Majewski <[email protected]>--- cmd/dfu.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
PATCH v2 3/4 dfu: Add optional timeout parameter
In reply to Andy ShevchenkoWhen the dfu command is called from the U-Boot environment, it now accepts an optional parameter that specifies a timeout (in seconds). If a DFU connection is not made within that time the dfu command exits (as it would if Ctrl+C was pressed). If the timeout is left empty or being zero the dfu command behaves as it does now.
This is useful for allowing U-Boot to check to see if anything wants to upload new firmware before continuing to boot.
The patch is based on the commit
https://github.com/01org/edison-u-boot/commit/5e966ccc3c65c18c9783741fa04e0c45e021780c
by Sebastien Colleur, which has been heavily reworked due to U-Boot changes in the past.
---
v2:
- add documentation part (Lukasz)
- drop original author's SoB due to bouncing email, give credit in the commit message anyway
cmd/dfu.c | 15 +++++++++++++-- common/dfu.c | 17 +++++++++++++++++ doc/README.dfu | 8 ++++++-- drivers/dfu/Kconfig | 6 ++++++ drivers/dfu/dfu.c | 15 +++++++++++++++ include/dfu.h | 5 +++++ 6 files changed, 62 insertions(+), 4 deletions(-)
cmd/dfu.c +13 -2
@@ -30,7 +30,7 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])#if defined(CONFIG_DFU_OVER_USB ) || defined(CONFIG_DFU_OVER_TFTP )char *interface =NULL ;char *devstring =NULL ; -#if defined(CONFIG_DFU_OVER_TFTP ) +#if defined(CONFIG_DFU_TIMEOUT ) || defined(CONFIG_DFU_OVER_TFTP )unsigned long value =0 ;#endif
@@ -39,7 +39,7 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) devstring = argv[3 ]; } -#if defined(CONFIG_DFU_OVER_TFTP ) +#if defined(CONFIG_DFU_TIMEOUT ) || defined(CONFIG_DFU_OVER_TFTP )if (argc ==5 || argc ==3 ) value =simple_strtoul (argv[argc -1 ],NULL ,0 );#endif
@@ -55,6 +55,10 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])if (ret) goto done; +#ifdef CONFIG_DFU_TIMEOUT +dfu_set_timeout (value *1000 ); +#endif + ret =CMD_RET_SUCCESS ;if (strcmp (argv[argc -1 ],"list" ) ==0 ) {dfu_show_entities ();
@@ -75,10 +79,17 @@ U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,"Device Firmware Upgrade" , ""#ifdef CONFIG_DFU_OVER_USB +#ifdef CONFIG_DFU_TIMEOUT +"<USB_controller> [<interface> <dev>] [<timeout>] [list]\n" +#else "<USB_controller> [<interface> <dev>] [list]\n" +#endif " - device firmware upgrade via <USB_controller>\n" " on device <dev>, attached to interface\n" " <interface>\n" +#ifdef CONFIG_DFU_TIMEOUT + " [<timeout>] - specify inactivity timeout in seconds\n" +#endif " [list] - list available alt settings\n" #endif #ifdef CONFIG_DFU_OVER_TFTP
common/dfu.c +17 -0
@@ -35,6 +35,10 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)return CMD_RET_FAILURE ; } +#ifdef CONFIG_DFU_TIMEOUT +unsigned long start_time =get_timer (0 ); +#endif +while (1 ) {if (g_dnl_detach ()) {/*
@@ -79,6 +83,19 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget) } } +#ifdef CONFIG_DFU_TIMEOUT +unsigned long wait_time =dfu_get_timeout (); + +if (wait_time) { +unsigned long current_time =get_timer (start_time); + +if (current_time > wait_time) { +debug ("Inactivity timeout, abort DFU\n" ); + goto exit; + } + } +#endif +WATCHDOG_RESET ();usb_gadget_handle_interrupts (usbctrl_index); }
doc/README.dfu +6 -2
@@ -43,6 +43,7 @@ Configuration Options: CONFIG_DFU_RAM CONFIG_DFU_SF CONFIG_DFU_SF_PART + CONFIG_DFU_TIMEOUT CONFIG_DFU_VIRTUAL CONFIG_CMD_DFU
@@ -70,12 +71,15 @@ Commands: dfu <USB_controller> [<interface> <dev>] list list the alternate device defined in "dfu_alt_info" - dfu <USB_controller> [<interface> <dev>] + dfu <USB_controller> [<interface> <dev>] [<timeout>] 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. + a DFU detach transaction from HOST. If CONFIG_DFU_TIMEOUT option + is enabled and <timeout> parameter is present in the command line, + the DFU operation will be aborted automatically after <timeout> + seconds of waiting remote to initiate DFU session. The possible values of <interface> are : (with <USB controller> = 0 in the dfu command example)
drivers/dfu/Kconfig +6 -0
@@ -23,6 +23,12 @@ config DFU_TFTP Detailed description of this feature can be found at ./doc/README.dfutftp +config DFU_TIMEOUT + bool "Timeout waiting for DFU" + help + This option adds an optional timeout parameter for DFU which, if set, + will cause DFU to only wait for that many seconds before exiting. + config DFU_MMC bool "MMC back end for DFU" help
drivers/dfu/dfu.c +15 -0
@@ -21,6 +21,9 @@ static LIST_HEAD(dfu_list);static int dfu_alt_num;static int alt_num_cnt;static struct hash_algo *dfu_hash_algo; +#ifdef CONFIG_DFU_TIMEOUT +static unsigned long dfu_timeout =0 ; +#endif /* * The purpose of the dfu_flush_callback() function is to
@@ -58,6 +61,18 @@ __weak bool dfu_usb_get_reset(void)#endif } +#ifdef CONFIG_DFU_TIMEOUT +void dfu_set_timeout (unsigned long timeout) +{ + dfu_timeout = timeout; +} + +unsigned long dfu_get_timeout (void ) +{ +return dfu_timeout; +} +#endif +static int dfu_find_alt_num (const char *s) {int i =0 ;
include/dfu.h +5 -0
@@ -178,6 +178,11 @@ unsigned char *dfu_free_buf(void);unsigned long dfu_get_buf_size (void );bool dfu_usb_get_reset (void ); +#ifdef CONFIG_DFU_TIMEOUT +unsigned long dfu_get_timeout (void ); +void dfu_set_timeout (unsigned long ); +#endif +int dfu_read (struct dfu_entity *de,void *buf,int size,int blk_seq_num);int dfu_write (struct dfu_entity *de,void *buf,int size,int blk_seq_num);int dfu_flush (struct dfu_entity *de,void *buf,int size,int blk_seq_num);
Signature · 1 line
2.24.0
PATCH v2 3/4 dfu: Add optional timeout parameter
HI Andy,
Quoted 54 lines · Andy Shevchenko
When the
dfucommand is called from the U-Boot environment, it now accepts an optional parameter that specifies a timeout (in seconds). If a DFU connection is not made within that time thedfucommand exits (as it would if Ctrl+C was pressed). If the timeout is left empty or being zero thedfucommand behaves as it does now.This is useful for allowing U-Boot to check to see if anything wants to upload new firmware before continuing to boot.
The patch is based on the commit
https://github.com/01org/edison-u-boot/commit/5e966ccc3c65c18c9783741fa04e0c45e021780c
by Sebastien Colleur, which has been heavily reworked due to U-Boot changes in the past.Signed-off-by Brad Campbell <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>---
v2:
- add documentation part (Lukasz)
- drop original author's SoB due to bouncing email, give credit in the commit message anywaycmd/dfu.c | 15 +++++++++++++-- common/dfu.c | 17 +++++++++++++++++ doc/README.dfu | 8 ++++++-- drivers/dfu/Kconfig | 6 ++++++ drivers/dfu/dfu.c | 15 +++++++++++++++ include/dfu.h | 5 +++++ 6 files changed, 62 insertions(+), 4 deletions(-)cmd/dfu.c +2
-2@@ -30,7 +30,7 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])#if defined(CONFIG_DFU_OVER_USB ) || defined(CONFIG_DFU_OVER_TFTP )char *interface =NULL ;char *devstring =NULL ; -#if defined(CONFIG_DFU_OVER_TFTP ) +#if defined(CONFIG_DFU_TIMEOUT ) || defined(CONFIG_DFU_OVER_TFTP )unsigned long value =0 ;#endif @@ -39,7 +39,7 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) devstring = argv[3 ]; } -#if defined(CONFIG_DFU_OVER_TFTP ) +#if defined(CONFIG_DFU_TIMEOUT ) || defined(CONFIG_DFU_OVER_TFTP )if (argc ==5 || argc ==3 ) value =simple_strtoul (argv[argc -1 ],NULL ,0 );#endif
cmd/dfu.c static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 58
Quoted 4 lines
cmd/dfu.c +1
-0@@ -55,6 +55,10 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])if (ret) goto done; +#ifdef CONFIG_DFU_TIMEOUT
Can this all use
if (IS_ENABLED(CONFIG_DFU_TIMEOUT))
to reduce the number of #ifdefs?
Also I wonder if CONFIG_VAL(...) returns 0 if the CONFIG doesn't exist? If so, you might be able to remove all the #ifdefs and use 0 as the value that means infinite?
Quoted 144 lines
cmd/dfu.c +10
-0+dfu_set_timeout (value *1000 ); +#endif + ret =CMD_RET_SUCCESS ;if (strcmp (argv[argc -1 ],"list" ) ==0 ) {dfu_show_entities ();@@ -75,10 +79,17 @@ U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,"Device Firmware Upgrade" , ""#ifdef CONFIG_DFU_OVER_USB +#ifdef CONFIG_DFU_TIMEOUT +"<USB_controller> [<interface> <dev>] [<timeout>] [list]\n" +#else "<USB_controller> [<interface> <dev>] [list]\n" +#endif " - device firmware upgrade via <USB_controller>\n" " on device <dev>, attached to interface\n" " <interface>\n" +#ifdef CONFIG_DFU_TIMEOUT + " [<timeout>] - specify inactivity timeout in seconds\n" +#endif " [list] - list available alt settings\n" #endif #ifdef CONFIG_DFU_OVER_TFTPcommon/dfu.c +17
-0@@ -35,6 +35,10 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget)return CMD_RET_FAILURE ; } +#ifdef CONFIG_DFU_TIMEOUT +unsigned long start_time =get_timer (0 ); +#endif +while (1 ) {if (g_dnl_detach ()) {/* @@ -79,6 +83,19 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget) } } +#ifdef CONFIG_DFU_TIMEOUT +unsigned long wait_time =dfu_get_timeout (); + +if (wait_time) { +unsigned long current_time =get_timer (start_time); + +if (current_time > wait_time) { +debug ("Inactivity timeout, abort DFU\n" ); + goto exit; + } + } +#endif +WATCHDOG_RESET ();usb_gadget_handle_interrupts (usbctrl_index); }doc/README.dfu +6
-2@@ -43,6 +43,7 @@ Configuration Options: CONFIG_DFU_RAM CONFIG_DFU_SF CONFIG_DFU_SF_PART + CONFIG_DFU_TIMEOUT CONFIG_DFU_VIRTUAL CONFIG_CMD_DFU@@ -70,12 +71,15 @@ Commands: dfu <USB_controller> [<interface> <dev>] list list the alternate device defined in "dfu_alt_info" - dfu <USB_controller> [<interface> <dev>] + dfu <USB_controller> [<interface> <dev>] [<timeout>] 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. + a DFU detach transaction from HOST. If CONFIG_DFU_TIMEOUT option + is enabled and <timeout> parameter is present in the command line, + the DFU operation will be aborted automatically after <timeout> + seconds of waiting remote to initiate DFU session. The possible values of <interface> are : (with <USB controller> = 0 in the dfu command example)drivers/dfu/Kconfig +6
-0@@ -23,6 +23,12 @@ config DFU_TFTP Detailed description of this feature can be found at ./doc/README.dfutftp +config DFU_TIMEOUT + bool "Timeout waiting for DFU" + help + This option adds an optional timeout parameter for DFU which, if set, + will cause DFU to only wait for that many seconds before exiting. + config DFU_MMC bool "MMC back end for DFU" helpdrivers/dfu/dfu.c +15
-0@@ -21,6 +21,9 @@ static LIST_HEAD(dfu_list);static int dfu_alt_num;static int alt_num_cnt;static struct hash_algo *dfu_hash_algo; +#ifdef CONFIG_DFU_TIMEOUT +static unsigned long dfu_timeout =0 ; +#endif /* * The purpose of the dfu_flush_callback() function is to @@ -58,6 +61,18 @@ __weak bool dfu_usb_get_reset(void)#endif } +#ifdef CONFIG_DFU_TIMEOUT +void dfu_set_timeout (unsigned long timeout) +{ + dfu_timeout = timeout; +} + +unsigned long dfu_get_timeout (void ) +{ +return dfu_timeout; +} +#endif +static int dfu_find_alt_num (const char *s) {int i =0 ;include/dfu.h +0
-0
include/dfu.h unsigned char *dfu_free_buf(void); · line 183
Quoted 6 lines
include/dfu.h +3
-0@@ -178,6 +178,11 @@ unsigned char *dfu_free_buf(void);unsigned long dfu_get_buf_size (void );bool dfu_usb_get_reset (void ); +#ifdef CONFIG_DFU_TIMEOUT +unsigned long dfu_get_timeout (void ); +void dfu_set_timeout (unsigned long );
Please add function comments.
Quoted 8 lines
include/dfu.h +2
-1+#endif +int dfu_read (struct dfu_entity *de,void *buf,int size,int blk_seq_num);int dfu_write (struct dfu_entity *de,void *buf,int size,int blk_seq_num);int dfu_flush (struct dfu_entity *de,void *buf,int size,int blk_seq_num); --2.24.0
Regards,
Simon
PATCH v2 4/4 x86: edison: Enable DFU timeout
In reply to Andy ShevchenkoThe stock U-Boot on Intel Edison has timeout parameter for DFU command. Enable it here to be compatible with the original U-Boot configuration.
---
v2:
- rebase on top of origin/master as of today (Lukasz)
configs/edison_defconfig | 1 + 1 file changed, 1 insertion(+)
configs/edison_defconfig +1 -0
@@ -34,6 +34,7 @@ CONFIG_SYS_REDUNDAND_ENVIRONMENT=y CONFIG_ENV_OFFSET_REDUND=0x600000 CONFIG_SYS_RELOC_GD_ENV_ADDR=y CONFIG_CPU=y +CONFIG_DFU_TIMEOUT=y CONFIG_DFU_MMC=y CONFIG_DFU_RAM=y CONFIG_SUPPORT_EMMC_BOOT=y
Signature · 1 line
2.24.0
PATCH v2 4/4 x86: edison: Enable DFU timeout
Quoted 10 lines · Andy Shevchenko
The stock U-Boot on Intel Edison has timeout parameter for DFU command. Enable it here to be compatible with the original U-Boot configuration.
Signed-off-by Andy Shevchenko <[email protected]>---
v2:
- rebase on top of origin/master as of today (Lukasz)configs/edison_defconfig | 1 + 1 file changed, 1 insertion(+)
But the Kconfig help says this is a value in seconds, not a bool...need to check that.
PATCH v2 1/4 dfu: Drop unused prototype of dfu_trigger_reset()
In reply to Andy ShevchenkoQuoted 4 lines · Andy Shevchenko
After the commit
1cc03c5c53c0("dfu: Provide means to find difference between dfu-util -e and -R") the dangling ptototype appeared. Remove it here.
Quoted 8 lines
Fixes 1cc03c5c53c0 ("dfu: Provide means to find difference between dfu-util -e and -R")Cc Lukasz Majewski <[email protected]>Cc Stephen Warren <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>Acked-by Lukasz Majewski <[email protected]>--- include/dfu.h | 1 - 1 file changed, 1 deletion(-)