cmd_ubifs.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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_RET_USAGE;
  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 ubifs_is_mounted(void)
  60. {
  61. return ubifs_mounted;
  62. }
  63. void cmd_ubifs_umount(void)
  64. {
  65. if (ubifs_sb) {
  66. printf("Unmounting UBIFS volume %s!\n",
  67. ((struct ubifs_info *)(ubifs_sb->s_fs_info))->vi.name);
  68. ubifs_umount(ubifs_sb->s_fs_info);
  69. }
  70. ubifs_sb = NULL;
  71. ubifs_mounted = 0;
  72. ubifs_initialized = 0;
  73. }
  74. int do_ubifs_umount(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  75. {
  76. if (argc != 1)
  77. return CMD_RET_USAGE;
  78. if (ubifs_initialized == 0) {
  79. printf("No UBIFS volume mounted!\n");
  80. return -1;
  81. }
  82. cmd_ubifs_umount();
  83. return 0;
  84. }
  85. int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  86. {
  87. char *filename = "/";
  88. int ret;
  89. if (!ubifs_mounted) {
  90. printf("UBIFS not mounted, use ubifsmount to mount volume first!\n");
  91. return -1;
  92. }
  93. if (argc == 2)
  94. filename = argv[1];
  95. debug("Using filename %s\n", filename);
  96. ret = ubifs_ls(filename);
  97. if (ret)
  98. printf("%s not found!\n", filename);
  99. return ret;
  100. }
  101. int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  102. {
  103. char *filename;
  104. char *endp;
  105. int ret;
  106. u32 addr;
  107. u32 size = 0;
  108. if (!ubifs_mounted) {
  109. printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
  110. return -1;
  111. }
  112. if (argc < 3)
  113. return CMD_RET_USAGE;
  114. addr = simple_strtoul(argv[1], &endp, 16);
  115. if (endp == argv[1])
  116. return CMD_RET_USAGE;
  117. filename = argv[2];
  118. if (argc == 4) {
  119. size = simple_strtoul(argv[3], &endp, 16);
  120. if (endp == argv[3])
  121. return CMD_RET_USAGE;
  122. }
  123. debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size);
  124. ret = ubifs_load(filename, addr, size);
  125. if (ret)
  126. printf("%s not found!\n", filename);
  127. return ret;
  128. }
  129. U_BOOT_CMD(
  130. ubifsmount, 2, 0, do_ubifs_mount,
  131. "mount UBIFS volume",
  132. "<volume-name>\n"
  133. " - mount 'volume-name' volume"
  134. );
  135. U_BOOT_CMD(
  136. ubifsumount, 1, 0, do_ubifs_umount,
  137. "unmount UBIFS volume",
  138. " - unmount current volume"
  139. );
  140. U_BOOT_CMD(
  141. ubifsls, 2, 0, do_ubifs_ls,
  142. "list files in a directory",
  143. "[directory]\n"
  144. " - list files in a 'directory' (default '/')"
  145. );
  146. U_BOOT_CMD(
  147. ubifsload, 4, 0, do_ubifs_load,
  148. "load file from an UBIFS filesystem",
  149. "<addr> <filename> [bytes]\n"
  150. " - load file 'filename' to address 'addr'"
  151. );