blob: daa44abeb72c30cc49f95b995e61f1ec530dd28b [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 <config.h>
17#include <command.h>
18
Charles Manning753ac612012-05-09 16:55:17 +000019#ifdef YAFFS2_DEBUG
20#define PRINTF(fmt, args...) printf(fmt, ##args)
William Juul90ef1172007-11-15 12:23:57 +010021#else
Charles Manning753ac612012-05-09 16:55:17 +000022#define PRINTF(fmt, args...) do { } while (0)
William Juul90ef1172007-11-15 12:23:57 +010023#endif
24
Charles Manning753ac612012-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 Juul90ef1172007-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 Manning753ac612012-05-09 16:55:17 +000032extern void cmd_yaffs_write_file(char *fn, char bval, int sizeOfFile);
William Juul90ef1172007-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 Manning753ac612012-05-09 16:55:17 +000041extern int yaffs_dump_dev(const char *path);
William Juul90ef1172007-11-15 12:23:57 +010042
Charles Manning753ac612012-05-09 16:55:17 +000043/* ytrace - show/set yaffs trace mask */
Simon Glass09140112020-05-10 11:40:03 -060044int do_ytrace(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +010045{
Charles Manning753ac612012-05-09 16:55:17 +000046 if (argc > 1)
47 cmd_yaffs_tracemask(1, simple_strtol(argv[1], NULL, 16));
48 else
49 cmd_yaffs_tracemask(0, 0);
Wolfgang Denk4b070802008-08-14 14:41:06 +020050
Charles Manning753ac612012-05-09 16:55:17 +000051 return 0;
William Juul90ef1172007-11-15 12:23:57 +010052}
53
Charles Manning753ac612012-05-09 16:55:17 +000054/* ydevls - lists yaffs mount points. */
Simon Glass09140112020-05-10 11:40:03 -060055int do_ydevls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +010056{
Charles Manning753ac612012-05-09 16:55:17 +000057 cmd_yaffs_dev_ls();
Wolfgang Denk4b070802008-08-14 14:41:06 +020058
Charles Manning753ac612012-05-09 16:55:17 +000059 return 0;
William Juul90ef1172007-11-15 12:23:57 +010060}
61
Charles Manning753ac612012-05-09 16:55:17 +000062/* ydevconfig mount_pt mtd_dev_num start_block end_block */
Simon Glass09140112020-05-10 11:40:03 -060063int do_ydevconfig(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +010064{
Charles Manning753ac612012-05-09 16:55:17 +000065 char *mtpoint;
66 int mtd_dev;
67 int start_block;
68 int end_block;
Wolfgang Denk4b070802008-08-14 14:41:06 +020069
Charles Manning753ac612012-05-09 16:55:17 +000070 if (argc != 5) {
71 printf
72 ("Bad arguments: ydevconfig mount_pt mtd_dev start_block end_block\n");
73 return -1;
74 }
William Juul90ef1172007-11-15 12:23:57 +010075
Charles Manning753ac612012-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 Juul90ef1172007-11-15 12:23:57 +010084}
85
Simon Glass09140112020-05-10 11:40:03 -060086int do_ymount(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +010087{
Charles Manning753ac612012-05-09 16:55:17 +000088 char *mtpoint;
William Juul90ef1172007-11-15 12:23:57 +010089
Charles Manning753ac612012-05-09 16:55:17 +000090 if (argc != 2) {
91 printf("Bad arguments: ymount mount_pt\n");
92 return -1;
93 }
William Juul90ef1172007-11-15 12:23:57 +010094
Charles Manning753ac612012-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 Juul90ef1172007-11-15 12:23:57 +0100101}
102
Simon Glass09140112020-05-10 11:40:03 -0600103int do_yumount(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100104{
Charles Manning753ac612012-05-09 16:55:17 +0000105 char *mtpoint;
William Juul90ef1172007-11-15 12:23:57 +0100106
Charles Manning753ac612012-05-09 16:55:17 +0000107 if (argc != 2) {
108 printf("Bad arguments: yumount mount_pt\n");
109 return -1;
110 }
William Juul90ef1172007-11-15 12:23:57 +0100111
Charles Manning753ac612012-05-09 16:55:17 +0000112 mtpoint = argv[1];
113 printf("Unmounting yaffs2 mount point %s\n", mtpoint);
114 cmd_yaffs_umount(mtpoint);
William Juul90ef1172007-11-15 12:23:57 +0100115
Charles Manning753ac612012-05-09 16:55:17 +0000116 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100117}
118
Simon Glass09140112020-05-10 11:40:03 -0600119int do_yls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100120{
Charles Manning753ac612012-05-09 16:55:17 +0000121 char *dirname;
William Juul90ef1172007-11-15 12:23:57 +0100122
Charles Manning753ac612012-05-09 16:55:17 +0000123 if (argc < 2 || argc > 3 || (argc == 3 && strcmp(argv[1], "-l"))) {
124 printf("Bad arguments: yls [-l] dir\n");
125 return -1;
126 }
William Juul90ef1172007-11-15 12:23:57 +0100127
Charles Manning753ac612012-05-09 16:55:17 +0000128 dirname = argv[argc - 1];
129
130 cmd_yaffs_ls(dirname, (argc > 2) ? 1 : 0);
131
132 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100133}
134
Simon Glass09140112020-05-10 11:40:03 -0600135int do_yrd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100136{
Charles Manning753ac612012-05-09 16:55:17 +0000137 char *filename;
William Juul90ef1172007-11-15 12:23:57 +0100138
Charles Manning753ac612012-05-09 16:55:17 +0000139 if (argc != 2) {
140 printf("Bad arguments: yrd file_name\n");
141 return -1;
142 }
William Juul90ef1172007-11-15 12:23:57 +0100143
Charles Manning753ac612012-05-09 16:55:17 +0000144 filename = argv[1];
145
146 printf("Reading file %s ", filename);
147
148 cmd_yaffs_read_file(filename);
149
150 printf("done\n");
151 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100152}
153
Simon Glass09140112020-05-10 11:40:03 -0600154int do_ywr(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100155{
Charles Manning753ac612012-05-09 16:55:17 +0000156 char *filename;
157 ulong value;
158 ulong numValues;
William Juul90ef1172007-11-15 12:23:57 +0100159
Charles Manning753ac612012-05-09 16:55:17 +0000160 if (argc != 4) {
161 printf("Bad arguments: ywr file_name value n_values\n");
162 return -1;
163 }
William Juul90ef1172007-11-15 12:23:57 +0100164
Charles Manning753ac612012-05-09 16:55:17 +0000165 filename = argv[1];
Simon Glass7e5f4602021-07-24 09:03:29 -0600166 value = hextoul(argv[2], NULL);
167 numValues = hextoul(argv[3], NULL);
Charles Manning753ac612012-05-09 16:55:17 +0000168
169 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 Juul90ef1172007-11-15 12:23:57 +0100176}
177
Simon Glass09140112020-05-10 11:40:03 -0600178int do_yrdm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100179{
Charles Manning753ac612012-05-09 16:55:17 +0000180 char *filename;
181 ulong addr;
William Juul90ef1172007-11-15 12:23:57 +0100182
Charles Manning753ac612012-05-09 16:55:17 +0000183 if (argc != 3) {
184 printf("Bad arguments: yrdm file_name addr\n");
185 return -1;
186 }
William Juul90ef1172007-11-15 12:23:57 +0100187
Charles Manning753ac612012-05-09 16:55:17 +0000188 filename = argv[1];
Simon Glass7e5f4602021-07-24 09:03:29 -0600189 addr = hextoul(argv[2], NULL);
Charles Manning753ac612012-05-09 16:55:17 +0000190
191 cmd_yaffs_mread_file(filename, (char *)addr);
192
193 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100194}
195
Simon Glass09140112020-05-10 11:40:03 -0600196int do_ywrm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100197{
Charles Manning753ac612012-05-09 16:55:17 +0000198 char *filename;
199 ulong addr;
200 ulong size;
William Juul90ef1172007-11-15 12:23:57 +0100201
Charles Manning753ac612012-05-09 16:55:17 +0000202 if (argc != 4) {
203 printf("Bad arguments: ywrm file_name addr size\n");
204 return -1;
205 }
William Juul90ef1172007-11-15 12:23:57 +0100206
Charles Manning753ac612012-05-09 16:55:17 +0000207 filename = argv[1];
Simon Glass7e5f4602021-07-24 09:03:29 -0600208 addr = hextoul(argv[2], NULL);
209 size = hextoul(argv[3], NULL);
Charles Manning753ac612012-05-09 16:55:17 +0000210
211 cmd_yaffs_mwrite_file(filename, (char *)addr, size);
212
213 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100214}
215
Simon Glass09140112020-05-10 11:40:03 -0600216int do_ymkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100217{
Charles Manning753ac612012-05-09 16:55:17 +0000218 char *dirname;
William Juul90ef1172007-11-15 12:23:57 +0100219
Charles Manning753ac612012-05-09 16:55:17 +0000220 if (argc != 2) {
221 printf("Bad arguments: ymkdir dir_name\n");
222 return -1;
223 }
William Juul90ef1172007-11-15 12:23:57 +0100224
Charles Manning753ac612012-05-09 16:55:17 +0000225 dirname = argv[1];
226 cmd_yaffs_mkdir(dirname);
227
228 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100229}
230
Simon Glass09140112020-05-10 11:40:03 -0600231int do_yrmdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100232{
Charles Manning753ac612012-05-09 16:55:17 +0000233 char *dirname;
234
235 if (argc != 2) {
236 printf("Bad arguments: yrmdir dir_name\n");
237 return -1;
238 }
239
240 dirname = argv[1];
241 cmd_yaffs_rmdir(dirname);
242
243 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100244}
245
Simon Glass09140112020-05-10 11:40:03 -0600246int do_yrm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Charles Manning753ac612012-05-09 16:55:17 +0000247{
248 char *name;
William Juul90ef1172007-11-15 12:23:57 +0100249
Charles Manning753ac612012-05-09 16:55:17 +0000250 if (argc != 2) {
251 printf("Bad arguments: yrm name\n");
252 return -1;
253 }
William Juul90ef1172007-11-15 12:23:57 +0100254
Charles Manning753ac612012-05-09 16:55:17 +0000255 name = argv[1];
William Juul90ef1172007-11-15 12:23:57 +0100256
Charles Manning753ac612012-05-09 16:55:17 +0000257 cmd_yaffs_rm(name);
William Juul90ef1172007-11-15 12:23:57 +0100258
Charles Manning753ac612012-05-09 16:55:17 +0000259 return 0;
260}
William Juul90ef1172007-11-15 12:23:57 +0100261
Simon Glass09140112020-05-10 11:40:03 -0600262int do_ymv(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Charles Manning753ac612012-05-09 16:55:17 +0000263{
264 char *oldPath;
265 char *newPath;
William Juul90ef1172007-11-15 12:23:57 +0100266
Charles Manning753ac612012-05-09 16:55:17 +0000267 if (argc != 3) {
268 printf("Bad arguments: ymv old_path new_path\n");
269 return -1;
270 }
William Juul90ef1172007-11-15 12:23:57 +0100271
Charles Manning753ac612012-05-09 16:55:17 +0000272 oldPath = argv[1];
273 newPath = argv[2];
William Juul90ef1172007-11-15 12:23:57 +0100274
Charles Manning753ac612012-05-09 16:55:17 +0000275 cmd_yaffs_mv(newPath, oldPath);
William Juul90ef1172007-11-15 12:23:57 +0100276
Charles Manning753ac612012-05-09 16:55:17 +0000277 return 0;
278}
William Juul90ef1172007-11-15 12:23:57 +0100279
Charles Manning753ac612012-05-09 16:55:17 +0000280U_BOOT_CMD(ytrace, 2, 0, do_ytrace,
281 "show/set yaffs trace mask",
Peter Tyser5bd15b72015-02-03 10:15:04 -0600282 "[new_mask] show/set yaffs trace mask");
William Juul90ef1172007-11-15 12:23:57 +0100283
Charles Manning753ac612012-05-09 16:55:17 +0000284U_BOOT_CMD(ydevls, 1, 0, do_ydevls,
285 "list yaffs mount points", "list yaffs mount points");
286
287U_BOOT_CMD(ydevconfig, 5, 0, do_ydevconfig,
288 "configure yaffs mount point",
Peter Tyser5bd15b72015-02-03 10:15:04 -0600289 "mtpoint mtd_id start_block end_block configures a yaffs2 mount point");
Charles Manning753ac612012-05-09 16:55:17 +0000290
291U_BOOT_CMD(ymount, 2, 0, do_ymount,
Peter Tyser5bd15b72015-02-03 10:15:04 -0600292 "mount yaffs", "mtpoint mounts a yaffs2 mount point");
Charles Manning753ac612012-05-09 16:55:17 +0000293
294U_BOOT_CMD(yumount, 2, 0, do_yumount,
Peter Tyser5bd15b72015-02-03 10:15:04 -0600295 "unmount yaffs", "mtpoint unmounts a yaffs2 mount point");
Charles Manning753ac612012-05-09 16:55:17 +0000296
Peter Tyser5bd15b72015-02-03 10:15:04 -0600297U_BOOT_CMD(yls, 3, 0, do_yls, "yaffs ls", "[-l] dirname");
Charles Manning753ac612012-05-09 16:55:17 +0000298
299U_BOOT_CMD(yrd, 2, 0, do_yrd,
Peter Tyser5bd15b72015-02-03 10:15:04 -0600300 "read file from yaffs", "path read file from yaffs");
Charles Manning753ac612012-05-09 16:55:17 +0000301
302U_BOOT_CMD(ywr, 4, 0, do_ywr,
303 "write file to yaffs",
Peter Tyser5bd15b72015-02-03 10:15:04 -0600304 "filename value num_vlues write values to yaffs file");
Charles Manning753ac612012-05-09 16:55:17 +0000305
306U_BOOT_CMD(yrdm, 3, 0, do_yrdm,
307 "read file to memory from yaffs",
Peter Tyser5bd15b72015-02-03 10:15:04 -0600308 "filename offset reads yaffs file into memory");
Charles Manning753ac612012-05-09 16:55:17 +0000309
310U_BOOT_CMD(ywrm, 4, 0, do_ywrm,
311 "write file from memory to yaffs",
Peter Tyser5bd15b72015-02-03 10:15:04 -0600312 "filename offset size writes memory to yaffs file");
Charles Manning753ac612012-05-09 16:55:17 +0000313
314U_BOOT_CMD(ymkdir, 2, 0, do_ymkdir,
Peter Tyser5bd15b72015-02-03 10:15:04 -0600315 "YAFFS mkdir", "dir create a yaffs directory");
Charles Manning753ac612012-05-09 16:55:17 +0000316
317U_BOOT_CMD(yrmdir, 2, 0, do_yrmdir,
Peter Tyser5bd15b72015-02-03 10:15:04 -0600318 "YAFFS rmdir", "dirname removes a yaffs directory");
Charles Manning753ac612012-05-09 16:55:17 +0000319
Peter Tyser5bd15b72015-02-03 10:15:04 -0600320U_BOOT_CMD(yrm, 2, 0, do_yrm, "YAFFS rm", "path removes a yaffs file");
Charles Manning753ac612012-05-09 16:55:17 +0000321
322U_BOOT_CMD(ymv, 4, 0, do_ymv,
323 "YAFFS mv",
Peter Tyser5bd15b72015-02-03 10:15:04 -0600324 "old_path new_path moves/rename files within a yaffs mount point");