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