]>
Commit | Line | Data |
---|---|---|
753ac610 CM |
1 | /* 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 | ||
90ef117b WJ |
16 | |
17 | #include <config.h> | |
18 | #include <command.h> | |
19 | ||
753ac610 CM |
20 | #ifdef YAFFS2_DEBUG |
21 | #define PRINTF(fmt, args...) printf(fmt, ##args) | |
90ef117b | 22 | #else |
753ac610 | 23 | #define PRINTF(fmt, args...) do { } while (0) |
90ef117b WJ |
24 | #endif |
25 | ||
753ac610 CM |
26 | extern void cmd_yaffs_dev_ls(void); |
27 | extern void cmd_yaffs_tracemask(unsigned set, unsigned mask); | |
28 | extern void cmd_yaffs_devconfig(char *mp, int flash_dev, | |
29 | int start_block, int end_block); | |
90ef117b WJ |
30 | extern void cmd_yaffs_mount(char *mp); |
31 | extern void cmd_yaffs_umount(char *mp); | |
32 | extern void cmd_yaffs_read_file(char *fn); | |
753ac610 | 33 | extern void cmd_yaffs_write_file(char *fn, char bval, int sizeOfFile); |
90ef117b WJ |
34 | extern void cmd_yaffs_ls(const char *mountpt, int longlist); |
35 | extern void cmd_yaffs_mwrite_file(char *fn, char *addr, int size); | |
36 | extern void cmd_yaffs_mread_file(char *fn, char *addr); | |
37 | extern void cmd_yaffs_mkdir(const char *dir); | |
38 | extern void cmd_yaffs_rmdir(const char *dir); | |
39 | extern void cmd_yaffs_rm(const char *path); | |
40 | extern void cmd_yaffs_mv(const char *oldPath, const char *newPath); | |
41 | ||
753ac610 CM |
42 | extern int yaffs_dump_dev(const char *path); |
43 | ||
44 | /* ytrace - show/set yaffs trace mask */ | |
09140113 | 45 | int do_ytrace(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
753ac610 CM |
46 | { |
47 | if (argc > 1) | |
48 | cmd_yaffs_tracemask(1, simple_strtol(argv[1], NULL, 16)); | |
49 | else | |
50 | cmd_yaffs_tracemask(0, 0); | |
90ef117b | 51 | |
753ac610 CM |
52 | return 0; |
53 | } | |
90ef117b | 54 | |
753ac610 | 55 | /* ydevls - lists yaffs mount points. */ |
09140113 | 56 | int do_ydevls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
90ef117b | 57 | { |
753ac610 | 58 | cmd_yaffs_dev_ls(); |
4b070809 | 59 | |
753ac610 | 60 | return 0; |
90ef117b WJ |
61 | } |
62 | ||
753ac610 | 63 | /* ydevconfig mount_pt mtd_dev_num start_block end_block */ |
09140113 | 64 | int do_ydevconfig(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
90ef117b | 65 | { |
753ac610 CM |
66 | char *mtpoint; |
67 | int mtd_dev; | |
68 | int start_block; | |
69 | int end_block; | |
70 | ||
71 | if (argc != 5) { | |
72 | printf | |
73 | ("Bad arguments: ydevconfig mount_pt mtd_dev start_block end_block\n"); | |
74 | return -1; | |
75 | } | |
76 | ||
77 | 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); | |
4b070809 | 81 | |
753ac610 CM |
82 | cmd_yaffs_devconfig(mtpoint, mtd_dev, start_block, end_block); |
83 | ||
84 | return 0; | |
90ef117b WJ |
85 | } |
86 | ||
09140113 | 87 | int do_ymount(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
90ef117b | 88 | { |
753ac610 CM |
89 | char *mtpoint; |
90 | ||
91 | if (argc != 2) { | |
92 | printf("Bad arguments: ymount mount_pt\n"); | |
93 | return -1; | |
94 | } | |
95 | ||
96 | mtpoint = argv[1]; | |
97 | printf("Mounting yaffs2 mount point %s\n", mtpoint); | |
4b070809 | 98 | |
753ac610 | 99 | cmd_yaffs_mount(mtpoint); |
90ef117b | 100 | |
753ac610 | 101 | return 0; |
90ef117b WJ |
102 | } |
103 | ||
09140113 | 104 | int do_yumount(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
90ef117b | 105 | { |
753ac610 | 106 | char *mtpoint; |
90ef117b | 107 | |
753ac610 CM |
108 | if (argc != 2) { |
109 | printf("Bad arguments: yumount mount_pt\n"); | |
110 | return -1; | |
111 | } | |
90ef117b | 112 | |
753ac610 CM |
113 | mtpoint = argv[1]; |
114 | printf("Unmounting yaffs2 mount point %s\n", mtpoint); | |
115 | cmd_yaffs_umount(mtpoint); | |
116 | ||
117 | return 0; | |
90ef117b WJ |
118 | } |
119 | ||
09140113 | 120 | int do_yls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
90ef117b | 121 | { |
753ac610 CM |
122 | char *dirname; |
123 | ||
124 | if (argc < 2 || argc > 3 || (argc == 3 && strcmp(argv[1], "-l"))) { | |
125 | printf("Bad arguments: yls [-l] dir\n"); | |
126 | return -1; | |
127 | } | |
90ef117b | 128 | |
753ac610 | 129 | dirname = argv[argc - 1]; |
90ef117b | 130 | |
753ac610 | 131 | cmd_yaffs_ls(dirname, (argc > 2) ? 1 : 0); |
90ef117b | 132 | |
753ac610 | 133 | return 0; |
90ef117b WJ |
134 | } |
135 | ||
09140113 | 136 | int do_yrd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
90ef117b | 137 | { |
753ac610 CM |
138 | char *filename; |
139 | ||
140 | if (argc != 2) { | |
141 | printf("Bad arguments: yrd file_name\n"); | |
142 | return -1; | |
143 | } | |
90ef117b | 144 | |
753ac610 | 145 | filename = argv[1]; |
90ef117b | 146 | |
753ac610 CM |
147 | printf("Reading file %s ", filename); |
148 | ||
149 | cmd_yaffs_read_file(filename); | |
150 | ||
151 | printf("done\n"); | |
152 | return 0; | |
90ef117b WJ |
153 | } |
154 | ||
09140113 | 155 | int do_ywr(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
90ef117b | 156 | { |
753ac610 CM |
157 | char *filename; |
158 | ulong value; | |
159 | ulong numValues; | |
160 | ||
161 | if (argc != 4) { | |
162 | printf("Bad arguments: ywr file_name value n_values\n"); | |
163 | return -1; | |
164 | } | |
90ef117b | 165 | |
753ac610 | 166 | filename = argv[1]; |
7e5f460e SG |
167 | value = hextoul(argv[2], NULL); |
168 | numValues = hextoul(argv[3], NULL); | |
90ef117b | 169 | |
753ac610 CM |
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; | |
90ef117b WJ |
177 | } |
178 | ||
09140113 | 179 | int do_yrdm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
90ef117b | 180 | { |
753ac610 CM |
181 | char *filename; |
182 | ulong addr; | |
183 | ||
184 | if (argc != 3) { | |
185 | printf("Bad arguments: yrdm file_name addr\n"); | |
186 | return -1; | |
187 | } | |
90ef117b | 188 | |
753ac610 | 189 | filename = argv[1]; |
7e5f460e | 190 | addr = hextoul(argv[2], NULL); |
90ef117b | 191 | |
753ac610 CM |
192 | cmd_yaffs_mread_file(filename, (char *)addr); |
193 | ||
194 | return 0; | |
90ef117b WJ |
195 | } |
196 | ||
09140113 | 197 | int do_ywrm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
90ef117b | 198 | { |
753ac610 CM |
199 | char *filename; |
200 | ulong addr; | |
201 | ulong size; | |
202 | ||
203 | if (argc != 4) { | |
204 | printf("Bad arguments: ywrm file_name addr size\n"); | |
205 | return -1; | |
206 | } | |
207 | ||
208 | filename = argv[1]; | |
7e5f460e SG |
209 | addr = hextoul(argv[2], NULL); |
210 | size = hextoul(argv[3], NULL); | |
90ef117b | 211 | |
753ac610 | 212 | cmd_yaffs_mwrite_file(filename, (char *)addr, size); |
90ef117b | 213 | |
753ac610 | 214 | return 0; |
90ef117b WJ |
215 | } |
216 | ||
09140113 | 217 | int do_ymkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
90ef117b | 218 | { |
753ac610 | 219 | char *dirname; |
90ef117b | 220 | |
753ac610 CM |
221 | if (argc != 2) { |
222 | printf("Bad arguments: ymkdir dir_name\n"); | |
223 | return -1; | |
224 | } | |
90ef117b | 225 | |
753ac610 CM |
226 | dirname = argv[1]; |
227 | cmd_yaffs_mkdir(dirname); | |
228 | ||
229 | return 0; | |
90ef117b WJ |
230 | } |
231 | ||
09140113 | 232 | int do_yrmdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
90ef117b | 233 | { |
753ac610 CM |
234 | char *dirname; |
235 | ||
236 | if (argc != 2) { | |
237 | printf("Bad arguments: yrmdir dir_name\n"); | |
238 | return -1; | |
239 | } | |
90ef117b | 240 | |
753ac610 CM |
241 | dirname = argv[1]; |
242 | cmd_yaffs_rmdir(dirname); | |
90ef117b | 243 | |
753ac610 | 244 | return 0; |
90ef117b WJ |
245 | } |
246 | ||
09140113 | 247 | int do_yrm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
90ef117b | 248 | { |
753ac610 CM |
249 | char *name; |
250 | ||
251 | if (argc != 2) { | |
252 | printf("Bad arguments: yrm name\n"); | |
253 | return -1; | |
254 | } | |
255 | ||
256 | name = argv[1]; | |
257 | ||
258 | cmd_yaffs_rm(name); | |
259 | ||
260 | return 0; | |
261 | } | |
262 | ||
09140113 | 263 | int do_ymv(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
753ac610 CM |
264 | { |
265 | char *oldPath; | |
266 | char *newPath; | |
267 | ||
268 | if (argc != 3) { | |
269 | printf("Bad arguments: ymv old_path new_path\n"); | |
270 | return -1; | |
271 | } | |
272 | ||
273 | oldPath = argv[1]; | |
274 | newPath = argv[2]; | |
275 | ||
276 | cmd_yaffs_mv(newPath, oldPath); | |
277 | ||
278 | return 0; | |
90ef117b WJ |
279 | } |
280 | ||
753ac610 CM |
281 | U_BOOT_CMD(ytrace, 2, 0, do_ytrace, |
282 | "show/set yaffs trace mask", | |
5bd15b7a | 283 | "[new_mask] show/set yaffs trace mask"); |
753ac610 CM |
284 | |
285 | U_BOOT_CMD(ydevls, 1, 0, do_ydevls, | |
286 | "list yaffs mount points", "list yaffs mount points"); | |
287 | ||
288 | U_BOOT_CMD(ydevconfig, 5, 0, do_ydevconfig, | |
289 | "configure yaffs mount point", | |
5bd15b7a | 290 | "mtpoint mtd_id start_block end_block configures a yaffs2 mount point"); |
753ac610 CM |
291 | |
292 | U_BOOT_CMD(ymount, 2, 0, do_ymount, | |
5bd15b7a | 293 | "mount yaffs", "mtpoint mounts a yaffs2 mount point"); |
753ac610 CM |
294 | |
295 | U_BOOT_CMD(yumount, 2, 0, do_yumount, | |
5bd15b7a | 296 | "unmount yaffs", "mtpoint unmounts a yaffs2 mount point"); |
753ac610 | 297 | |
5bd15b7a | 298 | U_BOOT_CMD(yls, 3, 0, do_yls, "yaffs ls", "[-l] dirname"); |
753ac610 CM |
299 | |
300 | U_BOOT_CMD(yrd, 2, 0, do_yrd, | |
5bd15b7a | 301 | "read file from yaffs", "path read file from yaffs"); |
753ac610 CM |
302 | |
303 | U_BOOT_CMD(ywr, 4, 0, do_ywr, | |
304 | "write file to yaffs", | |
5bd15b7a | 305 | "filename value num_vlues write values to yaffs file"); |
753ac610 CM |
306 | |
307 | U_BOOT_CMD(yrdm, 3, 0, do_yrdm, | |
308 | "read file to memory from yaffs", | |
5bd15b7a | 309 | "filename offset reads yaffs file into memory"); |
753ac610 CM |
310 | |
311 | U_BOOT_CMD(ywrm, 4, 0, do_ywrm, | |
312 | "write file from memory to yaffs", | |
5bd15b7a | 313 | "filename offset size writes memory to yaffs file"); |
753ac610 CM |
314 | |
315 | U_BOOT_CMD(ymkdir, 2, 0, do_ymkdir, | |
5bd15b7a | 316 | "YAFFS mkdir", "dir create a yaffs directory"); |
753ac610 CM |
317 | |
318 | U_BOOT_CMD(yrmdir, 2, 0, do_yrmdir, | |
5bd15b7a | 319 | "YAFFS rmdir", "dirname removes a yaffs directory"); |
753ac610 | 320 | |
5bd15b7a | 321 | U_BOOT_CMD(yrm, 2, 0, do_yrm, "YAFFS rm", "path removes a yaffs file"); |
753ac610 CM |
322 | |
323 | U_BOOT_CMD(ymv, 4, 0, do_ymv, | |
324 | "YAFFS mv", | |
5bd15b7a | 325 | "old_path new_path moves/rename files within a yaffs mount point"); |