]>
Commit | Line | Data |
---|---|---|
71f95118 WD |
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> | |
71f95118 WD |
29 | #include <s_record.h> |
30 | #include <net.h> | |
31 | #include <ata.h> | |
735dd97b | 32 | #include <part.h> |
71f95118 WD |
33 | #include <fat.h> |
34 | ||
7205e407 | 35 | |
54841ab5 | 36 | int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
71f95118 WD |
37 | { |
38 | long size; | |
39 | unsigned long offset; | |
1170e634 BT |
40 | unsigned long count = 0; |
41 | unsigned long pos = 0; | |
fbe4b5cb | 42 | char buf [12]; |
7205e407 | 43 | block_dev_desc_t *dev_desc=NULL; |
cfda5aea RH |
44 | disk_partition_t info; |
45 | int part, dev; | |
71f95118 | 46 | |
7205e407 | 47 | if (argc < 5) { |
cfda5aea | 48 | printf("usage: fatload <interface> [<dev[:part]>] " |
1170e634 | 49 | "<addr> <filename> [bytes [pos]]\n"); |
31a64923 | 50 | return 1; |
71f95118 | 51 | } |
7385c28e | 52 | |
10a37fd7 | 53 | part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1); |
cfda5aea | 54 | if (part < 0) |
7205e407 | 55 | return 1; |
cfda5aea RH |
56 | |
57 | dev = dev_desc->dev; | |
7205e407 | 58 | if (fat_register_device(dev_desc,part)!=0) { |
7385c28e WD |
59 | printf("\n** Unable to use %s %d:%d for fatload **\n", |
60 | argv[1], dev, part); | |
7205e407 WD |
61 | return 1; |
62 | } | |
7385c28e | 63 | offset = simple_strtoul(argv[3], NULL, 16); |
1170e634 | 64 | if (argc >= 6) |
7385c28e | 65 | count = simple_strtoul(argv[5], NULL, 16); |
1170e634 BT |
66 | if (argc >= 7) |
67 | pos = simple_strtoul(argv[6], NULL, 16); | |
68 | size = file_fat_read_at(argv[4], pos, (unsigned char *)offset, count); | |
71f95118 | 69 | |
fbe4b5cb | 70 | if(size==-1) { |
7385c28e WD |
71 | printf("\n** Unable to read \"%s\" from %s %d:%d **\n", |
72 | argv[4], argv[1], dev, part); | |
31a64923 | 73 | return 1; |
fbe4b5cb WD |
74 | } |
75 | ||
7385c28e | 76 | printf("\n%ld bytes read\n", size); |
31a64923 WD |
77 | |
78 | sprintf(buf, "%lX", size); | |
79 | setenv("filesize", buf); | |
80 | ||
81 | return 0; | |
71f95118 WD |
82 | } |
83 | ||
7205e407 | 84 | |
0d498393 | 85 | U_BOOT_CMD( |
1170e634 | 86 | fatload, 7, 0, do_fat_fsload, |
2fb2604d | 87 | "load binary file from a dos filesystem", |
1170e634 BT |
88 | "<interface> [<dev[:part]>] <addr> <filename> [bytes [pos]]\n" |
89 | " - Load binary file 'filename' from 'dev' on 'interface'\n" | |
90 | " to address 'addr' from dos filesystem.\n" | |
91 | " 'pos' gives the file position to start loading from.\n" | |
92 | " If 'pos' is omitted, 0 is used. 'pos' requires 'bytes'.\n" | |
93 | " 'bytes' gives the size to load. If 'bytes' is 0 or omitted,\n" | |
94 | " the load stops on end of file." | |
b0fce99b WD |
95 | ); |
96 | ||
54841ab5 | 97 | int do_fat_ls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
71f95118 WD |
98 | { |
99 | char *filename = "/"; | |
cfda5aea | 100 | int ret, dev, part; |
7205e407 | 101 | block_dev_desc_t *dev_desc=NULL; |
cfda5aea | 102 | disk_partition_t info; |
71f95118 | 103 | |
cfda5aea RH |
104 | if (argc < 2) { |
105 | printf("usage: fatls <interface> [<dev[:part]>] [directory]\n"); | |
7385c28e | 106 | return 0; |
7205e407 | 107 | } |
cfda5aea | 108 | |
10a37fd7 | 109 | part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1); |
cfda5aea | 110 | if (part < 0) |
7205e407 | 111 | return 1; |
cfda5aea RH |
112 | |
113 | dev = dev_desc->dev; | |
7205e407 | 114 | if (fat_register_device(dev_desc,part)!=0) { |
7385c28e WD |
115 | printf("\n** Unable to use %s %d:%d for fatls **\n", |
116 | argv[1], dev, part); | |
7205e407 WD |
117 | return 1; |
118 | } | |
119 | if (argc == 4) | |
7385c28e | 120 | ret = file_fat_ls(argv[3]); |
71f95118 | 121 | else |
7385c28e | 122 | ret = file_fat_ls(filename); |
71f95118 | 123 | |
7205e407 WD |
124 | if(ret!=0) |
125 | printf("No Fat FS detected\n"); | |
7385c28e | 126 | return ret; |
71f95118 WD |
127 | } |
128 | ||
0d498393 | 129 | U_BOOT_CMD( |
7205e407 | 130 | fatls, 4, 1, do_fat_ls, |
2fb2604d | 131 | "list files in a directory (default /)", |
cfda5aea | 132 | "<interface> [<dev[:part]>] [directory]\n" |
a89c33db | 133 | " - list files from 'dev' on 'interface' in a 'directory'" |
b0fce99b WD |
134 | ); |
135 | ||
54841ab5 | 136 | int do_fat_fsinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
71f95118 | 137 | { |
cfda5aea RH |
138 | int dev, part; |
139 | block_dev_desc_t *dev_desc; | |
140 | disk_partition_t info; | |
71f95118 | 141 | |
7205e407 | 142 | if (argc < 2) { |
cfda5aea | 143 | printf("usage: fatinfo <interface> [<dev[:part]>]\n"); |
7385c28e | 144 | return 0; |
7205e407 | 145 | } |
cfda5aea | 146 | |
10a37fd7 | 147 | part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1); |
cfda5aea | 148 | if (part < 0) |
7205e407 | 149 | return 1; |
cfda5aea RH |
150 | |
151 | dev = dev_desc->dev; | |
7205e407 | 152 | if (fat_register_device(dev_desc,part)!=0) { |
7385c28e WD |
153 | printf("\n** Unable to use %s %d:%d for fatinfo **\n", |
154 | argv[1], dev, part); | |
7205e407 WD |
155 | return 1; |
156 | } | |
7385c28e | 157 | return file_fat_detectfs(); |
71f95118 WD |
158 | } |
159 | ||
0d498393 | 160 | U_BOOT_CMD( |
7205e407 | 161 | fatinfo, 3, 1, do_fat_fsinfo, |
2fb2604d | 162 | "print information about filesystem", |
cfda5aea | 163 | "<interface> [<dev[:part]>]\n" |
a89c33db | 164 | " - print information about filesystem from 'dev' on 'interface'" |
b0fce99b | 165 | ); |
656f4c65 DK |
166 | |
167 | #ifdef CONFIG_FAT_WRITE | |
168 | static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag, | |
169 | int argc, char * const argv[]) | |
170 | { | |
171 | long size; | |
172 | unsigned long addr; | |
173 | unsigned long count; | |
174 | block_dev_desc_t *dev_desc = NULL; | |
cfda5aea | 175 | disk_partition_t info; |
656f4c65 DK |
176 | int dev = 0; |
177 | int part = 1; | |
656f4c65 DK |
178 | |
179 | if (argc < 5) | |
180 | return cmd_usage(cmdtp); | |
181 | ||
10a37fd7 | 182 | part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1); |
cfda5aea | 183 | if (part < 0) |
656f4c65 | 184 | return 1; |
cfda5aea RH |
185 | |
186 | dev = dev_desc->dev; | |
187 | ||
656f4c65 DK |
188 | if (fat_register_device(dev_desc, part) != 0) { |
189 | printf("\n** Unable to use %s %d:%d for fatwrite **\n", | |
190 | argv[1], dev, part); | |
191 | return 1; | |
192 | } | |
193 | addr = simple_strtoul(argv[3], NULL, 16); | |
194 | count = simple_strtoul(argv[5], NULL, 16); | |
195 | ||
196 | size = file_fat_write(argv[4], (void *)addr, count); | |
197 | if (size == -1) { | |
198 | printf("\n** Unable to write \"%s\" from %s %d:%d **\n", | |
199 | argv[4], argv[1], dev, part); | |
200 | return 1; | |
201 | } | |
202 | ||
203 | printf("%ld bytes written\n", size); | |
204 | ||
205 | return 0; | |
206 | } | |
207 | ||
208 | U_BOOT_CMD( | |
209 | fatwrite, 6, 0, do_fat_fswrite, | |
210 | "write file into a dos filesystem", | |
211 | "<interface> <dev[:part]> <addr> <filename> <bytes>\n" | |
212 | " - write file 'filename' from the address 'addr' in RAM\n" | |
213 | " to 'dev' on 'interface'" | |
214 | ); | |
215 | #endif |