cmd_ubifs.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * (C) Copyright 2008
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  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. /*
  25. * UBIFS command support
  26. */
  27. #undef DEBUG
  28. #include <common.h>
  29. #include <config.h>
  30. #include <command.h>
  31. #include "../fs/ubifs/ubifs.h"
  32. static int ubifs_initialized;
  33. static int ubifs_mounted;
  34. extern struct super_block *ubifs_sb;
  35. /* Prototypes */
  36. int ubifs_init(void);
  37. int ubifs_mount(char *vol_name);
  38. void ubifs_umount(struct ubifs_info *c);
  39. int ubifs_ls(char *dir_name);
  40. int ubifs_load(char *filename, u32 addr, u32 size);
  41. int do_ubifs_mount(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  42. {
  43. char *vol_name;
  44. int ret;
  45. if (argc != 2)
  46. return cmd_usage(cmdtp);
  47. vol_name = argv[1];
  48. debug("Using volume %s\n", vol_name);
  49. if (ubifs_initialized == 0) {
  50. ubifs_init();
  51. ubifs_initialized = 1;
  52. }
  53. ret = ubifs_mount(vol_name);
  54. if (ret)
  55. return -1;
  56. ubifs_mounted = 1;
  57. return 0;
  58. }
  59. int do_ubifs_umount(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  60. {
  61. if (argc != 1)
  62. return cmd_usage(cmdtp);
  63. if (ubifs_initialized == 0) {
  64. printf("No UBIFS volume mounted!\n");
  65. return -1;
  66. }
  67. if (ubifs_sb)
  68. ubifs_umount(ubifs_sb->s_fs_info);
  69. ubifs_sb = NULL;
  70. ubifs_mounted = 0;
  71. ubifs_initialized = 0;
  72. return 0;
  73. }
  74. int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  75. {
  76. char *filename = "/";
  77. int ret;
  78. if (!ubifs_mounted) {
  79. printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
  80. return -1;
  81. }
  82. if (argc == 2)
  83. filename = argv[1];
  84. debug("Using filename %s\n", filename);
  85. ret = ubifs_ls(filename);
  86. if (ret)
  87. printf("%s not found!\n", filename);
  88. return ret;
  89. }
  90. int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  91. {
  92. char *filename;
  93. char *endp;
  94. int ret;
  95. u32 addr;
  96. u32 size = 0;
  97. if (!ubifs_mounted) {
  98. printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
  99. return -1;
  100. }
  101. if (argc < 3)
  102. return cmd_usage(cmdtp);
  103. addr = simple_strtoul(argv[1], &endp, 16);
  104. if (endp == argv[1])
  105. return cmd_usage(cmdtp);
  106. filename = argv[2];
  107. if (argc == 4) {
  108. size = simple_strtoul(argv[3], &endp, 16);
  109. if (endp == argv[3])
  110. return cmd_usage(cmdtp);
  111. }
  112. debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size);
  113. ret = ubifs_load(filename, addr, size);
  114. if (ret)
  115. printf("%s not found!\n", filename);
  116. return ret;
  117. }
  118. U_BOOT_CMD(
  119. ubifsmount, 2, 0, do_ubifs_mount,
  120. "mount UBIFS volume",
  121. "<volume-name>\n"
  122. " - mount 'volume-name' volume"
  123. );
  124. U_BOOT_CMD(
  125. ubifsumount, 1, 0, do_ubifs_umount,
  126. "unmount UBIFS volume",
  127. " - unmount current volume"
  128. );
  129. U_BOOT_CMD(
  130. ubifsls, 2, 0, do_ubifs_ls,
  131. "list files in a directory",
  132. "[directory]\n"
  133. " - list files in a 'directory' (default '/')"
  134. );
  135. U_BOOT_CMD(
  136. ubifsload, 4, 0, do_ubifs_load,
  137. "load file from an UBIFS filesystem",
  138. "<addr> <filename> [bytes]\n"
  139. " - load file 'filename' to address 'addr'"
  140. );