cmd_fat: add FAT write command
PATCH v3 1/1 cmd_fat: add FAT write command
Once CONFIG_FAT_WRITE is defined,
users can invoke 'fatwrite' command that saves data in RAM as a FAT file.
By removing variable of 'part_size' in fs/fat.c,
compile error occurs when enabling FAT write feature.
The variable should be declared only when CONFIG_FAT_WRITE is defined. This patch also removes compile error when FAT write is enabled and compile warning when FAT write is disabled.
---
Changes for v3:
- use cmd_usage function
Changes for v2:
- merge the patch that fixes compile error when enabling FAT write
- change do_fat_fswrite to be static function
common/cmd_fat.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/fat/fat.c | 7 ++++++ 2 files changed, 64 insertions(+), 0 deletions(-)
common/cmd_fat.c +57 -0
@@ -184,3 +184,60 @@ U_BOOT_CMD("<interface> <dev[:part]>\n" " - print information about filesystem from 'dev' on 'interface'" ); + +#ifdef CONFIG_FAT_WRITE +static int do_fat_fswrite (cmd_tbl_t *cmdtp,int flag, +int argc,char *const argv[]) +{ +long size; +unsigned long addr; +unsigned long count; +block_dev_desc_t *dev_desc =NULL ; +int dev =0 ; +int part =1 ; +char *ep; + +if (argc <5 ) +return cmd_usage (cmdtp); + + dev = (int )simple_strtoul (argv[2 ], &ep,16 ); + dev_desc =get_dev (argv[1 ], dev); +if (dev_desc ==NULL ) { +puts ("\n** Invalid boot device **\n" ); +return 1 ; + } +if (*ep) { +if (*ep !=':' ) { +puts ("\n** Invalid boot device, use `dev[:part]' **\n" ); +return 1 ; + } + part = (int )simple_strtoul (++ep,NULL ,16 ); + } +if (fat_register_device (dev_desc, part) !=0 ) { +printf ("\n** Unable to use %s %d:%d for fatwrite **\n" , + argv[1 ], dev, part); +return 1 ; + } + addr =simple_strtoul (argv[3 ],NULL ,16 ); + count =simple_strtoul (argv[5 ],NULL ,16 ); + + size =file_fat_write (argv[4 ], (void *)addr, count); +if (size ==-1 ) { +printf ("\n** Unable to write \"%s\" from %s %d:%d **\n" , + argv[4 ], argv[1 ], dev, part); +return 1 ; + } + +printf ("%ld bytes write\n" , size); + +return 0 ; +} + +U_BOOT_CMD ( + fatwrite,6 ,0 , do_fat_fswrite, +"write file into a dos filesystem" , +"<interface> <dev[:part]> <addr> <filename> <bytes>\n" +" - write file 'filename' from the address 'addr' in RAM\n" +" to 'dev' on 'interface'" +); +#endif
fs/fat/fat.c +7 -0
@@ -47,6 +47,10 @@ static block_dev_desc_t *cur_dev = NULL;static unsigned long part_offset =0 ; +#ifdef CONFIG_FAT_WRITE +static unsigned long part_size; +#endif +static int cur_part =1 ;#define DOS_PART_TBL_OFFSET 0x1be
@@ -101,6 +105,9 @@ int fat_register_device (block_dev_desc_t * dev_desc, int part_no)if (!get_partition_info (dev_desc, part_no, &info)) { part_offset = info.start; cur_part = part_no; +#ifdef CONFIG_FAT_WRITE + part_size = info.size; +#endif } else if ((strncmp((char *)&buffer[DOS_FS_TYPE_OFFSET], "FAT", 3) == 0) || (strncmp((char *)&buffer[DOS_FS32_TYPE_OFFSET],
Signature · 1 line
1.7.4.1
PATCH v3 1/1 cmd_fat: add FAT write command
Dear Donggeun Kim,
Quoted 18 lines · In message <[email protected]> you wrote:
Once
CONFIG_FAT_WRITEis defined,
users can invoke 'fatwrite' command that saves data in RAM as a FAT file.By removing variable of '
part_size' infs/fat.c,
compile error occurs when enabling FAT write feature.
The variable should be declared only whenCONFIG_FAT_WRITEis defined. This patch also removes compile error when FAT write is enabled and compile warning when FAT write is disabled.Signed-off-by Donggeun Kim <[email protected]>Signed-off-by Kyungmin Park <[email protected]>---
Changes for v3:
- usecmd_usagefunction
Changes for v2:
- merge the patch that fixes compile error when enabling FAT write
- changedo_fat_fswriteto be static function
Quoted 3 lines
common/cmd_fat.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/fat/fat.c | 7 ++++++ 2 files changed, 64 insertions(+), 0 deletions(-)
This does not apply any more, please rebase against current master and resubmit.
Sorry.
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de The years of peak mental activity are undoubtedly between the ages of four and eighteen. At four we know all the questions, at eighteen all the answers.