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