#include <s_record.h>
#include <net.h>
#include <ata.h>
-
-#if (CONFIG_COMMANDS & CFG_CMD_FAT)
-
-#undef DEBUG
-
+#include <part.h>
#include <fat.h>
-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 <filename> <addr> [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 <interface> <dev[:part]> <addr> <filename> [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;
}
-cmd_tbl_t U_BOOT_CMD(FATLOAD) = MK_CMD_ENTRY(
- "fatload", 4, 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"
+
+U_BOOT_CMD(
+ fatload, 6, 0, do_fat_fsload,
+ "load binary file from a dos filesystem",
+ "<interface> <dev[:part]> <addr> <filename> [bytes]\n"
+ " - load binary file 'filename' from 'dev' on 'interface'\n"
+ " to address 'addr' from dos filesystem"
);
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 <interface> <dev[:part]> [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);
}
-cmd_tbl_t U_BOOT_CMD(FATLS) = MK_CMD_ENTRY(
- "fatls", 2, 1, do_fat_ls,
- "fatls - list files in a directory (default /)\n",
- "[ directory ]\n"
- " - list files in a directory\n"
+U_BOOT_CMD(
+ fatls, 4, 1, do_fat_ls,
+ "list files in a directory (default /)",
+ "<interface> <dev[:part]> [directory]\n"
+ " - list files from 'dev' on 'interface' in a 'directory'"
);
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 <interface> <dev[:part]>\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 ());
}
-cmd_tbl_t U_BOOT_CMD(FATINFO) = MK_CMD_ENTRY(
- "fatinfo", 1, 1, do_fat_fsinfo,
- "fatinfo - print information about filesystem\n",
- "\n"
- " - print information about filesystem\n"
+U_BOOT_CMD(
+ fatinfo, 3, 1, do_fat_fsinfo,
+ "print information about filesystem",
+ "<interface> <dev[:part]>\n"
+ " - print information about filesystem from 'dev' on 'interface'"
);
#ifdef NOT_IMPLEMENTED_YET
unsigned char *part_table;
unsigned char buffer[ATA_BLOCKSIZE];
- for (i = 0; i < CFG_IDE_MAXDEVICE; i++) {
+ for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; i++) {
dev_desc = ide_get_dev (i);
if (!dev_desc) {
debug ("couldn't get ide device!\n");
}
}
#endif /* NOT_IMPLEMENTED_YET */
-
-#endif /* CFG_CMD_FAT */