blob: d0724d9bea8fe8e8257d5f79f50e818dd110e720 [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
17#include <config.h>
18#include <command.h>
19
Charles Manning3796e1f2012-05-09 16:55:17 +000020#ifdef YAFFS2_DEBUG
21#define PRINTF(fmt, args...) printf(fmt, ##args)
William Juule24ebad2007-11-15 12:23:57 +010022#else
Charles Manning3796e1f2012-05-09 16:55:17 +000023#define PRINTF(fmt, args...) do { } while (0)
William Juule24ebad2007-11-15 12:23:57 +010024#endif
25
Charles Manning3796e1f2012-05-09 16:55:17 +000026extern void cmd_yaffs_dev_ls(void);
27extern void cmd_yaffs_tracemask(unsigned set, unsigned mask);
28extern void cmd_yaffs_devconfig(char *mp, int flash_dev,
29 int start_block, int end_block);
William Juule24ebad2007-11-15 12:23:57 +010030extern void cmd_yaffs_mount(char *mp);
31extern void cmd_yaffs_umount(char *mp);
32extern void cmd_yaffs_read_file(char *fn);
Charles Manning3796e1f2012-05-09 16:55:17 +000033extern void cmd_yaffs_write_file(char *fn, char bval, int sizeOfFile);
William Juule24ebad2007-11-15 12:23:57 +010034extern void cmd_yaffs_ls(const char *mountpt, int longlist);
35extern void cmd_yaffs_mwrite_file(char *fn, char *addr, int size);
36extern void cmd_yaffs_mread_file(char *fn, char *addr);
37extern void cmd_yaffs_mkdir(const char *dir);
38extern void cmd_yaffs_rmdir(const char *dir);
39extern void cmd_yaffs_rm(const char *path);
40extern void cmd_yaffs_mv(const char *oldPath, const char *newPath);
41
Charles Manning3796e1f2012-05-09 16:55:17 +000042extern int yaffs_dump_dev(const char *path);
William Juule24ebad2007-11-15 12:23:57 +010043
Charles Manning3796e1f2012-05-09 16:55:17 +000044/* ytrace - show/set yaffs trace mask */
Simon Glassed38aef2020-05-10 11:40:03 -060045int do_ytrace(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Charles Manning3796e1f2012-05-09 16:55:17 +000046{
47 if (argc > 1)
48 cmd_yaffs_tracemask(1, simple_strtol(argv[1], NULL, 16));
49 else
50 cmd_yaffs_tracemask(0, 0);
William Juule24ebad2007-11-15 12:23:57 +010051
Charles Manning3796e1f2012-05-09 16:55:17 +000052 return 0;
53}
54
55/* ydevls - lists yaffs mount points. */
Simon Glassed38aef2020-05-10 11:40:03 -060056int do_ydevls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +010057{
Charles Manning3796e1f2012-05-09 16:55:17 +000058 cmd_yaffs_dev_ls();
59
60 return 0;
61}
62
63/* ydevconfig mount_pt mtd_dev_num start_block end_block */
Simon Glassed38aef2020-05-10 11:40:03 -060064int do_ydevconfig(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Charles Manning3796e1f2012-05-09 16:55:17 +000065{
66 char *mtpoint;
67 int mtd_dev;
68 int start_block;
69 int end_block;
70
71 if (argc != 5) {
72 printf
73 ("Bad arguments: ydevconfig mount_pt mtd_dev start_block end_block\n");
74 return -1;
75 }
Wolfgang Denk74e0dde2008-08-14 14:41:06 +020076
Charles Manning3796e1f2012-05-09 16:55:17 +000077 mtpoint = argv[1];
78 mtd_dev = simple_strtol(argv[2], NULL, 16);
79 start_block = simple_strtol(argv[3], NULL, 16);
80 end_block = simple_strtol(argv[4], NULL, 16);
81
82 cmd_yaffs_devconfig(mtpoint, mtd_dev, start_block, end_block);
83
84 return 0;
William Juule24ebad2007-11-15 12:23:57 +010085}
86
Simon Glassed38aef2020-05-10 11:40:03 -060087int do_ymount(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +010088{
Charles Manning3796e1f2012-05-09 16:55:17 +000089 char *mtpoint;
90
91 if (argc != 2) {
92 printf("Bad arguments: ymount mount_pt\n");
93 return -1;
94 }
Wolfgang Denk74e0dde2008-08-14 14:41:06 +020095
Charles Manning3796e1f2012-05-09 16:55:17 +000096 mtpoint = argv[1];
97 printf("Mounting yaffs2 mount point %s\n", mtpoint);
98
99 cmd_yaffs_mount(mtpoint);
100
101 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100102}
103
Simon Glassed38aef2020-05-10 11:40:03 -0600104int do_yumount(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100105{
Charles Manning3796e1f2012-05-09 16:55:17 +0000106 char *mtpoint;
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200107
Charles Manning3796e1f2012-05-09 16:55:17 +0000108 if (argc != 2) {
109 printf("Bad arguments: yumount mount_pt\n");
110 return -1;
111 }
William Juule24ebad2007-11-15 12:23:57 +0100112
Charles Manning3796e1f2012-05-09 16:55:17 +0000113 mtpoint = argv[1];
114 printf("Unmounting yaffs2 mount point %s\n", mtpoint);
115 cmd_yaffs_umount(mtpoint);
116
117 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100118}
119
Simon Glassed38aef2020-05-10 11:40:03 -0600120int do_yls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100121{
Charles Manning3796e1f2012-05-09 16:55:17 +0000122 char *dirname;
123
124 if (argc < 2 || argc > 3 || (argc == 3 && strcmp(argv[1], "-l"))) {
125 printf("Bad arguments: yls [-l] dir\n");
126 return -1;
127 }
William Juule24ebad2007-11-15 12:23:57 +0100128
Charles Manning3796e1f2012-05-09 16:55:17 +0000129 dirname = argv[argc - 1];
William Juule24ebad2007-11-15 12:23:57 +0100130
Charles Manning3796e1f2012-05-09 16:55:17 +0000131 cmd_yaffs_ls(dirname, (argc > 2) ? 1 : 0);
132
133 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100134}
135
Simon Glassed38aef2020-05-10 11:40:03 -0600136int do_yrd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100137{
Charles Manning3796e1f2012-05-09 16:55:17 +0000138 char *filename;
139
140 if (argc != 2) {
141 printf("Bad arguments: yrd file_name\n");
142 return -1;
143 }
William Juule24ebad2007-11-15 12:23:57 +0100144
Charles Manning3796e1f2012-05-09 16:55:17 +0000145 filename = argv[1];
William Juule24ebad2007-11-15 12:23:57 +0100146
Charles Manning3796e1f2012-05-09 16:55:17 +0000147 printf("Reading file %s ", filename);
William Juule24ebad2007-11-15 12:23:57 +0100148
Charles Manning3796e1f2012-05-09 16:55:17 +0000149 cmd_yaffs_read_file(filename);
150
151 printf("done\n");
152 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100153}
154
Simon Glassed38aef2020-05-10 11:40:03 -0600155int do_ywr(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100156{
Charles Manning3796e1f2012-05-09 16:55:17 +0000157 char *filename;
158 ulong value;
159 ulong numValues;
160
161 if (argc != 4) {
162 printf("Bad arguments: ywr file_name value n_values\n");
163 return -1;
164 }
William Juule24ebad2007-11-15 12:23:57 +0100165
Charles Manning3796e1f2012-05-09 16:55:17 +0000166 filename = argv[1];
Simon Glass3ff49ec2021-07-24 09:03:29 -0600167 value = hextoul(argv[2], NULL);
168 numValues = hextoul(argv[3], NULL);
William Juule24ebad2007-11-15 12:23:57 +0100169
Charles Manning3796e1f2012-05-09 16:55:17 +0000170 printf("Writing value (%lx) %lx times to %s... ", value, numValues,
171 filename);
172
173 cmd_yaffs_write_file(filename, value, numValues);
174
175 printf("done\n");
176 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100177}
178
Simon Glassed38aef2020-05-10 11:40:03 -0600179int do_yrdm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100180{
Charles Manning3796e1f2012-05-09 16:55:17 +0000181 char *filename;
182 ulong addr;
William Juule24ebad2007-11-15 12:23:57 +0100183
Charles Manning3796e1f2012-05-09 16:55:17 +0000184 if (argc != 3) {
185 printf("Bad arguments: yrdm file_name addr\n");
186 return -1;
187 }
William Juule24ebad2007-11-15 12:23:57 +0100188
Charles Manning3796e1f2012-05-09 16:55:17 +0000189 filename = argv[1];
Simon Glass3ff49ec2021-07-24 09:03:29 -0600190 addr = hextoul(argv[2], NULL);
Charles Manning3796e1f2012-05-09 16:55:17 +0000191
192 cmd_yaffs_mread_file(filename, (char *)addr);
193
194 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100195}
196
Simon Glassed38aef2020-05-10 11:40:03 -0600197int do_ywrm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100198{
Charles Manning3796e1f2012-05-09 16:55:17 +0000199 char *filename;
200 ulong addr;
201 ulong size;
202
203 if (argc != 4) {
204 printf("Bad arguments: ywrm file_name addr size\n");
205 return -1;
206 }
William Juule24ebad2007-11-15 12:23:57 +0100207
Charles Manning3796e1f2012-05-09 16:55:17 +0000208 filename = argv[1];
Simon Glass3ff49ec2021-07-24 09:03:29 -0600209 addr = hextoul(argv[2], NULL);
210 size = hextoul(argv[3], NULL);
William Juule24ebad2007-11-15 12:23:57 +0100211
Charles Manning3796e1f2012-05-09 16:55:17 +0000212 cmd_yaffs_mwrite_file(filename, (char *)addr, size);
213
214 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100215}
216
Simon Glassed38aef2020-05-10 11:40:03 -0600217int do_ymkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100218{
Charles Manning3796e1f2012-05-09 16:55:17 +0000219 char *dirname;
220
221 if (argc != 2) {
222 printf("Bad arguments: ymkdir dir_name\n");
223 return -1;
224 }
William Juule24ebad2007-11-15 12:23:57 +0100225
Charles Manning3796e1f2012-05-09 16:55:17 +0000226 dirname = argv[1];
227 cmd_yaffs_mkdir(dirname);
William Juule24ebad2007-11-15 12:23:57 +0100228
Charles Manning3796e1f2012-05-09 16:55:17 +0000229 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100230}
231
Simon Glassed38aef2020-05-10 11:40:03 -0600232int do_yrmdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100233{
Charles Manning3796e1f2012-05-09 16:55:17 +0000234 char *dirname;
William Juule24ebad2007-11-15 12:23:57 +0100235
Charles Manning3796e1f2012-05-09 16:55:17 +0000236 if (argc != 2) {
237 printf("Bad arguments: yrmdir dir_name\n");
238 return -1;
239 }
William Juule24ebad2007-11-15 12:23:57 +0100240
Charles Manning3796e1f2012-05-09 16:55:17 +0000241 dirname = argv[1];
242 cmd_yaffs_rmdir(dirname);
243
244 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100245}
246
Simon Glassed38aef2020-05-10 11:40:03 -0600247int do_yrm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100248{
Charles Manning3796e1f2012-05-09 16:55:17 +0000249 char *name;
250
251 if (argc != 2) {
252 printf("Bad arguments: yrm name\n");
253 return -1;
254 }
William Juule24ebad2007-11-15 12:23:57 +0100255
Charles Manning3796e1f2012-05-09 16:55:17 +0000256 name = argv[1];
William Juule24ebad2007-11-15 12:23:57 +0100257
Charles Manning3796e1f2012-05-09 16:55:17 +0000258 cmd_yaffs_rm(name);
259
260 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100261}
262
Simon Glassed38aef2020-05-10 11:40:03 -0600263int do_ymv(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100264{
Charles Manning3796e1f2012-05-09 16:55:17 +0000265 char *oldPath;
266 char *newPath;
267
268 if (argc != 3) {
269 printf("Bad arguments: ymv old_path new_path\n");
270 return -1;
271 }
272
273 oldPath = argv[1];
274 newPath = argv[2];
275
276 cmd_yaffs_mv(newPath, oldPath);
277
278 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100279}
280
Charles Manning3796e1f2012-05-09 16:55:17 +0000281U_BOOT_CMD(ytrace, 2, 0, do_ytrace,
282 "show/set yaffs trace mask",
Peter Tyser2dd42d82015-02-03 10:15:04 -0600283 "[new_mask] show/set yaffs trace mask");
William Juule24ebad2007-11-15 12:23:57 +0100284
Charles Manning3796e1f2012-05-09 16:55:17 +0000285U_BOOT_CMD(ydevls, 1, 0, do_ydevls,
286 "list yaffs mount points", "list yaffs mount points");
William Juule24ebad2007-11-15 12:23:57 +0100287
Charles Manning3796e1f2012-05-09 16:55:17 +0000288U_BOOT_CMD(ydevconfig, 5, 0, do_ydevconfig,
289 "configure yaffs mount point",
Peter Tyser2dd42d82015-02-03 10:15:04 -0600290 "mtpoint mtd_id start_block end_block configures a yaffs2 mount point");
William Juule24ebad2007-11-15 12:23:57 +0100291
Charles Manning3796e1f2012-05-09 16:55:17 +0000292U_BOOT_CMD(ymount, 2, 0, do_ymount,
Peter Tyser2dd42d82015-02-03 10:15:04 -0600293 "mount yaffs", "mtpoint mounts a yaffs2 mount point");
William Juule24ebad2007-11-15 12:23:57 +0100294
Charles Manning3796e1f2012-05-09 16:55:17 +0000295U_BOOT_CMD(yumount, 2, 0, do_yumount,
Peter Tyser2dd42d82015-02-03 10:15:04 -0600296 "unmount yaffs", "mtpoint unmounts a yaffs2 mount point");
William Juule24ebad2007-11-15 12:23:57 +0100297
Peter Tyser2dd42d82015-02-03 10:15:04 -0600298U_BOOT_CMD(yls, 3, 0, do_yls, "yaffs ls", "[-l] dirname");
William Juule24ebad2007-11-15 12:23:57 +0100299
Charles Manning3796e1f2012-05-09 16:55:17 +0000300U_BOOT_CMD(yrd, 2, 0, do_yrd,
Peter Tyser2dd42d82015-02-03 10:15:04 -0600301 "read file from yaffs", "path read file from yaffs");
William Juule24ebad2007-11-15 12:23:57 +0100302
Charles Manning3796e1f2012-05-09 16:55:17 +0000303U_BOOT_CMD(ywr, 4, 0, do_ywr,
304 "write file to yaffs",
Peter Tyser2dd42d82015-02-03 10:15:04 -0600305 "filename value num_vlues write values to yaffs file");
William Juule24ebad2007-11-15 12:23:57 +0100306
Charles Manning3796e1f2012-05-09 16:55:17 +0000307U_BOOT_CMD(yrdm, 3, 0, do_yrdm,
308 "read file to memory from yaffs",
Peter Tyser2dd42d82015-02-03 10:15:04 -0600309 "filename offset reads yaffs file into memory");
William Juule24ebad2007-11-15 12:23:57 +0100310
Charles Manning3796e1f2012-05-09 16:55:17 +0000311U_BOOT_CMD(ywrm, 4, 0, do_ywrm,
312 "write file from memory to yaffs",
Peter Tyser2dd42d82015-02-03 10:15:04 -0600313 "filename offset size writes memory to yaffs file");
William Juule24ebad2007-11-15 12:23:57 +0100314
Charles Manning3796e1f2012-05-09 16:55:17 +0000315U_BOOT_CMD(ymkdir, 2, 0, do_ymkdir,
Peter Tyser2dd42d82015-02-03 10:15:04 -0600316 "YAFFS mkdir", "dir create a yaffs directory");
Charles Manning3796e1f2012-05-09 16:55:17 +0000317
318U_BOOT_CMD(yrmdir, 2, 0, do_yrmdir,
Peter Tyser2dd42d82015-02-03 10:15:04 -0600319 "YAFFS rmdir", "dirname removes a yaffs directory");
Charles Manning3796e1f2012-05-09 16:55:17 +0000320
Peter Tyser2dd42d82015-02-03 10:15:04 -0600321U_BOOT_CMD(yrm, 2, 0, do_yrm, "YAFFS rm", "path removes a yaffs file");
William Juule24ebad2007-11-15 12:23:57 +0100322
Charles Manning3796e1f2012-05-09 16:55:17 +0000323U_BOOT_CMD(ymv, 4, 0, do_ymv,
324 "YAFFS mv",
Peter Tyser2dd42d82015-02-03 10:15:04 -0600325 "old_path new_path moves/rename files within a yaffs mount point");