]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - common/cmd_fat.c
driver/serial: delete at91rm9200_usart
[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         int dev=0;
44         int part=1;
45         char *ep;
46
47         if (argc < 5) {
48                 printf( "usage: fatload <interface> <dev[:part]> "
49                         "<addr> <filename> [bytes]\n");
50                 return 1;
51         }
52
53         dev = (int)simple_strtoul(argv[2], &ep, 16);
54         dev_desc = get_dev(argv[1],dev);
55         if (dev_desc == NULL) {
56                 puts("\n** Invalid boot device **\n");
57                 return 1;
58         }
59         if (*ep) {
60                 if (*ep != ':') {
61                         puts("\n** Invalid boot device, use `dev[:part]' **\n");
62                         return 1;
63                 }
64                 part = (int)simple_strtoul(++ep, NULL, 16);
65         }
66         if (fat_register_device(dev_desc,part)!=0) {
67                 printf("\n** Unable to use %s %d:%d for fatload **\n",
68                         argv[1], dev, part);
69                 return 1;
70         }
71         offset = simple_strtoul(argv[3], NULL, 16);
72         if (argc == 6)
73                 count = simple_strtoul(argv[5], NULL, 16);
74         else
75                 count = 0;
76         size = file_fat_read(argv[4], (unsigned char *)offset, count);
77
78         if(size==-1) {
79                 printf("\n** Unable to read \"%s\" from %s %d:%d **\n",
80                         argv[4], argv[1], dev, part);
81                 return 1;
82         }
83
84         printf("\n%ld bytes read\n", size);
85
86         sprintf(buf, "%lX", size);
87         setenv("filesize", buf);
88
89         return 0;
90 }
91
92
93 U_BOOT_CMD(
94         fatload,        6,      0,      do_fat_fsload,
95         "load binary file from a dos filesystem",
96         "<interface> <dev[:part]>  <addr> <filename> [bytes]\n"
97         "    - load binary file 'filename' from 'dev' on 'interface'\n"
98         "      to address 'addr' from dos filesystem"
99 );
100
101 int do_fat_ls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
102 {
103         char *filename = "/";
104         int ret;
105         int dev=0;
106         int part=1;
107         char *ep;
108         block_dev_desc_t *dev_desc=NULL;
109
110         if (argc < 3) {
111                 printf("usage: fatls <interface> <dev[:part]> [directory]\n");
112                 return 0;
113         }
114         dev = (int)simple_strtoul(argv[2], &ep, 16);
115         dev_desc = get_dev(argv[1],dev);
116         if (dev_desc == NULL) {
117                 puts("\n** Invalid boot device **\n");
118                 return 1;
119         }
120         if (*ep) {
121                 if (*ep != ':') {
122                         puts("\n** Invalid boot device, use `dev[:part]' **\n");
123                         return 1;
124                 }
125                 part = (int)simple_strtoul(++ep, NULL, 16);
126         }
127         if (fat_register_device(dev_desc,part)!=0) {
128                 printf("\n** Unable to use %s %d:%d for fatls **\n",
129                         argv[1], dev, part);
130                 return 1;
131         }
132         if (argc == 4)
133                 ret = file_fat_ls(argv[3]);
134         else
135                 ret = file_fat_ls(filename);
136
137         if(ret!=0)
138                 printf("No Fat FS detected\n");
139         return ret;
140 }
141
142 U_BOOT_CMD(
143         fatls,  4,      1,      do_fat_ls,
144         "list files in a directory (default /)",
145         "<interface> <dev[:part]> [directory]\n"
146         "    - list files from 'dev' on 'interface' in a 'directory'"
147 );
148
149 int do_fat_fsinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
150 {
151         int dev=0;
152         int part=1;
153         char *ep;
154         block_dev_desc_t *dev_desc=NULL;
155
156         if (argc < 2) {
157                 printf("usage: fatinfo <interface> <dev[:part]>\n");
158                 return 0;
159         }
160         dev = (int)simple_strtoul(argv[2], &ep, 16);
161         dev_desc = get_dev(argv[1],dev);
162         if (dev_desc == NULL) {
163                 puts("\n** Invalid boot device **\n");
164                 return 1;
165         }
166         if (*ep) {
167                 if (*ep != ':') {
168                         puts("\n** Invalid boot device, use `dev[:part]' **\n");
169                         return 1;
170                 }
171                 part = (int)simple_strtoul(++ep, NULL, 16);
172         }
173         if (fat_register_device(dev_desc,part)!=0) {
174                 printf("\n** Unable to use %s %d:%d for fatinfo **\n",
175                         argv[1], dev, part);
176                 return 1;
177         }
178         return file_fat_detectfs();
179 }
180
181 U_BOOT_CMD(
182         fatinfo,        3,      1,      do_fat_fsinfo,
183         "print information about filesystem",
184         "<interface> <dev[:part]>\n"
185         "    - print information about filesystem from 'dev' on 'interface'"
186 );