3 * Richard Jones, rjones@nexus-tech.net
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
36 int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
42 block_dev_desc_t *dev_desc=NULL;
48 printf ("usage: fatload <interface> <dev[:part]> <addr> <filename> [bytes]\n");
51 dev = (int)simple_strtoul (argv[2], &ep, 16);
52 dev_desc=get_dev(argv[1],dev);
54 puts ("\n** Invalid boot device **\n");
59 puts ("\n** Invalid boot device, use `dev[:part]' **\n");
62 part = (int)simple_strtoul(++ep, NULL, 16);
64 if (fat_register_device(dev_desc,part)!=0) {
65 printf ("\n** Unable to use %s %d:%d for fatload **\n",argv[1],dev,part);
68 offset = simple_strtoul (argv[3], NULL, 16);
70 count = simple_strtoul (argv[5], NULL, 16);
73 size = file_fat_read (argv[4], (unsigned char *) offset, count);
76 printf("\n** Unable to read \"%s\" from %s %d:%d **\n",argv[4],argv[1],dev,part);
80 printf ("\n%ld bytes read\n", size);
82 sprintf(buf, "%lX", size);
83 setenv("filesize", buf);
90 fatload, 6, 0, do_fat_fsload,
91 "fatload - load binary file from a dos filesystem\n",
92 "<interface> <dev[:part]> <addr> <filename> [bytes]\n"
93 " - load binary file 'filename' from 'dev' on 'interface'\n"
94 " to address 'addr' from dos filesystem\n"
97 int do_fat_ls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
104 block_dev_desc_t *dev_desc=NULL;
107 printf ("usage: fatls <interface> <dev[:part]> [directory]\n");
110 dev = (int)simple_strtoul (argv[2], &ep, 16);
111 dev_desc=get_dev(argv[1],dev);
112 if (dev_desc==NULL) {
113 puts ("\n** Invalid boot device **\n");
118 puts ("\n** Invalid boot device, use `dev[:part]' **\n");
121 part = (int)simple_strtoul(++ep, NULL, 16);
123 if (fat_register_device(dev_desc,part)!=0) {
124 printf ("\n** Unable to use %s %d:%d for fatls **\n",argv[1],dev,part);
128 ret = file_fat_ls (argv[3]);
130 ret = file_fat_ls (filename);
133 printf("No Fat FS detected\n");
138 fatls, 4, 1, do_fat_ls,
139 "fatls - list files in a directory (default /)\n",
140 "<interface> <dev[:part]> [directory]\n"
141 " - list files from 'dev' on 'interface' in a 'directory'\n"
144 int do_fat_fsinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
149 block_dev_desc_t *dev_desc=NULL;
152 printf ("usage: fatinfo <interface> <dev[:part]>\n");
155 dev = (int)simple_strtoul (argv[2], &ep, 16);
156 dev_desc=get_dev(argv[1],dev);
157 if (dev_desc==NULL) {
158 puts ("\n** Invalid boot device **\n");
163 puts ("\n** Invalid boot device, use `dev[:part]' **\n");
166 part = (int)simple_strtoul(++ep, NULL, 16);
168 if (fat_register_device(dev_desc,part)!=0) {
169 printf ("\n** Unable to use %s %d:%d for fatinfo **\n",argv[1],dev,part);
172 return (file_fat_detectfs ());
176 fatinfo, 3, 1, do_fat_fsinfo,
177 "fatinfo - print information about filesystem\n",
178 "<interface> <dev[:part]>\n"
179 " - print information about filesystem from 'dev' on 'interface'\n"
182 #ifdef NOT_IMPLEMENTED_YET
183 /* find first device whose first partition is a DOS filesystem */
184 int find_fat_partition (void)
187 block_dev_desc_t *dev_desc;
188 unsigned char *part_table;
189 unsigned char buffer[ATA_BLOCKSIZE];
191 for (i = 0; i < CFG_IDE_MAXDEVICE; i++) {
192 dev_desc = ide_get_dev (i);
194 debug ("couldn't get ide device!\n");
197 if (dev_desc->part_type == PART_TYPE_DOS) {
199 block_read (dev_desc->dev, 0, 1, (ulong *) buffer) != 1) {
200 debug ("can't perform block_read!\n");
203 part_table = &buffer[0x1be]; /* start with partition #4 */
204 for (j = 0; j < 4; j++) {
205 if ((part_table[4] == 1 || /* 12-bit FAT */
206 part_table[4] == 4 || /* 16-bit FAT */
207 part_table[4] == 6) && /* > 32Meg part */
208 part_table[0] == 0x80) { /* bootable? */
210 part_offset = part_table[11];
212 part_offset |= part_table[10];
214 part_offset |= part_table[9];
216 part_offset |= part_table[8];
217 debug ("found partition start at %ld\n", part_offset);
225 debug ("no valid devices found!\n");
230 do_fat_dump (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
239 printf ("needs an argument!\n");
243 bknum = simple_strtoul (argv[1], NULL, 10);
245 if (disk_read (0, bknum, block) != 0) {
246 printf ("Error: reading block\n");
249 printf ("FAT dump: %d\n", bknum);
250 hexdump (512, block);
255 int disk_read (__u32 startblock, __u32 getsize, __u8 *bufptr)
258 block_dev_desc_t *dev_desc;
261 if (find_fat_partition () != 0)
265 dev_desc = ide_get_dev (curr_dev);
267 debug ("couldn't get ide device\n");
271 tot = dev_desc->block_read (0, startblock + part_offset,
272 getsize, (ulong *) bufptr);
274 /* should we do this here?
275 flush_cache ((ulong)buf, cnt*ide_dev_desc[device].blksz);
281 debug ("unable to read from device!\n");
287 static int isprint (unsigned char ch)
289 if (ch >= 32 && ch < 127)
296 void hexdump (int cnt, unsigned char *data)
304 printf ("%04X : ", offset);
310 for (i = 0; i < run; i++)
311 printf ("%02X ", (unsigned int) data[i]);
313 for (i = 0; i < run; i++)
314 printf ("%c", isprint (data[i]) ? data[i] : '.');
320 #endif /* NOT_IMPLEMENTED_YET */