cmd_fat.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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, 16);
  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.\n"
  35. " All numeric parameters are assumed to be hex."
  36. );
  37. static int do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  38. {
  39. return do_ls(cmdtp, flag, argc, argv, FS_TYPE_FAT);
  40. }
  41. U_BOOT_CMD(
  42. fatls, 4, 1, do_fat_ls,
  43. "list files in a directory (default /)",
  44. "<interface> [<dev[:part]>] [directory]\n"
  45. " - list files from 'dev' on 'interface' in a 'directory'"
  46. );
  47. static int do_fat_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc,
  48. char * const argv[])
  49. {
  50. int dev, part;
  51. block_dev_desc_t *dev_desc;
  52. disk_partition_t info;
  53. if (argc < 2) {
  54. printf("usage: fatinfo <interface> [<dev[:part]>]\n");
  55. return 0;
  56. }
  57. part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
  58. if (part < 0)
  59. return 1;
  60. dev = dev_desc->dev;
  61. if (fat_set_blk_dev(dev_desc, &info) != 0) {
  62. printf("\n** Unable to use %s %d:%d for fatinfo **\n",
  63. argv[1], dev, part);
  64. return 1;
  65. }
  66. return file_fat_detectfs();
  67. }
  68. U_BOOT_CMD(
  69. fatinfo, 3, 1, do_fat_fsinfo,
  70. "print information about filesystem",
  71. "<interface> [<dev[:part]>]\n"
  72. " - print information about filesystem from 'dev' on 'interface'"
  73. );
  74. #ifdef CONFIG_FAT_WRITE
  75. static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
  76. int argc, char * const argv[])
  77. {
  78. long size;
  79. unsigned long addr;
  80. unsigned long count;
  81. block_dev_desc_t *dev_desc = NULL;
  82. disk_partition_t info;
  83. int dev = 0;
  84. int part = 1;
  85. if (argc < 5)
  86. return cmd_usage(cmdtp);
  87. part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
  88. if (part < 0)
  89. return 1;
  90. dev = dev_desc->dev;
  91. if (fat_set_blk_dev(dev_desc, &info) != 0) {
  92. printf("\n** Unable to use %s %d:%d for fatwrite **\n",
  93. argv[1], dev, part);
  94. return 1;
  95. }
  96. addr = simple_strtoul(argv[3], NULL, 16);
  97. count = simple_strtoul(argv[5], NULL, 16);
  98. size = file_fat_write(argv[4], (void *)addr, count);
  99. if (size == -1) {
  100. printf("\n** Unable to write \"%s\" from %s %d:%d **\n",
  101. argv[4], argv[1], dev, part);
  102. return 1;
  103. }
  104. printf("%ld bytes written\n", size);
  105. return 0;
  106. }
  107. U_BOOT_CMD(
  108. fatwrite, 6, 0, do_fat_fswrite,
  109. "write file into a dos filesystem",
  110. "<interface> <dev[:part]> <addr> <filename> <bytes>\n"
  111. " - write file 'filename' from the address 'addr' in RAM\n"
  112. " to 'dev' on 'interface'"
  113. );
  114. #endif