X-Git-Url: https://git.kernelconcepts.de/?a=blobdiff_plain;f=common%2Fcmd_fat.c;h=54f0f9f9cec7f82a938888679212b9134d0c892a;hb=6cfd3c7bc813fb317ab7c0781f0d1874b1c0877c;hp=27f832282e8452cc6452425a1b8619e6829a1272;hpb=0d4983930a3559be92452761cfa268ee9d0f2773;p=karo-tx-uboot.git diff --git a/common/cmd_fat.c b/common/cmd_fat.c index 27f832282e..54f0f9f9ce 100644 --- a/common/cmd_fat.c +++ b/common/cmd_fat.c @@ -29,83 +29,159 @@ #include #include #include +#include -#if (CONFIG_COMMANDS & CFG_CMD_FAT) +#if defined(CONFIG_CMD_FAT) #undef DEBUG #include -extern block_dev_desc_t *ide_get_dev (int dev); int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { long size; unsigned long offset; unsigned long count; - - if (argc < 3) { - printf ("usage:fatload [bytes]\n"); - return (0); + char buf [12]; + block_dev_desc_t *dev_desc=NULL; + int dev=0; + int part=1; + char *ep; + + if (argc < 5) { + printf ("usage: fatload [bytes]\n"); + return 1; } - - offset = simple_strtoul (argv[2], NULL, 16); - if (argc == 4) - count = simple_strtoul (argv[3], NULL, 16); + 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 fatload **\n",argv[1],dev,part); + return 1; + } + offset = simple_strtoul (argv[3], NULL, 16); + if (argc == 6) + count = simple_strtoul (argv[5], NULL, 16); else count = 0; + size = file_fat_read (argv[4], (unsigned char *) offset, count); + + if(size==-1) { + printf("\n** Unable to read \"%s\" from %s %d:%d **\n",argv[4],argv[1],dev,part); + return 1; + } - size = file_fat_read (argv[1], (unsigned char *) offset, count); + printf ("\n%ld bytes read\n", size); - printf ("%ld bytes read\n", size); + sprintf(buf, "%lX", size); + setenv("filesize", buf); - return size; + return 0; } + U_BOOT_CMD( - fatload, 4, 0, do_fat_fsload, + fatload, 6, 0, do_fat_fsload, "fatload - load binary file from a dos filesystem\n", - "[ off ] [ filename ]\n" - " - load binary file from dos filesystem\n" - " with offset 'off'\n" + " [bytes]\n" + " - load binary file 'filename' from 'dev' on 'interface'\n" + " to address 'addr' from dos filesystem\n" ); int do_fat_ls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { char *filename = "/"; int ret; + int dev=0; + int part=1; + char *ep; + block_dev_desc_t *dev_desc=NULL; - if (argc == 2) - ret = file_fat_ls (argv[1]); + if (argc < 3) { + printf ("usage: fatls [directory]\n"); + return (0); + } + 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 fatls **\n",argv[1],dev,part); + return 1; + } + if (argc == 4) + ret = file_fat_ls (argv[3]); else ret = file_fat_ls (filename); + if(ret!=0) + printf("No Fat FS detected\n"); return (ret); } U_BOOT_CMD( - fatls, 2, 1, do_fat_ls, + fatls, 4, 1, do_fat_ls, "fatls - list files in a directory (default /)\n", - "[ directory ]\n" - " - list files in a directory\n" + " [directory]\n" + " - list files from 'dev' on 'interface' in a 'directory'\n" ); int do_fat_fsinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { - int ret; - - ret = 0; - - printf ("FAT info: %d\n", file_fat_detectfs ()); + int dev=0; + int part=1; + char *ep; + block_dev_desc_t *dev_desc=NULL; - return (ret); + if (argc < 2) { + printf ("usage: fatinfo \n"); + return (0); + } + 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 fatinfo **\n",argv[1],dev,part); + return 1; + } + return (file_fat_detectfs ()); } U_BOOT_CMD( - fatinfo, 1, 1, do_fat_fsinfo, + fatinfo, 3, 1, do_fat_fsinfo, "fatinfo - print information about filesystem\n", - "\n" - " - print information about filesystem\n" + " \n" + " - print information about filesystem from 'dev' on 'interface'\n" ); #ifdef NOT_IMPLEMENTED_YET @@ -248,4 +324,4 @@ void hexdump (int cnt, unsigned char *data) } #endif /* NOT_IMPLEMENTED_YET */ -#endif /* CFG_CMD_FAT */ +#endif