cmd_fat.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. int dev=0;
  41. int part=1;
  42. char *ep;
  43. if (argc < 5) {
  44. printf( "usage: fatload <interface> <dev[:part]> "
  45. "<addr> <filename> [bytes]\n");
  46. return 1;
  47. }
  48. dev = (int)simple_strtoul(argv[2], &ep, 16);
  49. dev_desc = get_dev(argv[1],dev);
  50. if (dev_desc == NULL) {
  51. puts("\n** Invalid boot device **\n");
  52. return 1;
  53. }
  54. if (*ep) {
  55. if (*ep != ':') {
  56. puts("\n** Invalid boot device, use `dev[:part]' **\n");
  57. return 1;
  58. }
  59. part = (int)simple_strtoul(++ep, NULL, 16);
  60. }
  61. if (fat_register_device(dev_desc,part)!=0) {
  62. printf("\n** Unable to use %s %d:%d for fatload **\n",
  63. argv[1], dev, part);
  64. return 1;
  65. }
  66. offset = simple_strtoul(argv[3], NULL, 16);
  67. if (argc == 6)
  68. count = simple_strtoul(argv[5], NULL, 16);
  69. else
  70. count = 0;
  71. size = file_fat_read(argv[4], (unsigned char *)offset, count);
  72. if(size==-1) {
  73. printf("\n** Unable to read \"%s\" from %s %d:%d **\n",
  74. argv[4], argv[1], dev, part);
  75. return 1;
  76. }
  77. printf("\n%ld bytes read\n", size);
  78. sprintf(buf, "%lX", size);
  79. setenv("filesize", buf);
  80. return 0;
  81. }
  82. U_BOOT_CMD(
  83. fatload, 6, 0, do_fat_fsload,
  84. "load binary file from a dos filesystem",
  85. "<interface> <dev[:part]> <addr> <filename> [bytes]\n"
  86. " - load binary file 'filename' from 'dev' on 'interface'\n"
  87. " to address 'addr' from dos filesystem"
  88. );
  89. int do_fat_ls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  90. {
  91. char *filename = "/";
  92. int ret;
  93. int dev=0;
  94. int part=1;
  95. char *ep;
  96. block_dev_desc_t *dev_desc=NULL;
  97. if (argc < 3) {
  98. printf("usage: fatls <interface> <dev[:part]> [directory]\n");
  99. return 0;
  100. }
  101. dev = (int)simple_strtoul(argv[2], &ep, 16);
  102. dev_desc = get_dev(argv[1],dev);
  103. if (dev_desc == NULL) {
  104. puts("\n** Invalid boot device **\n");
  105. return 1;
  106. }
  107. if (*ep) {
  108. if (*ep != ':') {
  109. puts("\n** Invalid boot device, use `dev[:part]' **\n");
  110. return 1;
  111. }
  112. part = (int)simple_strtoul(++ep, NULL, 16);
  113. }
  114. if (fat_register_device(dev_desc,part)!=0) {
  115. printf("\n** Unable to use %s %d:%d for fatls **\n",
  116. argv[1], dev, part);
  117. return 1;
  118. }
  119. if (argc == 4)
  120. ret = file_fat_ls(argv[3]);
  121. else
  122. ret = file_fat_ls(filename);
  123. if(ret!=0)
  124. printf("No Fat FS detected\n");
  125. return ret;
  126. }
  127. U_BOOT_CMD(
  128. fatls, 4, 1, do_fat_ls,
  129. "list files in a directory (default /)",
  130. "<interface> <dev[:part]> [directory]\n"
  131. " - list files from 'dev' on 'interface' in a 'directory'"
  132. );
  133. int do_fat_fsinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  134. {
  135. int dev=0;
  136. int part=1;
  137. char *ep;
  138. block_dev_desc_t *dev_desc=NULL;
  139. if (argc < 2) {
  140. printf("usage: fatinfo <interface> <dev[:part]>\n");
  141. return 0;
  142. }
  143. dev = (int)simple_strtoul(argv[2], &ep, 16);
  144. dev_desc = get_dev(argv[1],dev);
  145. if (dev_desc == NULL) {
  146. puts("\n** Invalid boot device **\n");
  147. return 1;
  148. }
  149. if (*ep) {
  150. if (*ep != ':') {
  151. puts("\n** Invalid boot device, use `dev[:part]' **\n");
  152. return 1;
  153. }
  154. part = (int)simple_strtoul(++ep, NULL, 16);
  155. }
  156. if (fat_register_device(dev_desc,part)!=0) {
  157. printf("\n** Unable to use %s %d:%d for fatinfo **\n",
  158. argv[1], dev, part);
  159. return 1;
  160. }
  161. return file_fat_detectfs();
  162. }
  163. U_BOOT_CMD(
  164. fatinfo, 3, 1, do_fat_fsinfo,
  165. "print information about filesystem",
  166. "<interface> <dev[:part]>\n"
  167. " - print information about filesystem from 'dev' on 'interface'"
  168. );