cmd_fat.c 3.2 KB

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