cmd_ubifs.c 3.1 KB

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