blob: d0724d9bea8fe8e8257d5f79f50e818dd110e720 [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
17#include <config.h>
18#include <command.h>
19
Charles Manning753ac612012-05-09 16:55:17 +000020#ifdef YAFFS2_DEBUG
21#define PRINTF(fmt, args...) printf(fmt, ##args)
William Juul90ef1172007-11-15 12:23:57 +010022#else
Charles Manning753ac612012-05-09 16:55:17 +000023#define PRINTF(fmt, args...) do { } while (0)
William Juul90ef1172007-11-15 12:23:57 +010024#endif
25
Charles Manning753ac612012-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 Juul90ef1172007-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 Manning753ac612012-05-09 16:55:17 +000033extern void cmd_yaffs_write_file(char *fn, char bval, int sizeOfFile);
William Juul90ef1172007-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 Manning753ac612012-05-09 16:55:17 +000042extern int yaffs_dump_dev(const char *path);
William Juul90ef1172007-11-15 12:23:57 +010043
Charles Manning753ac612012-05-09 16:55:17 +000044/* ytrace - show/set yaffs trace mask */
Simon Glass09140112020-05-10 11:40:03 -060045int do_ytrace(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +010046{
Charles Manning753ac612012-05-09 16:55:17 +000047 if (argc > 1)
48 cmd_yaffs_tracemask(1, simple_strtol(argv[1], NULL, 16));
49 else
50 cmd_yaffs_tracemask(0, 0);
Wolfgang Denk4b070802008-08-14 14:41:06 +020051
Charles Manning753ac612012-05-09 16:55:17 +000052 return 0;
William Juul90ef1172007-11-15 12:23:57 +010053}
54
Charles Manning753ac612012-05-09 16:55:17 +000055/* ydevls - lists yaffs mount points. */
Simon Glass09140112020-05-10 11:40:03 -060056int do_ydevls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +010057{
Charles Manning753ac612012-05-09 16:55:17 +000058 cmd_yaffs_dev_ls();
Wolfgang Denk4b070802008-08-14 14:41:06 +020059
Charles Manning753ac612012-05-09 16:55:17 +000060 return 0;
William Juul90ef1172007-11-15 12:23:57 +010061}
62
Charles Manning753ac612012-05-09 16:55:17 +000063/* ydevconfig mount_pt mtd_dev_num start_block end_block */
Simon Glass09140112020-05-10 11:40:03 -060064int do_ydevconfig(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +010065{
Charles Manning753ac612012-05-09 16:55:17 +000066 char *mtpoint;
67 int mtd_dev;
68 int start_block;
69 int end_block;
Wolfgang Denk4b070802008-08-14 14:41:06 +020070
Charles Manning753ac612012-05-09 16:55:17 +000071 if (argc != 5) {
72 printf
73 ("Bad arguments: ydevconfig mount_pt mtd_dev start_block end_block\n");
74 return -1;
75 }
William Juul90ef1172007-11-15 12:23:57 +010076
Charles Manning753ac612012-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 Juul90ef1172007-11-15 12:23:57 +010085}
86
Simon Glass09140112020-05-10 11:40:03 -060087int do_ymount(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +010088{
Charles Manning753ac612012-05-09 16:55:17 +000089 char *mtpoint;
William Juul90ef1172007-11-15 12:23:57 +010090
Charles Manning753ac612012-05-09 16:55:17 +000091 if (argc != 2) {
92 printf("Bad arguments: ymount mount_pt\n");
93 return -1;
94 }
William Juul90ef1172007-11-15 12:23:57 +010095
Charles Manning753ac612012-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 Juul90ef1172007-11-15 12:23:57 +0100102}
103
Simon Glass09140112020-05-10 11:40:03 -0600104int do_yumount(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100105{
Charles Manning753ac612012-05-09 16:55:17 +0000106 char *mtpoint;
William Juul90ef1172007-11-15 12:23:57 +0100107
Charles Manning753ac612012-05-09 16:55:17 +0000108 if (argc != 2) {
109 printf("Bad arguments: yumount mount_pt\n");
110 return -1;
111 }
William Juul90ef1172007-11-15 12:23:57 +0100112
Charles Manning753ac612012-05-09 16:55:17 +0000113 mtpoint = argv[1];
114 printf("Unmounting yaffs2 mount point %s\n", mtpoint);
115 cmd_yaffs_umount(mtpoint);
William Juul90ef1172007-11-15 12:23:57 +0100116
Charles Manning753ac612012-05-09 16:55:17 +0000117 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100118}
119
Simon Glass09140112020-05-10 11:40:03 -0600120int do_yls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100121{
Charles Manning753ac612012-05-09 16:55:17 +0000122 char *dirname;
William Juul90ef1172007-11-15 12:23:57 +0100123
Charles Manning753ac612012-05-09 16:55:17 +0000124 if (argc < 2 || argc > 3 || (argc == 3 && strcmp(argv[1], "-l"))) {
125 printf("Bad arguments: yls [-l] dir\n");
126 return -1;
127 }
William Juul90ef1172007-11-15 12:23:57 +0100128
Charles Manning753ac612012-05-09 16:55:17 +0000129 dirname = argv[argc - 1];
130
131 cmd_yaffs_ls(dirname, (argc > 2) ? 1 : 0);
132
133 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100134}
135
Simon Glass09140112020-05-10 11:40:03 -0600136int do_yrd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100137{
Charles Manning753ac612012-05-09 16:55:17 +0000138 char *filename;
William Juul90ef1172007-11-15 12:23:57 +0100139
Charles Manning753ac612012-05-09 16:55:17 +0000140 if (argc != 2) {
141 printf("Bad arguments: yrd file_name\n");
142 return -1;
143 }
William Juul90ef1172007-11-15 12:23:57 +0100144
Charles Manning753ac612012-05-09 16:55:17 +0000145 filename = argv[1];
146
147 printf("Reading file %s ", filename);
148
149 cmd_yaffs_read_file(filename);
150
151 printf("done\n");
152 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100153}
154
Simon Glass09140112020-05-10 11:40:03 -0600155int do_ywr(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100156{
Charles Manning753ac612012-05-09 16:55:17 +0000157 char *filename;
158 ulong value;
159 ulong numValues;
William Juul90ef1172007-11-15 12:23:57 +0100160
Charles Manning753ac612012-05-09 16:55:17 +0000161 if (argc != 4) {
162 printf("Bad arguments: ywr file_name value n_values\n");
163 return -1;
164 }
William Juul90ef1172007-11-15 12:23:57 +0100165
Charles Manning753ac612012-05-09 16:55:17 +0000166 filename = argv[1];
Simon Glass7e5f4602021-07-24 09:03:29 -0600167 value = hextoul(argv[2], NULL);
168 numValues = hextoul(argv[3], NULL);
Charles Manning753ac612012-05-09 16:55:17 +0000169
170 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 Juul90ef1172007-11-15 12:23:57 +0100177}
178
Simon Glass09140112020-05-10 11:40:03 -0600179int do_yrdm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100180{
Charles Manning753ac612012-05-09 16:55:17 +0000181 char *filename;
182 ulong addr;
William Juul90ef1172007-11-15 12:23:57 +0100183
Charles Manning753ac612012-05-09 16:55:17 +0000184 if (argc != 3) {
185 printf("Bad arguments: yrdm file_name addr\n");
186 return -1;
187 }
William Juul90ef1172007-11-15 12:23:57 +0100188
Charles Manning753ac612012-05-09 16:55:17 +0000189 filename = argv[1];
Simon Glass7e5f4602021-07-24 09:03:29 -0600190 addr = hextoul(argv[2], NULL);
Charles Manning753ac612012-05-09 16:55:17 +0000191
192 cmd_yaffs_mread_file(filename, (char *)addr);
193
194 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100195}
196
Simon Glass09140112020-05-10 11:40:03 -0600197int do_ywrm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100198{
Charles Manning753ac612012-05-09 16:55:17 +0000199 char *filename;
200 ulong addr;
201 ulong size;
William Juul90ef1172007-11-15 12:23:57 +0100202
Charles Manning753ac612012-05-09 16:55:17 +0000203 if (argc != 4) {
204 printf("Bad arguments: ywrm file_name addr size\n");
205 return -1;
206 }
William Juul90ef1172007-11-15 12:23:57 +0100207
Charles Manning753ac612012-05-09 16:55:17 +0000208 filename = argv[1];
Simon Glass7e5f4602021-07-24 09:03:29 -0600209 addr = hextoul(argv[2], NULL);
210 size = hextoul(argv[3], NULL);
Charles Manning753ac612012-05-09 16:55:17 +0000211
212 cmd_yaffs_mwrite_file(filename, (char *)addr, size);
213
214 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100215}
216
Simon Glass09140112020-05-10 11:40:03 -0600217int do_ymkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100218{
Charles Manning753ac612012-05-09 16:55:17 +0000219 char *dirname;
William Juul90ef1172007-11-15 12:23:57 +0100220
Charles Manning753ac612012-05-09 16:55:17 +0000221 if (argc != 2) {
222 printf("Bad arguments: ymkdir dir_name\n");
223 return -1;
224 }
William Juul90ef1172007-11-15 12:23:57 +0100225
Charles Manning753ac612012-05-09 16:55:17 +0000226 dirname = argv[1];
227 cmd_yaffs_mkdir(dirname);
228
229 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100230}
231
Simon Glass09140112020-05-10 11:40:03 -0600232int do_yrmdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100233{
Charles Manning753ac612012-05-09 16:55:17 +0000234 char *dirname;
235
236 if (argc != 2) {
237 printf("Bad arguments: yrmdir dir_name\n");
238 return -1;
239 }
240
241 dirname = argv[1];
242 cmd_yaffs_rmdir(dirname);
243
244 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100245}
246
Simon Glass09140112020-05-10 11:40:03 -0600247int do_yrm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Charles Manning753ac612012-05-09 16:55:17 +0000248{
249 char *name;
William Juul90ef1172007-11-15 12:23:57 +0100250
Charles Manning753ac612012-05-09 16:55:17 +0000251 if (argc != 2) {
252 printf("Bad arguments: yrm name\n");
253 return -1;
254 }
William Juul90ef1172007-11-15 12:23:57 +0100255
Charles Manning753ac612012-05-09 16:55:17 +0000256 name = argv[1];
William Juul90ef1172007-11-15 12:23:57 +0100257
Charles Manning753ac612012-05-09 16:55:17 +0000258 cmd_yaffs_rm(name);
William Juul90ef1172007-11-15 12:23:57 +0100259
Charles Manning753ac612012-05-09 16:55:17 +0000260 return 0;
261}
William Juul90ef1172007-11-15 12:23:57 +0100262
Simon Glass09140112020-05-10 11:40:03 -0600263int do_ymv(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Charles Manning753ac612012-05-09 16:55:17 +0000264{
265 char *oldPath;
266 char *newPath;
William Juul90ef1172007-11-15 12:23:57 +0100267
Charles Manning753ac612012-05-09 16:55:17 +0000268 if (argc != 3) {
269 printf("Bad arguments: ymv old_path new_path\n");
270 return -1;
271 }
William Juul90ef1172007-11-15 12:23:57 +0100272
Charles Manning753ac612012-05-09 16:55:17 +0000273 oldPath = argv[1];
274 newPath = argv[2];
William Juul90ef1172007-11-15 12:23:57 +0100275
Charles Manning753ac612012-05-09 16:55:17 +0000276 cmd_yaffs_mv(newPath, oldPath);
William Juul90ef1172007-11-15 12:23:57 +0100277
Charles Manning753ac612012-05-09 16:55:17 +0000278 return 0;
279}
William Juul90ef1172007-11-15 12:23:57 +0100280
Charles Manning753ac612012-05-09 16:55:17 +0000281U_BOOT_CMD(ytrace, 2, 0, do_ytrace,
282 "show/set yaffs trace mask",
Peter Tyser5bd15b72015-02-03 10:15:04 -0600283 "[new_mask] show/set yaffs trace mask");
William Juul90ef1172007-11-15 12:23:57 +0100284
Charles Manning753ac612012-05-09 16:55:17 +0000285U_BOOT_CMD(ydevls, 1, 0, do_ydevls,
286 "list yaffs mount points", "list yaffs mount points");
287
288U_BOOT_CMD(ydevconfig, 5, 0, do_ydevconfig,
289 "configure yaffs mount point",
Peter Tyser5bd15b72015-02-03 10:15:04 -0600290 "mtpoint mtd_id start_block end_block configures a yaffs2 mount point");
Charles Manning753ac612012-05-09 16:55:17 +0000291
292U_BOOT_CMD(ymount, 2, 0, do_ymount,
Peter Tyser5bd15b72015-02-03 10:15:04 -0600293 "mount yaffs", "mtpoint mounts a yaffs2 mount point");
Charles Manning753ac612012-05-09 16:55:17 +0000294
295U_BOOT_CMD(yumount, 2, 0, do_yumount,
Peter Tyser5bd15b72015-02-03 10:15:04 -0600296 "unmount yaffs", "mtpoint unmounts a yaffs2 mount point");
Charles Manning753ac612012-05-09 16:55:17 +0000297
Peter Tyser5bd15b72015-02-03 10:15:04 -0600298U_BOOT_CMD(yls, 3, 0, do_yls, "yaffs ls", "[-l] dirname");
Charles Manning753ac612012-05-09 16:55:17 +0000299
300U_BOOT_CMD(yrd, 2, 0, do_yrd,
Peter Tyser5bd15b72015-02-03 10:15:04 -0600301 "read file from yaffs", "path read file from yaffs");
Charles Manning753ac612012-05-09 16:55:17 +0000302
303U_BOOT_CMD(ywr, 4, 0, do_ywr,
304 "write file to yaffs",
Peter Tyser5bd15b72015-02-03 10:15:04 -0600305 "filename value num_vlues write values to yaffs file");
Charles Manning753ac612012-05-09 16:55:17 +0000306
307U_BOOT_CMD(yrdm, 3, 0, do_yrdm,
308 "read file to memory from yaffs",
Peter Tyser5bd15b72015-02-03 10:15:04 -0600309 "filename offset reads yaffs file into memory");
Charles Manning753ac612012-05-09 16:55:17 +0000310
311U_BOOT_CMD(ywrm, 4, 0, do_ywrm,
312 "write file from memory to yaffs",
Peter Tyser5bd15b72015-02-03 10:15:04 -0600313 "filename offset size writes memory to yaffs file");
Charles Manning753ac612012-05-09 16:55:17 +0000314
315U_BOOT_CMD(ymkdir, 2, 0, do_ymkdir,
Peter Tyser5bd15b72015-02-03 10:15:04 -0600316 "YAFFS mkdir", "dir create a yaffs directory");
Charles Manning753ac612012-05-09 16:55:17 +0000317
318U_BOOT_CMD(yrmdir, 2, 0, do_yrmdir,
Peter Tyser5bd15b72015-02-03 10:15:04 -0600319 "YAFFS rmdir", "dirname removes a yaffs directory");
Charles Manning753ac612012-05-09 16:55:17 +0000320
Peter Tyser5bd15b72015-02-03 10:15:04 -0600321U_BOOT_CMD(yrm, 2, 0, do_yrm, "YAFFS rm", "path removes a yaffs file");
Charles Manning753ac612012-05-09 16:55:17 +0000322
323U_BOOT_CMD(ymv, 4, 0, do_ymv,
324 "YAFFS mv",
Peter Tyser5bd15b72015-02-03 10:15:04 -0600325 "old_path new_path moves/rename files within a yaffs mount point");