blob: 27fbd1be8f750a6285a5dc0ef485f71bf848e6a9 [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 <common.h>
17
18#include <config.h>
19#include <command.h>
20
Charles Manning753ac612012-05-09 16:55:17 +000021#ifdef YAFFS2_DEBUG
22#define PRINTF(fmt, args...) printf(fmt, ##args)
William Juul90ef1172007-11-15 12:23:57 +010023#else
Charles Manning753ac612012-05-09 16:55:17 +000024#define PRINTF(fmt, args...) do { } while (0)
William Juul90ef1172007-11-15 12:23:57 +010025#endif
26
Charles Manning753ac612012-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 Juul90ef1172007-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 Manning753ac612012-05-09 16:55:17 +000034extern void cmd_yaffs_write_file(char *fn, char bval, int sizeOfFile);
William Juul90ef1172007-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 Manning753ac612012-05-09 16:55:17 +000043extern int yaffs_dump_dev(const char *path);
William Juul90ef1172007-11-15 12:23:57 +010044
Charles Manning753ac612012-05-09 16:55:17 +000045/* ytrace - show/set yaffs trace mask */
Simon Glass09140112020-05-10 11:40:03 -060046int do_ytrace(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +010047{
Charles Manning753ac612012-05-09 16:55:17 +000048 if (argc > 1)
49 cmd_yaffs_tracemask(1, simple_strtol(argv[1], NULL, 16));
50 else
51 cmd_yaffs_tracemask(0, 0);
Wolfgang Denk4b070802008-08-14 14:41:06 +020052
Charles Manning753ac612012-05-09 16:55:17 +000053 return 0;
William Juul90ef1172007-11-15 12:23:57 +010054}
55
Charles Manning753ac612012-05-09 16:55:17 +000056/* ydevls - lists yaffs mount points. */
Simon Glass09140112020-05-10 11:40:03 -060057int do_ydevls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +010058{
Charles Manning753ac612012-05-09 16:55:17 +000059 cmd_yaffs_dev_ls();
Wolfgang Denk4b070802008-08-14 14:41:06 +020060
Charles Manning753ac612012-05-09 16:55:17 +000061 return 0;
William Juul90ef1172007-11-15 12:23:57 +010062}
63
Charles Manning753ac612012-05-09 16:55:17 +000064/* ydevconfig mount_pt mtd_dev_num start_block end_block */
Simon Glass09140112020-05-10 11:40:03 -060065int do_ydevconfig(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +010066{
Charles Manning753ac612012-05-09 16:55:17 +000067 char *mtpoint;
68 int mtd_dev;
69 int start_block;
70 int end_block;
Wolfgang Denk4b070802008-08-14 14:41:06 +020071
Charles Manning753ac612012-05-09 16:55:17 +000072 if (argc != 5) {
73 printf
74 ("Bad arguments: ydevconfig mount_pt mtd_dev start_block end_block\n");
75 return -1;
76 }
William Juul90ef1172007-11-15 12:23:57 +010077
Charles Manning753ac612012-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 Juul90ef1172007-11-15 12:23:57 +010086}
87
Simon Glass09140112020-05-10 11:40:03 -060088int do_ymount(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +010089{
Charles Manning753ac612012-05-09 16:55:17 +000090 char *mtpoint;
William Juul90ef1172007-11-15 12:23:57 +010091
Charles Manning753ac612012-05-09 16:55:17 +000092 if (argc != 2) {
93 printf("Bad arguments: ymount mount_pt\n");
94 return -1;
95 }
William Juul90ef1172007-11-15 12:23:57 +010096
Charles Manning753ac612012-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 Juul90ef1172007-11-15 12:23:57 +0100103}
104
Simon Glass09140112020-05-10 11:40:03 -0600105int do_yumount(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100106{
Charles Manning753ac612012-05-09 16:55:17 +0000107 char *mtpoint;
William Juul90ef1172007-11-15 12:23:57 +0100108
Charles Manning753ac612012-05-09 16:55:17 +0000109 if (argc != 2) {
110 printf("Bad arguments: yumount mount_pt\n");
111 return -1;
112 }
William Juul90ef1172007-11-15 12:23:57 +0100113
Charles Manning753ac612012-05-09 16:55:17 +0000114 mtpoint = argv[1];
115 printf("Unmounting yaffs2 mount point %s\n", mtpoint);
116 cmd_yaffs_umount(mtpoint);
William Juul90ef1172007-11-15 12:23:57 +0100117
Charles Manning753ac612012-05-09 16:55:17 +0000118 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100119}
120
Simon Glass09140112020-05-10 11:40:03 -0600121int do_yls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100122{
Charles Manning753ac612012-05-09 16:55:17 +0000123 char *dirname;
William Juul90ef1172007-11-15 12:23:57 +0100124
Charles Manning753ac612012-05-09 16:55:17 +0000125 if (argc < 2 || argc > 3 || (argc == 3 && strcmp(argv[1], "-l"))) {
126 printf("Bad arguments: yls [-l] dir\n");
127 return -1;
128 }
William Juul90ef1172007-11-15 12:23:57 +0100129
Charles Manning753ac612012-05-09 16:55:17 +0000130 dirname = argv[argc - 1];
131
132 cmd_yaffs_ls(dirname, (argc > 2) ? 1 : 0);
133
134 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100135}
136
Simon Glass09140112020-05-10 11:40:03 -0600137int do_yrd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100138{
Charles Manning753ac612012-05-09 16:55:17 +0000139 char *filename;
William Juul90ef1172007-11-15 12:23:57 +0100140
Charles Manning753ac612012-05-09 16:55:17 +0000141 if (argc != 2) {
142 printf("Bad arguments: yrd file_name\n");
143 return -1;
144 }
William Juul90ef1172007-11-15 12:23:57 +0100145
Charles Manning753ac612012-05-09 16:55:17 +0000146 filename = argv[1];
147
148 printf("Reading file %s ", filename);
149
150 cmd_yaffs_read_file(filename);
151
152 printf("done\n");
153 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100154}
155
Simon Glass09140112020-05-10 11:40:03 -0600156int do_ywr(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100157{
Charles Manning753ac612012-05-09 16:55:17 +0000158 char *filename;
159 ulong value;
160 ulong numValues;
William Juul90ef1172007-11-15 12:23:57 +0100161
Charles Manning753ac612012-05-09 16:55:17 +0000162 if (argc != 4) {
163 printf("Bad arguments: ywr file_name value n_values\n");
164 return -1;
165 }
William Juul90ef1172007-11-15 12:23:57 +0100166
Charles Manning753ac612012-05-09 16:55:17 +0000167 filename = argv[1];
Simon Glass7e5f4602021-07-24 09:03:29 -0600168 value = hextoul(argv[2], NULL);
169 numValues = hextoul(argv[3], NULL);
Charles Manning753ac612012-05-09 16:55:17 +0000170
171 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 Juul90ef1172007-11-15 12:23:57 +0100178}
179
Simon Glass09140112020-05-10 11:40:03 -0600180int do_yrdm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100181{
Charles Manning753ac612012-05-09 16:55:17 +0000182 char *filename;
183 ulong addr;
William Juul90ef1172007-11-15 12:23:57 +0100184
Charles Manning753ac612012-05-09 16:55:17 +0000185 if (argc != 3) {
186 printf("Bad arguments: yrdm file_name addr\n");
187 return -1;
188 }
William Juul90ef1172007-11-15 12:23:57 +0100189
Charles Manning753ac612012-05-09 16:55:17 +0000190 filename = argv[1];
Simon Glass7e5f4602021-07-24 09:03:29 -0600191 addr = hextoul(argv[2], NULL);
Charles Manning753ac612012-05-09 16:55:17 +0000192
193 cmd_yaffs_mread_file(filename, (char *)addr);
194
195 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100196}
197
Simon Glass09140112020-05-10 11:40:03 -0600198int do_ywrm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100199{
Charles Manning753ac612012-05-09 16:55:17 +0000200 char *filename;
201 ulong addr;
202 ulong size;
William Juul90ef1172007-11-15 12:23:57 +0100203
Charles Manning753ac612012-05-09 16:55:17 +0000204 if (argc != 4) {
205 printf("Bad arguments: ywrm file_name addr size\n");
206 return -1;
207 }
William Juul90ef1172007-11-15 12:23:57 +0100208
Charles Manning753ac612012-05-09 16:55:17 +0000209 filename = argv[1];
Simon Glass7e5f4602021-07-24 09:03:29 -0600210 addr = hextoul(argv[2], NULL);
211 size = hextoul(argv[3], NULL);
Charles Manning753ac612012-05-09 16:55:17 +0000212
213 cmd_yaffs_mwrite_file(filename, (char *)addr, size);
214
215 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100216}
217
Simon Glass09140112020-05-10 11:40:03 -0600218int do_ymkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100219{
Charles Manning753ac612012-05-09 16:55:17 +0000220 char *dirname;
William Juul90ef1172007-11-15 12:23:57 +0100221
Charles Manning753ac612012-05-09 16:55:17 +0000222 if (argc != 2) {
223 printf("Bad arguments: ymkdir dir_name\n");
224 return -1;
225 }
William Juul90ef1172007-11-15 12:23:57 +0100226
Charles Manning753ac612012-05-09 16:55:17 +0000227 dirname = argv[1];
228 cmd_yaffs_mkdir(dirname);
229
230 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100231}
232
Simon Glass09140112020-05-10 11:40:03 -0600233int do_yrmdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
William Juul90ef1172007-11-15 12:23:57 +0100234{
Charles Manning753ac612012-05-09 16:55:17 +0000235 char *dirname;
236
237 if (argc != 2) {
238 printf("Bad arguments: yrmdir dir_name\n");
239 return -1;
240 }
241
242 dirname = argv[1];
243 cmd_yaffs_rmdir(dirname);
244
245 return 0;
William Juul90ef1172007-11-15 12:23:57 +0100246}
247
Simon Glass09140112020-05-10 11:40:03 -0600248int do_yrm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Charles Manning753ac612012-05-09 16:55:17 +0000249{
250 char *name;
William Juul90ef1172007-11-15 12:23:57 +0100251
Charles Manning753ac612012-05-09 16:55:17 +0000252 if (argc != 2) {
253 printf("Bad arguments: yrm name\n");
254 return -1;
255 }
William Juul90ef1172007-11-15 12:23:57 +0100256
Charles Manning753ac612012-05-09 16:55:17 +0000257 name = argv[1];
William Juul90ef1172007-11-15 12:23:57 +0100258
Charles Manning753ac612012-05-09 16:55:17 +0000259 cmd_yaffs_rm(name);
William Juul90ef1172007-11-15 12:23:57 +0100260
Charles Manning753ac612012-05-09 16:55:17 +0000261 return 0;
262}
William Juul90ef1172007-11-15 12:23:57 +0100263
Simon Glass09140112020-05-10 11:40:03 -0600264int do_ymv(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Charles Manning753ac612012-05-09 16:55:17 +0000265{
266 char *oldPath;
267 char *newPath;
William Juul90ef1172007-11-15 12:23:57 +0100268
Charles Manning753ac612012-05-09 16:55:17 +0000269 if (argc != 3) {
270 printf("Bad arguments: ymv old_path new_path\n");
271 return -1;
272 }
William Juul90ef1172007-11-15 12:23:57 +0100273
Charles Manning753ac612012-05-09 16:55:17 +0000274 oldPath = argv[1];
275 newPath = argv[2];
William Juul90ef1172007-11-15 12:23:57 +0100276
Charles Manning753ac612012-05-09 16:55:17 +0000277 cmd_yaffs_mv(newPath, oldPath);
William Juul90ef1172007-11-15 12:23:57 +0100278
Charles Manning753ac612012-05-09 16:55:17 +0000279 return 0;
280}
William Juul90ef1172007-11-15 12:23:57 +0100281
Charles Manning753ac612012-05-09 16:55:17 +0000282U_BOOT_CMD(ytrace, 2, 0, do_ytrace,
283 "show/set yaffs trace mask",
Peter Tyser5bd15b72015-02-03 10:15:04 -0600284 "[new_mask] show/set yaffs trace mask");
William Juul90ef1172007-11-15 12:23:57 +0100285
Charles Manning753ac612012-05-09 16:55:17 +0000286U_BOOT_CMD(ydevls, 1, 0, do_ydevls,
287 "list yaffs mount points", "list yaffs mount points");
288
289U_BOOT_CMD(ydevconfig, 5, 0, do_ydevconfig,
290 "configure yaffs mount point",
Peter Tyser5bd15b72015-02-03 10:15:04 -0600291 "mtpoint mtd_id start_block end_block configures a yaffs2 mount point");
Charles Manning753ac612012-05-09 16:55:17 +0000292
293U_BOOT_CMD(ymount, 2, 0, do_ymount,
Peter Tyser5bd15b72015-02-03 10:15:04 -0600294 "mount yaffs", "mtpoint mounts a yaffs2 mount point");
Charles Manning753ac612012-05-09 16:55:17 +0000295
296U_BOOT_CMD(yumount, 2, 0, do_yumount,
Peter Tyser5bd15b72015-02-03 10:15:04 -0600297 "unmount yaffs", "mtpoint unmounts a yaffs2 mount point");
Charles Manning753ac612012-05-09 16:55:17 +0000298
Peter Tyser5bd15b72015-02-03 10:15:04 -0600299U_BOOT_CMD(yls, 3, 0, do_yls, "yaffs ls", "[-l] dirname");
Charles Manning753ac612012-05-09 16:55:17 +0000300
301U_BOOT_CMD(yrd, 2, 0, do_yrd,
Peter Tyser5bd15b72015-02-03 10:15:04 -0600302 "read file from yaffs", "path read file from yaffs");
Charles Manning753ac612012-05-09 16:55:17 +0000303
304U_BOOT_CMD(ywr, 4, 0, do_ywr,
305 "write file to yaffs",
Peter Tyser5bd15b72015-02-03 10:15:04 -0600306 "filename value num_vlues write values to yaffs file");
Charles Manning753ac612012-05-09 16:55:17 +0000307
308U_BOOT_CMD(yrdm, 3, 0, do_yrdm,
309 "read file to memory from yaffs",
Peter Tyser5bd15b72015-02-03 10:15:04 -0600310 "filename offset reads yaffs file into memory");
Charles Manning753ac612012-05-09 16:55:17 +0000311
312U_BOOT_CMD(ywrm, 4, 0, do_ywrm,
313 "write file from memory to yaffs",
Peter Tyser5bd15b72015-02-03 10:15:04 -0600314 "filename offset size writes memory to yaffs file");
Charles Manning753ac612012-05-09 16:55:17 +0000315
316U_BOOT_CMD(ymkdir, 2, 0, do_ymkdir,
Peter Tyser5bd15b72015-02-03 10:15:04 -0600317 "YAFFS mkdir", "dir create a yaffs directory");
Charles Manning753ac612012-05-09 16:55:17 +0000318
319U_BOOT_CMD(yrmdir, 2, 0, do_yrmdir,
Peter Tyser5bd15b72015-02-03 10:15:04 -0600320 "YAFFS rmdir", "dirname removes a yaffs directory");
Charles Manning753ac612012-05-09 16:55:17 +0000321
Peter Tyser5bd15b72015-02-03 10:15:04 -0600322U_BOOT_CMD(yrm, 2, 0, do_yrm, "YAFFS rm", "path removes a yaffs file");
Charles Manning753ac612012-05-09 16:55:17 +0000323
324U_BOOT_CMD(ymv, 4, 0, do_ymv,
325 "YAFFS mv",
Peter Tyser5bd15b72015-02-03 10:15:04 -0600326 "old_path new_path moves/rename files within a yaffs mount point");