Merge branch '2024-11-22-assorted-fixes'
[u-boot.git] / cmd / yaffs2.c
blobdaa44abeb72c30cc49f95b995e61f1ec530dd28b
1 /* Yaffs commands.
2 * Modified by Charles Manning by adding ydevconfig command.
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 * ...
16 #include <config.h>
17 #include <command.h>
19 #ifdef YAFFS2_DEBUG
20 #define PRINTF(fmt, args...) printf(fmt, ##args)
21 #else
22 #define PRINTF(fmt, args...) do { } while (0)
23 #endif
25 extern void cmd_yaffs_dev_ls(void);
26 extern void cmd_yaffs_tracemask(unsigned set, unsigned mask);
27 extern void cmd_yaffs_devconfig(char *mp, int flash_dev,
28 int start_block, int end_block);
29 extern void cmd_yaffs_mount(char *mp);
30 extern void cmd_yaffs_umount(char *mp);
31 extern void cmd_yaffs_read_file(char *fn);
32 extern void cmd_yaffs_write_file(char *fn, char bval, int sizeOfFile);
33 extern void cmd_yaffs_ls(const char *mountpt, int longlist);
34 extern void cmd_yaffs_mwrite_file(char *fn, char *addr, int size);
35 extern void cmd_yaffs_mread_file(char *fn, char *addr);
36 extern void cmd_yaffs_mkdir(const char *dir);
37 extern void cmd_yaffs_rmdir(const char *dir);
38 extern void cmd_yaffs_rm(const char *path);
39 extern void cmd_yaffs_mv(const char *oldPath, const char *newPath);
41 extern int yaffs_dump_dev(const char *path);
43 /* ytrace - show/set yaffs trace mask */
44 int do_ytrace(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
46 if (argc > 1)
47 cmd_yaffs_tracemask(1, simple_strtol(argv[1], NULL, 16));
48 else
49 cmd_yaffs_tracemask(0, 0);
51 return 0;
54 /* ydevls - lists yaffs mount points. */
55 int do_ydevls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
57 cmd_yaffs_dev_ls();
59 return 0;
62 /* ydevconfig mount_pt mtd_dev_num start_block end_block */
63 int do_ydevconfig(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
65 char *mtpoint;
66 int mtd_dev;
67 int start_block;
68 int end_block;
70 if (argc != 5) {
71 printf
72 ("Bad arguments: ydevconfig mount_pt mtd_dev start_block end_block\n");
73 return -1;
76 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);
81 cmd_yaffs_devconfig(mtpoint, mtd_dev, start_block, end_block);
83 return 0;
86 int do_ymount(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
88 char *mtpoint;
90 if (argc != 2) {
91 printf("Bad arguments: ymount mount_pt\n");
92 return -1;
95 mtpoint = argv[1];
96 printf("Mounting yaffs2 mount point %s\n", mtpoint);
98 cmd_yaffs_mount(mtpoint);
100 return 0;
103 int do_yumount(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
105 char *mtpoint;
107 if (argc != 2) {
108 printf("Bad arguments: yumount mount_pt\n");
109 return -1;
112 mtpoint = argv[1];
113 printf("Unmounting yaffs2 mount point %s\n", mtpoint);
114 cmd_yaffs_umount(mtpoint);
116 return 0;
119 int do_yls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
121 char *dirname;
123 if (argc < 2 || argc > 3 || (argc == 3 && strcmp(argv[1], "-l"))) {
124 printf("Bad arguments: yls [-l] dir\n");
125 return -1;
128 dirname = argv[argc - 1];
130 cmd_yaffs_ls(dirname, (argc > 2) ? 1 : 0);
132 return 0;
135 int do_yrd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
137 char *filename;
139 if (argc != 2) {
140 printf("Bad arguments: yrd file_name\n");
141 return -1;
144 filename = argv[1];
146 printf("Reading file %s ", filename);
148 cmd_yaffs_read_file(filename);
150 printf("done\n");
151 return 0;
154 int do_ywr(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
156 char *filename;
157 ulong value;
158 ulong numValues;
160 if (argc != 4) {
161 printf("Bad arguments: ywr file_name value n_values\n");
162 return -1;
165 filename = argv[1];
166 value = hextoul(argv[2], NULL);
167 numValues = hextoul(argv[3], NULL);
169 printf("Writing value (%lx) %lx times to %s... ", value, numValues,
170 filename);
172 cmd_yaffs_write_file(filename, value, numValues);
174 printf("done\n");
175 return 0;
178 int do_yrdm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
180 char *filename;
181 ulong addr;
183 if (argc != 3) {
184 printf("Bad arguments: yrdm file_name addr\n");
185 return -1;
188 filename = argv[1];
189 addr = hextoul(argv[2], NULL);
191 cmd_yaffs_mread_file(filename, (char *)addr);
193 return 0;
196 int do_ywrm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
198 char *filename;
199 ulong addr;
200 ulong size;
202 if (argc != 4) {
203 printf("Bad arguments: ywrm file_name addr size\n");
204 return -1;
207 filename = argv[1];
208 addr = hextoul(argv[2], NULL);
209 size = hextoul(argv[3], NULL);
211 cmd_yaffs_mwrite_file(filename, (char *)addr, size);
213 return 0;
216 int do_ymkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
218 char *dirname;
220 if (argc != 2) {
221 printf("Bad arguments: ymkdir dir_name\n");
222 return -1;
225 dirname = argv[1];
226 cmd_yaffs_mkdir(dirname);
228 return 0;
231 int do_yrmdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
233 char *dirname;
235 if (argc != 2) {
236 printf("Bad arguments: yrmdir dir_name\n");
237 return -1;
240 dirname = argv[1];
241 cmd_yaffs_rmdir(dirname);
243 return 0;
246 int do_yrm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
248 char *name;
250 if (argc != 2) {
251 printf("Bad arguments: yrm name\n");
252 return -1;
255 name = argv[1];
257 cmd_yaffs_rm(name);
259 return 0;
262 int do_ymv(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
264 char *oldPath;
265 char *newPath;
267 if (argc != 3) {
268 printf("Bad arguments: ymv old_path new_path\n");
269 return -1;
272 oldPath = argv[1];
273 newPath = argv[2];
275 cmd_yaffs_mv(newPath, oldPath);
277 return 0;
280 U_BOOT_CMD(ytrace, 2, 0, do_ytrace,
281 "show/set yaffs trace mask",
282 "[new_mask] show/set yaffs trace mask");
284 U_BOOT_CMD(ydevls, 1, 0, do_ydevls,
285 "list yaffs mount points", "list yaffs mount points");
287 U_BOOT_CMD(ydevconfig, 5, 0, do_ydevconfig,
288 "configure yaffs mount point",
289 "mtpoint mtd_id start_block end_block configures a yaffs2 mount point");
291 U_BOOT_CMD(ymount, 2, 0, do_ymount,
292 "mount yaffs", "mtpoint mounts a yaffs2 mount point");
294 U_BOOT_CMD(yumount, 2, 0, do_yumount,
295 "unmount yaffs", "mtpoint unmounts a yaffs2 mount point");
297 U_BOOT_CMD(yls, 3, 0, do_yls, "yaffs ls", "[-l] dirname");
299 U_BOOT_CMD(yrd, 2, 0, do_yrd,
300 "read file from yaffs", "path read file from yaffs");
302 U_BOOT_CMD(ywr, 4, 0, do_ywr,
303 "write file to yaffs",
304 "filename value num_vlues write values to yaffs file");
306 U_BOOT_CMD(yrdm, 3, 0, do_yrdm,
307 "read file to memory from yaffs",
308 "filename offset reads yaffs file into memory");
310 U_BOOT_CMD(ywrm, 4, 0, do_ywrm,
311 "write file from memory to yaffs",
312 "filename offset size writes memory to yaffs file");
314 U_BOOT_CMD(ymkdir, 2, 0, do_ymkdir,
315 "YAFFS mkdir", "dir create a yaffs directory");
317 U_BOOT_CMD(yrmdir, 2, 0, do_yrmdir,
318 "YAFFS rmdir", "dirname removes a yaffs directory");
320 U_BOOT_CMD(yrm, 2, 0, do_yrm, "YAFFS rm", "path removes a yaffs file");
322 U_BOOT_CMD(ymv, 4, 0, do_ymv,
323 "YAFFS mv",
324 "old_path new_path moves/rename files within a yaffs mount point");