cmd_fat.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. #include <fs.h>
  34. int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  35. {
  36. return do_load(cmdtp, flag, argc, argv, FS_TYPE_FAT, 16);
  37. }
  38. U_BOOT_CMD(
  39. fatload, 7, 0, do_fat_fsload,
  40. "load binary file from a dos filesystem",
  41. "<interface> [<dev[:part]>] <addr> <filename> [bytes [pos]]\n"
  42. " - Load binary file 'filename' from 'dev' on 'interface'\n"
  43. " to address 'addr' from dos filesystem.\n"
  44. " 'pos' gives the file position to start loading from.\n"
  45. " If 'pos' is omitted, 0 is used. 'pos' requires 'bytes'.\n"
  46. " 'bytes' gives the size to load. If 'bytes' is 0 or omitted,\n"
  47. " the load stops on end of file.\n"
  48. " If either 'pos' or 'bytes' are not aligned to\n"
  49. " ARCH_DMA_MINALIGN then a misaligned buffer warning will\n"
  50. " be printed and performance will suffer for the load.\n"
  51. " All numeric parameters are assumed to be hex."
  52. );
  53. static int do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  54. {
  55. return do_ls(cmdtp, flag, argc, argv, FS_TYPE_FAT);
  56. }
  57. U_BOOT_CMD(
  58. fatls, 4, 1, do_fat_ls,
  59. "list files in a directory (default /)",
  60. "<interface> [<dev[:part]>] [directory]\n"
  61. " - list files from 'dev' on 'interface' in a 'directory'"
  62. );
  63. static int do_fat_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc,
  64. char * const argv[])
  65. {
  66. int dev, part;
  67. block_dev_desc_t *dev_desc;
  68. disk_partition_t info;
  69. if (argc < 2) {
  70. printf("usage: fatinfo <interface> [<dev[:part]>]\n");
  71. return 0;
  72. }
  73. part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
  74. if (part < 0)
  75. return 1;
  76. dev = dev_desc->dev;
  77. if (fat_set_blk_dev(dev_desc, &info) != 0) {
  78. printf("\n** Unable to use %s %d:%d for fatinfo **\n",
  79. argv[1], dev, part);
  80. return 1;
  81. }
  82. return file_fat_detectfs();
  83. }
  84. U_BOOT_CMD(
  85. fatinfo, 3, 1, do_fat_fsinfo,
  86. "print information about filesystem",
  87. "<interface> [<dev[:part]>]\n"
  88. " - print information about filesystem from 'dev' on 'interface'"
  89. );
  90. #ifdef CONFIG_FAT_WRITE
  91. static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
  92. int argc, char * const argv[])
  93. {
  94. long size;
  95. unsigned long addr;
  96. unsigned long count;
  97. block_dev_desc_t *dev_desc = NULL;
  98. disk_partition_t info;
  99. int dev = 0;
  100. int part = 1;
  101. if (argc < 5)
  102. return cmd_usage(cmdtp);
  103. part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
  104. if (part < 0)
  105. return 1;
  106. dev = dev_desc->dev;
  107. if (fat_set_blk_dev(dev_desc, &info) != 0) {
  108. printf("\n** Unable to use %s %d:%d for fatwrite **\n",
  109. argv[1], dev, part);
  110. return 1;
  111. }
  112. addr = simple_strtoul(argv[3], NULL, 16);
  113. count = simple_strtoul(argv[5], NULL, 16);
  114. size = file_fat_write(argv[4], (void *)addr, count);
  115. if (size == -1) {
  116. printf("\n** Unable to write \"%s\" from %s %d:%d **\n",
  117. argv[4], argv[1], dev, part);
  118. return 1;
  119. }
  120. printf("%ld bytes written\n", size);
  121. return 0;
  122. }
  123. U_BOOT_CMD(
  124. fatwrite, 6, 0, do_fat_fswrite,
  125. "write file into a dos filesystem",
  126. "<interface> <dev[:part]> <addr> <filename> <bytes>\n"
  127. " - write file 'filename' from the address 'addr' in RAM\n"
  128. " to 'dev' on 'interface'"
  129. );
  130. #endif