blob: f29ebcc026e5a46dcacf079dc39deb5c5fa10f06 [file] [log] [blame]
Charles Manning3796e1f2012-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 Juule24ebad2007-11-15 12:23:57 +010016#include <common.h>
17
18#include <config.h>
19#include <command.h>
20
Charles Manning3796e1f2012-05-09 16:55:17 +000021#ifdef YAFFS2_DEBUG
22#define PRINTF(fmt, args...) printf(fmt, ##args)
William Juule24ebad2007-11-15 12:23:57 +010023#else
Charles Manning3796e1f2012-05-09 16:55:17 +000024#define PRINTF(fmt, args...) do { } while (0)
William Juule24ebad2007-11-15 12:23:57 +010025#endif
26
Charles Manning3796e1f2012-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 Juule24ebad2007-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 Manning3796e1f2012-05-09 16:55:17 +000034extern void cmd_yaffs_write_file(char *fn, char bval, int sizeOfFile);
William Juule24ebad2007-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 Manning3796e1f2012-05-09 16:55:17 +000043extern int yaffs_dump_dev(const char *path);
William Juule24ebad2007-11-15 12:23:57 +010044
Charles Manning3796e1f2012-05-09 16:55:17 +000045/* ytrace - show/set yaffs trace mask */
Simon Glassed38aef2020-05-10 11:40:03 -060046int do_ytrace(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Charles Manning3796e1f2012-05-09 16:55:17 +000047{
48 if (argc > 1)
49 cmd_yaffs_tracemask(1, simple_strtol(argv[1], NULL, 16));
50 else
51 cmd_yaffs_tracemask(0, 0);
William Juule24ebad2007-11-15 12:23:57 +010052
Charles Manning3796e1f2012-05-09 16:55:17 +000053 return 0;
54}
55
56/* ydevls - lists yaffs mount points. */
Simon Glassed38aef2020-05-10 11:40:03 -060057int do_ydevls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +010058{
Charles Manning3796e1f2012-05-09 16:55:17 +000059 cmd_yaffs_dev_ls();
60
61 return 0;
62}
63
64/* ydevconfig mount_pt mtd_dev_num start_block end_block */
Simon Glassed38aef2020-05-10 11:40:03 -060065int do_ydevconfig(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Charles Manning3796e1f2012-05-09 16:55:17 +000066{
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 }
Wolfgang Denk74e0dde2008-08-14 14:41:06 +020077
Charles Manning3796e1f2012-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 Juule24ebad2007-11-15 12:23:57 +010086}
87
Simon Glassed38aef2020-05-10 11:40:03 -060088int do_ymount(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +010089{
Charles Manning3796e1f2012-05-09 16:55:17 +000090 char *mtpoint;
91
92 if (argc != 2) {
93 printf("Bad arguments: ymount mount_pt\n");
94 return -1;
95 }
Wolfgang Denk74e0dde2008-08-14 14:41:06 +020096
Charles Manning3796e1f2012-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 Juule24ebad2007-11-15 12:23:57 +0100103}
104
Simon Glassed38aef2020-05-10 11:40:03 -0600105int do_yumount(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100106{
Charles Manning3796e1f2012-05-09 16:55:17 +0000107 char *mtpoint;
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200108
Charles Manning3796e1f2012-05-09 16:55:17 +0000109 if (argc != 2) {
110 printf("Bad arguments: yumount mount_pt\n");
111 return -1;
112 }
William Juule24ebad2007-11-15 12:23:57 +0100113
Charles Manning3796e1f2012-05-09 16:55:17 +0000114 mtpoint = argv[1];
115 printf("Unmounting yaffs2 mount point %s\n", mtpoint);
116 cmd_yaffs_umount(mtpoint);
117
118 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100119}
120
Simon Glassed38aef2020-05-10 11:40:03 -0600121int do_yls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100122{
Charles Manning3796e1f2012-05-09 16:55:17 +0000123 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 }
William Juule24ebad2007-11-15 12:23:57 +0100129
Charles Manning3796e1f2012-05-09 16:55:17 +0000130 dirname = argv[argc - 1];
William Juule24ebad2007-11-15 12:23:57 +0100131
Charles Manning3796e1f2012-05-09 16:55:17 +0000132 cmd_yaffs_ls(dirname, (argc > 2) ? 1 : 0);
133
134 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100135}
136
Simon Glassed38aef2020-05-10 11:40:03 -0600137int do_yrd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100138{
Charles Manning3796e1f2012-05-09 16:55:17 +0000139 char *filename;
140
141 if (argc != 2) {
142 printf("Bad arguments: yrd file_name\n");
143 return -1;
144 }
William Juule24ebad2007-11-15 12:23:57 +0100145
Charles Manning3796e1f2012-05-09 16:55:17 +0000146 filename = argv[1];
William Juule24ebad2007-11-15 12:23:57 +0100147
Charles Manning3796e1f2012-05-09 16:55:17 +0000148 printf("Reading file %s ", filename);
William Juule24ebad2007-11-15 12:23:57 +0100149
Charles Manning3796e1f2012-05-09 16:55:17 +0000150 cmd_yaffs_read_file(filename);
151
152 printf("done\n");
153 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100154}
155
Simon Glassed38aef2020-05-10 11:40:03 -0600156int do_ywr(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100157{
Charles Manning3796e1f2012-05-09 16:55:17 +0000158 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 }
William Juule24ebad2007-11-15 12:23:57 +0100166
Charles Manning3796e1f2012-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);
William Juule24ebad2007-11-15 12:23:57 +0100170
Charles Manning3796e1f2012-05-09 16:55:17 +0000171 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 Juule24ebad2007-11-15 12:23:57 +0100178}
179
Simon Glassed38aef2020-05-10 11:40:03 -0600180int do_yrdm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100181{
Charles Manning3796e1f2012-05-09 16:55:17 +0000182 char *filename;
183 ulong addr;
William Juule24ebad2007-11-15 12:23:57 +0100184
Charles Manning3796e1f2012-05-09 16:55:17 +0000185 if (argc != 3) {
186 printf("Bad arguments: yrdm file_name addr\n");
187 return -1;
188 }
William Juule24ebad2007-11-15 12:23:57 +0100189
Charles Manning3796e1f2012-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 Juule24ebad2007-11-15 12:23:57 +0100196}
197
Simon Glassed38aef2020-05-10 11:40:03 -0600198int do_ywrm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100199{
Charles Manning3796e1f2012-05-09 16:55:17 +0000200 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 }
William Juule24ebad2007-11-15 12:23:57 +0100208
Charles Manning3796e1f2012-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);
William Juule24ebad2007-11-15 12:23:57 +0100212
Charles Manning3796e1f2012-05-09 16:55:17 +0000213 cmd_yaffs_mwrite_file(filename, (char *)addr, size);
214
215 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100216}
217
Simon Glassed38aef2020-05-10 11:40:03 -0600218int do_ymkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100219{
Charles Manning3796e1f2012-05-09 16:55:17 +0000220 char *dirname;
221
222 if (argc != 2) {
223 printf("Bad arguments: ymkdir dir_name\n");
224 return -1;
225 }
William Juule24ebad2007-11-15 12:23:57 +0100226
Charles Manning3796e1f2012-05-09 16:55:17 +0000227 dirname = argv[1];
228 cmd_yaffs_mkdir(dirname);
William Juule24ebad2007-11-15 12:23:57 +0100229
Charles Manning3796e1f2012-05-09 16:55:17 +0000230 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100231}
232
Simon Glassed38aef2020-05-10 11:40:03 -0600233int do_yrmdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100234{
Charles Manning3796e1f2012-05-09 16:55:17 +0000235 char *dirname;
William Juule24ebad2007-11-15 12:23:57 +0100236
Charles Manning3796e1f2012-05-09 16:55:17 +0000237 if (argc != 2) {
238 printf("Bad arguments: yrmdir dir_name\n");
239 return -1;
240 }
William Juule24ebad2007-11-15 12:23:57 +0100241
Charles Manning3796e1f2012-05-09 16:55:17 +0000242 dirname = argv[1];
243 cmd_yaffs_rmdir(dirname);
244
245 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100246}
247
Simon Glassed38aef2020-05-10 11:40:03 -0600248int do_yrm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100249{
Charles Manning3796e1f2012-05-09 16:55:17 +0000250 char *name;
251
252 if (argc != 2) {
253 printf("Bad arguments: yrm name\n");
254 return -1;
255 }
William Juule24ebad2007-11-15 12:23:57 +0100256
Charles Manning3796e1f2012-05-09 16:55:17 +0000257 name = argv[1];
William Juule24ebad2007-11-15 12:23:57 +0100258
Charles Manning3796e1f2012-05-09 16:55:17 +0000259 cmd_yaffs_rm(name);
260
261 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100262}
263
Simon Glassed38aef2020-05-10 11:40:03 -0600264int do_ymv(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100265{
Charles Manning3796e1f2012-05-09 16:55:17 +0000266 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;
William Juule24ebad2007-11-15 12:23:57 +0100280}
281
Charles Manning3796e1f2012-05-09 16:55:17 +0000282U_BOOT_CMD(ytrace, 2, 0, do_ytrace,
283 "show/set yaffs trace mask",
Peter Tyser2dd42d82015-02-03 10:15:04 -0600284 "[new_mask] show/set yaffs trace mask");
William Juule24ebad2007-11-15 12:23:57 +0100285
Charles Manning3796e1f2012-05-09 16:55:17 +0000286U_BOOT_CMD(ydevls, 1, 0, do_ydevls,
287 "list yaffs mount points", "list yaffs mount points");
William Juule24ebad2007-11-15 12:23:57 +0100288
Charles Manning3796e1f2012-05-09 16:55:17 +0000289U_BOOT_CMD(ydevconfig, 5, 0, do_ydevconfig,
290 "configure yaffs mount point",
Peter Tyser2dd42d82015-02-03 10:15:04 -0600291 "mtpoint mtd_id start_block end_block configures a yaffs2 mount point");
William Juule24ebad2007-11-15 12:23:57 +0100292
Charles Manning3796e1f2012-05-09 16:55:17 +0000293U_BOOT_CMD(ymount, 2, 0, do_ymount,
Peter Tyser2dd42d82015-02-03 10:15:04 -0600294 "mount yaffs", "mtpoint mounts a yaffs2 mount point");
William Juule24ebad2007-11-15 12:23:57 +0100295
Charles Manning3796e1f2012-05-09 16:55:17 +0000296U_BOOT_CMD(yumount, 2, 0, do_yumount,
Peter Tyser2dd42d82015-02-03 10:15:04 -0600297 "unmount yaffs", "mtpoint unmounts a yaffs2 mount point");
William Juule24ebad2007-11-15 12:23:57 +0100298
Peter Tyser2dd42d82015-02-03 10:15:04 -0600299U_BOOT_CMD(yls, 3, 0, do_yls, "yaffs ls", "[-l] dirname");
William Juule24ebad2007-11-15 12:23:57 +0100300
Charles Manning3796e1f2012-05-09 16:55:17 +0000301U_BOOT_CMD(yrd, 2, 0, do_yrd,
Peter Tyser2dd42d82015-02-03 10:15:04 -0600302 "read file from yaffs", "path read file from yaffs");
William Juule24ebad2007-11-15 12:23:57 +0100303
Charles Manning3796e1f2012-05-09 16:55:17 +0000304U_BOOT_CMD(ywr, 4, 0, do_ywr,
305 "write file to yaffs",
Peter Tyser2dd42d82015-02-03 10:15:04 -0600306 "filename value num_vlues write values to yaffs file");
William Juule24ebad2007-11-15 12:23:57 +0100307
Charles Manning3796e1f2012-05-09 16:55:17 +0000308U_BOOT_CMD(yrdm, 3, 0, do_yrdm,
309 "read file to memory from yaffs",
Peter Tyser2dd42d82015-02-03 10:15:04 -0600310 "filename offset reads yaffs file into memory");
William Juule24ebad2007-11-15 12:23:57 +0100311
Charles Manning3796e1f2012-05-09 16:55:17 +0000312U_BOOT_CMD(ywrm, 4, 0, do_ywrm,
313 "write file from memory to yaffs",
Peter Tyser2dd42d82015-02-03 10:15:04 -0600314 "filename offset size writes memory to yaffs file");
William Juule24ebad2007-11-15 12:23:57 +0100315
Charles Manning3796e1f2012-05-09 16:55:17 +0000316U_BOOT_CMD(ymkdir, 2, 0, do_ymkdir,
Peter Tyser2dd42d82015-02-03 10:15:04 -0600317 "YAFFS mkdir", "dir create a yaffs directory");
Charles Manning3796e1f2012-05-09 16:55:17 +0000318
319U_BOOT_CMD(yrmdir, 2, 0, do_yrmdir,
Peter Tyser2dd42d82015-02-03 10:15:04 -0600320 "YAFFS rmdir", "dirname removes a yaffs directory");
Charles Manning3796e1f2012-05-09 16:55:17 +0000321
Peter Tyser2dd42d82015-02-03 10:15:04 -0600322U_BOOT_CMD(yrm, 2, 0, do_yrm, "YAFFS rm", "path removes a yaffs file");
William Juule24ebad2007-11-15 12:23:57 +0100323
Charles Manning3796e1f2012-05-09 16:55:17 +0000324U_BOOT_CMD(ymv, 4, 0, do_ymv,
325 "YAFFS mv",
Peter Tyser2dd42d82015-02-03 10:15:04 -0600326 "old_path new_path moves/rename files within a yaffs mount point");