cmd_ubifs.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. static int ubifs_initialized;
  32. static int ubifs_mounted;
  33. /* Prototypes */
  34. int ubifs_init(void);
  35. int ubifs_mount(char *vol_name);
  36. int ubifs_ls(char *dir_name);
  37. int ubifs_load(char *filename, u32 addr, u32 size);
  38. int do_ubifs_mount(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  39. {
  40. char *vol_name;
  41. int ret;
  42. if (argc != 2) {
  43. cmd_usage(cmdtp);
  44. return 1;
  45. }
  46. vol_name = argv[1];
  47. debug("Using volume %s\n", vol_name);
  48. if (ubifs_initialized == 0) {
  49. ubifs_init();
  50. ubifs_initialized = 1;
  51. }
  52. ret = ubifs_mount(vol_name);
  53. if (ret)
  54. return -1;
  55. ubifs_mounted = 1;
  56. return 0;
  57. }
  58. int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  59. {
  60. char *filename = "/";
  61. int ret;
  62. if (!ubifs_mounted) {
  63. printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
  64. return -1;
  65. }
  66. if (argc == 2)
  67. filename = argv[1];
  68. debug("Using filename %s\n", filename);
  69. ret = ubifs_ls(filename);
  70. if (ret)
  71. printf("%s not found!\n", filename);
  72. return ret;
  73. }
  74. int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  75. {
  76. char *filename;
  77. char *endp;
  78. int ret;
  79. u32 addr;
  80. u32 size = 0;
  81. if (!ubifs_mounted) {
  82. printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
  83. return -1;
  84. }
  85. if (argc < 3) {
  86. cmd_usage(cmdtp);
  87. return -1;
  88. }
  89. addr = simple_strtoul(argv[1], &endp, 16);
  90. if (endp == argv[1]) {
  91. cmd_usage(cmdtp);
  92. return 1;
  93. }
  94. filename = argv[2];
  95. if (argc == 4) {
  96. size = simple_strtoul(argv[3], &endp, 16);
  97. if (endp == argv[3]) {
  98. cmd_usage(cmdtp);
  99. return 1;
  100. }
  101. }
  102. debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size);
  103. ret = ubifs_load(filename, addr, size);
  104. if (ret)
  105. printf("%s not found!\n", filename);
  106. return ret;
  107. }
  108. U_BOOT_CMD(
  109. ubifsmount, 2, 0, do_ubifs_mount,
  110. "mount UBIFS volume",
  111. "<volume-name>\n"
  112. " - mount 'volume-name' volume"
  113. );
  114. U_BOOT_CMD(ubifsls, 2, 0, do_ubifs_ls,
  115. "list files in a directory",
  116. "[directory]\n"
  117. " - list files in a 'directory' (default '/')"
  118. );
  119. U_BOOT_CMD(ubifsload, 4, 0, do_ubifs_load,
  120. "load file from an UBIFS filesystem",
  121. "<addr> <filename> [bytes]\n"
  122. " - load file 'filename' to address 'addr'"
  123. );