blob: d43a9d444c8f7077e8eb7652ca89e72d92a0c173 [file] [log] [blame]
Charles Manning753ac612012-05-09 16:55:17 +00001/* 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
William Juul90ef1172007-11-15 12:23:57 +010016#include <common.h>
17
18#include <config.h>
19#include <command.h>
20
Charles Manning753ac612012-05-09 16:55:17 +000021#ifdef YAFFS2_DEBUG
22#define PRINTF(fmt, args...) printf(fmt, ##args)
William Juul90ef1172007-11-15 12:23:57 +010023#else
Charles Manning753ac612012-05-09 16:55:17 +000024#define PRINTF(fmt, args...) do { } while (0)
William Juul90ef1172007-11-15 12:23:57 +010025#endif
26
Charles Manning753ac612012-05-09 16:55:17 +000027extern 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);
William Juul90ef1172007-11-15 12:23:57 +010031extern void cmd_yaffs_mount(char *mp);
32extern void cmd_yaffs_umount(char *mp);
33extern void cmd_yaffs_read_file(char *fn);
Charles Manning753ac612012-05-09 16:55:17 +000034extern void cmd_yaffs_write_file(char *fn, char bval, int sizeOfFile);
William Juul90ef1172007-11-15 12:23:57 +010035extern 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
Charles Manning753ac612012-05-09 16:55:17 +000043extern int yaffs_dump_dev(const char *path);
William Juul90ef1172007-11-15 12:23:57 +010044
Charles Manning753ac612012-05-09 16:55:17 +000045/* ytrace - show/set yaffs trace mask */
46int do_ytrace(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +010047{
Charles Manning753ac612012-05-09 16:55:17 +000048 if (argc > 1)
49 cmd_yaffs_tracemask(1, simple_strtol(argv[1], NULL, 16));
50 else
51 cmd_yaffs_tracemask(0, 0);
Wolfgang Denk4b070802008-08-14 14:41:06 +020052
Charles Manning753ac612012-05-09 16:55:17 +000053 return 0;
William Juul90ef1172007-11-15 12:23:57 +010054}
55
Charles Manning753ac612012-05-09 16:55:17 +000056/* ydevls - lists yaffs mount points. */
57int do_ydevls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +010058{
Charles Manning753ac612012-05-09 16:55:17 +000059 cmd_yaffs_dev_ls();
Wolfgang Denk4b070802008-08-14 14:41:06 +020060
Charles Manning753ac612012-05-09 16:55:17 +000061 return 0;
William Juul90ef1172007-11-15 12:23:57 +010062}
63
Charles Manning753ac612012-05-09 16:55:17 +000064/* ydevconfig mount_pt mtd_dev_num start_block end_block */
65int do_ydevconfig(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +010066{
Charles Manning753ac612012-05-09 16:55:17 +000067 char *mtpoint;
68 int mtd_dev;
69 int start_block;
70 int end_block;
Wolfgang Denk4b070802008-08-14 14:41:06 +020071
Charles Manning753ac612012-05-09 16:55:17 +000072 if (argc != 5) {
73 printf
74 ("Bad arguments: ydevconfig mount_pt mtd_dev start_block end_block\n");
75 return -1;
76 }
William Juul90ef1172007-11-15 12:23:57 +010077
Charles Manning753ac612012-05-09 16:55:17 +000078 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);
82
83 cmd_yaffs_devconfig(mtpoint, mtd_dev, start_block, end_block);
84
85 return 0;
William Juul90ef1172007-11-15 12:23:57 +010086}
87
Charles Manning753ac612012-05-09 16:55:17 +000088int do_ymount(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +010089{
Charles Manning753ac612012-05-09 16:55:17 +000090 char *mtpoint;
William Juul90ef1172007-11-15 12:23:57 +010091
Charles Manning753ac612012-05-09 16:55:17 +000092 if (argc != 2) {
93 printf("Bad arguments: ymount mount_pt\n");
94 return -1;
95 }
William Juul90ef1172007-11-15 12:23:57 +010096
Charles Manning753ac612012-05-09 16:55:17 +000097 mtpoint = argv[1];
98 printf("Mounting yaffs2 mount point %s\n", mtpoint);
99
100 cmd_yaffs_mount(mtpoint);
101
102 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100103}
104
Charles Manning753ac612012-05-09 16:55:17 +0000105int do_yumount(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100106{
Charles Manning753ac612012-05-09 16:55:17 +0000107 char *mtpoint;
William Juul90ef1172007-11-15 12:23:57 +0100108
Charles Manning753ac612012-05-09 16:55:17 +0000109 if (argc != 2) {
110 printf("Bad arguments: yumount mount_pt\n");
111 return -1;
112 }
William Juul90ef1172007-11-15 12:23:57 +0100113
Charles Manning753ac612012-05-09 16:55:17 +0000114 mtpoint = argv[1];
115 printf("Unmounting yaffs2 mount point %s\n", mtpoint);
116 cmd_yaffs_umount(mtpoint);
William Juul90ef1172007-11-15 12:23:57 +0100117
Charles Manning753ac612012-05-09 16:55:17 +0000118 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100119}
120
Charles Manning753ac612012-05-09 16:55:17 +0000121int do_yls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100122{
Charles Manning753ac612012-05-09 16:55:17 +0000123 char *dirname;
William Juul90ef1172007-11-15 12:23:57 +0100124
Charles Manning753ac612012-05-09 16:55:17 +0000125 if (argc < 2 || argc > 3 || (argc == 3 && strcmp(argv[1], "-l"))) {
126 printf("Bad arguments: yls [-l] dir\n");
127 return -1;
128 }
William Juul90ef1172007-11-15 12:23:57 +0100129
Charles Manning753ac612012-05-09 16:55:17 +0000130 dirname = argv[argc - 1];
131
132 cmd_yaffs_ls(dirname, (argc > 2) ? 1 : 0);
133
134 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100135}
136
Charles Manning753ac612012-05-09 16:55:17 +0000137int do_yrd(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100138{
Charles Manning753ac612012-05-09 16:55:17 +0000139 char *filename;
William Juul90ef1172007-11-15 12:23:57 +0100140
Charles Manning753ac612012-05-09 16:55:17 +0000141 if (argc != 2) {
142 printf("Bad arguments: yrd file_name\n");
143 return -1;
144 }
William Juul90ef1172007-11-15 12:23:57 +0100145
Charles Manning753ac612012-05-09 16:55:17 +0000146 filename = argv[1];
147
148 printf("Reading file %s ", filename);
149
150 cmd_yaffs_read_file(filename);
151
152 printf("done\n");
153 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100154}
155
Charles Manning753ac612012-05-09 16:55:17 +0000156int do_ywr(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100157{
Charles Manning753ac612012-05-09 16:55:17 +0000158 char *filename;
159 ulong value;
160 ulong numValues;
William Juul90ef1172007-11-15 12:23:57 +0100161
Charles Manning753ac612012-05-09 16:55:17 +0000162 if (argc != 4) {
163 printf("Bad arguments: ywr file_name value n_values\n");
164 return -1;
165 }
William Juul90ef1172007-11-15 12:23:57 +0100166
Charles Manning753ac612012-05-09 16:55:17 +0000167 filename = argv[1];
168 value = simple_strtoul(argv[2], NULL, 16);
169 numValues = simple_strtoul(argv[3], NULL, 16);
170
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;
William Juul90ef1172007-11-15 12:23:57 +0100178}
179
Charles Manning753ac612012-05-09 16:55:17 +0000180int do_yrdm(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100181{
Charles Manning753ac612012-05-09 16:55:17 +0000182 char *filename;
183 ulong addr;
William Juul90ef1172007-11-15 12:23:57 +0100184
Charles Manning753ac612012-05-09 16:55:17 +0000185 if (argc != 3) {
186 printf("Bad arguments: yrdm file_name addr\n");
187 return -1;
188 }
William Juul90ef1172007-11-15 12:23:57 +0100189
Charles Manning753ac612012-05-09 16:55:17 +0000190 filename = argv[1];
191 addr = simple_strtoul(argv[2], NULL, 16);
192
193 cmd_yaffs_mread_file(filename, (char *)addr);
194
195 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100196}
197
Charles Manning753ac612012-05-09 16:55:17 +0000198int do_ywrm(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100199{
Charles Manning753ac612012-05-09 16:55:17 +0000200 char *filename;
201 ulong addr;
202 ulong size;
William Juul90ef1172007-11-15 12:23:57 +0100203
Charles Manning753ac612012-05-09 16:55:17 +0000204 if (argc != 4) {
205 printf("Bad arguments: ywrm file_name addr size\n");
206 return -1;
207 }
William Juul90ef1172007-11-15 12:23:57 +0100208
Charles Manning753ac612012-05-09 16:55:17 +0000209 filename = argv[1];
210 addr = simple_strtoul(argv[2], NULL, 16);
211 size = simple_strtoul(argv[3], NULL, 16);
212
213 cmd_yaffs_mwrite_file(filename, (char *)addr, size);
214
215 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100216}
217
Charles Manning753ac612012-05-09 16:55:17 +0000218int do_ymkdir(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100219{
Charles Manning753ac612012-05-09 16:55:17 +0000220 char *dirname;
William Juul90ef1172007-11-15 12:23:57 +0100221
Charles Manning753ac612012-05-09 16:55:17 +0000222 if (argc != 2) {
223 printf("Bad arguments: ymkdir dir_name\n");
224 return -1;
225 }
William Juul90ef1172007-11-15 12:23:57 +0100226
Charles Manning753ac612012-05-09 16:55:17 +0000227 dirname = argv[1];
228 cmd_yaffs_mkdir(dirname);
229
230 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100231}
232
Charles Manning753ac612012-05-09 16:55:17 +0000233int do_yrmdir(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100234{
Charles Manning753ac612012-05-09 16:55:17 +0000235 char *dirname;
236
237 if (argc != 2) {
238 printf("Bad arguments: yrmdir dir_name\n");
239 return -1;
240 }
241
242 dirname = argv[1];
243 cmd_yaffs_rmdir(dirname);
244
245 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100246}
247
Charles Manning753ac612012-05-09 16:55:17 +0000248int do_yrm(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
249{
250 char *name;
William Juul90ef1172007-11-15 12:23:57 +0100251
Charles Manning753ac612012-05-09 16:55:17 +0000252 if (argc != 2) {
253 printf("Bad arguments: yrm name\n");
254 return -1;
255 }
William Juul90ef1172007-11-15 12:23:57 +0100256
Charles Manning753ac612012-05-09 16:55:17 +0000257 name = argv[1];
William Juul90ef1172007-11-15 12:23:57 +0100258
Charles Manning753ac612012-05-09 16:55:17 +0000259 cmd_yaffs_rm(name);
William Juul90ef1172007-11-15 12:23:57 +0100260
Charles Manning753ac612012-05-09 16:55:17 +0000261 return 0;
262}
William Juul90ef1172007-11-15 12:23:57 +0100263
Charles Manning753ac612012-05-09 16:55:17 +0000264int do_ymv(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
265{
266 char *oldPath;
267 char *newPath;
William Juul90ef1172007-11-15 12:23:57 +0100268
Charles Manning753ac612012-05-09 16:55:17 +0000269 if (argc != 3) {
270 printf("Bad arguments: ymv old_path new_path\n");
271 return -1;
272 }
William Juul90ef1172007-11-15 12:23:57 +0100273
Charles Manning753ac612012-05-09 16:55:17 +0000274 oldPath = argv[1];
275 newPath = argv[2];
William Juul90ef1172007-11-15 12:23:57 +0100276
Charles Manning753ac612012-05-09 16:55:17 +0000277 cmd_yaffs_mv(newPath, oldPath);
William Juul90ef1172007-11-15 12:23:57 +0100278
Charles Manning753ac612012-05-09 16:55:17 +0000279 return 0;
280}
William Juul90ef1172007-11-15 12:23:57 +0100281
Charles Manning753ac612012-05-09 16:55:17 +0000282U_BOOT_CMD(ytrace, 2, 0, do_ytrace,
283 "show/set yaffs trace mask",
284 "ytrace [new_mask] show/set yaffs trace mask");
William Juul90ef1172007-11-15 12:23:57 +0100285
Charles Manning753ac612012-05-09 16:55:17 +0000286U_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",
291 "ydevconfig mtpoint mtd_id start_block end_block configures a yaffs2 mount point");
292
293U_BOOT_CMD(ymount, 2, 0, do_ymount,
294 "mount yaffs", "ymount mtpoint mounts a yaffs2 mount point");
295
296U_BOOT_CMD(yumount, 2, 0, do_yumount,
297 "unmount yaffs", "yunmount mtpoint unmounts a yaffs2 mount point");
298
299U_BOOT_CMD(yls, 3, 0, do_yls, "yaffs ls", "yls [-l] dirname");
300
301U_BOOT_CMD(yrd, 2, 0, do_yrd,
302 "read file from yaffs", "yrd path read file from yaffs");
303
304U_BOOT_CMD(ywr, 4, 0, do_ywr,
305 "write file to yaffs",
306 "ywr filename value num_vlues write values to yaffs file");
307
308U_BOOT_CMD(yrdm, 3, 0, do_yrdm,
309 "read file to memory from yaffs",
310 "yrdm filename offset reads yaffs file into memory");
311
312U_BOOT_CMD(ywrm, 4, 0, do_ywrm,
313 "write file from memory to yaffs",
314 "ywrm filename offset size writes memory to yaffs file");
315
316U_BOOT_CMD(ymkdir, 2, 0, do_ymkdir,
317 "YAFFS mkdir", "ymkdir dir create a yaffs directory");
318
319U_BOOT_CMD(yrmdir, 2, 0, do_yrmdir,
320 "YAFFS rmdir", "yrmdir dirname removes a yaffs directory");
321
322U_BOOT_CMD(yrm, 2, 0, do_yrm, "YAFFS rm", "yrm path removes a yaffs file");
323
324U_BOOT_CMD(ymv, 4, 0, do_ymv,
325 "YAFFS mv",
326 "ymv old_path new_path moves/rename files within a yaffs mount point");