cmd_fat.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * (C) Copyright 2002
  3. * Richard Jones, rjones@nexus-tech.net
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * Boot support
  25. */
  26. #include <common.h>
  27. #include <command.h>
  28. #include <s_record.h>
  29. #include <net.h>
  30. #include <ata.h>
  31. #include <part.h>
  32. #include <fat.h>
  33. int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  34. {
  35. long size;
  36. unsigned long offset;
  37. unsigned long count;
  38. char buf [12];
  39. block_dev_desc_t *dev_desc=NULL;
  40. disk_partition_t info;
  41. int part, dev;
  42. if (argc < 5) {
  43. printf("usage: fatload <interface> [<dev[:part]>] "
  44. "<addr> <filename> [bytes]\n");
  45. return 1;
  46. }
  47. part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info);
  48. if (part < 0)
  49. return 1;
  50. dev = dev_desc->dev;
  51. if (fat_register_device(dev_desc,part)!=0) {
  52. printf("\n** Unable to use %s %d:%d for fatload **\n",
  53. argv[1], dev, part);
  54. return 1;
  55. }
  56. offset = simple_strtoul(argv[3], NULL, 16);
  57. if (argc == 6)
  58. count = simple_strtoul(argv[5], NULL, 16);
  59. else
  60. count = 0;
  61. size = file_fat_read(argv[4], (unsigned char *)offset, count);
  62. if(size==-1) {
  63. printf("\n** Unable to read \"%s\" from %s %d:%d **\n",
  64. argv[4], argv[1], dev, part);
  65. return 1;
  66. }
  67. printf("\n%ld bytes read\n", size);
  68. sprintf(buf, "%lX", size);
  69. setenv("filesize", buf);
  70. return 0;
  71. }
  72. U_BOOT_CMD(
  73. fatload, 6, 0, do_fat_fsload,
  74. "load binary file from a dos filesystem",
  75. "<interface> [<dev[:part]>] <addr> <filename> [bytes]\n"
  76. " - load binary file 'filename' from 'dev' on 'interface'\n"
  77. " to address 'addr' from dos filesystem"
  78. );
  79. int do_fat_ls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  80. {
  81. char *filename = "/";
  82. int ret, dev, part;
  83. block_dev_desc_t *dev_desc=NULL;
  84. disk_partition_t info;
  85. if (argc < 2) {
  86. printf("usage: fatls <interface> [<dev[:part]>] [directory]\n");
  87. return 0;
  88. }
  89. part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info);
  90. if (part < 0)
  91. return 1;
  92. dev = dev_desc->dev;
  93. if (fat_register_device(dev_desc,part)!=0) {
  94. printf("\n** Unable to use %s %d:%d for fatls **\n",
  95. argv[1], dev, part);
  96. return 1;
  97. }
  98. if (argc == 4)
  99. ret = file_fat_ls(argv[3]);
  100. else
  101. ret = file_fat_ls(filename);
  102. if(ret!=0)
  103. printf("No Fat FS detected\n");
  104. return ret;
  105. }
  106. U_BOOT_CMD(
  107. fatls, 4, 1, do_fat_ls,
  108. "list files in a directory (default /)",
  109. "<interface> [<dev[:part]>] [directory]\n"
  110. " - list files from 'dev' on 'interface' in a 'directory'"
  111. );
  112. int do_fat_fsinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  113. {
  114. int dev, part;
  115. block_dev_desc_t *dev_desc;
  116. disk_partition_t info;
  117. if (argc < 2) {
  118. printf("usage: fatinfo <interface> [<dev[:part]>]\n");
  119. return 0;
  120. }
  121. part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info);
  122. if (part < 0)
  123. return 1;
  124. dev = dev_desc->dev;
  125. if (fat_register_device(dev_desc,part)!=0) {
  126. printf("\n** Unable to use %s %d:%d for fatinfo **\n",
  127. argv[1], dev, part);
  128. return 1;
  129. }
  130. return file_fat_detectfs();
  131. }
  132. U_BOOT_CMD(
  133. fatinfo, 3, 1, do_fat_fsinfo,
  134. "print information about filesystem",
  135. "<interface> [<dev[:part]>]\n"
  136. " - print information about filesystem from 'dev' on 'interface'"
  137. );
  138. #ifdef CONFIG_FAT_WRITE
  139. static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
  140. int argc, char * const argv[])
  141. {
  142. long size;
  143. unsigned long addr;
  144. unsigned long count;
  145. block_dev_desc_t *dev_desc = NULL;
  146. disk_partition_t info;
  147. int dev = 0;
  148. int part = 1;
  149. char *ep;
  150. if (argc < 5)
  151. return cmd_usage(cmdtp);
  152. part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info);
  153. if (part < 0)
  154. return 1;
  155. dev = dev_desc->dev;
  156. if (fat_register_device(dev_desc, part) != 0) {
  157. printf("\n** Unable to use %s %d:%d for fatwrite **\n",
  158. argv[1], dev, part);
  159. return 1;
  160. }
  161. addr = simple_strtoul(argv[3], NULL, 16);
  162. count = simple_strtoul(argv[5], NULL, 16);
  163. size = file_fat_write(argv[4], (void *)addr, count);
  164. if (size == -1) {
  165. printf("\n** Unable to write \"%s\" from %s %d:%d **\n",
  166. argv[4], argv[1], dev, part);
  167. return 1;
  168. }
  169. printf("%ld bytes written\n", size);
  170. return 0;
  171. }
  172. U_BOOT_CMD(
  173. fatwrite, 6, 0, do_fat_fswrite,
  174. "write file into a dos filesystem",
  175. "<interface> <dev[:part]> <addr> <filename> <bytes>\n"
  176. " - write file 'filename' from the address 'addr' in RAM\n"
  177. " to 'dev' on 'interface'"
  178. );
  179. #endif