blob: daa44abeb72c30cc49f95b995e61f1ec530dd28b [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 <config.h>
17#include <command.h>
18
Charles Manning3796e1f2012-05-09 16:55:17 +000019#ifdef YAFFS2_DEBUG
20#define PRINTF(fmt, args...) printf(fmt, ##args)
William Juule24ebad2007-11-15 12:23:57 +010021#else
Charles Manning3796e1f2012-05-09 16:55:17 +000022#define PRINTF(fmt, args...) do { } while (0)
William Juule24ebad2007-11-15 12:23:57 +010023#endif
24
Charles Manning3796e1f2012-05-09 16:55:17 +000025extern void cmd_yaffs_dev_ls(void);
26extern void cmd_yaffs_tracemask(unsigned set, unsigned mask);
27extern void cmd_yaffs_devconfig(char *mp, int flash_dev,
28 int start_block, int end_block);
William Juule24ebad2007-11-15 12:23:57 +010029extern void cmd_yaffs_mount(char *mp);
30extern void cmd_yaffs_umount(char *mp);
31extern void cmd_yaffs_read_file(char *fn);
Charles Manning3796e1f2012-05-09 16:55:17 +000032extern void cmd_yaffs_write_file(char *fn, char bval, int sizeOfFile);
William Juule24ebad2007-11-15 12:23:57 +010033extern void cmd_yaffs_ls(const char *mountpt, int longlist);
34extern void cmd_yaffs_mwrite_file(char *fn, char *addr, int size);
35extern void cmd_yaffs_mread_file(char *fn, char *addr);
36extern void cmd_yaffs_mkdir(const char *dir);
37extern void cmd_yaffs_rmdir(const char *dir);
38extern void cmd_yaffs_rm(const char *path);
39extern void cmd_yaffs_mv(const char *oldPath, const char *newPath);
40
Charles Manning3796e1f2012-05-09 16:55:17 +000041extern int yaffs_dump_dev(const char *path);
William Juule24ebad2007-11-15 12:23:57 +010042
Charles Manning3796e1f2012-05-09 16:55:17 +000043/* ytrace - show/set yaffs trace mask */
Simon Glassed38aef2020-05-10 11:40:03 -060044int do_ytrace(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Charles Manning3796e1f2012-05-09 16:55:17 +000045{
46 if (argc > 1)
47 cmd_yaffs_tracemask(1, simple_strtol(argv[1], NULL, 16));
48 else
49 cmd_yaffs_tracemask(0, 0);
William Juule24ebad2007-11-15 12:23:57 +010050
Charles Manning3796e1f2012-05-09 16:55:17 +000051 return 0;
52}
53
54/* ydevls - lists yaffs mount points. */
Simon Glassed38aef2020-05-10 11:40:03 -060055int do_ydevls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +010056{
Charles Manning3796e1f2012-05-09 16:55:17 +000057 cmd_yaffs_dev_ls();
58
59 return 0;
60}
61
62/* ydevconfig mount_pt mtd_dev_num start_block end_block */
Simon Glassed38aef2020-05-10 11:40:03 -060063int do_ydevconfig(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Charles Manning3796e1f2012-05-09 16:55:17 +000064{
65 char *mtpoint;
66 int mtd_dev;
67 int start_block;
68 int end_block;
69
70 if (argc != 5) {
71 printf
72 ("Bad arguments: ydevconfig mount_pt mtd_dev start_block end_block\n");
73 return -1;
74 }
Wolfgang Denk74e0dde2008-08-14 14:41:06 +020075
Charles Manning3796e1f2012-05-09 16:55:17 +000076 mtpoint = argv[1];
77 mtd_dev = simple_strtol(argv[2], NULL, 16);
78 start_block = simple_strtol(argv[3], NULL, 16);
79 end_block = simple_strtol(argv[4], NULL, 16);
80
81 cmd_yaffs_devconfig(mtpoint, mtd_dev, start_block, end_block);
82
83 return 0;
William Juule24ebad2007-11-15 12:23:57 +010084}
85
Simon Glassed38aef2020-05-10 11:40:03 -060086int do_ymount(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +010087{
Charles Manning3796e1f2012-05-09 16:55:17 +000088 char *mtpoint;
89
90 if (argc != 2) {
91 printf("Bad arguments: ymount mount_pt\n");
92 return -1;
93 }
Wolfgang Denk74e0dde2008-08-14 14:41:06 +020094
Charles Manning3796e1f2012-05-09 16:55:17 +000095 mtpoint = argv[1];
96 printf("Mounting yaffs2 mount point %s\n", mtpoint);
97
98 cmd_yaffs_mount(mtpoint);
99
100 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100101}
102
Simon Glassed38aef2020-05-10 11:40:03 -0600103int do_yumount(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100104{
Charles Manning3796e1f2012-05-09 16:55:17 +0000105 char *mtpoint;
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200106
Charles Manning3796e1f2012-05-09 16:55:17 +0000107 if (argc != 2) {
108 printf("Bad arguments: yumount mount_pt\n");
109 return -1;
110 }
William Juule24ebad2007-11-15 12:23:57 +0100111
Charles Manning3796e1f2012-05-09 16:55:17 +0000112 mtpoint = argv[1];
113 printf("Unmounting yaffs2 mount point %s\n", mtpoint);
114 cmd_yaffs_umount(mtpoint);
115
116 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100117}
118
Simon Glassed38aef2020-05-10 11:40:03 -0600119int do_yls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100120{
Charles Manning3796e1f2012-05-09 16:55:17 +0000121 char *dirname;
122
123 if (argc < 2 || argc > 3 || (argc == 3 && strcmp(argv[1], "-l"))) {
124 printf("Bad arguments: yls [-l] dir\n");
125 return -1;
126 }
William Juule24ebad2007-11-15 12:23:57 +0100127
Charles Manning3796e1f2012-05-09 16:55:17 +0000128 dirname = argv[argc - 1];
William Juule24ebad2007-11-15 12:23:57 +0100129
Charles Manning3796e1f2012-05-09 16:55:17 +0000130 cmd_yaffs_ls(dirname, (argc > 2) ? 1 : 0);
131
132 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100133}
134
Simon Glassed38aef2020-05-10 11:40:03 -0600135int do_yrd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100136{
Charles Manning3796e1f2012-05-09 16:55:17 +0000137 char *filename;
138
139 if (argc != 2) {
140 printf("Bad arguments: yrd file_name\n");
141 return -1;
142 }
William Juule24ebad2007-11-15 12:23:57 +0100143
Charles Manning3796e1f2012-05-09 16:55:17 +0000144 filename = argv[1];
William Juule24ebad2007-11-15 12:23:57 +0100145
Charles Manning3796e1f2012-05-09 16:55:17 +0000146 printf("Reading file %s ", filename);
William Juule24ebad2007-11-15 12:23:57 +0100147
Charles Manning3796e1f2012-05-09 16:55:17 +0000148 cmd_yaffs_read_file(filename);
149
150 printf("done\n");
151 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100152}
153
Simon Glassed38aef2020-05-10 11:40:03 -0600154int do_ywr(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100155{
Charles Manning3796e1f2012-05-09 16:55:17 +0000156 char *filename;
157 ulong value;
158 ulong numValues;
159
160 if (argc != 4) {
161 printf("Bad arguments: ywr file_name value n_values\n");
162 return -1;
163 }
William Juule24ebad2007-11-15 12:23:57 +0100164
Charles Manning3796e1f2012-05-09 16:55:17 +0000165 filename = argv[1];
Simon Glass3ff49ec2021-07-24 09:03:29 -0600166 value = hextoul(argv[2], NULL);
167 numValues = hextoul(argv[3], NULL);
William Juule24ebad2007-11-15 12:23:57 +0100168
Charles Manning3796e1f2012-05-09 16:55:17 +0000169 printf("Writing value (%lx) %lx times to %s... ", value, numValues,
170 filename);
171
172 cmd_yaffs_write_file(filename, value, numValues);
173
174 printf("done\n");
175 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100176}
177
Simon Glassed38aef2020-05-10 11:40:03 -0600178int do_yrdm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100179{
Charles Manning3796e1f2012-05-09 16:55:17 +0000180 char *filename;
181 ulong addr;
William Juule24ebad2007-11-15 12:23:57 +0100182
Charles Manning3796e1f2012-05-09 16:55:17 +0000183 if (argc != 3) {
184 printf("Bad arguments: yrdm file_name addr\n");
185 return -1;
186 }
William Juule24ebad2007-11-15 12:23:57 +0100187
Charles Manning3796e1f2012-05-09 16:55:17 +0000188 filename = argv[1];
Simon Glass3ff49ec2021-07-24 09:03:29 -0600189 addr = hextoul(argv[2], NULL);
Charles Manning3796e1f2012-05-09 16:55:17 +0000190
191 cmd_yaffs_mread_file(filename, (char *)addr);
192
193 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100194}
195
Simon Glassed38aef2020-05-10 11:40:03 -0600196int do_ywrm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100197{
Charles Manning3796e1f2012-05-09 16:55:17 +0000198 char *filename;
199 ulong addr;
200 ulong size;
201
202 if (argc != 4) {
203 printf("Bad arguments: ywrm file_name addr size\n");
204 return -1;
205 }
William Juule24ebad2007-11-15 12:23:57 +0100206
Charles Manning3796e1f2012-05-09 16:55:17 +0000207 filename = argv[1];
Simon Glass3ff49ec2021-07-24 09:03:29 -0600208 addr = hextoul(argv[2], NULL);
209 size = hextoul(argv[3], NULL);
William Juule24ebad2007-11-15 12:23:57 +0100210
Charles Manning3796e1f2012-05-09 16:55:17 +0000211 cmd_yaffs_mwrite_file(filename, (char *)addr, size);
212
213 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100214}
215
Simon Glassed38aef2020-05-10 11:40:03 -0600216int do_ymkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100217{
Charles Manning3796e1f2012-05-09 16:55:17 +0000218 char *dirname;
219
220 if (argc != 2) {
221 printf("Bad arguments: ymkdir dir_name\n");
222 return -1;
223 }
William Juule24ebad2007-11-15 12:23:57 +0100224
Charles Manning3796e1f2012-05-09 16:55:17 +0000225 dirname = argv[1];
226 cmd_yaffs_mkdir(dirname);
William Juule24ebad2007-11-15 12:23:57 +0100227
Charles Manning3796e1f2012-05-09 16:55:17 +0000228 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100229}
230
Simon Glassed38aef2020-05-10 11:40:03 -0600231int do_yrmdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100232{
Charles Manning3796e1f2012-05-09 16:55:17 +0000233 char *dirname;
William Juule24ebad2007-11-15 12:23:57 +0100234
Charles Manning3796e1f2012-05-09 16:55:17 +0000235 if (argc != 2) {
236 printf("Bad arguments: yrmdir dir_name\n");
237 return -1;
238 }
William Juule24ebad2007-11-15 12:23:57 +0100239
Charles Manning3796e1f2012-05-09 16:55:17 +0000240 dirname = argv[1];
241 cmd_yaffs_rmdir(dirname);
242
243 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100244}
245
Simon Glassed38aef2020-05-10 11:40:03 -0600246int do_yrm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100247{
Charles Manning3796e1f2012-05-09 16:55:17 +0000248 char *name;
249
250 if (argc != 2) {
251 printf("Bad arguments: yrm name\n");
252 return -1;
253 }
William Juule24ebad2007-11-15 12:23:57 +0100254
Charles Manning3796e1f2012-05-09 16:55:17 +0000255 name = argv[1];
William Juule24ebad2007-11-15 12:23:57 +0100256
Charles Manning3796e1f2012-05-09 16:55:17 +0000257 cmd_yaffs_rm(name);
258
259 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100260}
261
Simon Glassed38aef2020-05-10 11:40:03 -0600262int do_ymv(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juule24ebad2007-11-15 12:23:57 +0100263{
Charles Manning3796e1f2012-05-09 16:55:17 +0000264 char *oldPath;
265 char *newPath;
266
267 if (argc != 3) {
268 printf("Bad arguments: ymv old_path new_path\n");
269 return -1;
270 }
271
272 oldPath = argv[1];
273 newPath = argv[2];
274
275 cmd_yaffs_mv(newPath, oldPath);
276
277 return 0;
William Juule24ebad2007-11-15 12:23:57 +0100278}
279
Charles Manning3796e1f2012-05-09 16:55:17 +0000280U_BOOT_CMD(ytrace, 2, 0, do_ytrace,
281 "show/set yaffs trace mask",
Peter Tyser2dd42d82015-02-03 10:15:04 -0600282 "[new_mask] show/set yaffs trace mask");
William Juule24ebad2007-11-15 12:23:57 +0100283
Charles Manning3796e1f2012-05-09 16:55:17 +0000284U_BOOT_CMD(ydevls, 1, 0, do_ydevls,
285 "list yaffs mount points", "list yaffs mount points");
William Juule24ebad2007-11-15 12:23:57 +0100286
Charles Manning3796e1f2012-05-09 16:55:17 +0000287U_BOOT_CMD(ydevconfig, 5, 0, do_ydevconfig,
288 "configure yaffs mount point",
Peter Tyser2dd42d82015-02-03 10:15:04 -0600289 "mtpoint mtd_id start_block end_block configures a yaffs2 mount point");
William Juule24ebad2007-11-15 12:23:57 +0100290
Charles Manning3796e1f2012-05-09 16:55:17 +0000291U_BOOT_CMD(ymount, 2, 0, do_ymount,
Peter Tyser2dd42d82015-02-03 10:15:04 -0600292 "mount yaffs", "mtpoint mounts a yaffs2 mount point");
William Juule24ebad2007-11-15 12:23:57 +0100293
Charles Manning3796e1f2012-05-09 16:55:17 +0000294U_BOOT_CMD(yumount, 2, 0, do_yumount,
Peter Tyser2dd42d82015-02-03 10:15:04 -0600295 "unmount yaffs", "mtpoint unmounts a yaffs2 mount point");
William Juule24ebad2007-11-15 12:23:57 +0100296
Peter Tyser2dd42d82015-02-03 10:15:04 -0600297U_BOOT_CMD(yls, 3, 0, do_yls, "yaffs ls", "[-l] dirname");
William Juule24ebad2007-11-15 12:23:57 +0100298
Charles Manning3796e1f2012-05-09 16:55:17 +0000299U_BOOT_CMD(yrd, 2, 0, do_yrd,
Peter Tyser2dd42d82015-02-03 10:15:04 -0600300 "read file from yaffs", "path read file from yaffs");
William Juule24ebad2007-11-15 12:23:57 +0100301
Charles Manning3796e1f2012-05-09 16:55:17 +0000302U_BOOT_CMD(ywr, 4, 0, do_ywr,
303 "write file to yaffs",
Peter Tyser2dd42d82015-02-03 10:15:04 -0600304 "filename value num_vlues write values to yaffs file");
William Juule24ebad2007-11-15 12:23:57 +0100305
Charles Manning3796e1f2012-05-09 16:55:17 +0000306U_BOOT_CMD(yrdm, 3, 0, do_yrdm,
307 "read file to memory from yaffs",
Peter Tyser2dd42d82015-02-03 10:15:04 -0600308 "filename offset reads yaffs file into memory");
William Juule24ebad2007-11-15 12:23:57 +0100309
Charles Manning3796e1f2012-05-09 16:55:17 +0000310U_BOOT_CMD(ywrm, 4, 0, do_ywrm,
311 "write file from memory to yaffs",
Peter Tyser2dd42d82015-02-03 10:15:04 -0600312 "filename offset size writes memory to yaffs file");
William Juule24ebad2007-11-15 12:23:57 +0100313
Charles Manning3796e1f2012-05-09 16:55:17 +0000314U_BOOT_CMD(ymkdir, 2, 0, do_ymkdir,
Peter Tyser2dd42d82015-02-03 10:15:04 -0600315 "YAFFS mkdir", "dir create a yaffs directory");
Charles Manning3796e1f2012-05-09 16:55:17 +0000316
317U_BOOT_CMD(yrmdir, 2, 0, do_yrmdir,
Peter Tyser2dd42d82015-02-03 10:15:04 -0600318 "YAFFS rmdir", "dirname removes a yaffs directory");
Charles Manning3796e1f2012-05-09 16:55:17 +0000319
Peter Tyser2dd42d82015-02-03 10:15:04 -0600320U_BOOT_CMD(yrm, 2, 0, do_yrm, "YAFFS rm", "path removes a yaffs file");
William Juule24ebad2007-11-15 12:23:57 +0100321
Charles Manning3796e1f2012-05-09 16:55:17 +0000322U_BOOT_CMD(ymv, 4, 0, do_ymv,
323 "YAFFS mv",
Peter Tyser2dd42d82015-02-03 10:15:04 -0600324 "old_path new_path moves/rename files within a yaffs mount point");