RFC: dfu: mmc: call fs functions instead of run_command
PATCH 1/1 RFC: dfu: mmc: call fs functions instead of run_command
This unbreaks dfu mmc_file_op which is currently broken since using the load cmd on a buffer from heap is not allowed.
---
drivers/dfu/dfu_mmc.c | 67 ++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 36 deletions(-)
drivers/dfu/dfu_mmc.c +31 -36
@@ -108,17 +108,17 @@ static int mmc_file_buffer(struct dfu_entity *dfu, void *buf, long *len)static int mmc_file_op (enum dfu_op op,struct dfu_entity *dfu,void *buf,u64 *len) { -const char *fsname, *opname; -char cmd_buf[DFU_CMD_BUF_SIZE ]; -char *str_env; +char dev_part_str[DFU_CMD_BUF_SIZE ];int ret; +int fstype; +loff_t size =0 ;switch (dfu->layout) {case DFU_FS_FAT : - fsname ="fat" ; + fstype =FS_TYPE_FAT ;break ;case DFU_FS_EXT4 : - fsname ="ext4" ; + fstype =FS_TYPE_EXT ;break ;default : printf("%s: Layout (%s) not (yet) supported!\n", __func__,
@@ -126,48 +126,43 @@ static int mmc_file_op(enum dfu_op op, struct dfu_entity *dfu,return -1 ; } +snprintf (dev_part_str,DFU_CMD_BUF_SIZE ,"%d:%d" , dfu->data.mmc.dev, + dfu->data.mmc.part); + + ret =fs_set_blk_dev ("mmc" , dev_part_str, fstype); +if (ret) { +puts ("dfu: fs_set_blk_dev error!\n" ); +return ret; + } +switch (op) {case DFU_OP_READ : - opname ="load" ; + ret =fs_read (dfu->name, (size_t )buf,0 ,0 , &size); +if (ret) { +puts ("dfu: fs_read error!\n" ); +return ret; + } + *len = size;break ;case DFU_OP_WRITE : - opname ="write" ; + ret =fs_write (dfu->name, (size_t )buf,0 , *len, &size); +if (ret) { +puts ("dfu: fs_write error!\n" ); +return ret; + }break ;case DFU_OP_SIZE : - opname ="size" ; + ret =fs_size (dfu->name, &size); +if (ret) { +puts ("dfu: fs_size error!\n" ); +return ret; + } + *len = size;break ;default :return -1 ; } -sprintf (cmd_buf,"%s%s mmc %d:%d" , fsname, opname, - dfu->data.mmc.dev, dfu->data.mmc.part); - -if (op !=DFU_OP_SIZE ) -sprintf (cmd_buf +strlen (cmd_buf)," %p" , buf); - -sprintf (cmd_buf +strlen (cmd_buf)," %s" , dfu->name); - -if (op ==DFU_OP_WRITE ) -sprintf (cmd_buf +strlen (cmd_buf)," %llx" , *len); - -debug ("%s: %s 0x%p\n" , __func__, cmd_buf, cmd_buf); - - ret =run_command (cmd_buf,0 ); -if (ret) { -puts ("dfu: Read error!\n" ); -return ret; - } - -if (op !=DFU_OP_WRITE ) { - str_env =env_get ("filesize" ); -if (str_env ==NULL ) { -puts ("dfu: Wrong file size!\n" ); -return -1 ; - } - *len =simple_strtoul (str_env,NULL ,16 ); - } -return ret; }
Signature · 1 line
2.17.1
PATCH 1/1 RFC: dfu: mmc: call fs functions instead of run_command
Steven,
Am Do., 24. Jan. 2019, 19:39 hat Simon Goldschmidt < [email protected]> geschrieben:
Quoted 5 lines
This unbreaks dfu
mmc_file_opwhich is currently broken since using the load cmd on a buffer from heap is not allowed.Signed-off-by Simon Goldschmidt <[email protected]>
I'd be very thankful if you could test this! It's RFC as I don't know to test DFU.
Thanks,
Simon
---
Quoted 113 lines
drivers/dfu/dfu_mmc.c | 67 ++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 36 deletions(-)drivers/dfu/dfu_mmc.c +5
-5@@ -108,17 +108,17 @@ static int mmc_file_buffer(struct dfu_entity *dfu, void *buf, long *len) static int mmc_file_op(enum dfu_op op, struct dfu_entity *dfu, void *buf, u64 *len) { - const char *fsname, *opname; -char cmd_buf[DFU_CMD_BUF_SIZE ]; -char *str_env; + char dev_part_str[DFU_CMD_BUF_SIZE];int ret; +int fstype; +loff_t size =0 ;switch (dfu->layout) {case DFU_FS_FAT : - fsname ="fat" ; + fstype =FS_TYPE_FAT ;break ;case DFU_FS_EXT4 : - fsname ="ext4" ; + fstype =FS_TYPE_EXT ;break ;default :printf("%s: Layout (%s) not (yet) supported!\n", __func__,drivers/dfu/dfu_mmc.c +26
-31@@ -126,48 +126,43 @@ static int mmc_file_op(enum dfu_op op, struct dfu_entity *dfu, return -1 ; } +snprintf (dev_part_str,DFU_CMD_BUF_SIZE ,"%d:%d" , dfu->data.mmc.dev, + dfu->data.mmc.part); + + ret =fs_set_blk_dev ("mmc" , dev_part_str, fstype); +if (ret) { +puts ("dfu: fs_set_blk_dev error!\n" ); +return ret; + } +switch (op) {case DFU_OP_READ : - opname ="load" ; + ret =fs_read (dfu->name, (size_t )buf,0 ,0 , &size); +if (ret) { +puts ("dfu: fs_read error!\n" ); +return ret; + } + *len = size;break ;case DFU_OP_WRITE : - opname ="write" ; + ret =fs_write (dfu->name, (size_t )buf,0 , *len, &size); +if (ret) { +puts ("dfu: fs_write error!\n" ); +return ret; + }break ;case DFU_OP_SIZE : - opname ="size" ; + ret =fs_size (dfu->name, &size); +if (ret) { +puts ("dfu: fs_size error!\n" ); +return ret; + } + *len = size;break ;default :return -1 ; } -sprintf (cmd_buf,"%s%s mmc %d:%d" , fsname, opname, - dfu->data.mmc.dev, dfu->data.mmc.part); - -if (op !=DFU_OP_SIZE ) -sprintf (cmd_buf +strlen (cmd_buf)," %p" , buf); - -sprintf (cmd_buf +strlen (cmd_buf)," %s" , dfu->name); - -if (op ==DFU_OP_WRITE ) -sprintf (cmd_buf +strlen (cmd_buf)," %llx" , *len); - -debug ("%s: %s 0x%p\n" , __func__, cmd_buf, cmd_buf); - - ret =run_command (cmd_buf,0 ); -if (ret) { -puts ("dfu: Read error!\n" ); -return ret; - } - -if (op !=DFU_OP_WRITE ) { - str_env =env_get ("filesize" ); -if (str_env ==NULL ) { -puts ("dfu: Wrong file size!\n" ); -return -1 ; - } - *len =simple_strtoul (str_env,NULL ,16 ); - } -return ret;}
--
2.17.1
PATCH 1/1 RFC: dfu: mmc: call fs functions instead of run_command
In reply to Simon GoldschmidtQuoted 2 lines · Simon Goldschmidt
This unbreaks dfu
mmc_file_opwhich is currently broken since using the load cmd on a buffer from heap is not allowed.
drivers/dfu/dfu_mmc.c static int mmc_file_buffer(struct dfu_entity *dfu, void *buf, long *len) · line 111
Quoted 9 lines
drivers/dfu/dfu_mmc.c +1
-3static int mmc_file_op (enum dfu_op op,struct dfu_entity *dfu,void *buf,u64 *len) { -const char *fsname, *opname; -char cmd_buf[DFU_CMD_BUF_SIZE ]; -char *str_env; +char dev_part_str[DFU_CMD_BUF_SIZE ];
This can be a lot smaller now, but I guess it's fine as is.
PATCH 1/1 RFC: dfu: mmc: call fs functions instead of run_command
Am Do., 24. Jan. 2019, 21:05 hat Stephen Warren <[email protected]> geschrieben:
Quoted 6 lines · Simon Goldschmidt
Quoted 2 lines
This unbreaks dfu
mmc_file_opwhich is currently broken since using the load cmd on a buffer from heap is not allowed.Tested-by Stephen Warren <[email protected]>
That was fast, thanks!
Quoted 10 lines
drivers/dfu/dfu_mmc.c static int mmc_file_buffer(struct dfu_entity *dfu, void *buf, long *len) · line 111
Quoted 9 lines
drivers/dfu/dfu_mmc.c +1
-3static int mmc_file_op (enum dfu_op op,struct dfu_entity *dfu,void *buf,u64 *len) { -const char *fsname, *opname; -char cmd_buf[DFU_CMD_BUF_SIZE ]; -char *str_env; +char dev_part_str[DFU_CMD_BUF_SIZE ];
Quoted 2 lines
This can be a lot smaller now, but I guess it's fine as is.
This is why this is RFC. I wanted to find a way to prevent the conversion to string and back first.
Regards,
Simon