aboutsummaryrefslogtreecommitdiff
path: root/common/cmd_fat.c
diff options
context:
space:
mode:
authorwdenk2003-09-10 22:30:53 +0000
committerwdenk2003-09-10 22:30:53 +0000
commit7205e4075d8b50e4dd89fe39ed03860b23cbb704 (patch)
tree0dfa865e7087ff4ee07967a2531c91ff5645a802 /common/cmd_fat.c
parent149dded2b178bc0fb62cb6f61b87968d914b580a (diff)
* Patches by Denis Peter, 9 Sep 2003:
add FAT support for IDE, SCSI and USB * Patches by Gleb Natapov, 2 Sep 2003: - cleanup of POST code for unsupported architectures - MPC824x locks way0 of data cache for use as initial RAM; this patch unlocks it after relocation to RAM and invalidates the locked entries. * Patch by Gleb Natapov, 30 Aug 2003: new I2C driver for mpc107 bridge. Now works from flash. * Patch by Dave Ellis, 11 Aug 2003: - JFFS2: fix typo in common/cmd_jffs2.c - JFFS2: fix CFG_JFFS2_SORT_FRAGMENTS option - JFFS2: remove node version 0 warning - JFFS2: accept JFFS2 PADDING nodes - SXNI855T: add AM29LV800 support - SXNI855T: move environment from EEPROM to flash - SXNI855T: boot from JFFS2 in NOR or NAND flash * Patch by Bill Hargen, 11 Aug 2003: fixes for I2C on MPC8240 - fix i2c_write routine - fix iprobe command - eliminates use of global variables, plus dead code, cleanup.
Diffstat (limited to 'common/cmd_fat.c')
-rw-r--r--common/cmd_fat.c159
1 files changed, 131 insertions, 28 deletions
diff --git a/common/cmd_fat.c b/common/cmd_fat.c
index 27f832282e8..2a1da95b819 100644
--- a/common/cmd_fat.c
+++ b/common/cmd_fat.c
@@ -36,76 +36,179 @@
#include <fat.h>
-extern block_dev_desc_t *ide_get_dev (int dev);
+
+
+
+block_dev_desc_t *get_dev (char* ifname, int dev)
+{
+#if (CONFIG_COMMANDS & CFG_CMD_IDE)
+ if (strncmp(ifname,"ide",3)==0) {
+ extern block_dev_desc_t * ide_get_dev(int dev);
+ return(ide_get_dev(dev));
+ }
+#endif
+#if (CONFIG_COMMANDS & CFG_CMD_SCSI)
+ if (strncmp(ifname,"scsi",4)==0) {
+ extern block_dev_desc_t * scsi_get_dev(int dev);
+ return(scsi_get_dev(dev));
+ }
+#endif
+#if ((CONFIG_COMMANDS & CFG_CMD_USB) && defined(CONFIG_USB_STORAGE))
+ if (strncmp(ifname,"usb",3)==0) {
+ extern block_dev_desc_t * usb_stor_get_dev(int dev);
+ return(usb_stor_get_dev(dev));
+ }
+#endif
+#if defined(CONFIG_MMC)
+ if (strncmp(ifname,"mmc",3)==0) {
+ extern block_dev_desc_t * mmc_get_dev(int dev);
+ return(mmc_get_dev(dev));
+ }
+#endif
+ return NULL;
+}
+
int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
long size;
unsigned long offset;
unsigned long count;
+ block_dev_desc_t *dev_desc=NULL;
+ int dev=0;
+ int part=1;
+ char *ep;
- if (argc < 3) {
- printf ("usage:fatload <filename> <addr> [bytes]\n");
+ if (argc < 5) {
+ printf ("usage: fatload <interface> <dev[:part]> <addr> <filename> [bytes]\n");
return (0);
}
-
- 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);
- size = file_fat_read (argv[1], (unsigned char *) offset, count);
-
- printf ("%ld bytes read\n", size);
+ if(size==-1)
+ printf("\n** Unable to read \"%s\" from %s %d:%d **\n",argv[4],argv[1],dev,part);
+ else
+ printf ("\n%ld bytes read\n", size);
return size;
}
+
+
+
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"
+ "<interface> <dev[:part]> <addr> <filename> [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 <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);
}
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"
+ "<interface> <dev[:part]> [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;
+ int dev=0;
+ int part=1;
+ char *ep;
+ block_dev_desc_t *dev_desc=NULL;
- ret = 0;
-
- printf ("FAT info: %d\n", file_fat_detectfs ());
-
- 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 ());
}
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"
+ "<interface> <dev[:part]>\n"
+ " - print information about filesystem from 'dev' on 'interface'\n"
);
#ifdef NOT_IMPLEMENTED_YET