]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - common/cmd_fat.c
Merge branch 'master' of git://git.denx.de/u-boot-video
[karo-tx-uboot.git] / common / cmd_fat.c
1 /*
2  * (C) Copyright 2002
3  * Richard Jones, rjones@nexus-tech.net
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
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.
12  *
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.
17  *
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,
21  * MA 02111-1307 USA
22  */
23
24 /*
25  * Boot support
26  */
27 #include <common.h>
28 #include <command.h>
29 #include <s_record.h>
30 #include <net.h>
31 #include <ata.h>
32 #include <part.h>
33 #include <fat.h>
34
35
36 int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
37 {
38         long size;
39         unsigned long offset;
40         unsigned long count;
41         char buf [12];
42         block_dev_desc_t *dev_desc=NULL;
43         disk_partition_t info;
44         int part, dev;
45
46         if (argc < 5) {
47                 printf("usage: fatload <interface> [<dev[:part]>] "
48                         "<addr> <filename> [bytes]\n");
49                 return 1;
50         }
51
52         part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
53         if (part < 0)
54                 return 1;
55
56         dev = dev_desc->dev;
57         if (fat_register_device(dev_desc,part)!=0) {
58                 printf("\n** Unable to use %s %d:%d for fatload **\n",
59                         argv[1], dev, part);
60                 return 1;
61         }
62         offset = simple_strtoul(argv[3], NULL, 16);
63         if (argc == 6)
64                 count = simple_strtoul(argv[5], NULL, 16);
65         else
66                 count = 0;
67         size = file_fat_read(argv[4], (unsigned char *)offset, count);
68
69         if(size==-1) {
70                 printf("\n** Unable to read \"%s\" from %s %d:%d **\n",
71                         argv[4], argv[1], dev, part);
72                 return 1;
73         }
74
75         printf("\n%ld bytes read\n", size);
76
77         sprintf(buf, "%lX", size);
78         setenv("filesize", buf);
79
80         return 0;
81 }
82
83
84 U_BOOT_CMD(
85         fatload,        6,      0,      do_fat_fsload,
86         "load binary file from a dos filesystem",
87         "<interface> [<dev[:part]>]  <addr> <filename> [bytes]\n"
88         "    - load binary file 'filename' from 'dev' on 'interface'\n"
89         "      to address 'addr' from dos filesystem"
90 );
91
92 int do_fat_ls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
93 {
94         char *filename = "/";
95         int ret, dev, part;
96         block_dev_desc_t *dev_desc=NULL;
97         disk_partition_t info;
98
99         if (argc < 2) {
100                 printf("usage: fatls <interface> [<dev[:part]>] [directory]\n");
101                 return 0;
102         }
103
104         part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
105         if (part < 0)
106                 return 1;
107
108         dev = dev_desc->dev;
109         if (fat_register_device(dev_desc,part)!=0) {
110                 printf("\n** Unable to use %s %d:%d for fatls **\n",
111                         argv[1], dev, part);
112                 return 1;
113         }
114         if (argc == 4)
115                 ret = file_fat_ls(argv[3]);
116         else
117                 ret = file_fat_ls(filename);
118
119         if(ret!=0)
120                 printf("No Fat FS detected\n");
121         return ret;
122 }
123
124 U_BOOT_CMD(
125         fatls,  4,      1,      do_fat_ls,
126         "list files in a directory (default /)",
127         "<interface> [<dev[:part]>] [directory]\n"
128         "    - list files from 'dev' on 'interface' in a 'directory'"
129 );
130
131 int do_fat_fsinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
132 {
133         int dev, part;
134         block_dev_desc_t *dev_desc;
135         disk_partition_t info;
136
137         if (argc < 2) {
138                 printf("usage: fatinfo <interface> [<dev[:part]>]\n");
139                 return 0;
140         }
141
142         part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
143         if (part < 0)
144                 return 1;
145
146         dev = dev_desc->dev;
147         if (fat_register_device(dev_desc,part)!=0) {
148                 printf("\n** Unable to use %s %d:%d for fatinfo **\n",
149                         argv[1], dev, part);
150                 return 1;
151         }
152         return file_fat_detectfs();
153 }
154
155 U_BOOT_CMD(
156         fatinfo,        3,      1,      do_fat_fsinfo,
157         "print information about filesystem",
158         "<interface> [<dev[:part]>]\n"
159         "    - print information about filesystem from 'dev' on 'interface'"
160 );
161
162 #ifdef CONFIG_FAT_WRITE
163 static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
164                 int argc, char * const argv[])
165 {
166         long size;
167         unsigned long addr;
168         unsigned long count;
169         block_dev_desc_t *dev_desc = NULL;
170         disk_partition_t info;
171         int dev = 0;
172         int part = 1;
173         char *ep;
174
175         if (argc < 5)
176                 return cmd_usage(cmdtp);
177
178         part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
179         if (part < 0)
180                 return 1;
181
182         dev = dev_desc->dev;
183
184         if (fat_register_device(dev_desc, part) != 0) {
185                 printf("\n** Unable to use %s %d:%d for fatwrite **\n",
186                         argv[1], dev, part);
187                 return 1;
188         }
189         addr = simple_strtoul(argv[3], NULL, 16);
190         count = simple_strtoul(argv[5], NULL, 16);
191
192         size = file_fat_write(argv[4], (void *)addr, count);
193         if (size == -1) {
194                 printf("\n** Unable to write \"%s\" from %s %d:%d **\n",
195                         argv[4], argv[1], dev, part);
196                 return 1;
197         }
198
199         printf("%ld bytes written\n", size);
200
201         return 0;
202 }
203
204 U_BOOT_CMD(
205         fatwrite,       6,      0,      do_fat_fswrite,
206         "write file into a dos filesystem",
207         "<interface> <dev[:part]> <addr> <filename> <bytes>\n"
208         "    - write file 'filename' from the address 'addr' in RAM\n"
209         "      to 'dev' on 'interface'"
210 );
211 #endif