]> git.ipfire.org Git - people/ms/u-boot.git/blame - common/cmd_yaffs2.c
board: ti: beagle_x15: added USB initializtion code
[people/ms/u-boot.git] / common / cmd_yaffs2.c
CommitLineData
753ac610
CM
1/* Yaffs commands.
2 * Modified by Charles Manning by adding ydevconfig command.
3 *
4 * Use ydevconfig to configure a mountpoint before use.
5 * For example:
6 * # Configure mountpt xxx using nand device 0 using blocks 100-500
7 * ydevconfig xxx 0 100 500
8 * # Mount it
9 * ymount xxx
10 * # yls, yrdm etc
11 * yls -l xxx
12 * yrdm xxx/boot-image 82000000
13 * ...
14 */
15
90ef117b
WJ
16#include <common.h>
17
18#include <config.h>
19#include <command.h>
20
753ac610
CM
21#ifdef YAFFS2_DEBUG
22#define PRINTF(fmt, args...) printf(fmt, ##args)
90ef117b 23#else
753ac610 24#define PRINTF(fmt, args...) do { } while (0)
90ef117b
WJ
25#endif
26
753ac610
CM
27extern void cmd_yaffs_dev_ls(void);
28extern void cmd_yaffs_tracemask(unsigned set, unsigned mask);
29extern void cmd_yaffs_devconfig(char *mp, int flash_dev,
30 int start_block, int end_block);
90ef117b
WJ
31extern void cmd_yaffs_mount(char *mp);
32extern void cmd_yaffs_umount(char *mp);
33extern void cmd_yaffs_read_file(char *fn);
753ac610 34extern void cmd_yaffs_write_file(char *fn, char bval, int sizeOfFile);
90ef117b
WJ
35extern void cmd_yaffs_ls(const char *mountpt, int longlist);
36extern void cmd_yaffs_mwrite_file(char *fn, char *addr, int size);
37extern void cmd_yaffs_mread_file(char *fn, char *addr);
38extern void cmd_yaffs_mkdir(const char *dir);
39extern void cmd_yaffs_rmdir(const char *dir);
40extern void cmd_yaffs_rm(const char *path);
41extern void cmd_yaffs_mv(const char *oldPath, const char *newPath);
42
753ac610
CM
43extern int yaffs_dump_dev(const char *path);
44
45/* ytrace - show/set yaffs trace mask */
46int do_ytrace(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
47{
48 if (argc > 1)
49 cmd_yaffs_tracemask(1, simple_strtol(argv[1], NULL, 16));
50 else
51 cmd_yaffs_tracemask(0, 0);
90ef117b 52
753ac610
CM
53 return 0;
54}
90ef117b 55
753ac610
CM
56/* ydevls - lists yaffs mount points. */
57int do_ydevls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
90ef117b 58{
753ac610 59 cmd_yaffs_dev_ls();
4b070809 60
753ac610 61 return 0;
90ef117b
WJ
62}
63
753ac610
CM
64/* ydevconfig mount_pt mtd_dev_num start_block end_block */
65int do_ydevconfig(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
90ef117b 66{
753ac610
CM
67 char *mtpoint;
68 int mtd_dev;
69 int start_block;
70 int end_block;
71
72 if (argc != 5) {
73 printf
74 ("Bad arguments: ydevconfig mount_pt mtd_dev start_block end_block\n");
75 return -1;
76 }
77
78 mtpoint = argv[1];
79 mtd_dev = simple_strtol(argv[2], NULL, 16);
80 start_block = simple_strtol(argv[3], NULL, 16);
81 end_block = simple_strtol(argv[4], NULL, 16);
4b070809 82
753ac610
CM
83 cmd_yaffs_devconfig(mtpoint, mtd_dev, start_block, end_block);
84
85 return 0;
90ef117b
WJ
86}
87
753ac610 88int do_ymount(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
90ef117b 89{
753ac610
CM
90 char *mtpoint;
91
92 if (argc != 2) {
93 printf("Bad arguments: ymount mount_pt\n");
94 return -1;
95 }
96
97 mtpoint = argv[1];
98 printf("Mounting yaffs2 mount point %s\n", mtpoint);
4b070809 99
753ac610 100 cmd_yaffs_mount(mtpoint);
90ef117b 101
753ac610 102 return 0;
90ef117b
WJ
103}
104
753ac610 105int do_yumount(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
90ef117b 106{
753ac610 107 char *mtpoint;
90ef117b 108
753ac610
CM
109 if (argc != 2) {
110 printf("Bad arguments: yumount mount_pt\n");
111 return -1;
112 }
90ef117b 113
753ac610
CM
114 mtpoint = argv[1];
115 printf("Unmounting yaffs2 mount point %s\n", mtpoint);
116 cmd_yaffs_umount(mtpoint);
117
118 return 0;
90ef117b
WJ
119}
120
753ac610 121int do_yls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
90ef117b 122{
753ac610
CM
123 char *dirname;
124
125 if (argc < 2 || argc > 3 || (argc == 3 && strcmp(argv[1], "-l"))) {
126 printf("Bad arguments: yls [-l] dir\n");
127 return -1;
128 }
90ef117b 129
753ac610 130 dirname = argv[argc - 1];
90ef117b 131
753ac610 132 cmd_yaffs_ls(dirname, (argc > 2) ? 1 : 0);
90ef117b 133
753ac610 134 return 0;
90ef117b
WJ
135}
136
753ac610 137int do_yrd(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
90ef117b 138{
753ac610
CM
139 char *filename;
140
141 if (argc != 2) {
142 printf("Bad arguments: yrd file_name\n");
143 return -1;
144 }
90ef117b 145
753ac610 146 filename = argv[1];
90ef117b 147
753ac610
CM
148 printf("Reading file %s ", filename);
149
150 cmd_yaffs_read_file(filename);
151
152 printf("done\n");
153 return 0;
90ef117b
WJ
154}
155
753ac610 156int do_ywr(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
90ef117b 157{
753ac610
CM
158 char *filename;
159 ulong value;
160 ulong numValues;
161
162 if (argc != 4) {
163 printf("Bad arguments: ywr file_name value n_values\n");
164 return -1;
165 }
90ef117b 166
753ac610
CM
167 filename = argv[1];
168 value = simple_strtoul(argv[2], NULL, 16);
169 numValues = simple_strtoul(argv[3], NULL, 16);
90ef117b 170
753ac610
CM
171 printf("Writing value (%lx) %lx times to %s... ", value, numValues,
172 filename);
173
174 cmd_yaffs_write_file(filename, value, numValues);
175
176 printf("done\n");
177 return 0;
90ef117b
WJ
178}
179
753ac610 180int do_yrdm(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
90ef117b 181{
753ac610
CM
182 char *filename;
183 ulong addr;
184
185 if (argc != 3) {
186 printf("Bad arguments: yrdm file_name addr\n");
187 return -1;
188 }
90ef117b 189
753ac610
CM
190 filename = argv[1];
191 addr = simple_strtoul(argv[2], NULL, 16);
90ef117b 192
753ac610
CM
193 cmd_yaffs_mread_file(filename, (char *)addr);
194
195 return 0;
90ef117b
WJ
196}
197
753ac610 198int do_ywrm(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
90ef117b 199{
753ac610
CM
200 char *filename;
201 ulong addr;
202 ulong size;
203
204 if (argc != 4) {
205 printf("Bad arguments: ywrm file_name addr size\n");
206 return -1;
207 }
208
209 filename = argv[1];
210 addr = simple_strtoul(argv[2], NULL, 16);
211 size = simple_strtoul(argv[3], NULL, 16);
90ef117b 212
753ac610 213 cmd_yaffs_mwrite_file(filename, (char *)addr, size);
90ef117b 214
753ac610 215 return 0;
90ef117b
WJ
216}
217
753ac610 218int do_ymkdir(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
90ef117b 219{
753ac610 220 char *dirname;
90ef117b 221
753ac610
CM
222 if (argc != 2) {
223 printf("Bad arguments: ymkdir dir_name\n");
224 return -1;
225 }
90ef117b 226
753ac610
CM
227 dirname = argv[1];
228 cmd_yaffs_mkdir(dirname);
229
230 return 0;
90ef117b
WJ
231}
232
753ac610 233int do_yrmdir(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
90ef117b 234{
753ac610
CM
235 char *dirname;
236
237 if (argc != 2) {
238 printf("Bad arguments: yrmdir dir_name\n");
239 return -1;
240 }
90ef117b 241
753ac610
CM
242 dirname = argv[1];
243 cmd_yaffs_rmdir(dirname);
90ef117b 244
753ac610 245 return 0;
90ef117b
WJ
246}
247
753ac610 248int do_yrm(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
90ef117b 249{
753ac610
CM
250 char *name;
251
252 if (argc != 2) {
253 printf("Bad arguments: yrm name\n");
254 return -1;
255 }
256
257 name = argv[1];
258
259 cmd_yaffs_rm(name);
260
261 return 0;
262}
263
264int do_ymv(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
265{
266 char *oldPath;
267 char *newPath;
268
269 if (argc != 3) {
270 printf("Bad arguments: ymv old_path new_path\n");
271 return -1;
272 }
273
274 oldPath = argv[1];
275 newPath = argv[2];
276
277 cmd_yaffs_mv(newPath, oldPath);
278
279 return 0;
90ef117b
WJ
280}
281
753ac610
CM
282U_BOOT_CMD(ytrace, 2, 0, do_ytrace,
283 "show/set yaffs trace mask",
5bd15b7a 284 "[new_mask] show/set yaffs trace mask");
753ac610
CM
285
286U_BOOT_CMD(ydevls, 1, 0, do_ydevls,
287 "list yaffs mount points", "list yaffs mount points");
288
289U_BOOT_CMD(ydevconfig, 5, 0, do_ydevconfig,
290 "configure yaffs mount point",
5bd15b7a 291 "mtpoint mtd_id start_block end_block configures a yaffs2 mount point");
753ac610
CM
292
293U_BOOT_CMD(ymount, 2, 0, do_ymount,
5bd15b7a 294 "mount yaffs", "mtpoint mounts a yaffs2 mount point");
753ac610
CM
295
296U_BOOT_CMD(yumount, 2, 0, do_yumount,
5bd15b7a 297 "unmount yaffs", "mtpoint unmounts a yaffs2 mount point");
753ac610 298
5bd15b7a 299U_BOOT_CMD(yls, 3, 0, do_yls, "yaffs ls", "[-l] dirname");
753ac610
CM
300
301U_BOOT_CMD(yrd, 2, 0, do_yrd,
5bd15b7a 302 "read file from yaffs", "path read file from yaffs");
753ac610
CM
303
304U_BOOT_CMD(ywr, 4, 0, do_ywr,
305 "write file to yaffs",
5bd15b7a 306 "filename value num_vlues write values to yaffs file");
753ac610
CM
307
308U_BOOT_CMD(yrdm, 3, 0, do_yrdm,
309 "read file to memory from yaffs",
5bd15b7a 310 "filename offset reads yaffs file into memory");
753ac610
CM
311
312U_BOOT_CMD(ywrm, 4, 0, do_ywrm,
313 "write file from memory to yaffs",
5bd15b7a 314 "filename offset size writes memory to yaffs file");
753ac610
CM
315
316U_BOOT_CMD(ymkdir, 2, 0, do_ymkdir,
5bd15b7a 317 "YAFFS mkdir", "dir create a yaffs directory");
753ac610
CM
318
319U_BOOT_CMD(yrmdir, 2, 0, do_yrmdir,
5bd15b7a 320 "YAFFS rmdir", "dirname removes a yaffs directory");
753ac610 321
5bd15b7a 322U_BOOT_CMD(yrm, 2, 0, do_yrm, "YAFFS rm", "path removes a yaffs file");
753ac610
CM
323
324U_BOOT_CMD(ymv, 4, 0, do_ymv,
325 "YAFFS mv",
5bd15b7a 326 "old_path new_path moves/rename files within a yaffs mount point");