fat.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * (C) Copyright 2002
  3. * Richard Jones, rjones@nexus-tech.net
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /*
  8. * Boot support
  9. */
  10. #include <common.h>
  11. #include <command.h>
  12. #include <s_record.h>
  13. #include <net.h>
  14. #include <ata.h>
  15. #include <asm/io.h>
  16. #include <mapmem.h>
  17. #include <part.h>
  18. #include <fat.h>
  19. #include <fs.h>
  20. int do_fat_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  21. {
  22. return do_size(cmdtp, flag, argc, argv, FS_TYPE_FAT);
  23. }
  24. U_BOOT_CMD(
  25. fatsize, 4, 0, do_fat_size,
  26. "determine a file's size",
  27. "<interface> <dev[:part]> <filename>\n"
  28. " - Find file 'filename' from 'dev' on 'interface'\n"
  29. " and determine its size."
  30. );
  31. int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  32. {
  33. return do_load(cmdtp, flag, argc, argv, FS_TYPE_FAT);
  34. }
  35. U_BOOT_CMD(
  36. fatload, 7, 0, do_fat_fsload,
  37. "load binary file from a dos filesystem",
  38. "<interface> [<dev[:part]> [<addr> [<filename> [bytes [pos]]]]]\n"
  39. " - Load binary file 'filename' from 'dev' on 'interface'\n"
  40. " to address 'addr' from dos filesystem.\n"
  41. " 'pos' gives the file position to start loading from.\n"
  42. " If 'pos' is omitted, 0 is used. 'pos' requires 'bytes'.\n"
  43. " 'bytes' gives the size to load. If 'bytes' is 0 or omitted,\n"
  44. " the load stops on end of file.\n"
  45. " If either 'pos' or 'bytes' are not aligned to\n"
  46. " ARCH_DMA_MINALIGN then a misaligned buffer warning will\n"
  47. " be printed and performance will suffer for the load."
  48. );
  49. static int do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  50. {
  51. return do_ls(cmdtp, flag, argc, argv, FS_TYPE_FAT);
  52. }
  53. U_BOOT_CMD(
  54. fatls, 4, 1, do_fat_ls,
  55. "list files in a directory (default /)",
  56. "<interface> [<dev[:part]>] [directory]\n"
  57. " - list files from 'dev' on 'interface' in a 'directory'"
  58. );
  59. static int do_fat_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc,
  60. char * const argv[])
  61. {
  62. int dev, part;
  63. struct blk_desc *dev_desc;
  64. disk_partition_t info;
  65. if (argc < 2) {
  66. printf("usage: fatinfo <interface> [<dev[:part]>]\n");
  67. return 0;
  68. }
  69. part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
  70. if (part < 0)
  71. return 1;
  72. dev = dev_desc->devnum;
  73. if (fat_set_blk_dev(dev_desc, &info) != 0) {
  74. printf("\n** Unable to use %s %d:%d for fatinfo **\n",
  75. argv[1], dev, part);
  76. return 1;
  77. }
  78. return file_fat_detectfs();
  79. }
  80. U_BOOT_CMD(
  81. fatinfo, 3, 1, do_fat_fsinfo,
  82. "print information about filesystem",
  83. "<interface> [<dev[:part]>]\n"
  84. " - print information about filesystem from 'dev' on 'interface'"
  85. );
  86. #ifdef CONFIG_FAT_WRITE
  87. static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
  88. int argc, char * const argv[])
  89. {
  90. loff_t size;
  91. int ret;
  92. unsigned long addr;
  93. unsigned long count;
  94. struct blk_desc *dev_desc = NULL;
  95. disk_partition_t info;
  96. int dev = 0;
  97. int part = 1;
  98. void *buf;
  99. if (argc < 5)
  100. return cmd_usage(cmdtp);
  101. part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
  102. if (part < 0)
  103. return 1;
  104. dev = dev_desc->devnum;
  105. if (fat_set_blk_dev(dev_desc, &info) != 0) {
  106. printf("\n** Unable to use %s %d:%d for fatwrite **\n",
  107. argv[1], dev, part);
  108. return 1;
  109. }
  110. addr = simple_strtoul(argv[3], NULL, 16);
  111. count = simple_strtoul(argv[5], NULL, 16);
  112. buf = map_sysmem(addr, count);
  113. ret = file_fat_write(argv[4], buf, 0, count, &size);
  114. unmap_sysmem(buf);
  115. if (ret < 0) {
  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("%llu 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