]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * (C) Copyright 2014,2016,2018 Leo C. <erbl259-lmu@yahoo.de> | |
3 | * | |
4 | * SPDX-License-Identifier: GPL-2.0 | |
5 | */ | |
6 | ||
7 | /* | |
8 | * FAT filesystem commands | |
9 | */ | |
10 | ||
11 | #include "cmd_fat.h" | |
12 | #include <ctype.h> | |
13 | ||
14 | #include "ff.h" | |
15 | #include "z80-if.h" | |
16 | #include "eval_arg.h" | |
17 | #include "con-utils.h" | |
18 | #include "print-utils.h" | |
19 | #include "time.h" | |
20 | #include "timer.h" | |
21 | #include "debug.h" | |
22 | #include "env.h" | |
23 | ||
24 | ||
25 | #define DEBUG_FA 0 /* set to 1 to debug */ | |
26 | ||
27 | #define debug_fa(fmt, args...) \ | |
28 | debug_cond(DEBUG_FA, fmt, ##args) | |
29 | ||
30 | ||
31 | /* TODO: use memory size test function (detect_ramsize() in cmd_loadihex.c) */ | |
32 | /* TODO: detect_ramsize() should be moved to z80-if.c */ | |
33 | #define MAX_MEMORY CONFIG_SYS_RAMSIZE_MAX | |
34 | #define BUFFER_SIZE FF_MAX_SS | |
35 | #define PATH_MAX CONFIG_SYS_MAX_PATHLEN | |
36 | ||
37 | ||
38 | /* | |
39 | * Multible (fat) partitions per physical drive are not supported, | |
40 | * but we have up to 2 sdcard slots. | |
41 | */ | |
42 | FATFS FatFs0; | |
43 | FATFS FatFs1; | |
44 | ||
45 | command_ret_t command_ret; | |
46 | char *cmdname; | |
47 | ||
48 | ||
49 | void setup_fatfs(void) | |
50 | { | |
51 | f_mount(&FatFs0, "0:", 0); | |
52 | f_mount(&FatFs1, "1:", 0); | |
53 | } | |
54 | ||
55 | DWORD get_fattime (void) | |
56 | { | |
57 | time_t timer; | |
58 | struct tm tm_timer; | |
59 | ||
60 | time(&timer); | |
61 | gmtime_r(&timer, &tm_timer); | |
62 | ||
63 | return fatfs_time(&tm_timer); | |
64 | } | |
65 | ||
66 | ||
67 | static bool check_abort(void) | |
68 | { | |
69 | bool ret = ctrlc(); | |
70 | ||
71 | if (ret) | |
72 | printf_P(PSTR("Abort\n")); | |
73 | ||
74 | return ret; | |
75 | } | |
76 | ||
77 | ||
78 | static const FLASH char * const FLASH rc_names[] = { | |
79 | FSTR("OK"), | |
80 | FSTR("DISK_ERR"), | |
81 | FSTR("INT_ERR"), | |
82 | FSTR("NOT_READY"), | |
83 | FSTR("NO_FILE"), | |
84 | FSTR("NO_PATH"), | |
85 | FSTR("INVALID_NAME"), | |
86 | FSTR("DENIED"), | |
87 | FSTR("EXIST"), | |
88 | FSTR("INVALID_OBJECT"), | |
89 | FSTR("WRITE_PROTECTED"), | |
90 | FSTR("INVALID_DRIVE"), | |
91 | FSTR("NOT_ENABLED"), | |
92 | FSTR("NO_FILE_SYSTEM"), | |
93 | FSTR("MKFS_ABORTED"), | |
94 | FSTR("TIMEOUT"), | |
95 | FSTR("LOCKED"), | |
96 | FSTR("NOT_ENOUGH_CORE"), | |
97 | FSTR("TOO_MANY_OPEN_FILES"), | |
98 | FSTR("INVALID_PARAMETER") | |
99 | }; | |
100 | ||
101 | static | |
102 | void put_rc (FRESULT rc) | |
103 | { | |
104 | #if GCC_BUG_61443 | |
105 | printf_P(PSTR("rc=%u FR_"), rc); | |
106 | my_puts_P(rc < ARRAY_SIZE(rc_names) ? rc_names[rc] : PSTR(" Unknown Error")); | |
107 | my_puts_P(PSTR("\n")); | |
108 | #else | |
109 | printf_P(PSTR("rc=%u FR_%S\n"), rc, | |
110 | rc < ARRAY_SIZE(rc_names) ? rc_names[rc] : PSTR(" Unknown Error")); | |
111 | #endif | |
112 | } | |
113 | ||
114 | ||
115 | void err(const char *fmt, ...) | |
116 | { | |
117 | va_list ap; | |
118 | va_start(ap, fmt); | |
119 | printf_P(PSTR("fat %s: "), cmdname); | |
120 | vfprintf_P(stdout, fmt, ap); | |
121 | va_end(ap); | |
122 | printf_P(PSTR("\n")); | |
123 | _delay_ms(20); | |
124 | command_ret = CMD_RET_FAILURE; | |
125 | } | |
126 | ||
127 | static void swirl(void) | |
128 | { | |
129 | static const FLASH char swirlchar[] = { '-','\\','|','/' }; | |
130 | static uint_fast8_t cnt; | |
131 | static uint32_t tstamp; | |
132 | ||
133 | if (get_timer(0) > tstamp) { | |
134 | tstamp = get_timer(0) + 250; | |
135 | putchar('\b'); | |
136 | cnt = (cnt+1) & 3; | |
137 | putchar(swirlchar[cnt]); | |
138 | } | |
139 | } | |
140 | ||
141 | typedef struct { | |
142 | char *p_end; /* pointer to NULL at end of path */ | |
143 | char p_path[PATH_MAX + 1]; /* pointer to the start of a path */ | |
144 | } PATH_T; | |
145 | ||
146 | ||
147 | static char *path_skip_heading(char *p) | |
148 | { | |
149 | if (isdigit(p[0]) && p[1] == ':') { | |
150 | p += 2; | |
151 | } else { | |
152 | char *q = p; | |
153 | if (*q++ == '.') { | |
154 | if (*q == '.') | |
155 | ++q; | |
156 | if (*q == '\0' || *q == '/') | |
157 | p = q; | |
158 | } | |
159 | return p; | |
160 | } | |
161 | if (*p == '/') | |
162 | ++p; | |
163 | ||
164 | return p; | |
165 | } | |
166 | ||
167 | static void strip_trailing_slash(PATH_T *p) | |
168 | { | |
169 | char *beg = path_skip_heading(p->p_path); | |
170 | char *end = p->p_end; | |
171 | ||
172 | while (end > beg && end[-1] == '/') | |
173 | *--end = '\0'; | |
174 | ||
175 | p->p_end =end; | |
176 | } | |
177 | ||
178 | /* | |
179 | * Move specified string into path. Convert "" to "." to handle BSD | |
180 | * semantics for a null path. Strip trailing slashes. | |
181 | */ | |
182 | static PATH_T *path_setup(char *string) | |
183 | { | |
184 | if (strlen(string) > PATH_MAX) { | |
185 | err(PSTR("'%s': name too long"), string); | |
186 | return NULL; | |
187 | } | |
188 | ||
189 | PATH_T *p = (PATH_T *) malloc(sizeof *p); | |
190 | if (p == NULL) { | |
191 | err(PSTR("'%s': Out of Memory"), string); | |
192 | return NULL; | |
193 | } | |
194 | ||
195 | strcpy(p->p_path, string); | |
196 | size_t len = strlen(string); | |
197 | if (len > 1 && p->p_path[1] == ':' && p->p_path[2] != '/') { | |
198 | if (len < PATH_MAX) { | |
199 | memmove(p->p_path+3, p->p_path+2, len-1); | |
200 | p->p_path[2] = '/'; | |
201 | len += 1; | |
202 | } else { | |
203 | err(PSTR("'%s': Out of Memory"), string); | |
204 | return NULL; | |
205 | } | |
206 | } | |
207 | ||
208 | p->p_end = p->p_path + len; | |
209 | if (p->p_path == p->p_end) { | |
210 | *p->p_end++ = '.'; | |
211 | *p->p_end = '\0'; | |
212 | } | |
213 | ||
214 | strip_trailing_slash(p); | |
215 | return p; | |
216 | } | |
217 | ||
218 | /* | |
219 | * pwd - Print current directory of the current drive. | |
220 | * | |
221 | */ | |
222 | command_ret_t do_pwd(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc UNUSED, char * const argv[] UNUSED) | |
223 | { | |
224 | FRESULT res; | |
225 | char *buf; | |
226 | ||
227 | buf = (char *) malloc(PATH_MAX); | |
228 | if (buf == NULL) { | |
229 | printf_P(PSTR("pwd: Out of Memory!\n")); | |
230 | return CMD_RET_FAILURE; | |
231 | } | |
232 | *buf = '\0'; | |
233 | res = f_getcwd(buf, PATH_MAX); /* Get current directory path */ | |
234 | ||
235 | debug_fa("### f_getcwd(): buf: '%s', res: %d\n", buf, res); | |
236 | ||
237 | if (res == FR_OK) { | |
238 | puts(buf); | |
239 | } | |
240 | free(buf); | |
241 | if (res != FR_OK) { | |
242 | put_rc(res); | |
243 | return CMD_RET_FAILURE; | |
244 | } | |
245 | return CMD_RET_SUCCESS; | |
246 | } | |
247 | ||
248 | ||
249 | /* | |
250 | * cd - Change the current/working directory. | |
251 | * | |
252 | */ | |
253 | command_ret_t do_cd(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[]) | |
254 | { | |
255 | char *arg; | |
256 | FRESULT res = FR_OK; | |
257 | ||
258 | cmdname = argv[0]; | |
259 | ||
260 | if (argc < 2) { | |
261 | arg = getenv_str(PSTR(ENV_HOME)); | |
262 | if (arg == NULL) { | |
263 | printf_P(PSTR("%s: \"%S\" is not set\n"), argv[0], PSTR(ENV_HOME)); | |
264 | return CMD_RET_FAILURE; | |
265 | } | |
266 | } else | |
267 | arg = argv[1]; | |
268 | ||
269 | PATH_T *path = path_setup(arg); | |
270 | if (path == NULL) | |
271 | return CMD_RET_FAILURE; | |
272 | ||
273 | if (strlen(path->p_path) > 1 && path->p_path[1] == ':') { | |
274 | res = f_chdrive(path->p_path); | |
275 | debug_fa("### f_chdrive(): p_path: '%s', res: %d\n", path->p_path, res); | |
276 | } | |
277 | if (res == FR_OK) { | |
278 | res = f_chdir(path->p_path); | |
279 | debug_fa("### f_chdir(): p_path: '%s', res: %d\n", path->p_path, res); | |
280 | } | |
281 | free(path); | |
282 | if (res != FR_OK) { | |
283 | put_rc(res); | |
284 | return CMD_RET_FAILURE; | |
285 | } | |
286 | return CMD_RET_SUCCESS; | |
287 | } | |
288 | ||
289 | ||
290 | /* | |
291 | * ls path - Directory listing | |
292 | * | |
293 | */ | |
294 | command_ret_t do_ls(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[]) | |
295 | { | |
296 | FATFS *fs; | |
297 | DIR Dir; /* Directory object */ | |
298 | FILINFO Finfo; | |
299 | unsigned long p1; | |
300 | unsigned int s1, s2; | |
301 | FRESULT res = FR_OK; | |
302 | char *buf; | |
303 | ||
304 | ||
305 | buf = (char *) malloc(PATH_MAX); | |
306 | if (buf == NULL) { | |
307 | printf_P(PSTR("pwd: Out of Memory!\n")); | |
308 | return CMD_RET_FAILURE; | |
309 | } | |
310 | ||
311 | if (argc < 2) | |
312 | res = f_getcwd(buf, PATH_MAX); /* Get current directory path */ | |
313 | else | |
314 | strncpy(buf, argv[1], PATH_MAX); | |
315 | ||
316 | if (res == FR_OK) | |
317 | res = f_opendir(&Dir, buf); | |
318 | if (res != FR_OK) { | |
319 | free(buf); | |
320 | put_rc(res); | |
321 | return CMD_RET_FAILURE; | |
322 | } | |
323 | ||
324 | p1 = s1 = s2 = 0; | |
325 | for(;;) { | |
326 | res = f_readdir(&Dir, &Finfo); | |
327 | if ((res != FR_OK) || !Finfo.fname[0]) | |
328 | break; | |
329 | if (Finfo.fattrib & AM_DIR) { | |
330 | s2++; | |
331 | } else { | |
332 | s1++; p1 += Finfo.fsize; | |
333 | } | |
334 | printf_P(PSTR("%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu %s\n"), | |
335 | (Finfo.fattrib & AM_DIR) ? 'D' : '-', | |
336 | (Finfo.fattrib & AM_RDO) ? 'R' : '-', | |
337 | (Finfo.fattrib & AM_HID) ? 'H' : '-', | |
338 | (Finfo.fattrib & AM_SYS) ? 'S' : '-', | |
339 | (Finfo.fattrib & AM_ARC) ? 'A' : '-', | |
340 | (Finfo.fdate >> 9) + 1980, (Finfo.fdate >> 5) & 15, Finfo.fdate & 31, | |
341 | (Finfo.ftime >> 11), (Finfo.ftime >> 5) & 63, | |
342 | Finfo.fsize, Finfo.fname); | |
343 | if (check_abort()) | |
344 | break; | |
345 | } | |
346 | ||
347 | if (res == FR_OK) { | |
348 | printf_P(PSTR("%4u File(s),%10lu bytes total\n%4u Dir(s)"), s1, p1, s2); | |
349 | if (f_getfree(buf, (DWORD*)&p1, &fs) == FR_OK) | |
350 | printf_P(PSTR(", %10luK bytes free\n"), p1 * fs->csize / 2); | |
351 | } | |
352 | ||
353 | free(buf); | |
354 | if (res) { | |
355 | put_rc(res); | |
356 | return CMD_RET_FAILURE; | |
357 | } | |
358 | ||
359 | return CMD_RET_SUCCESS; | |
360 | } | |
361 | ||
362 | #if 0 | |
363 | static | |
364 | FRESULT mkpath(TCHAR *path) | |
365 | { | |
366 | /* TODO: */ | |
367 | (void) path; | |
368 | FILINFO fd | |
369 | TCHAR *p, *q; | |
370 | FRESULT ret; | |
371 | ||
372 | res = f_stat (path, &fd) | |
373 | ||
374 | p = strchr(path, ':'); | |
375 | if (p == NULL || *++p == '\0' || *p++ != '/') | |
376 | return FR_OK; | |
377 | ||
378 | while ((q = strchr(p, '/')) != NULL) { | |
379 | *q = '\0'; | |
380 | ret = f_mkdir(path); | |
381 | *q = '/'; | |
382 | if (ret != FR_OK && ret != FR_EXIST) | |
383 | return ret; | |
384 | p = q + 1; | |
385 | } | |
386 | ||
387 | return FR_OK; | |
388 | } | |
389 | #endif | |
390 | ||
391 | /* Work register for fs command */ | |
392 | struct stat_dat_s { | |
393 | DWORD AccSize; | |
394 | WORD AccFiles, AccDirs; | |
395 | FILINFO Finfo; | |
396 | }; | |
397 | ||
398 | static | |
399 | FRESULT scan_files ( | |
400 | char *path, /* Pointer to the working buffer with start path */ | |
401 | struct stat_dat_s *statp | |
402 | ) | |
403 | { | |
404 | DIR dirs; | |
405 | FRESULT res; | |
406 | int i; | |
407 | char *fn; | |
408 | ||
409 | res = f_opendir(&dirs, path); | |
410 | swirl(); | |
411 | if (res == FR_OK) { | |
412 | i = strlen(path); | |
413 | while (((res = f_readdir(&dirs, &statp->Finfo)) == FR_OK) && | |
414 | statp->Finfo.fname[0]) { | |
415 | if (FF_FS_RPATH && statp->Finfo.fname[0] == '.') | |
416 | continue; | |
417 | fn = statp->Finfo.fname; | |
418 | if (statp->Finfo.fattrib & AM_DIR) { | |
419 | statp->AccDirs++; | |
420 | path[i] = '/'; | |
421 | strcpy(path+i+1, fn); | |
422 | res = scan_files(path, statp); | |
423 | path[i] = '\0'; | |
424 | if (res != FR_OK) | |
425 | break; | |
426 | } else { | |
427 | //printf_P(PSTR("%s/%s\n"), path, fn); | |
428 | statp->AccFiles++; | |
429 | statp->AccSize += statp->Finfo.fsize; | |
430 | } | |
431 | if (check_abort()) { | |
432 | res = 255; | |
433 | break; | |
434 | } | |
435 | } | |
436 | } | |
437 | ||
438 | return res; | |
439 | } | |
440 | ||
441 | ||
442 | /* | |
443 | * fatstat path - Show logical drive status | |
444 | * | |
445 | */ | |
446 | command_ret_t do_stat(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[]) | |
447 | { | |
448 | FATFS *fs; | |
449 | DWORD nfreeclst; | |
450 | FRESULT res; | |
451 | char *buf; | |
452 | char *path = ""; | |
453 | struct stat_dat_s statp; | |
454 | ||
455 | buf = (char *) malloc(PATH_MAX); | |
456 | if (buf == NULL) { | |
457 | printf_P(PSTR("fat stat: Out of Memory!\n")); | |
458 | return CMD_RET_FAILURE; | |
459 | } | |
460 | ||
461 | if (argc > 1) | |
462 | path = argv[1]; | |
463 | res = f_getfree(path, &nfreeclst, &fs); | |
464 | if (!res) { | |
465 | printf_P(PSTR( | |
466 | "FAT type: %u\n" | |
467 | "Bytes/Cluster: %lu\n" | |
468 | "Number of FATs: %u\n" | |
469 | "Root DIR entries: %u\n" | |
470 | "Sectors/FAT: %lu\n" | |
471 | "Number of clusters: %lu\n" | |
472 | "FAT start (lba): %lu\n" | |
473 | "DIR start (lba,cluster): %lu\n" | |
474 | "Data start (lba): %lu\n"), | |
475 | fs->fs_type, (DWORD)fs->csize * 512, fs->n_fats, | |
476 | fs->n_rootdir, fs->fsize, fs->n_fatent - 2, | |
477 | fs->fatbase, fs->dirbase, fs->database); | |
478 | ||
479 | #if FF_USE_LABEL | |
480 | DWORD serial; | |
481 | res = f_getlabel(path, buf, &serial); | |
482 | if (!res) { | |
483 | printf_P(PSTR( | |
484 | "Volume name: %s\n" | |
485 | "Volume S/N: %04X-%04X\n"), | |
486 | buf, (WORD)(serial >> 16), (WORD)(serial & 0xFFFF)); | |
487 | } | |
488 | #endif | |
489 | if (!res) { | |
490 | statp.AccSize = statp.AccFiles = statp.AccDirs = 0; | |
491 | strcpy(buf, path); | |
492 | ||
493 | my_puts_P(PSTR("\nCounting... ")); | |
494 | res = scan_files(buf, &statp); | |
495 | putchar('\r'); | |
496 | } | |
497 | if (!res) { | |
498 | printf_P(PSTR("%u files, %lu bytes.\n%u folders.\n" | |
499 | "%lu KB total disk space.\n%lu KB available.\n"), | |
500 | statp.AccFiles, statp.AccSize, statp.AccDirs, | |
501 | (fs->n_fatent - 2) * (fs->csize / 2), nfreeclst * (fs->csize / 2) | |
502 | ); | |
503 | } | |
504 | } | |
505 | ||
506 | free(buf); | |
507 | if (res) { | |
508 | put_rc(res); | |
509 | return CMD_RET_FAILURE; | |
510 | } | |
511 | return CMD_RET_SUCCESS; | |
512 | } | |
513 | ||
514 | /* | |
515 | * fatread/write - load binary file to/from a dos filesystem | |
516 | * read <d:/path/filename> <addr> [bytes [pos]] | |
517 | * write <d:/path/filename> <addr> <bytes> | |
518 | */ | |
519 | command_ret_t do_rw(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[]) | |
520 | { | |
521 | FIL File; | |
522 | uint32_t addr; | |
523 | unsigned long bytes; | |
524 | unsigned long pos; | |
525 | unsigned long bytes_rw; | |
526 | ||
527 | bool dowrite = (argv[0][0] == 'w'); | |
528 | FRESULT res = FR_OK; | |
529 | bool buserr = 0; | |
530 | uint32_t timer; | |
531 | uint8_t *buffer; | |
532 | ||
533 | if (argc < (dowrite ? 4 : 3)) | |
534 | return CMD_RET_USAGE; | |
535 | ||
536 | addr = eval_arg(argv[2], NULL); | |
537 | if (addr >= MAX_MEMORY) { | |
538 | printf_P(PSTR("address too high: 0x%0lx\n"), addr); | |
539 | return CMD_RET_FAILURE; | |
540 | } | |
541 | if (argc > 3) | |
542 | bytes = eval_arg(argv[3], NULL); | |
543 | else | |
544 | bytes = MAX_MEMORY; | |
545 | if (argc > 4) | |
546 | pos = eval_arg(argv[4], NULL); | |
547 | else | |
548 | pos = 0; | |
549 | ||
550 | if (addr + bytes > MAX_MEMORY) | |
551 | bytes = MAX_MEMORY - addr; | |
552 | ||
553 | buffer = (uint8_t *) malloc(BUFFER_SIZE); | |
554 | if (buffer == NULL) { | |
555 | printf_P(PSTR("fatstat: Out of Memory!\n")); | |
556 | return CMD_RET_FAILURE; | |
557 | } | |
558 | ||
559 | if (!res) { | |
560 | res = f_open(&File, argv[1], dowrite ? FA_WRITE | FA_CREATE_ALWAYS | |
561 | : FA_READ ); | |
562 | ||
563 | if (!res) { | |
564 | res = f_lseek(&File, pos); | |
565 | if (!res) { | |
566 | bytes_rw = 0; | |
567 | timer = get_timer(0); | |
568 | while (bytes) { | |
569 | unsigned int cnt, br; | |
570 | ||
571 | if (bytes >= BUFFER_SIZE) { | |
572 | cnt = BUFFER_SIZE; | |
573 | bytes -= BUFFER_SIZE; | |
574 | } else { | |
575 | cnt = bytes; bytes = 0; | |
576 | } | |
577 | if (dowrite) { | |
578 | if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { | |
579 | buserr = 1; | |
580 | break; | |
581 | } | |
582 | z80_read_block(buffer, addr, cnt); | |
583 | z80_bus_cmd(Release); | |
584 | res = f_write(&File, buffer, cnt, &br); | |
585 | if (res != FR_OK) | |
586 | break; | |
587 | } else { | |
588 | res = f_read(&File, buffer, cnt, &br); | |
589 | if (res != FR_OK) | |
590 | break; | |
591 | if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) { | |
592 | buserr = 1; | |
593 | break; | |
594 | } | |
595 | z80_write_block(buffer, addr, br); | |
596 | z80_bus_cmd(Release); | |
597 | } | |
598 | addr += br; | |
599 | ||
600 | bytes_rw += br; | |
601 | if (cnt != br) { | |
602 | if (dowrite) | |
603 | printf_P(PSTR("Disk full?\n")); | |
604 | break; | |
605 | } | |
606 | if (check_abort()) | |
607 | break; | |
608 | } | |
609 | ||
610 | FRESULT fr = f_close(&File); | |
611 | if (!res) | |
612 | res = fr; | |
613 | timer = get_timer(timer); | |
614 | printf_P(PSTR("%lu (0x%lx) bytes read/written with %lu bytes/sec.\n"), | |
615 | bytes_rw, bytes_rw, timer ? (bytes_rw * 1000 / timer) : 0); | |
616 | } | |
617 | } | |
618 | } | |
619 | ||
620 | free(buffer); | |
621 | ||
622 | if (buserr) | |
623 | my_puts_P(PSTR("Bus timeout\n")); | |
624 | if (res) | |
625 | put_rc(res); | |
626 | if (buserr || res) | |
627 | return CMD_RET_FAILURE; | |
628 | ||
629 | return CMD_RET_SUCCESS; | |
630 | } | |
631 | ||
632 | /* | |
633 | * command table for fat subcommands | |
634 | */ | |
635 | ||
636 | cmd_tbl_t cmd_tbl_fat[] = { | |
637 | CMD_TBL_ITEM( | |
638 | status, 2, CTBL_RPT, do_stat, | |
639 | "Show logical drive status", | |
640 | "dev" | |
641 | ), | |
642 | CMD_TBL_ITEM( | |
643 | pwd, 2, CTBL_RPT|CTBL_SUBCMDAUTO, do_pwd, | |
644 | "Print name of current/working directory", | |
645 | "" | |
646 | ), | |
647 | CMD_TBL_ITEM( | |
648 | cd, 2, 0|CTBL_SUBCMDAUTO, do_cd, | |
649 | "Change the current/working directory.", | |
650 | "path" | |
651 | ), | |
652 | CMD_TBL_ITEM( | |
653 | ls, 2, CTBL_RPT|CTBL_SUBCMDAUTO, do_ls, | |
654 | "Directory listing", | |
655 | "path" | |
656 | ), | |
657 | CMD_TBL_ITEM( | |
658 | load, 5, 0, do_rw, | |
659 | "load binary file from a dos filesystem", | |
660 | "<d:/path/filename> <addr> [bytes [pos]]\n" | |
661 | " - Load binary file 'path/filename' on logical drive 'd'\n" | |
662 | " to address 'addr' from dos filesystem.\n" | |
663 | " 'pos' gives the file position to start loading from.\n" | |
664 | " If 'pos' is omitted, 0 is used. 'pos' requires 'bytes'.\n" | |
665 | " 'bytes' gives the size to load. If 'bytes' is 0 or omitted,\n" | |
666 | " the load stops on end of file." | |
667 | ), | |
668 | CMD_TBL_ITEM( | |
669 | write, 4, 0, do_rw, | |
670 | "write file into a dos filesystem", | |
671 | "<d:/path/filename> <addr> <bytes>\n" | |
672 | " - Write file to 'path/filename' on logical drive 'd' from RAM\n" | |
673 | " starting at address 'addr'.\n" | |
674 | ), | |
675 | ||
676 | CMD_TBL_ITEM( | |
677 | help, CONFIG_SYS_MAXARGS, CTBL_RPT, do_help, | |
678 | "Print sub command description/usage", | |
679 | "\n" | |
680 | " - print brief description of all sub commands\n" | |
681 | "fat help command ...\n" | |
682 | " - print detailed usage of sub cmd 'command'" | |
683 | ), | |
684 | ||
685 | /* This does not use the CMD_TBL_ITEM macro as ? can't be used in symbol names */ | |
686 | {FSTR("?"), CONFIG_SYS_MAXARGS, 1, do_help, | |
687 | NULL, | |
688 | #ifdef CONFIG_SYS_LONGHELP | |
689 | FSTR(""), | |
690 | #endif /* CONFIG_SYS_LONGHELP */ | |
691 | NULL, | |
692 | #ifdef CONFIG_AUTO_COMPLETE | |
693 | NULL, | |
694 | #endif | |
695 | }, | |
696 | /* Mark end of table */ | |
697 | CMD_TBL_END(cmd_tbl_fat) | |
698 | }; | |
699 | ||
700 | ||
701 | command_ret_t do_fat(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc UNUSED, char * const argv[] UNUSED) | |
702 | { | |
703 | puts_P(PSTR("Huch?")); | |
704 | ||
705 | return CMD_RET_USAGE; | |
706 | } |